这个还有onnx推理代码和报错解决
Insightface中ArcFace MxNet2ONNX踩坑 - 知乎
转换代码:
import numpy as np
import mxnet as mx
from mxnet.contrib import onnx as onnx_mxnet
sym = './model-symbol.json'
params = './model-0000.params'
input_shape = (1, 3, 112, 112)
onnx_file = './mobilefacenet.onnx'
converted_model_path = onnx_mxnet.export_model(sym, params, [input_shape], np.float32, onnx_file)
onnx1.9 报错:
spatial for operator BatchNormalization
onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: spatial for operator BatchNormalization
==> Context: Bad node spec: input: "conv_1_conv2d" input: "conv_1_batchnorm_gamma" input: "conv_1_batchnorm_beta" input: "conv_1_batchnorm_moving_mean" input: "conv_1_batchnorm_moving_var" output: "conv_1_batchnorm" name: "conv_1_batchnorm" op_type: "BatchNormalization" attribute { name: "epsilon" f: 0.001 type: FLOAT } attribute { name: "momentum" f: 0.9 type: FLOAT } attribute { name: "spatial" i: 0 type: INT }
解决方法:
请看这篇文章:https://zhuanlan.zhihu.com/p/165294876?utm_source=ZHShareTargetIDMore
用root权限编辑文件 /usr/local/lib/python3.6/dist-packages/mxnet/contrib/onnx/mx2onnx/_op_translations.py
把 359行的 spatial=0 屏蔽掉即可。
测试确实可以转:
原文链接:https://blog.csdn.net/u012505617/article/details/110530821
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/jacke121/article/details/123063266
内容来源于网络,如有侵权,请联系作者删除!