Incubator-mxnet: MXNet to ONNX export bug

Created on 4 May 2019  路  22Comments  路  Source: apache/incubator-mxnet

When trying to convert yolov3_mobilenetv1.0_coco pretrained from gluonCV v0.5 to ONNX via onnx_mxnet.export_model (using mxnet-cu90mkl==1.5.0b20190313 ), I get the following error:

/anaconda3/lib/python3.7/site-packages/mxnet/contrib/onnx/mx2onnx/_op_translations.py in convert_slice_axis(node, **kwargs)
   1320     axes = int(attrs.get("axis"))
   1321     starts = int(attrs.get("begin"))
-> 1322     ends = int(attrs.get("end", None))
   1323     if not ends:
   1324         raise ValueError("Slice: ONNX doesnt't support 'None' in 'end' attribute")

ValueError: invalid literal for int() with base 10: 'None'

This matches this line which is a bug introduced in #12878 .

Bug ONNX

All 22 comments

Hey, this is the MXNet Label Bot.
Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it.
Here are my recommended labels: ONNX, Bug

@Roshrini Could you please take a look?

@ehsanmok mxnet isn't responsible for this error, it's only ONNX.
update your ONNX version, should work when ONNX==1.2.2

@AnaRhisT94 No, my ONNX is already the latest v1.5.0. It's when calling export_model causes that to happen. int(None) is never valid.

Try to use ONNX 1.2.2

Same error with ONNX 1.2.2

@mxnet-label-bot add [Bug]

@ehsanmok I'm looking into this, could you share your script?

Same error with ONNX 1.2.2

I see, well just delete the None then?

@vandanavk here is an MVE

from os import path as osp
import numpy as np
import mxnet as mx
from mxnet.contrib import onnx as onnx_mxnet
from mxnet import gluon
from gluoncv import model_zoo, data, utils

OUTPUT = "./output"
DATA = "./data/cat.png"
SIZE = 320
MODEL = "yolo3_mobilenet1.0_coco"
INPUT_SHAPE = (1, 3, SIZE, SIZE)

net = model_zoo.get_model(MODEL, pretrained=True)
net.hybridize()
# pass an img to trigger init after hybridize
x, _ = data.transforms.presets.yolo.load_test(DATA, short=SIZE)
_, _ = net(x)

net.export(osp.join(OUTPUT, MODEL))
sym = osp.join(OUTPUT, MODEL + "-symbol.json")
params = osp.join(OUTPUT, MODEL + "-0000.params")
onnx_file = osp.join(OUTPUT, MODEL + ".onnx")

converted_model_path = onnx_mxnet.export_model(sym, params, [INPUT_SHAPE], np.float32, onnx_file, verbose=True)

@ehsanmok I tried the following code with the PR https://github.com/apache/incubator-mxnet/pull/14942. ValueError: invalid literal for int() with base 10: 'None' error doesn't occur anymore but I do see AttributeError: No conversion function registered for op type _arange yet.. _arange export can be filed as separate feature request. Please try PR https://github.com/apache/incubator-mxnet/pull/14942 and let me know if it works for you.

from os import path as osp
import numpy as np
import mxnet as mx
from mxnet.contrib import onnx as onnx_mxnet
from mxnet import gluon
from gluoncv import model_zoo, data, utils

OUTPUT = "./"
DATA = "./cat.jpg"
SIZE = 320
MODEL = "yolo3_darknet53_coco"
INPUT_SHAPE = (1, 3, SIZE, SIZE)

net = model_zoo.get_model(MODEL, pretrained=True)
net.hybridize()
# pass an img to trigger init after hybridize
x, _ = data.transforms.presets.yolo.load_test(DATA, short=SIZE)
_ = net(x)

net.export(osp.join(OUTPUT, MODEL))
sym = osp.join(OUTPUT, MODEL + "-symbol.json")
params = osp.join(OUTPUT, MODEL + "-0000.params")
onnx_file = osp.join(OUTPUT, MODEL + ".onnx")

converted_model_path = onnx_mxnet.export_model(sym, params, [INPUT_SHAPE], np.float32, onnx_file, verbose=True)

@ehsanmok I met the same problem with you. I saw the issue has been around for 3 months. Did you solve it?

@ehsanmok I met the same problem with you. I saw the issue has been around for 3 months. Did you solve it?

Can you try the PR https://github.com/apache/incubator-mxnet/pull/14942? I dint see the issue with this PR.

I found that there are several ops not supported during converting, including slice_axis(..., end =None), slice_like, repeat, arange. But for a fixed input dimension, these operations can be replaced with normal slice_like, concat. The main problem is in box_nms.

Not sure if this is the right place to post, but I used the fixes from PR #14942, fixed the issue for me but the next error is:
'AttributeError: No conversion function registered for op type _greater_scalar yet.'

Attempting to export 'ssd_512_mobilenet1.0_voc'

@caiqi @ntomer feel free to contribute the ONNX conversion for these missing operators :+1:

Does anyone have any update on this ? I am having the same issue ...

the bug is happen in yolo3.py line 161, there is a None param, fix it. and then u will meet the _arange op not regist

Not sure if this is the right place to post, but I used the fixes from PR #14942, fixed the issue for me but the next error is:
'AttributeError: No conversion function registered for op type _greater_scalar yet.'

Attempting to export 'ssd_512_mobilenet1.0_voc'

Did you find some ways to fix it? I meet it with "ssd_512_resnet50_v1_voc"

nope, raised a ticket in Amazon but no one is currently working on this ..

same problom, when used torch yolov32onnx.py, so easy to convert
I will give up mxnet never look back

I met the same problem.
And I tried the solution in PR#14942, found a new bug.

File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_model.py", line 83, in export_model
verbose=verbose)
File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_onnx.py", line 253, in create_onnx_graph_proto
idx=idx
File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_onnx.py", line 90, in convert_layer
raise AttributeError("No conversion function registered for op type %s yet." % op)
AttributeError: No conversion function registered for op type _arange yet.

I met the same problem.
And I tried the solution in PR#14942, found a new bug.

File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_model.py", line 83, in export_model
verbose=verbose)
File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_onnx.py", line 253, in create_onnx_graph_proto
idx=idx
File "D:WorkingSoftwareAnaconda3libsite-packagesmxnetcontribonnxmx2onnxexport_onnx.py", line 90, in convert_layer
raise AttributeError("No conversion function registered for op type %s yet." % op)
AttributeError: No conversion function registered for op type _arange yet.

Had same error on Nov 5, 2019.. tried to build make the operator but didnt work..

Was this page helpful?
0 / 5 - 0 ratings