RuntimeError: Only tuples, lists and Variables supported as JIT inputs/outputs. Dictionaries and strings are also accepted but their usage is not recommended. But got unsupported type NoneType

username: Sayak_Paul
cooked: <p>Hi.</p>
<p>I am trying to convert the <a href="https://github.com/NVIDIA/FastPhotoStyle" rel="nofollow noopener">FastPhotoStyle model (PyTorch) by NVIDIA</a>. The stylization module takes four inputs i.e. the style image, the content image, and two segmentation masks.</p>
<p>I am running the conversion step like so -</p>
<pre><code class="lang-python">torch.onnx.export(stylization_module, [cont_img, styl_img, cont_img, styl_img], 'stylization_module.onnx', input_names=['content', 'style', 'content_seg', 'style_seg'], output_names=['stylized_image'])`
</code></pre>
<p>It is producing:</p>
<pre><code class="lang-auto">RuntimeError: Only tuples, lists and Variables supported as JIT inputs/outputs. Dictionaries and strings are also accepted but their usage is not recommended. But got unsupported type NoneType
</code></pre>
<p>Here’s the <a href="https://colab.research.google.com/gist/sayakpaul/109d7641834c5c32384081b686e858a5/scratchpad.ipynb" rel="nofollow noopener">Colab Notebook</a> for full reproducibility.</p>
<p>Any pointers to resolve the issue would be great.</p>

username: ptrblck
cooked: <p>It seems that the implementation of the <code>PhotoWCT</code> model doesn’t use the standard <code>forward</code> methods as seen in <a href="https://github.com/NVIDIA/FastPhotoStyle/blob/af0c8fecce58aa71f76488546231214f6684be02/photo_wct.py#L170-L171">these lines of code</a>, but instead apparently relies on the <code>transform</code> function.</p>
<p>The ONNX export however, uses the <code>forward</code> method to call the model, which would return <code>None</code> at the moment. I don’t know, why the model authors skipped these standard implementation and instead went with the custom <code>transform</code> method (which would also break any data parallel approach etc.).</p>
<p>Anyway, you could monkey patch the model by assigning the <code>transform</code> to <code>p_wct.forward</code> and make sure the model executes properly in eager mode before trying to export it.<br>
After I’ve patched the method, it seems that more errors are raised.</p>

username: Sayak_Paul
cooked: <p>Thank you. So, if I understand correctly you did try the monkey patching way and got into errors, could you share them?</p>

username: ptrblck
cooked: <p>Sorry, don’t have the terminal open anymore, but just use <code>p_wct.transform(cont_img, styl_img, cont_img, styl_img)</code> to raise this error.</p>

username: Sayak_Paul
cooked: <p>Inside the export call, right? Sorry about the back and forth.</p>

username: ptrblck
cooked: <p>No, try to run the model without any exports first.<br>
Once it’s working properly with the <code>transform</code> method as well as with the direct model call (<code>p_wct(cont_img, ...)</code>), which calls the <code>forward</code> method, you could start trying to export it.<br>
If your model isn’t working in eager mode first, the export would probably raise unhelpful errors.</p>

username: Sayak_Paul
cooked: <p>Understood. Thank you.</p>