Skip to content

Latest commit

 

History

History
278 lines (219 loc) · 7.28 KB

README.md

File metadata and controls

278 lines (219 loc) · 7.28 KB

YOLOX-ROS-CPP

Requirements

  • ROS2 Iron
    • ros-iron-generate-parameter-library
    • ros-iron-vision-msgs
    • ros-iron-usb-cam
  • OpenCV 4.x
  • OpenVINO 2024.*
  • TensorRT 10.x *
  • ONNXRuntime *
  • Tensorflow Lite *
  • CUDA 12

※ Either one of OpenVINO or TensorRT or ONNXRuntime or Tensorflow Lite is required.

※ Tensorflow Lite support XNNPACK Delegate only.

※ Tensorflow Lite support float model and does not support integer model.

Clone YOLOX-ROS

cd ~/ros2_ws/src
git clone --recursive https://github.com/Ar-Ray-code/YOLOX-ROS -b iron

Model Convert or Download

OpenVINO・ONNXRuntime

cd ~/ros2_ws

./src/YOLOX-ROS/weights/onnx/download.bash yolox_tiny

TensorRT

cd ~/ros2_ws

# Download onnx model and convert to TensorRT engine.
# argument is model name. set yolox_tiny, yolox_nano, yolox_s, yolox_m or yolox_l.
./src/YOLOX-ROS/weights/tensorrt/convert.bash yolox_tiny

Tensorflow Lite

cd ~/ros2_ws

# Download tflite Person Detection model: https://github.com/Kazuhito00/Person-Detection-using-RaspberryPi-CPU/
./src/YOLOX-ROS/weights/tflite/download_model.bash

PINTO_model_zoo

  • Support PINTO_model_zoo model

  • Download model using the following script.

  • ONNX model copy to weight dir

    • cp resouces_new/saved_model_yolox_tiny_480x640/yolox_tiny_480x640.onnx ./src/YOLOX-ROS/weights/onnx/
  • Convert to TensorRT engine

    • ./src/YOLOX-ROS/weights/tensorrt/convert.bash yolox_tiny_480x640
  • tflite model copy to weight dir

    • cp resouces_new/saved_model_yolox_tiny_480x640/model_float32.tflite ./src/YOLOX-ROS/weights/tflite/

Build

OpenVINO

# build with openvino
source /opt/ros/humble/setup.bash
source /opt/intel/openvino_2021/bin/setupvars.sh
colcon build --symlink-install --cmake-args -DYOLOX_USE_OPENVINO=ON

TensorRT

# build with tensorrt
source /opt/ros/iron/setup.bash
colcon build --symlink-install --cmake-args -DYOLOX_USE_TENSORRT=ON

TFLite

TFLite build

https://www.tensorflow.org/lite/guide/build_cmake

Below is an example build script. Please change ${WORKSPACE} as appropriate for your environment.

export WORKSPACE=${HOME}/ws_tflite
mkdir -p ${WORKSPACE}
cd ${WORKSPACE}
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build
cd tflite_build

cmake ../tensorflow_src/tensorflow/lite \
  -DBUILD_SHARED_LIBS=ON \
  -DTFLITE_ENABLE_INSTALL=OFF \
  -DTFLITE_ENABLE_XNNPACK=ON \
  -DTFLITE_ENABLE_RUY=OFF \
  -DCMAKE_BUILD_TYPE=Release

make -j"$(nproc)"
colcon build --symlink-install \
   --cmake-args \
    -DYOLOX_USE_TFLITE=ON \
    -DTFLITE_LIB_PATH=${WORKSPACE}/tflite_build \
    -DTFLITE_INCLUDE_DIR=${WORKSPACE}/tensorflow_src/ \
    -DABSEIL_CPP_ICLUDE_DIR=${WORKSPACE}/tflite_build/abseil-cpp \
    -DFLATBUFFERS_INCLUDE_DIR=${WORKSPACE}/tflite_build/flatbuffers/include

Run

OpenVINO

ros2 launch yolox_ros_cpp yolox_openvino.launch.py

## run other model
# ros2 launch yolox_ros_cpp yolox_openvino.launch.py \
#     model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/openvino/yolox_s.xml

## run PINTO_model_zoo model (version 0.1.0)
# ros2 launch yolox_ros_cpp yolox_openvino.launch.py \
#     model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/onnx/yolox_tiny_480x640.onnx \
#     model_version:="0.1.0"

TensorRT

ros2 launch yolox_ros_cpp yolox_tensorrt.launch.py

## run PINTO_model_zoo model (version 0.1.0)
# ros2 launch yolox_ros_cpp yolox_tensorrt.launch.py \
#     model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tensorrt/yolox_tiny_480x640.trt \
#     model_version:="0.1.0"

ONNXRuntime

# run yolox_tiny
ros2 launch yolox_ros_cpp yolox_onnxruntime.launch.py

Tensorflow Lite

ros2 launch yolox_ros_cpp yolox_tflite.launch.py

# # run PINTO_model_zoo model (version 0.1.0)
# ros2 launch yolox_ros_cpp yolox_tflite.launch.py \
#     model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model_float32.tflite \
#     model_version:=0.1.0 \
#     num_classes:=80 \
#     is_nchw:=false

Parameter

OpenVINO example
  • model_path: ./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx
  • p6: false
  • class_labels_path: ""
    • if not set, use coco_names.
    • See here for label format.
  • num_classes: 80
  • model_version: 0.1.1rc0
  • openvino_device: AUTO
  • nms: 0.45
  • imshow_isshow: true
  • src_image_topic_name: /image_raw
  • publish_image_topic_name: /yolox/image_raw
  • publish_boundingbox_topic_name: /yolox/bounding_boxes
  • use_bbox_ex_msgs: false
  • publish_resized_image: false
TensorRT example
  • model_path: ../src/YOLOX-ROS/weights/tensorrt/yolox_tiny.trt
  • p6: false
  • class_labels_path: ""
  • num_classes: 80
  • model_version: 0.1.1rc0
  • tensorrt_device: 0
  • conf: 0.3
  • nms: 0.45
  • imshow_isshow: true
  • src_image_topic_name: /image_raw
  • publish_image_topic_name: /yolox/image_raw
  • publish_boundingbox_topic_name: /yolox/bounding_boxes
  • use_bbox_ex_msgs: false
  • publish_resized_image: false
ONNXRuntime example
  • model_path: ./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx
  • p6: false
  • class_labels_path: ""
  • num_classes: 80
  • model_version: 0.1.1rc0
  • onnxruntime_use_cuda: true
  • onnxruntime_use_parallel: false
  • onnxruntime_device_id: 0
  • onnxruntime_inter_op_num_threads: 1
    • if onnxruntime_use_parallel is true, the number of threads used to parallelize the execution of the graph (across nodes).
  • onnxruntime_intra_op_num_threads: 1
    • the number of threads to use to run the model
  • conf: 0.3
  • nms: 0.45
  • imshow_isshow: true
  • src_image_topic_name: /image_raw
  • publish_image_topic_name: /yolox/image_raw
  • publish_boundingbox_topic_name: /yolox/bounding_boxes
  • use_bbox_ex_msgs: false
  • publish_resized_image: false
Tensorflow Lite example
  • model_path: ./src/YOLOX-ROS/weights/tflite/model.tflite
  • p6: false
  • is_nchw: true
  • class_labels_path: ""
  • num_classes: 1
  • model_version: 0.1.1rc0
  • tflite_num_threads: 1
  • conf: 0.3
  • nms: 0.45
  • imshow_isshow: true
  • src_image_topic_name: /image_raw
  • publish_image_topic_name: /yolox/image_raw
  • publish_boundingbox_topic_name: /yolox/bounding_boxes
  • use_bbox_ex_msgs: false
  • publish_resized_image: false

Reference

Reference from YOLOX demo code.