PyTorch for Jetson

Hi @Raymond_456, I haven’t tried to build this older version of PyTorch for JetPack 5.0, so JetPack 5.0’s newer CUDA version may have required some updates in PyTorch. I think the first version I built for it was PyTorch 1.11.

Is anyone installed torchvision for pytorch 1.11? which version you used?

I’m using torchvision 0.12 for PyTorch 1.11, and haven’t encountered this error. I ran this test code which uses the same torchvision.ops.nms function, and it runs fine here and doesn’t throw the exception.

import torch
import torchvision

def test_nms(N=128):
    boxes = []
    scores = []
    
    for n in range(N):
        boxes.append((n, n+1, n, n+1))
        scores.append(n)

    boxes = torch.Tensor(boxes)
    scores = torch.Tensor(scores)
    indices = torchvision.ops.nms(boxes, scores, 0.5)
    
test_nms()

I am running the exact same code you copied and it gives me error:
python3 test.py
/home/x1demo/.local/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")
Traceback (most recent call last):
File “test.py”, line 16, in
test_nms()
File “test.py”, line 14, in test_nms
indices = torchvision.ops.nms(boxes, scores, 0.5)
File “/home/x1demo/.local/lib/python3.8/site-packages/torchvision/ops/boxes.py”, line 39, in nms
_assert_has_ops()
File “/home/x1demo/.local/lib/python3.8/site-packages/torchvision/extension.py”, line 33, in _assert_has_ops
raise RuntimeError(
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.

should I reinstall my torchvision from the github?

Yes you could try that or try using the l4t-pytorch container. If you could save the build log from when you build torchvision that could be helpful to see any errors.

would you please tell me what exact branch of torchvision I need to install from github? I installed torch1.11 from * Python 3.8 - torch-1.11.0-cp38-cp38-linux_aarch64.whl

For PyTorch 1.11, I am using the v0.12.0 tag of torchvision: https://github.com/pytorch/vision/tree/v0.12.0

Thanks for your help I flash the orin and install the new jetpack 5.0.1
then I installed torch 1.11
then the torchvision 0.12.0
and it worked.

HI! I ran into a problem during the installation of torchvision. I’m an Jetson NX With Jetpack 4.6.1. Installed PyTorch 1.10 without any problems but I’m getting the following message during torchvision install. Any help what might be causing this?

gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory
error: command ‘/usr/local/cuda/bin/nvcc’ failed with exit status 1

Hmm, can you try running sudo apt-get install build-essential ?

Then make sure you can do:

$ gcc --version
$ g++ --version

Thank you for the answer. Already tried build-essential previously, it’s up to date.
gcc version is 8.4.0
g++ version is 7.5.0

Nevermind, sorry for the silly question. Received the device from someone else, and found it strange that gcc and g++ versions were different. Used same main versions and now it works.

I too had similar problem as @user22290 after installing @dusty_nv 's torch-1.11.0-cp38-cp38 wheel on Xavier NX devkit with JP 5.01, no pip torchvision version worked, only after I built it from source it works now.

could you provide the exact lines of code you use for building both torch1.11 and torchvision0.12.0 on jetson agx 5.0.1DP?

Hi @rodrigo.sanchez, the code changes I used to build PyTorch 1.11 are here:

pytorch-1-11-jetpack-5-0.patch

torchvision didn’t require code changes to build/run.

Hi,whitch Jetpack 4.6.2[L4T R32.7.2] version of the adapter pytorch.
I only could see Jetpack 4.6.1[L4T R32.6.1].
I accept you received!!! Thank you!!!

Hi @18660039930, you can use any of the wheels that say for JetPack 4.6.1 (L4T R32.6.1).

Hey Nvidia expert:
I have tired the whl you provided but all could not work completely.

I am using nvidia Xavier NX with tegra system, cuda= 10.2, jetpack=4.6 (L4T 32.6.1), archetecture: aarch64, python: 3.8.0

Could u kindly provide me a link for a working whl file for torch and torchvision ? Ideally, the version for torch should be higher than 1.7 because that is the requirement for the program i would like to run

thank u. stuck here for weeks

Hi @xsun0054, the PyTorch wheels that we provide are built for the default version of Python3 that ships with Ubuntu, and on JetPack 4.x that’s Ubuntu 18.04 and Python 3.6. So for Python 3.8, you would need to build the wheel yourself.

Here’s a post about building PyTorch for Python 3.8 though: