Torchvision::nms ops cannot be found

So I am working with the Android demo APP for image segmentation with Pytorch.

The demo APP works just fine with deeplabv3.
But instead of using the default deeplabv3 models, I am trying to use detecton2.

Here is what I have achieved and tested successfully in Python:

  • converted detectron2 to TorchScript using tracing. Validated and got correct inference results.
  • Optimized the TorchScript model for mobile.
  • Saved the optimized torchscript model for lite interpreter (.ptl).

IDE environment:

  • Android Studio.
  • pytorch lite version: implementation ‘org.pytorch:pytorch_android_lite:1.13.0’
  • torchvision lite version: implementation ‘org.pytorch:pytorch_android_torchvision_lite:1.13.0’

Error
Following ops cannot be found: [torchvision::nms].

Do any one know how to solve this issue?

Any help and ideas will be appreciated.

Solved this problem by adding extra dependency:

implementation 'org.pytorch:torchvision_ops:0.13.0'

To solve the duplicate files, extra packagingOptions are added as well:


        pickFirst 'lib/arm64-v8a/libfbjni.so'
        pickFirst 'lib/armeabi-v7a/libfbjni.so'
        pickFirst 'lib/x86/libfbjni.so'
        pickFirst 'lib/x86_64/libfbjni.so'
        pickFirst 'lib/arm64-v8a/libpytorch_jni_lite.so'
        pickFirst 'lib/armeabi-v7a/libpytorch_jni_lite.so'
        pickFirst 'lib/x86/libpytorch_jni_lite.so'
        pickFirst 'lib/x86_64/libpytorch_jni_lite.so'
        exclude 'META-INF/native-image/**'

Now detectron2 successfully loaded in the demo APP.