Pytorch for Android - LiteModuleLoader

vjayd: <p>I am getting an error as</p>
<p>java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.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 8 ()<br>
Exception raised from parseMethods at …/torch/csrc/jit/mobile/import.cpp:320 (most recent call first):<br>
(no backtrace available)</p>
<p>My gradle settings<br>
dependencies {<br>
implementation ‘androidx.appcompat:appcompat:1.1.0’<br>
implementation ‘org.pytorch:pytorch_android_lite:1.9.0’<br>
implementation ‘org.pytorch:pytorch_android_torchvision:1.9.0’<br>
}</p>
<p><a href="https://github.com/pytorch/android-demo-app" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/android-demo-app: PyTorch android examples of usage in applications</a>  HelloWorld from this app.</p>
<p>I converted my GAN model to .ptl  and then I tried to load the .ptl file in the same way as mentioned in this sample. I am consistently getting the above error</p>

cccclai: <p>Looks like the model is generated from a newer runtime, while 1.9 is more than one year old. Possibly try</p>
<pre><code class="lang-auto">implementation ‘org.pytorch:pytorch_android_lite:1.12.0’
implementation ‘org.pytorch:pytorch_android_torchvision:1.12.0’
</code></pre>
<p>and see if it works?</p>

vjayd: <p><a class="mention" href="/u/cccclai">@cccclai</a>  No it’s not working</p>
<p>import org.pytorch.IValue;<br>
import org.pytorch.LiteModuleLoader;<br>
import org.pytorch.Module;<br>
import org.pytorch.Tensor;<br>
import org.pytorch.torchvision.TensorImageUtils;<br>
import org.pytorch.MemoryFormat;</p>
<p>If I use 1.12 then I cannot resolve any of the pytorch symbols</p>

vjayd: <p>I was able to fix it by changing to</p>
<p>implementation ‘org.pytorch:pytorch_android_lite:1.12.2’<br>
implementation ‘org.pytorch:pytorch_android_torchvision:1.12.2’</p>
<p>Seems like 1.12.0 is not stable. By the way do we have any website where we can see the stable android builds. It’s hard to trial and error</p>

kartikpodugu: <p>Hi Vijay,</p>
<p>I got the same error when I tried to work on HelloWorldApp (MobilenetV3 based object classification on static image) from <a href="https://github.com/pytorch/android-demo-app/tree/master/HelloWorldApp" rel="noopener nofollow ugc">https://github.com/pytorch/android-demo-app/tree/master/HelloWorldApp</a></p>
<p>I was able to fix my issue with your solution, but now, though the app works, the classification result changes and is wrong now.</p>
<p>Any idea how to fix this?</p>
<p>Also one more observation.</p>
<p>The repository provides a script named <strong>trace_model.py</strong> to create a PyTorch Mobile model file.<br>
I used the same script to generate the model.<br>
If the extension is .pt, I don’t even face the above problem and everything works perfectly fine.<br>
If i rename the extension to .ptl, I get the problem, and after fixing it using your solution, the problem goes away, but classification results go for a toss.</p>
<p>Overall file is same, just changing extension causes problems.</p>

vjayd: <p><a class="mention" href="/u/kartikpodugu">@kartikpodugu</a> , I think you should export the model to .ptl file through mobile lite interpreter, just renaming it form .pt to .ptl will not work accurately</p>

Cagatay_Bilgin: <p>We have open sourced ExecuTorch a few years ago, deprecating the older stack. <a href="https://github.com/pytorch/executorch" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/executorch: On-device AI across mobile, embedded and edge for PyTorch</a> Join our discord channel at<br>
<a href="https://discord.gg/Wyn9PWqP" class="inline-onebox" rel="noopener nofollow ugc">PyTorch Edge</a> where the team hangs out and can answer questions. We discuss a lot of the plans openly there.</p>