Torchvision Compatibility Issues with PyTorch on Jetson Orin Nano
Issue Overview
Users are experiencing compatibility issues when trying to install and use PyTorch and Torchvision on the Nvidia Jetson Orin Nano developer board. The main symptoms include:
-
Error message during YOLOv8 object detection model training:
"AttributeError: partially initialized module ‘torchvision’ has no attribute ‘extension’ (most likely due to a circular import)" -
Incompatibility between installed Torchvision version (0.19.0) and PyTorch version (torch-2.3.0a0+ebedce2).
-
Attempting to install Torchvision 0.18.0 through pip results in uninstalling the CUDA-enabled PyTorch version and reinstalling a non-CUDA version.
-
Compilation errors when trying to build Torchvision from source, specifically related to PNG handling libraries.
These issues are preventing users from successfully setting up and running machine learning models on their Jetson Orin Nano devices.
Possible Causes
-
Mismatched versions: The pre-built PyTorch and Torchvision packages available through pip are not compatible with the ARM64 architecture of the Jetson platform.
-
Incorrect installation method: Using standard pip install commands instead of the Jetson-specific installation procedures.
-
Missing dependencies: The compilation errors suggest that some required development libraries might be missing from the system.
-
JetPack version mismatch: Using packages or installation methods not compatible with the specific JetPack version installed on the device.
-
Circular import issues: The error message suggests a potential circular import problem within the Torchvision package.
Troubleshooting Steps, Solutions & Fixes
-
Identify your JetPack version:
Before proceeding, determine which JetPack version is installed on your Jetson Orin Nano. This information is crucial for selecting the correct package versions. -
Remove existing incompatible packages:
pip uninstall torch torchvision torchaudio
-
Install the correct PyTorch version:
For JetPack 6.0, use the following command:pip install https://developer.download.nvidia.cn/compute/redist/jp/v60dp/pytorch/torch-2.3.0-cp310-cp310-linux_aarch64.whl
-
Install Torchvision and Torchaudio:
Use these commands for JetPack 6.0:pip install https://developer.download.nvidia.cn/compute/redist/jp/v60dp/pytorch/torchaudio-2.3.0+952ea74-cp310-cp310-linux_aarch64.whl pip install https://developer.download.nvidia.cn/compute/redist/jp/v60dp/pytorch/torchvision-0.18.0a0+6043bc2-cp310-cp310-linux_aarch64.whl
-
If building from source is necessary:
a. Install required dependencies:sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev
b. Clone the Torchvision repository:
git clone --branch v0.18.0 https://github.com/pytorch/vision torchvision
c. Build and install:
cd torchvision python3 setup.py install --user
-
Verify the installation:
After installation, run the following Python commands to ensure CUDA is enabled:import torch print(torch.cuda.is_available()) import torchvision print(torchvision.__version__)
-
If you encounter PNG-related errors during compilation:
Ensure that libpng development files are installed:sudo apt-get install libpng-dev
-
For persistent issues:
Consider using the pre-built L4T PyTorch container provided by NVIDIA, which includes compatible versions of PyTorch, Torchvision, and other related libraries:docker pull nvcr.io/nvidia/l4t-pytorch:r35.2.1-pth2.0-py3
Remember to always use the packages and installation methods specific to your Jetson device and JetPack version. The NVIDIA Developer Forums and official documentation are valuable resources for the most up-to-date information on compatibility and installation procedures.