Skip to content

Commit

Permalink
Merge pull request #54 from fateshelled/dev_cpp
Browse files Browse the repository at this point in the history
Preprocess speed up and some fix
  • Loading branch information
Ar-Ray-code authored Sep 16, 2024
2 parents 037e03c + 659a7d6 commit 612f82f
Show file tree
Hide file tree
Showing 25 changed files with 294 additions and 281 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Check [this URL](./yolox_ros_cpp/README.md).

<!-- - yolox/image_raw : Resized image (`sensor_msgs/Image`) -->

- bounding_boxes: Output BoundingBoxes like darknet_ros_msgs (`bboxes_ex_msgs/BoundingBoxes`)

※ If you want to use `darknet_ros_msgs` , replace `bboxes_ex_msgs` with `darknet_ros_msgs`.
- bounding_boxes (`bboxes_ex_msgs/BoundingBoxes` or `vision_msgs/Detection2DArray`)
- `bboxes_ex_msgs/BoundingBoxes`: Output BoundingBoxes like darknet_ros_msgs
- ※ If you want to use `darknet_ros_msgs` , replace `bboxes_ex_msgs` with `darknet_ros_msgs`.

<!-- ![yolox_topic](images_for_readme/yolox_topic.png) -->

Expand Down
44 changes: 24 additions & 20 deletions weights/onnx/download.bash
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#!/bin/bash

# if $1 is empty
if [ -z "$1" ]; then
echo "Usage: $0 <target-model>"
echo "Target-Models :"
echo "yolox_tiny, yolox_nano, yolox_s, yolox_m, yolox_l, all"
exit 1
fi
MODEL=$1
MODEL_VERSION=0.1.1rc0
SCRIPT_DIR=$(cd $(dirname $0); pwd)
function download {
# if $1 is empty
if [ -z "$1" ]; then
echo "Usage: $0 <target-model>"
echo "Target-Models :"
echo "yolox_tiny, yolox_nano, yolox_s, yolox_m, yolox_l, all"
return
fi
MODEL=$1
MODEL_VERSION=0.1.1rc0
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)

echo $MODEL
if [ "$MODEL" = "all" ]; then
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_tiny.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_nano.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_s.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_m.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_l.onnx -P $SCRIPT_DIR
else
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/$MODEL.onnx -P $SCRIPT_DIR
fi
echo $MODEL
if [ "$MODEL" = "all" ]; then
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_tiny.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_nano.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_s.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_m.onnx -P $SCRIPT_DIR
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/yolox_l.onnx -P $SCRIPT_DIR
else
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/$MODEL_VERSION/$MODEL.onnx -P $SCRIPT_DIR
fi
}

download $1
50 changes: 27 additions & 23 deletions weights/tensorrt/convert.bash
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
#!/bin/bash

# if $1 is empty
if [ -z "$1" ]; then
echo "Usage: $0 <target-model>"
echo "Target-Models : yolox_tiny, yolox_nano, yolox_s, yolox_m, yolox_l"
exit 1
fi
function convert {
# if $1 is empty
if [ -z "$1" ]; then
echo "Usage: $0 <target-model>"
echo "Target-Models : yolox_tiny, yolox_nano, yolox_s, yolox_m, yolox_l"
return
fi

MODEL=$1
SCRIPT_DIR=$(cd $(dirname $0); pwd)
MODEL=$1
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)

echo "Model Name: ${MODEL}"
echo ""
echo "Model Name: ${MODEL}"
echo ""

ONNX_MODEL_PATH=$SCRIPT_DIR/../onnx/$MODEL.onnx
if [ ! -e $ONNX_MODEL_PATH ]; then
$SCRIPT_DIR/../onnx/download.bash $MODEL
fi
ONNX_MODEL_PATH=$SCRIPT_DIR/../onnx/$MODEL.onnx
if [ ! -e $ONNX_MODEL_PATH ]; then
$SCRIPT_DIR/../onnx/download.bash $MODEL
fi

if [ ! -e $ONNX_MODEL_PATH ]; then
echo "[ERROR] Not Found ${ONNX_MODEL_PATH}"
echo "[ERROR] Please check target model name."
exit 1
fi
if [ ! -e $ONNX_MODEL_PATH ]; then
echo "[ERROR] Not Found ${ONNX_MODEL_PATH}"
echo "[ERROR] Please check target model name."
return
fi

/usr/src/tensorrt/bin/trtexec \
--onnx=$SCRIPT_DIR/../onnx/$MODEL.onnx \
--saveEngine=$SCRIPT_DIR/$MODEL.trt \
--fp16 --verbose
/usr/src/tensorrt/bin/trtexec \
--onnx=$SCRIPT_DIR/../onnx/$MODEL.onnx \
--saveEngine=$SCRIPT_DIR/$MODEL.trt \
--fp16 --verbose
}

convert $1
75 changes: 40 additions & 35 deletions yolox_ros_cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Requirements
- ROS2 Iron
- ros-iron-generate-parameter-library
- ros-iron-vision-msgs
- ros-iron-usb-cam
- OpenCV 4.x
- OpenVINO 2024.*
- TensorRT 10.x *
Expand Down Expand Up @@ -30,28 +32,26 @@ git clone --recursive https://github.com/Ar-Ray-code/YOLOX-ROS -b iron
cd ~/ros2_ws

./src/YOLOX-ROS/weights/onnx/download.bash yolox_tiny
# Download onnx file and convert to IR format.
# ./src/YOLOX-ROS/weights/openvino/download.bash yolox_tiny
```

### TensorRT
```bash
cd ~/ros2_ws

# Download onnx model and convert to TensorRT engine.
# 1st arg is model name. 2nd is workspace size.
# 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
### Tensorflow Lite
```bash
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
### PINTO_model_zoo
- Support PINTO_model_zoo model
- Download model using the following script.
- https://github.com/PINTO0309/PINTO_model_zoo/blob/main/132_YOLOX/download_nano.sh
Expand All @@ -77,15 +77,15 @@ cd ~/ros2_ws
# build with openvino
source /opt/ros/humble/setup.bash
source /opt/intel/openvino_2021/bin/setupvars.sh
colcon build --cmake-args -DYOLOX_USE_OPENVINO=ON
colcon build --symlink-install --cmake-args -DYOLOX_USE_OPENVINO=ON
```

### TensorRT

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

### TFLite
Expand Down Expand Up @@ -115,12 +115,13 @@ make -j"$(nproc)"
```

```bash
colcon build --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
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
```

<br>
Expand All @@ -139,10 +140,6 @@ ros2 launch yolox_ros_cpp yolox_openvino.launch.py
# 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"

## run YOLOX-tiny with NCS2
# ros2 launch yolox_ros_cpp yolox_openvino_ncs2.launch.py

```

### TensorRT
Expand All @@ -156,20 +153,20 @@ ros2 launch yolox_ros_cpp yolox_tensorrt.launch.py

```

### Jetson + TensorRT
<!-- ### Jetson + TensorRT
Jetson docker container cannot display GUI.
If you want to show image with bounding box drawn, subscribe from host jetson or other PC.
```bash
# run yolox_tiny
ros2 launch yolox_ros_cpp yolox_tensorrt_jetson.launch.py
```
``` -->

<!-- ### ONNXRuntime
### ONNXRuntime
```bash
# run yolox_tiny
ros2 launch yolox_ros_cpp yolox_onnxruntime.launch.py
``` -->
```

### Tensorflow Lite
```bash
Expand All @@ -188,82 +185,90 @@ ros2 launch yolox_ros_cpp yolox_tflite.launch.py
<details>
<summary>OpenVINO example</summary>

- `model_path`: ./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/openvino/yolox_tiny.xml
- `model_path`: ./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx
- `p6`: false
- `class_labels_path`: ""
- if not set, use coco_names.
- See [here](https://github.com/fateshelled/YOLOX-ROS/blob/dev_cpp/yolox_ros_cpp/yolox_ros_cpp/labels/coco_names.txt) for label format.
- `num_classes`: 80
- `model_version`: 0.1.1rc0
- `openvino/device`: AUTO
- `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

</details>


<details>
<summary>TensorRT example</summary>

- `model_path`: ./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tensorrt/yolox_tiny.trt
- `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
- `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

</details>

<details>
<summary>ONNXRuntime example</summary>


- `model_path`: ./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/onnx/yolox_tiny.onnx
- `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
- `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

</details>

<details>
<summary>Tensorflow Lite example</summary>

- `model_path`: ./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model.tflite
- `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
- `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

</details>

Expand Down
Loading

0 comments on commit 612f82f

Please sign in to comment.