alibaba / MNN

MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba
http://www.mnn.zone/
8.73k stars 1.67k forks source link

Don't support type [BatchNorm] onnx转化MNN失败 #1136

Closed gofugoo closed 4 years ago

gofugoo commented 4 years ago

平台(如果交叉编译请再附上交叉编译目标平台):

Platform(Include target platform as well if cross-compiling):

MAC 上

Github版本:

Github Version:

https://github.com/alibaba/MNN/commit/3ea9dd1866e1c502f3632e1564b2fbc546559863

编译方式:

Compiling Method

cmake -GXcode -DMNN_BUILD_CONVERTER=ON ..

按照这个修复resize算子,还有如下下面错误。 https://github.com/alibaba/MNN/issues/1133

转化失败日志: onnxConverter.cpp:29: ONNX Model ir version: 6 Start to Optimize the MNN Net... Don't support type [BatchNorm], 222 Don't support type [BatchNorm], 222 Check failed: shape->dimensions() == 1 ==> "shape rank should be one" Check failed: indices->length(indicesDimension - 1) == 1 ==> "indices.shape[-1] = shape.rank" Check failed: updates->dimensions() == dimension ==> "updates dimension should be equal to given shape" Don't support type [BatchNorm], 222 Don't support type [BatchNorm], 222 Check failed: shape->dimensions() == 1 ==> "shape rank should be one" Check failed: indices->length(indicesDimension - 1) == 1 ==> "indices.shape[-1] = shape.rank" Check failed: updates->dimensions() == dimension ==> "updates dimension should be equal to given shape"

模型 yolov_simp.onnx.zip

hjchen2 commented 4 years ago

@gofugoo 看你的模型中存在多个convolution输出concat之后计算BatchNorm的结构,这种网络结构在现在的MNN中不支持。由于MNN本身不支持BatchNorm算子,因此BatchNorm都需要fuse到前一个convolution中,但由于中间存在concat的情况,BatchNorm无法被fuse,转换就会失败。解决方法: 1、修改模型结构,把batchnorm挪到concat之前。 2、修改MNN的转换工具,把BatchNorm转换成scale + bias_add,(必要时需要修改一下convolution和batchnorm的fusion逻辑)。 3、等MNN更新,时间可能会比较长~

gofugoo commented 4 years ago

@hjchen2 谢谢回复,修改这个类把OnnxBatchNormTransform默认的转换修改成scale + bias_add ?

hjchen2 commented 4 years ago

OnnxBatchNormTransform

是的

gofugoo commented 4 years ago

OnnxBatchNormTransform

是的 2、修改MNN的转换工具,把BatchNorm转换成scale + bias_add,(必要时需要修改一下convolution和batchnorm的fusion逻辑)。 大神能不能简单写一点代码粘贴上来,我对项目不是很熟?

jxt1234 commented 4 years ago

Fixed