Jetson Orin Nano – PyTorch setup and Yolov8

Jetson Orin

In the previous article, how to boot the Jetson Orin Nano from NVMe storage was explained. In this article, the PyTorch installation and running Yolov8 is described. If the setup has not been done yet, refer to the previous article to set it up in advance.

Introducing CUDA

Introduce CUDA.

sudo apt update sudo apt install -y cuda libcudnn8
Code language: Bash (bash)

Introducing other packages

Install other packages required to run Python.

sudo apt install -y python3-pip python3-venv libopenblas-dev
Code language: Bash (bash)

To install PyTorch and other libraries in a venv environment, clone the Yolov8 repository and create a venv virtual environment under it.

git clone cd ultralytics python3 -m venv venv source venv/bin/activate pip install -U pip
Code language: Bash (bash)

Introducing PyTorch

Since we are using Jetson Linux 36.2 (=JetPack 6.0 DP (=Developer Preview)), access the directory with a browser and check for the latest packages.

The latest package at this time was torch-2.2.0a0+81ea7a4.nv24.01-cp310-cp310-linux_aarch64.whl.

Code language: Bash (bash)

Install the downloaded package, as well as numpy.

pip install ./torch-2.2.0a0+81ea7a4.nv24.01-cp310-cp310-linux_aarch64.whl pip install numpy
Code language: Bash (bash)

Check PyTorch is working once. It is successful if you see True and pytorch’s version as shown below.

$ python3 -c "import torch;print(torch.cuda.is_available(), torch.__version__)" True 2.2.0a0+81ea7a4
Code language: Bash (bash)

Introducing PyTorchVision

Install PyTorchVision by referring to the section here. Note that the PyTorchVision version torchvision==0.17 corresponding to PyTorch 2.2.0 should be installed based on

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev git clone --branch v0.17.0 torchvision cd torchvision pip install packaging export BUILD_VERSION=0.17.0 python3 install cd ..
Code language: Bash (bash)

Introducing Yolov8

Follow to install Yolov8.

pip install -e .
Code language: Bash (bash)

Let’s run the Yolov8 segmentation on the webcam video.

yolo predict source=0 show=True
Code language: Bash (bash)

It seems to be working well. The model above seems to be running at about 16FPS.

Finally, the output of pip freeze is posted. If you encounter problems, please refer to the version information below.

$ pip freeze certifi==2024.2.2 charset-normalizer==3.3.2 contourpy==1.2.0 cycler==0.12.1 filelock==3.13.1 fonttools==4.49.0 fsspec==2024.2.0 idna==3.6 Jinja2==3.1.3 kiwisolver==1.4.5 MarkupSafe==2.1.5 matplotlib==3.8.3 mpmath==1.3.0 networkx==3.2.1 numpy==1.26.4 opencv-python== packaging==23.2 pandas==2.2.0 pillow==10.2.0 psutil==5.9.8 py-cpuinfo==9.0.0 pyparsing==3.1.1 python-dateutil==2.8.2 pytz==2024.1 PyYAML==6.0.1 requests==2.31.0 scipy==1.12.0 seaborn==0.13.2 six==1.16.0 sympy==1.12 thop==0.1.1.post2209072238 torch @ file:///home/jetson/torch/ultralytics/torch-2.2.0a0%2B81ea7a4.nv24.01-cp310-cp310-linux_aarch64.whl#sha256=10b9966e419ab76b07912377da299a12ea3c49d310c81ff5af359a1de23e1afb torchvision==0.17.0 tqdm==4.66.2 typing_extensions==4.9.0 tzdata==2024.1 -e git+ urllib3==2.2.0
Code language: Bash (bash)

That’s it!


Installing PyTorch for Jetson Platform - NVIDIA Docs
This guide provides instructions for installing PyTorch for Jetson Platform.
PyTorch for Jetson
Below are pre-built PyTorch pip wheel installers for Jetson Nano, TX1/TX2, Xavier, and Orin with JetPack 4.2 and newer. Download one of the PyTorch binaries f...