tusen-ai / simpledet

A Simple and Versatile Framework for Object Detection and Instance Recognition
Apache License 2.0
3.08k stars 486 forks source link

Cannot export the models in the model zoo to onnx? #249

Closed CoinCheung closed 4 years ago

CoinCheung commented 4 years ago

I downloaded the model from the link given in the MODEL_ZOO.md, after unzipping it, I tried to export the model to onnx like this:

import mxnet as mx
from mxnet.contrib import onnx as mx_onnx
import numpy as np
import onnx

sym = 'faster_r101v1_fpn_1x/checkpoint-symbol.json'
params = 'faster_r101v1_fpn_1x/checkpoint-0006.params'

input_shape = (1, 3, 800, 1333)
outpth = './faster_r101v1_fpn_1x.onnx'

pth = mx_onnx.export_model(sym, params, [input_shape, ], np.float32, outpth)

model = onnx.load_model(pth)
onnx.checker.check_graph(model.graph)

And I get the error like this:

[03:50:45] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.3.1. Attempting to upgrade... Traceback (most recent call last): File "exporter.py", line 15, in pth = mx_onnx.export_model(sym, params, [input_shape, ], np.float32, outpth) File "/miniconda/envs/py36/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/export_model.py", line 80, in export_model sym_obj, params_obj = load_module(sym, params) File "/miniconda/envs/py36/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/_export_helper.py", line 58, in load_module sym, arg_params, aux_params = mx.model.load_checkpoint(model_name, num_epochs) File "/miniconda/envs/py36/lib/python3.6/site-packages/mxnet/model.py", line 450, in load_checkpoint symbol = sym.load('%s-symbol.json' % prefix) File "/miniconda/envs/py36/lib/python3.6/site-packages/mxnet/symbol/symbol.py", line 2787, in load check_call(_LIB.MXSymbolCreateFromFile(c_str(fname), ctypes.byref(handle))) File "/miniconda/envs/py36/lib/python3.6/site-packages/mxnet/base.py", line 254, in check_call raise MXNetError(py_str(_LIB.MXGetLastError())) mxnet.base.MXNetError: [03:50:45] src/operator/custom/custom.cc:99: Check failed: CustomOperator::Get()->Find(params.op_type) != nullptr: Cannot find custom operator get_top_proposal Stack trace: [bt] (0) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x56bffb) [0x7f7de8fc2ffb] [bt] (1) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x99c1cc) [0x7f7de93f31cc] [bt] (2) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d8f533) [0x7f7deb7e6533] [bt] (3) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d805d1) [0x7f7deb7d75d1] [bt] (4) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d8de5f) [0x7f7deb7e4e5f] [bt] (5) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d805d1) [0x7f7deb7d75d1] [bt] (6) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x7d0747d) [0x7f7df075e47d] [bt] (7) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2ab0dd7) [0x7f7deb507dd7] [bt] (8) /miniconda/envs/py36/lib/python3.6/site-packages/mxnet/libmxnet.so(MXSymbolCreateFromFile+0x491) [0x7f7deb5154b1]

What is the correct way to deploy the models with simpledet ?

apatsekin commented 4 years ago

I don't think the correct way exists at all, since simpledet uses own compiled layers on top of standard MXNet. And that's what your errors are about. I would run it in a docker as an API server for deployment.

xiaoyazhu commented 4 years ago

Do you mean there is no way to convert to an onnx model? If i want to use tensorrt to accelerate, what should i do ?

apatsekin commented 4 years ago

@xiaoyazhu correct. Usually those converters take a layer from one framework, and use corresponding layer in another framework. But in case Simpledet, there are some core layers added to MXNet. There may be corresponding layers in ONNX (or sth similar), but I'm not sure auto conversion will work due to reasons above.

CoinCheung commented 4 years ago

since conclusion is definite, I am closing this, thanks for support !!!