pytorch / android-demo-app

PyTorch android examples of usage in applications
1.45k stars 596 forks source link

Lite Interpreter version number does not match. #263

Closed ahmadbajwa8282 closed 1 year ago

ahmadbajwa8282 commented 1 year ago

Caused by: com.facebook.jni.CppException: Lite Interpreter version number does not match. The model version must be between 3 and 7 but the model version is 8 () Exception raised from parseMethods at ../torch/csrc/jit/mobile/import.cpp:317 (most recent call first): (no backtrace available)

import torch
from torch.utils.mobile_optimizer import optimize_for_mobile

model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet50', pretrained=True)
model.eval()

scripted_module = torch.jit.script(model)
# Export full jit version model (not compatible mobile interpreter), leave it here for comparison
scripted_module.save("deeplabv3_scripted.pt")
# Export mobile interpreter version model (compatible with mobile interpreter)
optimized_scripted_module = optimize_for_mobile(scripted_module)
optimized_scripted_module._save_for_lite_interpreter("deeplabv3_scripted.ptl")
supremassi commented 1 year ago

Did you find a solution ? I have the same error with the ObjectDetection demo

ahmadbajwa8282 commented 1 year ago

@supremassi try old version of python and PyTorch

HripsimeS commented 1 year ago

@ahmadbajwa8282 Hello. Which version of python and PyTorch versions helped you to fix the issue with Lite Interpreter version? Thank you very much in advance!

SLchowis commented 1 year ago

@HripsimeS , @ahmadbajwa8282

Here is what you can refer to Convert between different model versions.

weixu-tf4 commented 11 months ago

`dependencies { ...

implementation 'org.pytorch:pytorch_android_lite:1.13.1'
implementation 'org.pytorch:pytorch_android_torchvision_lite:1.13.1'

}` This works for me.