pytorch / android-demo-app

PyTorch android examples of usage in applications
1.46k stars 604 forks source link

Caused by: com.facebook.jni.CppException: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 7 () #219

Closed NeighborhoodCoding closed 1 year ago

NeighborhoodCoding commented 2 years ago

Hi, I made video classfication model convert by build.py but this error comes out...

 Caused by: com.facebook.jni.CppException: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 7 ()
2021-12-09 14:29:19.733 29182-29182/org.pytorch.demo.torchvideo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.pytorch.demo.torchvideo, PID: 29182
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.torchvideo/org.pytorch.demo.torchvideo.MainActivity}: com.facebook.jni.CppException: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 7 ()
    Exception raised from parseMethods at ../torch/csrc/jit/mobile/import.cpp:320 (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: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 7 ()
    Exception raised from parseMethods at ../torch/csrc/jit/mobile/import.cpp:320 (most recent call first):
    (no backtrace available)
        at org.pytorch.LiteNativePeer.initHybrid(Native Method)
        at org.pytorch.LiteNativePeer.<init>(LiteNativePeer.java:23)
        at org.pytorch.LiteModuleLoader.load(LiteModuleLoader.java:29)
        at org.pytorch.demo.torchvideo.MainActivity.onCreate(MainActivity.java:82)
        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)
            ... 11 more
2021-12-09 14:29:19.764 29182-29182/? I/Process: Sending signal. PID: 29182 SIG: 9

How to resolve this error? thx.

syl4356 commented 2 years ago

I'm working with 'SpeechRecognition' demo app, and I got the same error message 🥲

2021-12-10 13:13:44.250 10430-10461/org.pytorch.demo.speechrecognition E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: org.pytorch.demo.speechrecognition, PID: 10430
    com.facebook.jni.CppException: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 7 ()
    Exception raised from parseMethods at ../torch/csrc/jit/mobile/import.cpp:320 (most recent call first):
    (no backtrace available)
        at org.pytorch.LiteNativePeer.initHybrid(Native Method)
        at org.pytorch.LiteNativePeer.<init>(LiteNativePeer.java:23)
        at org.pytorch.LiteModuleLoader.load(LiteModuleLoader.java:29)
        at org.pytorch.demo.speechrecognition.MainActivity.recognize(MainActivity.java:197)
        at org.pytorch.demo.speechrecognition.MainActivity.run(MainActivity.java:183)
        at java.lang.Thread.run(Thread.java:923)
syl4356 commented 2 years ago

https://github.com/pytorch/android-demo-app/issues/202#issuecomment-972664735 This (in issue #202) worked for me. hope it helps :)

mictiong85 commented 2 years ago

I fix it by adding changing dependencies to implementation 'org.pytorch:pytorch_android_lite:1.10.0'

raedle commented 2 years ago

The torch.jit.mobile has a _backport_for_mobile function to "backport" a model to a given version

from torch.jit.mobile import (
    _backport_for_mobile,
    _get_model_bytecode_version,
)

MODEL_INPUT_FILE = "model_v7.ptl"
MODEL_OUTPUT_FILE = "model_v5.ptl"

print("model version", _get_model_bytecode_version(f_input=MODEL_INPUT_FILE))

_backport_for_mobile(f_input=MODEL_INPUT_FILE, f_output=MODEL_OUTPUT_FILE, to_version=5)

print("new model version", _get_model_bytecode_version(MODEL_OUTPUT_FILE))
aravinthk00 commented 1 year ago

The torch.jit.mobile has a _backport_for_mobile function to "backport" a model to a given version

from torch.jit.mobile import (
    _backport_for_mobile,
    _get_model_bytecode_version,
)

MODEL_INPUT_FILE = "model_v7.ptl"
MODEL_OUTPUT_FILE = "model_v5.ptl"

print("model version", _get_model_bytecode_version(f_input=MODEL_INPUT_FILE))

_backport_for_mobile(f_input=MODEL_INPUT_FILE, f_output=MODEL_OUTPUT_FILE, to_version=5)

print("new model version", _get_model_bytecode_version(MODEL_OUTPUT_FILE))

this lines solve model version issue But I facing similar error like below logcast

errorinas

please anyone give solution about issue ... thanks in advanced.

HripsimeS commented 1 year ago

@NeighborhoodCoding Hello. Were you able to fix the issue? If yes, can you please share your experience what did you modify. Thanks a lot in advance!

NeighborhoodCoding commented 1 year ago

It's git source is updated about 6 month ago, and I noticed the problem is solved.

kartikpodugu commented 1 year ago

I fix it by adding changing dependencies to implementation 'org.pytorch:pytorch_android_lite:1.10.0'

I am getting, Duplicate Class errors if i change version to any version than existing. How to resolve this issue?

kartikpodugu commented 1 year ago

The torch.jit.mobile has a _backport_for_mobile function to "backport" a model to a given version

from torch.jit.mobile import (
    _backport_for_mobile,
    _get_model_bytecode_version,
)

MODEL_INPUT_FILE = "model_v7.ptl"
MODEL_OUTPUT_FILE = "model_v5.ptl"

print("model version", _get_model_bytecode_version(f_input=MODEL_INPUT_FILE))

_backport_for_mobile(f_input=MODEL_INPUT_FILE, f_output=MODEL_OUTPUT_FILE, to_version=5)

print("new model version", _get_model_bytecode_version(MODEL_OUTPUT_FILE))

this lines solve model version issue But I facing similar error like below logcast errorinas

please anyone give solution about issue ... thanks in advanced.

I am getting similar error, what is the solution ?