NX入门教程软件篇-安装yolov5
文章说明
- 本教程主要介绍如何在NVIDIA Jetson Xavier NX上安装yolov5
- 测试环境:NVIDIA Jetson Xavier NX + Ubuntu 20.04 + JetPack 5.0.2
- 测试所用镜像:JP502-xnx-sd-card-image-b231
安装步骤
安装yolov5
- 安装pip
- 安装pip和v4l2-camera
$ sudo apt update
$ sudo apt install -y python3-pip
$ pip3 install --upgrade pip
$ sudo apt install ros-galactic-v4l2-camera
- 下载源码并安装
$ cd ~/tools/
$ git clone -b v7.0 https://ghproxy.com/https://github.com/ultralytics/yolov5
$ cd yolov5
$ vim requirements.txt
// 注释掉以下两项,该两项将在后面单独安装
# torch>=1.7.0
# torchvision>=0.8.1
# 安装依赖
$ sudo apt install -y libfreetype6-dev
# 安装必要的软件包
$ pip3 install -r requirements.txt
# 下载模型到yolov5文件下,如果下载不成功可手动下载
$ wget https://ghproxy.com/https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt
安装PyTorch和Torchvision
ARM aarch64 架构的平台不能直接用pip安装PyTorch和Torchvision,故需要单独源码安装
- 安装前需要确定JetPack版本,当前版本L4T 35.1,JetPack即为5.0.2 | JetPack版本信息表
$ cd
$ cat /etc/nv_tegra_release
# R35 (release), REVISION: 1.0, GCID: 31346300, BOARD: t186ref, EABI: aarch64, DATE: Thu Aug 25 18:41:45 UTC 2022
PyTorch v1.12.0
Supported by JetPack 5.0 (L4T R34.1.0) / JetPack 5.0.1 (L4T R34.1.1) / JetPack 5.0.2 (L4T R35.1.0) with Python 3.8
PyTorch v1.12 - torchvision v0.13.0
- 安装torch
$ cd ~/tools
$ sudo apt-get install -y libopenblas-base libopenmpi-dev
$ wget https://developer.download.nvidia.com/compute/redist/jp/v50/pytorch/torch-1.12.0a0+2c916ef.nv22.3-cp38-cp38-linux_aarch64.whl
$ sudo pip3 install torch-1.12.0a0+2c916ef.nv22.3-cp38-cp38-linux_aarch64.whl
- 下载并安装torchvision
$ sudo apt install -y libjpeg-dev zlib1g-dev
$ cd ~/tools
$ git clone --branch v0.13.0 https://ghproxy.com/hhttps://github.com/pytorch/vision torchvision
$ cd torchvision
$ sudo python3 setup.py install
测试步骤
使用示例图片测试
- 启动测试
$ cd ~/tools/yolov5
$ python detect.py --source data/images/ --weights yolov5s.pt --conf 0.4
detect: weights=['yolov5s.pt'], source=data/images/, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.4, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 v7.0-0-g915bbf2 Python-3.8.10 torch-1.12.0a0+2c916ef.nv22.3 CUDA:0 (Xavier, 7505MiB)
Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
image 1/2 /home/ubuntu/tools/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, 58.0ms
image 2/2 /home/ubuntu/tools/yolov5/data/images/zidane.jpg: 384x640 2 persons, 1 tie, 64.5ms
Speed: 1.5ms pre-process, 61.3ms inference, 5.7ms NMS per image at shape (1, 3, 640, 640)
Results saved to runs/detect/exp4
- 测试保存在
~/tools/yolov5/detect/exp4
文件夹下
$ cd ~/tools/yolov5/runs/detect/exp4 && ls
bus.jpg zidane.jpg
$ eog zidane.jpg
使用罗技C270相机测试
- 启动测试
$ cd ~/tools/yolov5
$ python detect.py --source 0 --weights yolov5s.pt
detect: weights=['“weights/yolov5s.pt'], source=0, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 v7.0-0-g915bbf2 Python-3.8.10 torch-1.12.0a0+2c916ef.nv22.3 CUDA:0 (Xavier, 7505MiB)
Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
1/1: 0... Success (inf frames 640x480 at 30.00 FPS)
0: 480x640 (no detections), 6580.3ms
0: 480x640 (no detections), 41.9ms
0: 480x640 (no detections), 56.3ms
参考资料
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号