Setting up CUDA PyTorch & torchvision on NVIDIA Jetson Orin for YOLOv7 GPU Usage.

NVIDIA JETSON ORIN

NVIDIA Jetson AGX Orin modules deliver up to 275 TOPS of AI performance with power configurable between 15W and 60W. This gives you up to 8X the performance of Jetson AGX Xavier in the same compact form factor. Jetson AGX Orin is available in 64GB and 32GB versions.

PyTorch and  torchvision

PyTorch Geometric is a library for deep learning on irregular input data such as graphs, point clouds, and manifolds. Torch vision library is part of the PyTorch project. PyTorch is an open source machine learning framework.

YOLOv7

YOLOv7 is the fastest and most accurate real-time object detection model for computer vision tasks.

Installing pytorch and torchvision

Clone YOLOv7 repo and run test code

If you don,t have python in your system then you can install python following our previous article. Installing pytorch and torchvision in jetson orin is not straightforward as that of our desktop computer or laptop. This is because embedded device usually has arm processor.  In order to run YOLOv7 github repo code https://github.com/WongKinYiu/yolov7 , pytorch and torch vision is needed. You can clone the project to the folder and run required library using requirement.txt file.

git clone https://github.com/WongKinYiu/yolov7

Install all python libraries using command:

pip3 install -r requirements.txt

Run detect code to test dependencies.

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg

Code run successfully but CPU is used which is seen clearly in figure below. You can also check using python by importing torch and checking cud available command.

>>> import torch
>>> torch.cuda.is_available()
False
Screenshots showing CPU for YOLOv7

When visualizing the torch and torch vision command pip list following version is shown at the time of this article writing.

Torch and torchvision version shown
Install Cuda supported library for jetson orin

We have to install separate torch and torch vision libraries. For this we need to install prerequisite libraries and jetpack. By this time latest torch version and torch vision supported by https://pypi.org/project/torchvision/ were 1.13 & 0.14. We are installing torch version 1.11. For this download the whl file using website https://nvidia.box.com/shared/static/ssf2v7pf5i245fk4i0q926hy4imzs2ph.whl from nvidia built for jetson devices. We can also install 1.12 using https://developer.download.nvidia.com/compute/redist/jp/v50/pytorch/torch-1.12.0a0+2c916ef.nv22.3-cp38-cp38-linux_aarch64.whl.

After that install torch using command below.

pip3 install torch-1.11.0-cp38-cp38-linux_aarch64.whl

After that we have to install torch vision version supported by 1.11. For this we have to clone and install tochvision from git hub repo using command below. For 1.12 version torch vision branch should  be v0.13.0

git clone --branch v0.12.0 https://github.com/pytorch/vision torchvision
cd tochvision
pip3 uninstall torhvision
python3 setup.py install --user
After this you can check the torch and torchvision version, which shows.

 

Installed pytorch version for torch and torchvision.

Finally you can see the yolov7 running smoothly using GPU.

Screenshot showing successful run of yolov7 model with torch and torchvision installed using CUDA for GPU.

The purpose of making this tutorial is because, this issues could be headache for developer when working on projects.

About RK Chhetri

RK is the sport lover, who write the content about the sports.

View all posts by RK Chhetri →