Torchvision on Jetson AGX Orin DevKit


I need to install torch and torchvision for a python project on my Jetson AGX Orin.

I installed pytorch following this tutorial Installing PyTorch for Jetson Platform - NVIDIA Docs
I picked the wheel torch-2.0.0a0+8aa34602.nv23.03-cp38-cp38-linux_aarch64.whl
It works well, torch.cuda.is_available returns True and i can use torch tensors.

Then to install torchvision, it doesn’t work with pip (incompatible version) and it is required to build it, as pointed out by multiple topics in here.

I followed this tutorial PyTorch for Jetson
Building the torchvision 0.15.1 to be compatible with my version.
(i installed the required libraries mentioned in the tutorial before building.)

import torchvision is successful and print(torchvision.version) returns 0.15.1.

Still, when i run my script i’ve got :
-A warning :
“UserWarning: Failed to load image Python extension: ''If you don’t plan on using image functionality from, 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?

-An error : “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.”

I tried following this PyTorch and torchvision versions are incompatible using an older version (torch 1.11.0, torchvision 0.12.0a0+9b5a3fe), and i’ve got the same error, but a different warning :
“UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}”)"

I tried using the unreleased wheel torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl that was suggested on a different topic, and i’ve got the same error, even after rebuilding torchvision 0.15.1.

(Also, i had to follow this What is the compatible torchvision version for torch-1.14.0a0+44dac51c.nv23.2 installed on AGX ORIN( Ubuntu-22.04, JP-5.1/5.0, Python-3.8, CUDA-11.4) - #14 by fpsychosis, modifying cpp_extension to be able to build torchvision otherwise i had errors during compiling.)

I know there’s a Docker container which should work but i don’t know what is wrong with my current configuration.

Thank you.

Hi @AZTEC, do you have a console log of when you built torchvision? You should see it building C++/CUDA code when you build it. I would recommend cross-referencing the PyTorch dockerfile to double-check that you have all the dependencies installed (including cmake, build-essential, ect)

building_torchvision (144.3 KB)

Here’s the log of the building of torchvision 0.12.0 (when i tried with torch 1.11.0).

In the meantime i tried with nvidia’s L4T Pytorch container and it works just fine ; for the time being it should be enough for me, tough i’ll try to update all the packages you linked.


Building from sources is fun!
I had to change a line in to build torchvision from the sources for orin
from use_nvjpeg = os.getenv(“TORCHVISION_USE_NVJPEG”, “1”) == “1”
to use_nvjpeg = False
around line 150
best regards dieter

Interesting…I haven’t had to do this before as I don’t believe that nvjpeg.h is included in JetPack (on Jetson, the hw-accelerated JPEG codec is provided through GStreamer or L4T Multimedia API). Regardless, you should be able to just run export TORCHVISION_USE_NVJPEG=0 beforehand to avoid editing the source.

1 Like

I’ve been digging into this a bit more and it would seem this error emanates from here in the torchvision code:

Since I’ve been unable to reproduce this, what I would do is recommend adding print statements in there to your locally-installed version (you can find the directory under which it was installed by doing pip3 show torchvision)

For example, try modifying your installed copy of torchvision/ so that it prints out the path to the extension to confirm that it found it:

    lib_path = _get_extension_path("_C")
    print(f"TORCHVISION EXTENSION PATH:  {lib_path}")

(BTW on my system, this is found under /usr/local/lib/python3.8/dist-packages/torchvision-0.15.1a0+42759b1-py3.8-linux-aarch64.egg/torchvision/

Thank you for the advice. NVIDIA JPEG library (nvJPEG) was friendly delivered by Ubuntu.

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