Vision: Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132)

Created on 5 Mar 2020  路  18Comments  路  Source: pytorch/vision

I have created .pt file of keypoint_rcnn using torch=1.5 and vision=0.6.0 now trying to integrate it with my android app. The error I am getting is as below.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.pytorch.helloworld, PID: 15691
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132)
(no backtrace available)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
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:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
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:870)
Caused by: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132)
(no backtrace available)
at org.pytorch.NativePeer.initHybrid(Native Method)
at org.pytorch.NativePeer.(NativePeer.java:18)
at org.pytorch.Module.load(Module.java:23)
at org.pytorch.helloworld.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:7148)
at android.app.Activity.performCreate(Activity.java:7139)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1293)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
... 11 more

models needs discussion mobile object detection

Most helpful comment

If anyone encounters this, this is what happened to me:

  1. Updated torchvision to a version not compatible with torch
  2. Run code that loaded a torchvision dataset, then threw an error
  3. Downgraded torchvision to proper version
  4. Re-ran code that loaded that dataset, which had been downloaded in a newer format, which couldn't be recognized by older torchvision

To fix it, I removed the dataset that torchvision had already downloaded.

All 18 comments

Hi,

I suppose you are trying to use torchscript to convert the model to mobile, is that correct?

I suspect that this might not work out-of-the-box currently, because PyTorch mobile doesn't yet support using operators registered outside of PyTorch (like roi_align in torchvision).

@dreiss is that still the case?

Yes, but I think this issue is unrelated. It's just due to a change in the serialization format (which I think was reverted).

Ok, following @dreiss comment, if you update PyTorch and torchvision this issue should go away, but you'll still have issues exporting keypoint-rcnn to mobile.

Yes @fmassa you are correct. I used pytorch 1.4 snapshot as a dependency, above error disappeared. But still I am getting build failed that even without showing any error. Now I am confused with what should be exact issue.

@hurricane013 as I mentioned in the above post, we currently do not support exporting keypoint-rcnn to mobile yet unfortunately, but support for it will be added in future releases.

Hi, I wrote a simple MNIST classifier with CNN and got the same error on my android project.

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.predictor, PID: 7253 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.predictor/com.example.predictor.MainActivity}: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132) (no backtrace available) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132) (no backtrace available) at org.pytorch.NativePeer.initHybrid(Native Method) at org.pytorch.NativePeer.<init>(NativePeer.java:18) at org.pytorch.Module.load(Module.java:23) at com.example.predictor.MainActivity.onCreate(MainActivity.kt:47) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) ... 11 more Disconnected from the target VM, address: 'localhost:8602', transport: 'socket'

@hurricane013 simple CNN models should work with mobile, I would expect this to be a version issue and if you update PyTorch / torchvision and re-save your weights, it should work

I see.
These are my package versions:

import torch
torch.__version__
'1.5.0.dev20200306'
import torchvision
torchvision.__version__
'0.6.0a0+f534fb5'

and this is what I added to dependencies.

implementation 'org.pytorch:pytorch_android:1.4.0'
implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'

Should I install pytorch's 1.4 version or is there any implementation for 1.5?

Yes, I think you might want to install PyTorch 1.4 and torchvision 0.5.0.

But I would recommend posting this question on the pytorch discuss forums, as this is outside of the scope of torchvision and I don't have much context to be able to help with android-specific issues

@hurricane013 simple CNN models should work with mobile, I would expect this to be a version issue and if you update PyTorch / torchvision and re-save your weights, it should work

@fmassa As I mentioned, I used 1.4 snapshot which is latest as a dependency in my android app, but i am still getting build failed without any error.

If anyone encounters this, this is what happened to me:

  1. Updated torchvision to a version not compatible with torch
  2. Run code that loaded a torchvision dataset, then threw an error
  3. Downgraded torchvision to proper version
  4. Re-ran code that loaded that dataset, which had been downloaded in a newer format, which couldn't be recognized by older torchvision

To fix it, I removed the dataset that torchvision had already downloaded.

@jxmorris12 maybe doing new colab env is much easier...

It just happend to me....so ANNOYING!!
What version of torch, torchvision is needed....???!
EDIT : PyTorch 1.4 and torchvision 0.5.0 seems to work but I'm not perfectly sure yet, and maybe there is more good version to safe. I don know latest version of org.pytorch:pytorch_android yet also.

I'm having the same issues on torch=1.4.0 and torchvision=0.5.0. Here's my error message:

Traceback (most recent call last):
File "train.py", line 15, in
model.setup(opt)
File "/home/cchoi/n2d/models/base_model.py", line 29, in setup
self.load_networks(opt.epoch)
File "/home/cchoi/n2d/models/base_model.py", line 129, in load_networks
state_dict = torch.load(load_path, map_location=str(self.device))
File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 527, in load
with _open_zipfile_reader(f) as opened_zipfile:
File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 224, in __init__
super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f0db93f5627 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::init() + 0x1f5b (0x7f0dbde669ab in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #2: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::string const&) + 0x64 (0x7f0dbde67bc4 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #3: + 0x6ce4b6 (0x7f0deba224b6 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #4: + 0x28b8a7 (0x7f0deb5df8a7 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)

frame #35: __libc_start_main + 0xf0 (0x7f0dfb530840 in /lib/x86_64-linux-gnu/libc.so.6)

I ran into the same problem with pytorch 1.4

The model you are trying to load is trained on PyTorch V1.6 or above. Upgrade your PyTorch version to 1.6.

Does anyone know how I can reshape Tensor object on android?

The model trained with PyTorch 1.7 and the backbone is resnet50 , but PyTorch version 1.4 loading the model occurred the same error

There could be other serious bugs inside.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpha-gradient picture alpha-gradient  路  3Comments

varagrawal picture varagrawal  路  3Comments

martinarjovsky picture martinarjovsky  路  4Comments

Wadaboa picture Wadaboa  路  3Comments

Linardos picture Linardos  路  4Comments