MNN模型转换报Don't support type [ ConvolutionDepthwise ]

MNN模型转换Don't support type [ ConvolutionDepthwise ]

  • 问题
  • 解决方法

问题

当将caffe模型转换成mnn模型时抛如下异常

Start to Convert Other Model Format To MNN Model...
[16:34:45] :143: Don't support type [ ConvolutionDepthwise ], for conv1_1/dw_new
Start to Optimize the MNN Net...
[16:34:45] :46: Inputs: data
[16:34:45] :56: Outputs: relu1_1/in/pw_new, Type = Convolution
Converted Done!

解决方法

当分组数量等于输入map数量,输出map数量也等于输入map数量,即G=N=C(G:分组数量,N:卷积核个数,C:通道数),N个卷积核每个尺寸为1∗K∗K时,Group Convolution就成了Depthwise Convolution。
因此将caffe模型中的prototxt中ConvolutionDepthwise替换成Convolution,并在其convolution_param中添加的group属性,group的值等于输出通道数。

例如conv1_1/dw_new层的修改:

layer {
  name: "conv1_1/dw_new"
  type: "ConvolutionDepthwise"
  bottom: "conv1_1/in/pw_new"
  top: "conv1_1/dw_new"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  convolution_param {
    num_output: 64
    bias_term: false
    pad: 1
    kernel_size: 3
    stride: 2
    weight_filler {
      type: "msra"
    }
    engine: CAFFE
  }
}
layer {
  name: "conv1_1/dw_new"
  type: "Convolution"
  bottom: "conv1_1/in/pw_new"
  top: "conv1_1/dw_new"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  convolution_param {
    num_output: 64
    group: 64
    bias_term: false
    pad: 1
    kernel_size: 3
    stride: 2
    weight_filler {
      type: "msra"
    }
    engine: CAFFE
  }
}

修改前后的模型转换成ncnn模型,通过ncnn对比了两个模型每层的feature map一模一样。

参考:https://github.com/alibaba/MNN/issues/176,可以“Use convolution with group instead of ConvolutionDepthwise”。
参考:https://blog.csdn.net/blogshinelee/article/details/86094419

你可能感兴趣的:(mnn)