models icon indicating copy to clipboard operation
models copied to clipboard

question: How to convert MXNet model to onnx model?

Open JerryShih opened this issue 5 years ago • 4 comments

In this page[1], there are a lot of pre-trained onnx models and they work well. But how does these models come? Are these models from MXNet? Here is the MXNet document in the same page[2]. If I just convert the MXNet model to onnx using MXNet native onnx exporter, I can't get the same model as the model in [1].

[1] https://github.com/onnx/models/tree/master/models/image_classification/resnet [2] https://github.com/onnx/models/blob/master/models/image_classification/resnet/train_resnet.ipynb

JerryShih avatar Nov 20 '18 03:11 JerryShih

@houseroad @abhinavs95 @prasanthpul Do you know how to generate the resnet models in the page[1]?

[1] https://github.com/onnx/models/tree/master/models/image_classification/resnet

JerryShih avatar Nov 20 '18 03:11 JerryShih

@JerryShih You are correct the models in [1] has been generated using the training script [2]. The models have been generated from MXNet. How are you trying to convert the MXNet symbols and params to ONNX models. Could you please post the code snippet so that we can help?

ankkhedia avatar Nov 20 '18 17:11 ankkhedia

@JerryShih You are correct the models in [1] has been generated using the training script [2]. The models have been generated from MXNet. How are you trying to convert the MXNet symbols and params to ONNX models. Could you please post the code snippet so that we can help?

@ankkhedia can you check my code, pls, I trained my arcface model with the code by this code https://github.com/onnx/models/blob/master/vision/body_analysis/arcface/dependencies/train_arcface.ipynb I used mxnet==1.6.0, when I convert mxnet model to onnx, I got this error:

onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: spatial for operator BatchNormalization

My convert code here:

import onnx
import numpy as np
from mxnet.contrib import onnx as onnx_mxnet
sym_file = './slim_output/model-symbol.json'
params_file = './slim_output/model-0000.params'
input_shape = (1,3,112,112)
des_model = 'resnet01.onnx'
converted_model_path = onnx_mxnet.export_model(sym_file, params_file, [input_shape], np.float32, des_model)

When I use mxnet==1.3.0, it's work but I got wrong onnx model. I can not run it like model in https://github.com/onnx/models/tree/master/vision/body_analysis/arcface/model

kiepluhanh97 avatar Aug 20 '20 10:08 kiepluhanh97

image I recognize your onnx model have Reshape layer before PRelu, can you tell me how can I add that layer into origin arcface model?

kiepluhanh97 avatar Aug 21 '20 04:08 kiepluhanh97