Torchscript support for Deformable Convolution v2

Hello!
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 (https://github.com/CharlesShang/DCNv2/tree/master).
My question is does the support for Deformable Convolution mean I can jit it to torchscript?
And if I add the DCv2 layer to PyTroch from the aforementioned repository can I convert it to torchscript?

Thank you.

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

1 Like

Thanks a lot!
I will try it out.

Any progress yet ? regarding dcnv2

It works fine.

Which libtorch version did u use to compile dcn_v2_cuda_forward_v2? I got error when compiling

candidate: constexpr torch::jit::RegisterOperators::RegisterOperators(torch::jit::RegisterOperators&&)
/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

In newer versions operator registration api changed, you should type like this

static auto registry = torch::RegisterOperators(“my_ops::warp_perspective”, &warp_perspective);

Change your first line.