pytorch / android-demo-app

PyTorch android examples of usage in applications
1.48k stars 608 forks source link

Yolov6 model #262

Open kkm-atom opened 2 years ago

kkm-atom commented 2 years ago

How to use Yolov6 model in the Object detection demo app? Taking a Yolov6 model out of the box causes the below crash:

    --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.pytorch.demo.objectdetection, PID: 6967
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: Could not run 'aten::empty_strided' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::empty_strided' is only available for these backends: [CPU, Vulkan, BackendSelect, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC].

    CPU: registered at aten/src/ATen/RegisterCPU.cpp:18433 [kernel]
    Vulkan: registered at ../aten/src/ATen/native/vulkan/ops/Factory.cpp:47 [kernel]
    BackendSelect: registered at aten/src/ATen/RegisterBackendSelect.cpp:665 [kernel]
    ADInplaceOrView: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]
    AutogradOther: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:35 [backend fallback]
    AutogradCPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:39 [backend fallback]
    AutogradCUDA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:47 [backend fallback]
    AutogradXLA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:51 [backend fallback]
    AutogradLazy: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:55 [backend fallback]
    AutogradXPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:43 [backend fallback]
    AutogradMLC: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:59 [backend fallback]
     ()
    Exception raised from reportError at ../aten/src/ATen/core/dispatch/OperatorEntry.cpp:431 (most recent call first):
    (no backtrace available)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: com.facebook.jni.CppException: Could not run 'aten::empty_strided' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::empty_strided' is only available for these backends: [CPU, Vulkan, BackendSelect, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC].

    CPU: registered at aten/src/ATen/RegisterCPU.cpp:18433 [kernel]
    Vulkan: registered at ../aten/src/ATen/native/vulkan/ops/Factory.cpp:47 [kernel]
    BackendSelect: registered at aten/src/ATen/RegisterBackendSelect.cpp:665 [kernel]
    ADInplaceOrView: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]
    AutogradOther: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:35 [backend fallback]
E/AndroidRuntime: AutogradCPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:39 [backend fallback]
    AutogradCUDA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:47 [backend fallback]
    AutogradXLA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:51 [backend fallback]
    AutogradLazy: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:55 [backend fallback]
    AutogradXPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:43 [backend fallback]
    AutogradMLC: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:59 [backend fallback]
     ()
    Exception raised from reportError at ../aten/src/ATen/core/dispatch/OperatorEntry.cpp:431 (most recent call first):
    (no backtrace available)
        at org.pytorch.LiteNativePeer.initHybrid(Native Method)
        at org.pytorch.LiteNativePeer.<init>(LiteNativePeer.java:28)
        at org.pytorch.LiteModuleLoader.load(LiteModuleLoader.java:30)
        at org.pytorch.demo.objectdetection.MainActivity.onCreate(MainActivity.java:186)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)

I/Process: Sending signal. PID: 6967 SIG: 9
TUANANH-INU commented 2 years ago

Looks like pytorch mobile doesn't support cuda yet. so when converting weights, don't use .cuda() commands for inputs or models.

NeighborhoodCoding commented 1 year ago

Did you solve the issue?