0

I am trying to convert an mxnet Pre-trained model: https://www.dropbox.com/s/akxeqp99jvsd6z7/model-MobileFaceNet-arcface-ms1m-refine-v1.zip?dl=0

I am trying to convert a pretrained model from mxnet to pytorch, but it always seems to fail. So, first I download, unzip the model files and run:

mmconvert -sf mxnet -in model-symbol.json -iw model-0000.params -df pytorch -om pytorch.pth --inputShape 3,112,112 and I get:

weight = self.weight_data.get(source_node.name + "_weight").asnumpy().transpose((1, 0))
AttributeError: 'NoneType' object has no attribute 'asnumpy'

which is the issue described here: https://github.com/microsoft/MMdnn/issues/231

so, I changed the line 408 in mxnet_parser.py to: weight = self.weight_data.get("fc1_weight").asnumpy().transpose((1, 0))

Now, I run again:

mmconvert -sf mxnet -in model-symbol.json -iw model-0000.params -df pytorch -om pytorch.pth --inputShape 3,112,112 and I get:

  File "pytorch.py", line 30, in __init__
    self.conv_2_dw_conv2d = self.__conv(2, name='conv_2_dw_conv2d', in_channels=64, out_channels=4096, kernel_size=(3, 3), stride=(1, 1), groups=64, bias=False)
  File "pytorch.py", line 335, in __conv
    layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
RuntimeError: The size of tensor a (4096) must match the size of tensor b (64) at non-singleton dimension 0

I am not sure what it is trying to tell me other than that there seems a size mismatch. I was wondering if anyone has encountered this and have a solution for this?

Also, I get a warning during the conversion:

 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)

Is this error something I can safely ignore? Sorry, I am VERY new to MXNET.

JohnJ
  • 6,736
  • 13
  • 49
  • 82
  • Maybe it would be easier with [`onnx`](https://github.com/onnx/tutorials)? – Szymon Maszke Jul 08 '20 at 11:20
  • onnx does not do onnx to pytorch from what I can see.. Do you have a link which shows otherwise? Thank you! – JohnJ Jul 08 '20 at 11:27
  • you are right, after checking you can't do that without workaround and hacks. I'm not into ONNX much and not into MXNet at all, but I imagine you could export trained weights into `np.array`'s, code model from scratch in pytorch and load them from `np.array`s (I'm assuming you have model's source code). – Szymon Maszke Jul 08 '20 at 12:17

0 Answers0