Torch and torchvision versions are not compatible

Hello,I have a jetson agx orin (version of jetpack is 5.1.2) and I’m having some problems with the environment:
I installed anaconda on orin and created a python3.8 environment. I’m in the web site Installing PyTorch for Jetson Platform - NVIDIA Docs to download the torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl, and installed torch2.0 in the anaconda environment. I according to the site after the tutorial (PyTorch for Jetson) to download and install the torchvision 0.15.1, but torchvision is not available after installation.

when I import torchvision,It will give me the following error:

>>>import torchvision
/home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: '/home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/image.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs’If you don’t plan on using image functionality from torchvision.io, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have libjpeg or libpng installed before building torchvision from source?

So how do I install torchvision now?

Hi,

Please try TorchVision v0.14.1 for our v2.0.0 PyTorch.
Or you can use our l4t-pytorch that has both PyTorch and TorchVision installed.

Thanks.

1 Like

I installed torchvision v0.14.1, but it gave me a new error:

>>>import torchvision
/home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/image.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
warn(f"Failed to load image Python extension: {e}")
>>>torchvision.__version__
‘0.14.1’
>>>import torch
>>>torch.__version__
‘2.0.0+nv23.05’

I downloaded the l4t-pytorch image, but the torch and torchvision versions of the python environment are different from mine. Here’s what’s inside the image(version of image is l4t-pytorch:r35.2.1-pth2.0-py3):

python3 environment of the image

>>>import torchvision
>>>torchvision.__version__
‘0.14.1a0+5e8e2f1’
>>>import torch
>>>torch.__version__
‘2.0.0a0+ec3941ad.nv23.02’

These two versions seem to fit together well. How do I install the same version of torch and torchvision?

Hi,

Do you build TorchVision from the source?

The pip installation doesn’t have CUDA support.
Please install it from the source with the instructions shared in the below topic:

Thanks.

Thanks for your reply, I successfully installed torchvision. Unfortunately, it still reports errors

>>>import torchvision
/home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /home/thmos/anaconda3/envs/env1/lib/python3.8/site-packages/torchvision/image.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
warn(f"Failed to load image Python extension: {e}")
>>>torchvision.__version__
>>>‘0.14.1a0+5e8e2f1’

Do I still need to build pytorch from source code that I don’t see anyone else doing? And I tried to do that without success, and there were a lot of other bugs.

This is how I installed pytorch earlier:

pip install torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl

Hi,

No, you just need to build TorchVision from the source.
BUILD_VERSION should be 0.14.1.

$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev
$ git clone --branch <version> https://github.com/pytorch/vision torchvision   # see below for version of torchvision to download
$ cd torchvision
$ export BUILD_VERSION=0.x.x  # where 0.x.0 is the torchvision version  
$ python3 setup.py install --user

Thanks.

Sorry, I tried this many times, both in anaconda environment and ubuntu default environment, and I successfully installed torch2.0.0+nv23.05 and torchvision0.14.1a0+5e8e2f1, but I still got an error:

/home/bigai/torchvision_0.14.1/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")

I even changed to another orin and it’s still the same. I have no idea what to do now.

For PyTorch 2.0.0, the Torchvision version should be 0.15.X, v0.15.1 is what is in use the the Jetson l4t-pytorch containers (https://github.com/dusty-nv/jetson-containers/tree/master/packages/l4t/l4t-pytorch).

To match up versions of Torch with Torchvision see: GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision

Thanks for your help, I successfully installed torchvision. Ultimately, the problem is anaconda. I was unable to install torchvision from the source code in the conda environment. And if I had torch 2.0.0+nv23.05 installed in both conda and the default environment, neither environment would work with torchvision, meaning an error would be reported. However, if you uninstall torch in the conda environment, or install another version of torch, such as torch1.14. This will make torchvision normal in the default system environment.

In summary, it is not recommended to use the anaconda environment on top of orin.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.