Incompatibility between PyTorch and Torchvision for Jetpack 5.1.2 on AGX Orin

Hi, I have followed the instruction here PyTorch for Jetson to install pytorch and torchvision.

PyTorch v2.1 - torchvision v0.16.1

Here is my AGX ORIN Spec:
Jetpack 5.1.2-b104
l4t 35.4.1
Ubuntu 20.04
CUDA 11.4

After I done the installation, I can import torch and cuda.available is True. GPU is detected as Orin. However, when I try to show the version of torchvision. It stated that module ‘torchvision’ has no attribute ‘version.

Then when I perform the command “pip show torchvision” , it is stated that Torchvision not found. Here is the prove that torchvision v0.16.1 is installed.

image

Also, I tried another way which direct using “pip install torchvision==0.16.1” which turned out that the error of

UserWarning: Failed to load image Python extension: '/home/agx_orin/Documents/SP40/.venv/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?
** warn(**

After that, Runtime error is occured.

RuntimeError: Couldn’t load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision for the compatibility matrix. Please check your PyTorch version with torch.version and your torchvision version with torchvision.version and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.

Here is the pip list:
image

I am confused that I followed step by step according to the instruction to ensure for the compatibility of torch and torchvision but still encounter the same problem. Anyone has solution for this problem?

Hi,

We only provide TorchVision for JetPack 6 users.

For JetPack 5, please build it from the source instead of using pip installation.
You can find the instructions under installation.

Thanks.

Ok, may I know what is the patch for pytorch v2.1.0a0+41361538 or pytorch for Jetpack 5.1.12?
Because I only saw patch for pytorch version up to v1.9.

Hi, I have built torchvision from source, however “pip show torchvision” still result module ‘torchvision’ has no attribute ‘version . It can be imported but version cannot be shown and error still exist.

Is it because it is installed to root? Or do you have any other solution to solve it?

Hi,

Could you share how you install TorchVision?
Do you build it from the source or install it with pip?

Thanks.

Hi, I think I have solved the problem, when I try to use python3 setup.py install instead of python3 setup.py install --user

Below are the step I rebuilt for the source, this time I am using torch version 2.0.0+nv23.05 right now, so the current version of torchvision that I built is version 0.15.1.

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch v0.15.1 https://github.com/pytorch/vision torchvision
cd torchvision
export BUILD_VERSION=0.15.1
python3 setup.py install
cd ../

After the torchvision is built, I restart the kernel and import again and the problem is not occurred again. Torchvision can be imported and version is shown.

image

Thank you.

Good to know the issue is solved.
Thanks for the feedback.