PyTorch for Jetson

I found problem as below when install pytorch 1.8 & torchvision 0.9.0. Kindly advice what could be wrong.
$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
'>>> import torch
'>>> import torchvision
/home/vpd03/.local/lib/python3.6/site-packages/torchvision/io/image.py:11: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")
'>>>

Hi @ramchuen, I’ve been unable to reproduce this - can you try installing libpng and libjpeg with apt? https://github.com/pytorch/vision/issues/5413#issuecomment-1039234856

thank you for your reply.
if you mean libpng-dev and libjpeg-dev. yes I can install them with no error.
my jetson more detail as below…
jetpack = 4.6 [L4T 32.6.1]
cudnn = 8.2.1.32
cuda = 10.2.300
opencv = 4.5

Hi @ramchuen, I’m not sure what causes the error, whether it is some image library package version or what. Are you able to use l4t-pytorch container, which already has torch/torchvision installed?

Hi @dusty_nv, could you please suggest, when pytorch for JetPack 5.0.2 can be available to download?Thanks in advance!

Hi @shahizat, you can use the JetPack 5.x wheels from here: https://developer.download.nvidia.com/compute/redist/jp/v50/pytorch/

1 Like

I tried to install PyTorch 1.12 with python = 3.8 on a recently purchased Jetson Orin AGX devkit.

$ cat /etc/nv_tegra_release

returns:

R35 (release), REVISION: 1.0, GCID: 31250864, BOARD: t186ref, EABI: aarch64, DATE: Thu Aug 11 03:40:29 UTC 2022

After installing Jetpack,

$ sudo apt-cache show nvidia-jetpack

returns:

Package: nvidia-jetpack
Version: 5.0.2-b231
Architecture: arm64
Maintainer: NVIDIA Corporation
Installed-Size: 194
Depends: nvidia-jetpack-runtime (= 5.0.2-b231), nvidia-jetpack-dev (= 5.0.2-b231)
Homepage: http://developer.nvidia.com/jetson
Priority: standard
Section: metapackages
Filename: pool/main/n/nvidia-jetpack/nvidia-jetpack_5.0.2-b231_arm64.deb

I followed instructions given in this link. PyTorch seems to be successfully installed:

Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import torch
>>> print (torch._version_)
1.12.0a0+84d1cb9.nv22.4
>>> print (torch._file_)
/home/nvidia/venvs/myenv/lib/python3.8/site-packages/torch/init.py

I then installed Torchvision using pip:

$ pip install torchvision==0.13.0

Unfortunately it didn’t work:

Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import torchvision
/home/nvidia/venvs/myenv/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}")

1 Like

I’m not sure if installing torchvision just from pip will work - you may need to build it from source so it actually builds with CUDA enabled.

If you continue having issues with it, I recommend trying the l4t-pytorch container which already has PyTorch+torchvision installed. You could use nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3 for JetPack 5.0.2

1 Like

ok, thanks for one more time!

Compiling from source worked:

$ git clone --branch v0.13.0 https://github.com/pytorch/vision torchvision
$ cd torchvision/
$ export BUILD_VERSION=0.13.0
$ python3 setup.py install

Hello I already install pytorch and torchvision but when I import torchvision I got this error:

>>> import torchvision
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jetson/.local/lib/python3.6/site-packages/torchvision-0.9.0-py3.6-linux-aarch64.egg/torchvision/__init__.py", line 7, in <module>
    from torchvision import datasets
  File "/home/jetson/.local/lib/python3.6/site-packages/torchvision-0.9.0-py3.6-linux-aarch64.egg/torchvision/datasets/__init__.py", line 1, in <module>
    from .lsun import LSUN, LSUNClass
  File "/home/jetson/.local/lib/python3.6/site-packages/torchvision-0.9.0-py3.6-linux-aarch64.egg/torchvision/datasets/lsun.py", line 2, in <module>
    from PIL import Image
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/home/jetson/.local/lib/python3.6/site-packages/Pillow-9.2.0-py3.6-linux-aarch64.egg/PIL/Image.py", line 52, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1131, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1112, in _legacy_get_spec
  File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 544, in spec_from_file_location
  File "/home/jetson/.local/lib/python3.6/site-packages/Pillow-9.2.0-py3.6-linux-aarch64.egg/PIL/_deprecate.py", line 1
SyntaxError: future feature annotations is not defined

How can you help me please?
thank you

Hi @BunchhatKh, can you try running this: pip3 install 'pillow<9'

2 Likes

Thank you now it work

sorry i guess i meet some problems , its jetpack 4.6 on my jetson xavier nx platform.
but when i install torch1.10.0 following above steps,i got this when verification:
torch.cuda.is_available() —> false.
i use jtop and i can see its cuda 10.2.300, cudnn 8.2.1.32.
i dont know how to resolve after trying many methods.
when i run “nvidia-setting” , i got “can not load nvidia driver”
and when i run ./deviceQuery to verify cuda , i got “no cuda-capable device is detected”
but in jtop i can see cuda version. so i think if some problems with nvidia driver, but i cant find jetson nx’s any driver. PLS help me. thanks

Hi @dusty_nv, is that possible to install pytorch below 1.11 on the jetpack 5.0.2, since I am experiencing issues with newer versions?

Sucessfully installed torchvision from source on top of torch 1.13 installed from wheel.
Orin devkit 5.02. Only set up flag for CUDA before building:

export FORCE_CUDA=1
python3 setup.py install --user

Hi @shahizat, that PyTorch 1.11 wheel can be installed on JetPack 5.0.2 as well. I’ve not tried building PyTorch < 1.11 for JetPack 5.x

Hi @user46852, there is no nvidia-settings program for Jetson. If you installed the nvidia graphics drivers from Ubuntu apt repo, I would recommend re-flashing your device as these shouldn’t be installed. The CUDA deviceQuery program not working indicates there is some driver issue with your Jetson’s environment.

thanks for your anwser, i want to ask one more question. Will the driver be installed with CUDA?
In other words, can I reinstall another version of CUDA to solve my problem about driver?

Or how can i reinstall my driver through bash command.If there are other ways, I don’t want to solve the problem by re-flashing my device.

The Jetson integrated GPU driver comes from the low-level L4T board support package (BSP). Unlike desktop/PC it doesn’t come from CUDA Toolkit. I’m not entirely sure how to re-install it without re-flashing. These are the nvidia-l4t apt packages for JetPack 4.6 though that you could try re-installing (after backing up your work):

$ apt-cache search nvidia-l4t
nvidia-l4t-3d-core - NVIDIA GL EGL Package
nvidia-l4t-apt-source - NVIDIA L4T apt source list debian package
nvidia-l4t-bootloader - NVIDIA Bootloader Package
nvidia-l4t-camera - NVIDIA Camera Package
nvidia-l4t-configs - NVIDIA configs debian package
nvidia-l4t-core - NVIDIA Core Package
nvidia-l4t-cuda - NVIDIA CUDA Package
nvidia-l4t-firmware - NVIDIA Firmware Package
nvidia-l4t-gputools - NVIDIA dgpu helper Package
nvidia-l4t-graphics-demos - NVIDIA graphics demo applications
nvidia-l4t-gstreamer - NVIDIA GST Application files
nvidia-l4t-init - NVIDIA Init debian package
nvidia-l4t-initrd - NVIDIA initrd debian package
nvidia-l4t-jetson-io - NVIDIA Jetson.IO debian package
nvidia-l4t-jetson-multimedia-api - NVIDIA Jetson Multimedia API is a collection of lower-level APIs that support flexible application development.
nvidia-l4t-kernel - NVIDIA Kernel Package
nvidia-l4t-kernel-dtbs - NVIDIA Kernel DTB Package
nvidia-l4t-kernel-headers - NVIDIA Linux Tegra Kernel Headers Package
nvidia-l4t-libvulkan - NVIDIA Vulkan Loader Package
nvidia-l4t-multimedia - NVIDIA Multimedia Package
nvidia-l4t-multimedia-utils - NVIDIA Multimedia Package
nvidia-l4t-oem-config - NVIDIA OEM-Config Package
nvidia-l4t-tools - NVIDIA Public Test Tools Package
nvidia-l4t-wayland - NVIDIA Wayland Package
nvidia-l4t-weston - NVIDIA Weston Package
nvidia-l4t-x11 - NVIDIA X11 Package
nvidia-l4t-xusb-firmware - NVIDIA USB Firmware Package

If you have more problems with it, I would create a new topic about the CUDA deviceQuery not working, or just re-flash your device before spending a lot of time on it.