Skip to content

Latest commit

 

History

History
105 lines (88 loc) · 2.9 KB

How_to_build_and_run.md

File metadata and controls

105 lines (88 loc) · 2.9 KB

Ros Requirement

ROS Noetic Ninjemys (Recommanded)

or

ROS Melodic Morenia (Need to build cv_bridge(python3 version))

Clone and Install requirement

mkdir -p catkin_ws_pytorch_yolov5/src
cd catkin_ws_pytorch_yolov5/src
git clone https://github.com/Shua-Kang/ros_pytorch_yolov5.git

# If pytorch gpu is needed, install pytorch with gpu firstly. See https://pytorch.org/get-started/locally/
# Upgrade pip and install requirement
cd ros_pytorch_yolov5/yolov5/
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt

Build in ROS Noetic Ninjemys

Build yolov5 pytorch

cd catkin_ws_pytorch_yolov5
catkin init
catkin build

Build in ROS Melodic Morenia

Build cv_bridge (Ros Melodic require)

The default cv_bridge in ros melodic is python2 version. Follow the instruction to build python3 version.

mkdir -p catkin_ws_cv_bridge/src
cd catkin_ws_cv_bridge/src
git clone https://github.com/ros-perception/vision_opencv.git
cd vision_opencv
# the newer version may require python>3.7
git checkout 1.13.0
cd ..
catkin init
# Instruct catkin to set cmake variables
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
# Instruct catkin to install built packages into install place. It is $CATKIN_WORKSPACE/install folder
catkin config --install
catkin build
# If it has opencv version error, replace opencv4 with opencv3 by pip. See [issue3](https://github.com/Shua-Kang/ros_pytorch_yolov5/issues/3) for more help

Build yolov5 pytorch

cd ros_pytorch_yolov5
catkin init
catkin build

Start

(For ROS Noetic) Launch yolov5_torch Node in One Terminal

cd catkin_ws_pytorch_yolov5
source devel/setup.bash
roslaunch ros_pytorch_yolov5 detector.launch device:=cpu view_img:=True
#or launch with gpu device 0
roslaunch yolov5_torch detector.launch device:=0 view_img:=True
# multi-gpu: roslaunch yolov5_torch detector.launch device:=0,1

(For ROS Melodic) Launch yolov5_torch Node in One Terminal

cd catkin_ws_pytorch_yolov5
source devel/setup.bash
cd catkin_ws_cv_bridge
# using --extend to avoid replace previous source
source install/setup.bash --extend

roslaunch ros_pytorch_yolov5 detector.launch device:=cpu view_img:=True
#or launch with gpu device 0
roslaunch ros_pytorch_yolov5 detector.launch device:=0 view_img:=True
# multi-gpu: roslaunch yolov5_torch detector.launch device:=0,1

Rosbag Play in Another Terminal

cd catkin_ws_pytorch_yolov5
source devel/setup.bash
# download Noraml.bag from https://star-center.shanghaitech.edu.cn/seafile/d/0ea45d1878914077ade5/ as test.bag
rosbag play test.bag

Rviz

remove view_img:=True or set view_img:=False

cd catkin_ws_pytorch_yolov5
source devel/setup.bash
rivz
  1. Add Displays panel.
  2. Set Display type to Image.
  3. Set Image Topic to /detections_image_topic