Mxnet to pytorch via mmdnn

John_J_Watson: <p>I am trying to convert an mxnet Pre-trained model:<br>
</p><aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://cfl.dropboxstatic.com/static/images/favicon-vflUeLeeY.ico" class="site-icon" width="32" height="32">
      <a href="https://www.dropbox.com/s/akxeqp99jvsd6z7/model-MobileFaceNet-arcface-ms1m-refine-v1.zip?dl=0" target="_blank" rel="nofollow noopener">Dropbox</a>
  </header>
  <article class="onebox-body">
    <img src="https://www.dropbox.com/static/images/spectrum-icons/generated/content/content-zip-large.png" class="thumbnail onebox-avatar" width="160" height="160">

<h3><a href="https://www.dropbox.com/s/akxeqp99jvsd6z7/model-MobileFaceNet-arcface-ms1m-refine-v1.zip?dl=0" target="_blank" rel="nofollow noopener">model-MobileFaceNet-arcface-ms1m-refine-v1.zip</a></h3>

<p>Shared with Dropbox</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>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:</p>
<p><code>mmconvert -sf mxnet -in model-symbol.json -iw model-0000.params -df pytorch -om pytorch.pth --inputShape 3,112,112 </code><br>
and I get:</p>
<pre><code class="lang-auto">weight = self.weight_data.get(source_node.name + "_weight").asnumpy().transpose((1, 0))
AttributeError: 'NoneType' object has no attribute 'asnumpy'
</code></pre>
<p>which is the issue described here:<br>
</p><aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/microsoft/MMdnn/issues/231" target="_blank" rel="nofollow noopener">github.com/microsoft/MMdnn</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/microsoft/MMdnn/issues/231" target="_blank" rel="nofollow noopener">failed to convert MXnet model to TF</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2018-06-05" data-time="11:48:44" data-timezone="UTC">11:48AM - 05 Jun 18 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2018-06-11" data-time="17:18:43" data-timezone="UTC">05:18PM - 11 Jun 18 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/IdeoG" target="_blank" rel="nofollow noopener">
          <img alt="IdeoG" src="https://avatars0.githubusercontent.com/u/20797092?v=4" class="onebox-avatar-inline" width="20" height="20">
          IdeoG
        </a>
      </div>
    </div>
  </div>
</div>

<div class="github-row">
  <p class="github-content">Platform (like ubuntu 16.04/win10):
Manjaro 17.1
Python version:
Python 3.6.5
Source framework with version (like Tensorflow 1.4.1 with GPU):
mxnet-latest with GPU
Destination framework with version (like...</p>
</div>

<div class="labels">
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>so, I changed the line 408 in mxnet_parser.py to:<br>
<code>weight = self.weight_data.get("fc1_weight").asnumpy().transpose((1, 0))</code></p>
<p>Now, I run again:</p>
<p><code>mmconvert -sf mxnet -in model-symbol.json -iw model-0000.params -df pytorch -om pytorch.pth --inputShape 3,112,112 </code><br>
and I get:</p>
<pre><code class="lang-auto">  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
</code></pre>
<p>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?</p>
<p>Also, I get a warning during the conversion:</p>
<pre><code class="lang-auto"> 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)
</code></pre>
<p>Is this error something I can safely ignore? Sorry, I am VERY new to MXNET.</p>

ptrblck: <p>I have no idea about MXNet, but the shape error seems to point to a mismatch between the input and output channels.<br>
Could the <code>transpose</code> call have caused this issue?</p>

John_J_Watson: <p><a class="mention" href="/u/ptrblck">@ptrblck</a>: it turned out that there was bug in mxnet --&gt; pytorch conversion via mdnn! problem solved. Thank you.</p>