onnx model 导出


#1

有没有api能吧gluon model_zoo的好模式转换成onnx格式的呢
比如net = gluon.model_zoo.vision.get_model(name, **kwargs)
转换成了net ,但是导出onnx的函数mxnet.contrib.onnx.export_model
export_model(sym, params, input_shape, input_type=np.float32,onnx_file_path=‘model.onnx’, verbose=False):
是这样的,有没有比较简单的方法来转换呢


#2

from gluoncv import model_zoo, utils, data
import mxnet as mx
from mxnet import nd
import numpy as np

mx_model = ‘yolo3_darknet53_coco’
mx_model_root = ‘mx_model/’

onnx_model_root = ‘onnx_model/’

net = model_zoo.get_model(mx_model, pretrained=True, root=mx_model_root)
x = nd.zeros((1, 3, 512, 512))
net.hybridize()
net(x)
net.export(mx_model_root + mx_model)
mx.contrib.onnx.export_model(mx_model_root + mx_model + ‘-symbol.json’, mx_model_root + mx_model + ‘-0000.params’,
[x.shape], np.float32, onnx_model_root + mx_model + ‘.onnx’, verbose=False)

报的错误见下面
D:\ML_PY\python.exe E:/Python/ML/onnx_model_export.py
D:\ML_PY\lib\site-packages\mxnet\gluon\block.py:420: UserWarning: load_params is deprecated. Please use load_parameters.
warnings.warn(“load_params is deprecated. Please use load_parameters.”)
Traceback (most recent call last):
File “E:/Python/ML/onnx_model_export.py”, line 18, in
[x.shape], np.float32, onnx_model_root + mx_model + ‘.onnx’, verbose=False)
File “D:\ML_PY\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_model.py”, line 77, in export_model
verbose=verbose)
File “D:\ML_PY\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py”, line 281, in create_onnx_graph_proto
idx=idx
File “D:\ML_PY\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py”, line 92, in convert_layer
return convert_func(node, **kwargs)
File “D:\ML_PY\lib\site-packages\mxnet\contrib\onnx\mx2onnx_op_translations.py”, line 1731, in convert_slice_axis
raise ValueError(“Slice: ONNX doesnt’t support ‘None’ in ‘end’ attribute”)
ValueError: Slice: ONNX doesnt’t support ‘None’ in ‘end’ attribute

请问下怎么处理?


#3

请问您解决了吗,我也遇到了相同的问题,是不是onnx还不够完善,还是gluon模型导出时需要设置什么?


#4

请问你们解决了吗


#5

那个自己算一下,然后在源码里面改一下就行