Error in loading pytorch model with torch version >1.10 on ubuntu 20.04
38 visualizaciones (últimos 30 días)
I'm running MATLAB R2022b on Ubuntu 20.04. I'm trying to load a pytorch model in MATLAB by running the following script:
torch = py.importlib.import_module('torch');
a = torch.tensor([1, 2, 3, 4]);
However, there always exists an error:
Error using serialization>__init__
Python Error: RuntimeError: [enforce fail at inline_container.cc:120] . archive does
not contain any files
Error in serialization>load (line 777)
I made several tests and located that the error could be due to the torch version I'm using. As discussed here: https://www.mathworks.com/matlabcentral/answers/1694510-python-error-runtimeerror-enf[…]ontainer-cc-106-archive-does-not-contain-any?s_tid=srchtitle, I was using torch version 1.13.0 that caused the error. When I downgraded the torch version to 1.10, the error disappeared. However, my other scripts need to use torch version > 1.10. If there's any way can let me successfully load torch model with torch version greater than 1.10? Thank you!
Amith el 27 de Abr. de 2023
As per your understanding you wanted to load pytorch model in matlab and are currently facing problems with the error message shown above.
The error message above suggests that there is a problem with loading a serialized object in MATLAB that was created using PyTorch 1.11.0.
Here are a few things you can try to resolve the issue:
1. Check that the serialized object file exists and is not empty. You can do this by opening the file in a text editor and verifying that it contains some data.
2. Make sure that you are using the correct version of PyTorch for your MATLAB installation. The supported versions are 1.8.0 ,1.9.0 ,1.11.0.
3. Check that you have the necessary dependencies installed for both PyTorch and MATLAB. You can refer to the documentation for both software packages to see which dependencies are required.
4. Try using a different serialization method to save the PyTorch object. For example, you can try using the `pickle` module in Python to save the object, and then load it in MATLAB using the `load` function.