pytorch / android-demo-app

PyTorch android examples of usage in applications
1.47k stars 606 forks source link

couldn't find "libpytorch_jni.so" #159

Open zaeemasvatisazi opened 3 years ago

zaeemasvatisazi commented 3 years ago

Hi

I'm trying to run an object detection model using PyTorch Mobile in Android Studio, but I'm getting this error: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ai.isazi.android.brandi.distribution-d262fPg6Kfh8SoY_fVmG7w==/base.apk"],nativeLibraryDirectories=[/data/app/ai.isazi.android.brandi.distribution-d262fPg6Kfh8SoY_fVmG7w==/lib/arm64, /data/app/ai.isazi.android.brandi.distribution-d262fPg6Kfh8SoY_fVmG7w==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]] couldn't find "libpytorch_jni.so"

when loading the model file as follows: val objectDetector: Module = Module.load(assetFilePath(this, "model.pt")

This is how the dependencies in my build.grade file looks: implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'org.pytorch:pytorch_android_lite:1.9.0' implementation 'org.pytorch:pytorch_android_torchvision:1.9.0

Any help or suggestions would be greatly appreciated

sadCloud6 commented 3 years ago

Hi. Maybe you can try to use org.pytorch.LiteModuleLoader to load your model. More information is in https://github.com/pytorch/pytorch/issues/58913.

jeffxtang commented 3 years ago

Yes if you use implementation 'org.pytorch:pytorch_android_lite:1.9.0' in the build.gradle, you need to use LiteModuleLoader.load - here's an example