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.79k stars 964 forks source link

Cannot convert models of Insight face(mxnet) to IR #434

Open stereomatchingkiss opened 5 years ago

stereomatchingkiss commented 5 years ago

Platform : win10 64 bits

Python version: Anaconda 3.6

Source framework with version: mxnet 1.3.0

Destination framework with version: Ultimate goal is convert to caffe model, but fail to convert to IR

Pre-trained model path : insight face model zoo, converting MobileFaceNet

Running scripts(try all of them):

  1. python -m mmdnn.conversion._script.convertToIR -f mxnet -n model-symbol.json -w model-0000.params -d mobile_face_net --inputShape 1 3 112 112
  2. python -m mmdnn.conversion._script.convertToIR -f mxnet -n model-symbol.json -w model-0000.params -d mobile_face_net --inputShape 3 112 112
  3. python -m mmdnn.conversion._script.convertToIR -f mxnet -n model-symbol.json -w model-0000.params -d mobile_face_net --inputShape 112 112

Error message:

 File "C:\Users\yyyy\Anaconda3\lib\site-packages\mxnet\base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator conv0: [00:40:56] c:\jenkins\workspace\mxnet\mxnet\src\operator\nn\convolution.cc:148: Check failed: dshp.ndim() == 4U (2 vs. 4) Input data should be 4D in batch-num_filter-y-x

Any suggestions?Thanks

rainLiuplus commented 5 years ago

Hi @stereomatchingkiss , The --inputShape should be 3,112,112.

stereomatchingkiss commented 5 years ago

Hi @stereomatchingkiss , The --inputShape should be 3,112,112.

Thanks, the dimension problem solved, but I found new issues. When I convert the resnet34 models of insight face, I saw following warnings

 C:\Users\yyyy\Anaconda3\lib\site-packages\mxnet\module\base_module.py:56: UserWarning: You created Module with Module(..., label_names=['softmax_label']) but input with name 'softmax_label' is not found in symbol.list_arguments(). Did you mean one of:
        data
  warnings.warn(msg)
Warning: MXNet Parser has not supported operator null with name data.
Warning: convert the null operator with name [data] into input layer.
IR network structure is saved as [mobile_face_net.json].
IR network structure is saved as [mobile_face_net.pb].
IR weights are saved as [mobile_face_net.npy].

Although I can convert the models to IR files, but not sure this is safe or not

When I convert MobileFaceNet, saw error messages

C:\Users\yyyy\Anaconda3\lib\site-packages\mxnet\module\base_module.py:56: UserWarning: You created Module with Module(..., label_names=['softmax_label']) but input with name 'softmax_label' is not found in symbol.list_arguments(). Did you mean one of:
        data
  warnings.warn(msg)
Warning: MXNet Parser has not supported operator null with name data.
Warning: convert the null operator with name [data] into input layer.
Traceback (most recent call last):
  File "C:\Users\yyyy\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\yyyy\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\_script\convertToIR.py", line 197, in <module>
    _main()
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\_script\convertToIR.py", line 192, in _main
    ret = _convert(args)
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\_script\convertToIR.py", line 115, in _convert
    parser.run(args.dstPath)
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\common\DataStructure\parser.py", line 22, in run
    self.gen_IR()
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\mxnet\mxnet_parser.py", line 262, in gen_IR
    func(current_node)
  File "C:\Users\yyyy\Anaconda3\lib\site-packages\mmdnn\conversion\mxnet\mxnet_parser.py", line 398, in rename_FullyConnected
    weight = self.weight_data.get(source_node.name + "_weight").asnumpy().transpose((1, 0))
AttributeError: 'NoneType' object has no attribute 'asnumpy'
namizzz commented 5 years ago

Hi @stereomatchingkiss, this warning doesn't matter. I find there is no 'pre_fc1_weight' object in the self.weight_data. But I find the 'fc1_weight' in the self.weight_data in the shape of (128, 512). I think it may be the weight of the fully connected layer 'pre_fc1' which the num_hidden is 128. Maybe you can change this line:

weight = self.weight_data.get(source_node.name + "_weight").asnumpy().transpose((1, 0))

into

weight = self.weight_data.get(source_node.name.split('pre_')[-1] + "_weight").asnumpy().transpose((1, 0))

I tried, it works. Thanks!

kaishijeng commented 5 years ago

@namizzz

I am able to convert mobilefacenet with your suggestion. My goal is to convert to pytorch or tensorflow. DO you know how to convert this IR model to tensorflow or pytorhc?

Thanks,

kaishijeng commented 5 years ago

@namizzz

Do you know how to convert this IR model to tensorflow or pytorch?
Your help will be appreciated.

Thanks, FC

nakohli commented 5 years ago

I got it converted to pytorch by using the below command

mmtocode -f pytorch -n mobile_face_net.pb -w mobile_face_net.npy -d torch_converted.py -dw torch_converted.pt

However the major issue is that PRelu operation is not yet supported as a pytorch emitter.

@namizzz Can you suggest what extra changes will have to be made for this model to be successfully converted to pytorch model

Thanks

tengerye commented 5 years ago

Hi, any progress on this issue? I have a similar problem #499 @rainLiuplus @namizzz