Pytorch Android mobile: PytorchStreamReader failed reading zip archive error

Viewed 3956

I want use my pytorch model in my Android project. I save my model.pt as below:

model.load_state_dict(torch.load(Mymodel.pt)
model.eval()
example_inputs=torch.rand(1,1,266,300)
Mymodel_traced=torch.jit.trace(model,example_inputs=example_inputs)
Mymodel_traced.save("model_traced.pt")

But when I copy this model in my Android Studio project, I have error:

Process: org.pytorch.helloworld, PID: 15383
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: com.facebook.jni.CppException: [enforce fail at inline_container.cc:143] . PytorchStreamReader failed reading zip archive: failed finding central directory
    (no backtrace available)

In my gradle I have:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
   implementation 'org.pytorch:pytorch_android:1.4.0'
    implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'

}

Why I have this problem? I read that it can be caused by as the model was salved, but I followed the guidelines of Pytorch website (https://pytorch.org/mobile/android/)

0 Answers
Related