< >
Home » NX入门教程软件篇 » NX入门教程软件篇-安装yolov5-ros2包

NX入门教程软件篇-安装yolov5-ros2包

文章说明

  • 本教程主要介绍如何在NVIDIA Jetson Xavier NX上安装yolov5的ros2包
  • 测试环境:NVIDIA Jetson Xavier NX + Ubuntu 20.04 + JetPack 5.0.2 + ROS2 Galactic
  • 测试所用镜像:JP502-xnx-sd-card-image-b231

安装步骤

安装yolov5
  • 安装pip
$ sudo apt update
$ sudo apt install -y python3-pip
$ pip3 install --upgrade pip
  • 下载源码并安装
$ mkdir -p ~/ros2_yolo5_ws/src
$ cd ~/ros2_yolo5_ws/src
$ git clone https://ghproxy.com/https://github.com/EndlessLoops/YOLOv5-ROS
$ git clone https://ghproxy.com/https://github.com/EndlessLoops/bbox_ex_msgs
$ cd ~/ros2_yolo5_ws/src/YOLOv5-ROS/

$ vim requirements.txt
//  注释掉以下两项,该两项将在后面单独安装
# torch>=1.7.0
# torchvision>=0.8.1

# 安装依赖
$ sudo apt install -y libfreetype6-dev
# 安装必要的软件包
$ pip3 install -r requirements.txt
安装PyTorch和Torchvision

ARM aarch64 架构的平台不能直接用pip安装PyTorch和Torchvision,故需要单独源码安装

$ 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/https://github.com/pytorch/vision torchvision
$ cd torchvision
$ sudo python3 setup.py install 
编译软件包
  • 编译
$ cd ~/ros2_yolo5_ws
$ colcon build --symlink-install
$ source ~/ros2_yolo5_ws/install/setup.bash

测试步骤

罗技C270相机测试
  • 启动测试,使用默认的yolov5s.pt模型
$ ros2 launch yolov5_ros yolov5s_simple.launch.py 
D435i相机测试
  • 启动相机
$ ros2 launch realsense2_camera rs_launch.py 
  • 启动yolov5,使用默认的yolov5s.pt模型
$ ros2 launch yolov5_ros yolov5s_simple.launch.py open_webcam:=false image_topic:=/camera/color/image_raw

参考资料

FAQ

Q1
  • 运行例程,出现报错
$ ros2 launch yolov5_ros yolov5s_simple.launch.py 
...
[yolov5_ros-2] RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
[ERROR] [yolov5_ros-2]: process has died [pid 5540, exit code 1, cmd '/home/ubuntu/ros2_yolo5_ws/install/yolov5_ros/lib/yolov5_ros/yolov5_ros --ros-args --params-file /tmp/launch_params_4b_l_knw --params-file /tmp/launch_params_gijbsiek --params-file /tmp/launch_params_r8l3y3eg --params-file /tmp/launch_params_idcszlhq --params-file /tmp/launch_params_2xy9foee --params-file /tmp/launch_params_8dny22_k --params-file /tmp/launch_params_wobzeapf --params-file /tmp/launch_params_8qdcr2tw --params-file /tmp/launch_params_78ugg15c --params-file /tmp/launch_params_niam_8uf --params-file /tmp/launch_params_xl1g08z4 --params-file /tmp/launch_params_tj_vlw0m --params-file /tmp/launch_params_o6kdf36l --params-file /tmp/launch_params_5ml_eq8z'].
A1
  • 检查torch版本,发现torch的1.12.0并没有装成功
$ pip list | grep torch
torch                                  2.0.0
torchvision                          0.13.0a0+da3794e
  • 再重装一下
$ cd ~/tools
$ pip3 install torch-1.12.0a0+2c916ef.nv22.3-cp38-cp38-linux_aarch64.whl
  • 装完再检查下torch版本
$ pip list | grep torch
torch                                 1.12.0a0+2c916ef.nv22.3
torchvision                          0.13.0a0+da3794e

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none