PYTORCH 1.0 , convert-caffe2-to-onnx: No module onnx

jujubi: <p>After installing pytorch1.0, I am trying convert a caffe2 model (in particular caffe2/python/models/seq2seq/translate.py) into ONNX.</p>
<p>I thought I would use the command line script convert-caffe2-to-onnx.</p>
<p>I get a fail saying "No module named ‘onnx’’ from line 13 of conversion.py</p>
<p>I did not install ONNX explicitly.</p>

ptrblck: <p>If you need the whole ONNX library, you should install it via:</p>
<pre><code class="lang-auto">conda install -c conda-forge onnx
</code></pre>

jujubi: <p>Hmm. Am I to understand when I install pytorch1.0 the onnx support is not complete enough to convert a caffe2 model to ONNX?</p>
<p>Also, I asked about this in the ONNX forum. They said this conda-forge version is not being maintained  and asked to install from source.<br>
Thanks <a class="mention" href="/u/ptrblck">@ptrblck</a> for the advice.</p>
<p>Hmm. getting unsatisfiable conflict. ONNX requires python2.7 and I have python3.7 in the pytorch1.0 conda environment.</p>

ptrblck: <p>I didn’t know that the <code>conda-forge</code> version is not being maintained, as it’s recommended to install it using this command in the <a href="https://pytorch.org/docs/stable/onnx.html" rel="nofollow noopener">PyTorch ONNX docs</a>.<br>
Could you post the link to the thread in the ONNX forum?</p>
<p>I guess if you build ONNX from source it should also work with Python 3.7.</p>

jujubi: <p>This is the exchange in the ONNX/optimizer gitter:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/e/e0797aafab6cad1f711b9358fc957fda0b68df1a.png" data-download-href="https://discuss.pytorch.org/uploads/default/e0797aafab6cad1f711b9358fc957fda0b68df1a" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/e/e0797aafab6cad1f711b9358fc957fda0b68df1a_2_690x370.png" alt="image" data-base62-sha1="w1NdJhJuINALztTmxmaGgAuV2D8" width="690" height="370" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/e/e0797aafab6cad1f711b9358fc957fda0b68df1a_2_690x370.png, https://discuss.pytorch.org/uploads/default/optimized/2X/e/e0797aafab6cad1f711b9358fc957fda0b68df1a_2_1035x555.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/e/e0797aafab6cad1f711b9358fc957fda0b68df1a.png 2x" data-dominant-color="F3F3F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1069×574 71.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p><a class="mention" href="/u/houseroad">@houseroad</a> Should the docs be changed to the <code>pip</code> install command?<br>
It seems the <code>conda-forge onnx</code> version wasn’t updated in 7 months, but is still in the official <a href="https://github.com/onnx/onnx#binaries" rel="nofollow noopener">ONNX install guide</a>.</p>
<p>Let me know, what you think about this and I can fix it quickly.</p>

jujubi: <p>The pip version seems to have problem too.<br>
Assertion Error: type is ConstantFill<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/6/610f48844b9a0193db4905b1602cb5a47332aea2.png" data-download-href="https://discuss.pytorch.org/uploads/default/610f48844b9a0193db4905b1602cb5a47332aea2" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/2X/6/610f48844b9a0193db4905b1602cb5a47332aea2.png" alt="image" data-base62-sha1="dQD3Em6jjN5imXpkfgvr0cJB0Fc" width="690" height="58" data-dominant-color="E5E5E5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">990×84 2.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>While searching for this type of error, AFAI understand, it is alluded to be  fixed in 'facebook archived" version.</p><aside class="onebox githubissue" data-onebox-src="https://github.com/onnx/tutorials/issues/8">
  <header class="source">

      <a href="https://github.com/onnx/tutorials/issues/8" target="_blank" rel="noopener nofollow ugc">github.com/onnx/tutorials</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 fill-rule="evenodd" 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/onnx/tutorials/issues/8" target="_blank" rel="noopener nofollow ugc">Caffe2 to ONNX tutorial assertion fails - re.match('GivenTensor.*Fill', op.type)</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2017-12-11" data-time="15:53:36" data-timezone="UTC">03:53PM - 11 Dec 17 UTC</span>
      </div>


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

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

  <div class="github-row">
    <p class="github-body-container">I followed the instructions on Caffe2OnnxExport.ipynb
on Ubuntu16.04, ran the f<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">ollowing command line:
`convert-caffe2-to-onnx /home/eran/Downloads/squeezenet_caffe2/predict_net.pb --caffe2-init-net /home/eran/Downloads/squeezenet_caffe2/exec_net.pb --value-info '{"data": [1, [1, 3, 224, 224]]}' -o sqeezenet.onnx --caffe2-net-name sqeezenet
`

Got the following error:
`
Traceback (most recent call last):
  File "/usr/local/bin/convert-caffe2-to-onnx", line 11, in &lt;module&gt;
    load_entry_point('onnx-caffe2==1.0.0', 'console_scripts', 'convert-caffe2-to-onnx')()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/bin/conversion.py", line 61, in caffe2_to_onnx
    value_info=value_info)
  File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 517, in caffe2_net_to_onnx_model
    model = make_model(cls.caffe2_net_to_onnx_graph(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 357, in caffe2_net_to_onnx_graph
    cls._ssa_rewrite(predict_net, init_net, value_info)
  File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 492, in _ssa_rewrite
    assert re.match('GivenTensor.*Fill', op.type)
AssertionError
`

@jamesr66a 
@bddppq</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


SantMan: <p>Installing from source with the below command worked for me.</p>
<pre><code class="lang-auto">python setup.py develop
</code></pre>
<p>Notice the option <strong>develop</strong> instead of <strong>install</strong></p>
<p>Here is the link where I figured it out.</p>
<aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/onnx/onnx/issues/1302" target="_blank" rel="nofollow noopener">github.com/onnx/onnx</a>
  </header>
  <article class="onebox-body">
    <a href="https://github.com/elboyran" rel="nofollow noopener">
<img src="https://avatars1.githubusercontent.com/u/3244249?v=2&amp;s=96" class="thumbnail onebox-avatar" width="60" height="60">
</a>

<h4><a href="https://github.com/onnx/onnx/issues/1302" target="_blank" rel="nofollow noopener">Issue: Problem installing onnx from source</a></h4>

<div class="date" style="margin-top:10px;">
	<div class="user" style="margin-top:10px;">
	opened by <a href="https://github.com/elboyran" target="_blank" rel="nofollow noopener">elboyran</a>
	on <a href="https://github.com/onnx/onnx/issues/1302" target="_blank" rel="nofollow noopener">2018-08-17</a>
	</div>
	<div class="user">
	</div>
</div>

<pre class="content" style="white-space: pre-wrap;">After installing onnx from binaries and encountering problems (missing functions) when running the Python API notebooks and after an advice to...</pre>

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

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


hoanghui: <p>it worked, thank you ^^</p>