【mxnet转onnx报错】Unrecognized attribute: spatial for operator BatchNormalization
程序员文章站
2022-06-15 19:14:11
问题描述mxnet版本:1.7.0 (latest)onnx版本:1.7.0 (latest)按照Exporting to ONNX format教程中的方法导出mxnet模型,报错情况如下:>>> python mx2onnx.pyINFO:root:Converting json and weight file to sym and params[10:45:36] src/nnvm/legacy_json_util.cc:209: Loading symbol sav...
问题描述
mxnet版本:1.7.0 (latest)
onnx版本:1.7.0 (latest)
按照Exporting to ONNX format教程中的方法导出mxnet模型,报错情况如下:
>>> python mx2onnx.py
INFO:root:Converting json and weight file to sym and params [10:45:36] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.2.0. Attempting to upgrade... [10:45:36] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded! Traceback (most recent call last):
File "mx2onnx.py", line 19, in <module> converted_model_path = onnx_mxnet.export_model(sym, params, [input_shape], np.float32, onnx_file) File "/opt/ptt_pkgs/anaconda3/envs/mxnet/lib/python3.7/site-packages/mxnet/contrib/onnx/mx2onnx/export_model.py", line 79, in export_model
verbose=verbose) File "/opt/ptt_pkgs/anaconda3/envs/mxnet/lib/python3.7/site-packages/mxnet/contrib/onnx/mx2onnx/export_onnx.py", line 308, in create_onnx_graph_proto
checker.check_graph(graph) File "/opt/ptt_pkgs/anaconda3/envs/mxnet/lib/python3.7/site-packages/onnx/checker.py", line 54, in checker
proto.SerializeToString(), ctx) onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: spatial for operator BatchNormalization ==> Context: Bad node spec: input: "conv0" input: "bn0_gamma" input: "bn0_beta" input: "bn0_moving_mean" input: "bn0_moving_var" output: "bn0" name: "bn0" op_type: "BatchNormalization" attribute { name: "epsilon" f: 2e-05 type: FLOAT } attribute { name: "momentum" f: 0.9 type: FLOAT } attribute { name: "spatial" i: 0 type: INT }
解决方法
卸载已安装的onnx1.7.0,并安装1.3.0版本:
pip uninstall onnx
pip install onnx==1.3.0
再次运行测试,导出成功:
>>> python mx2onnx.py
INFO:root:Converting json and weight file to sym and params [11:03:20] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.2.0. Attempting to upgrade... [11:03:20] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded! INFO:root:Input shape of the model [(1, 3, 112, 112)] INFO:root:Exported ONNX file ./onnx/mxnet_exported_resnet100.onnx saved to disk
参考链接:https://discuss.mxnet.apache.org/t/export-to-onnx-error-when-i-use-a-batchnorm-layer/4178
本文地址:https://blog.csdn.net/vam_kindred/article/details/109047098
上一篇: 如何判断女友是什么类型?