Torchscript support for Deformable Convolution v2

username: igor_davidyuk
cooked: <p>Hello!<br>
I heard PyTorch supports Deformable Convolution out of the box since 1.4 release, I just can not say by looking at code if it is version 1 or version 2 (<a href="https://github.com/CharlesShang/DCNv2/tree/master" rel="nofollow noopener">https://github.com/CharlesShang/DCNv2/tree/master</a>).<br>
My question is does the support for Deformable Convolution mean I can jit it to torchscript?<br>
And if I add the DCv2 layer to PyTroch from the aforementioned repository can I convert it to torchscript?</p>
<p>Thank you.</p>

username: zdevito
cooked: <p>It looks like the custom kernels in the repo linked are bound using pybind (<a href="https://github.com/CharlesShang/DCNv2/blob/master/src/vision.cpp" rel="nofollow noopener">https://github.com/CharlesShang/DCNv2/blob/master/src/vision.cpp</a>). So they will not work with TorchScript as is. However, it is possible to register the operator with TorchScript following <a href="https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html" rel="nofollow noopener">https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html</a>, which would work with TorchScript.</p>

username: igor_davidyuk
cooked: <p>Thanks a lot!<br>
I will try it out.</p>

username: Kiki_Rizki_Arpiandi
cooked: <p>Any progress yet ? regarding dcnv2</p>

username: igor_davidyuk
cooked: <p>It works fine.<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/xi11xi19/CenterNet2TorchScript" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars1.githubusercontent.com/u/11573107?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/xi11xi19/CenterNet2TorchScript" target="_blank" rel="nofollow noopener">xi11xi19/CenterNet2TorchScript</a></h3>

<p>centernet pytorch model to torch script model. Contribute to xi11xi19/CenterNet2TorchScript development by creating an account on GitHub.</p>


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

username: Kiki_Rizki_Arpiandi
cooked: <p>Which libtorch version did u use to compile dcn_v2_cuda_forward_v2? I got error when compiling</p>
<pre><code class="lang-auto">candidate: constexpr torch::jit::RegisterOperators::RegisterOperators(torch::jit::RegisterOperators&amp;&amp;)
/usr/lib/libtorch_abi11_14/include/torch/csrc/jit/custom_operator.h:16:18: note:   candidate expects 1 argument, 2 provided
CMakeFiles/dcn_v2_cuda_forward_v2.dir/build.make:1509: recipe for target 'CMakeFiles/dcn_v2_cuda_forward_v2.dir/vision.cpp.o' faile
</code></pre>

username: igor_davidyuk
cooked: <p>In newer versions operator registration api changed, you should type like this</p>
<blockquote>
<p>static auto registry = torch::RegisterOperators(“my_ops::warp_perspective”, &amp;warp_perspective);</p>
</blockquote>
<p>Change your first line.</p>

username: Kiki_Rizki_Arpiandi
cooked: <p>Now it works fine (pythorch 1.4), thanks, btw do you try using  pytorch version 1.5 I got this error:<br>
Could not export Python function call ‘_DCNv2’. Remove calls to Python functions before export</p>

username: Kiki_Rizki_Arpiandi
cooked: <p>I try to trace model for CenterTrack model, but I got this error</p>
<blockquote>
<p>TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error:<br>
Not within tolerance rtol=1e-05 atol=1e-05 at input[26, 79, 149] (-1.9391770362854004 vs. -1.9395387172698975) and 669 other locations (0.00%)<br>
check_tolerance, _force_outplace, True, _module_class)</p>
</blockquote>