microsoft / MMdnn

MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.
MIT License
5.8k stars 965 forks source link

Custom operator support for conversion from MXNet to PyTorch #316

Open farleylai opened 6 years ago

farleylai commented 6 years ago

Platform: ubuntu 16.04: Python version: 3.6 Source framework with version: mxnet-cu92mkl 1.2.0 Destination framework with version: pytorch-0.4 with GPU Running scripts:

SYM=mxnet/Deformable-ConvNets/rfcn/resnet_v1_101_rfcn_dcn.json
PARAMS=mxnet/Deformable-ConvNets/params/rfcn_dcn_coco-0000.params

mmconvert -sf mxnet -in $SYM -iw $PARAMS --dstNodeName MMdnn_Output -df pytorch -om res101_rfcn_dcn_coco.pth --inputShape 3 224 224

Error:

Traceback (most recent call last):
  File "/home/ml/farleylai/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/ml/farleylai/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 189, in <module>
    _main()
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 184, in _main
    ret = _convert(args)
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 68, in _convert
    parser = MXNetParser(model)
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 239, in __init__
    self.model, self.weight_data = MXNetParser._load_model(input_arg[1], input_arg[2])
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 172, in _load_model
    sym, arg_params, aux_params = mx.model.load_checkpoint(weights, int(epoch))
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mxnet/model.py", line 419, in load_checkpoint
    symbol = sym.load('%s-symbol.json' % prefix)
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mxnet/symbol/symbol.py", line 2535, in load
    check_call(_LIB.MXSymbolCreateFromFile(c_str(fname), ctypes.byref(handle)))
  File "/home/ml/farleylai/anaconda3/lib/python3.6/site-packages/mxnet/base.py", line 149, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [00:13:37] src/operator/custom/custom.cc:104: Check failed: CustomOperator::Get()->Find(params.op_type) != nullptr Cannot find custom operator proposal

The pre-trained model is downloaded from the Deformable-ConvNets which contains a custom operator 'proposal.'

The custom operator is a python module in the source tree. Is there any way to instruct MMdnn to import the custom operator? Or the custom operator for conversion from MXNet is not suppored yet?

namizzz commented 6 years ago

Hi @farleylai ,Could you provide your model file(.json and .params) for us to test?

farleylai commented 6 years ago

Sure, the network symbol is generated by calling tojson() as attached FYI. The network source is located at resnet_v1_101_rfcn_dcn.py.

resnet_v1_101_rfcn_dcn.json.zip

The params is quite large (~254MB) but I believe you can download from the official site (stored on OneDrive with file named rfcn_dcn_coco-0000.params).

The CustomOp proposal source is available in Python or by calling C++ contrib APIs.

Let me know if you need something else.

kitstar commented 6 years ago

Hi @farleylai . In current MMdnn, custom operator is not supported yet. Thanks.