Skip to content

Commit df4e605

Browse files
committed
add tflite support
1 parent f7ae623 commit df4e605

File tree

5 files changed

+67
-64
lines changed

5 files changed

+67
-64
lines changed

yolox_ros_cpp/README.md

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

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

13-
<!-- ※ ONNXRuntime support CPU or CUDA execute provider.
13+
<!-- ※ ONNXRuntime support CPU or CUDA execute provider. -->
1414

1515
※ Tensorflow Lite support XNNPACK Delegate only.
1616

17-
※ Tensorflow Lite support float model and does not support integer model. -->
17+
※ Tensorflow Lite support float model and does not support integer model.
1818

1919
※ Model convert script is not supported OpenVINO 2022.*
2020

@@ -144,12 +144,11 @@ cd ~/ros2_ws
144144
./src/YOLOX-ROS/weights/tensorrt/convert.bash yolox_tiny 16
145145
```
146146

147-
<!-- #### Tensorflow Lite
147+
#### Tensorflow Lite
148148
```bash
149149
cd ~/ros2_ws
150150

151-
# Download tflite Person Detection model
152-
# https://github.com/Kazuhito00/Person-Detection-using-RaspberryPi-CPU/
151+
# Download tflite Person Detection model: https://github.com/Kazuhito00/Person-Detection-using-RaspberryPi-CPU/
153152
./src/YOLOX-ROS/weights/tflite/download_model.bash
154153
```
155154

@@ -166,20 +165,42 @@ cd ~/ros2_ws
166165
- `./src/YOLOX-ROS/weights/tensorrt/convert.bash yolox_tiny_480x640`
167166

168167
- tflite model copy to weight dir
169-
- `cp resouces_new/saved_model_yolox_tiny_480x640/model_float32.tflite ./src/YOLOX-ROS/weights/tflite/` -->
168+
- `cp resouces_new/saved_model_yolox_tiny_480x640/model_float32.tflite ./src/YOLOX-ROS/weights/tflite/`
170169

171170

171+
<br>
172172

173+
## Build
174+
175+
### OpenVINO
176+
177+
```bash
178+
# build with openvino
179+
source /opt/ros/humble/setup.bash
180+
source /opt/intel/openvino_2021/bin/setupvars.sh
181+
colcon build --cmake-args -DYOLOX_USE_OPENVINO=ON
182+
```
173183

174-
<!-- #### build yolox_ros_cpp with tflite
184+
### TensorRT
185+
186+
```bash
187+
# build with tensorrt
188+
source /opt/ros/humble/setup.bash
189+
colcon build --cmake-args -DYOLOX_USE_TENSORRT=ON
190+
```
191+
192+
### TFLite
193+
194+
**TFLite build**
175195

176-
##### build tflite
177196
https://www.tensorflow.org/lite/guide/build_cmake
178197

179198
Below is an example build script.
180-
Please change `${workspace}` as appropriate for your environment.
199+
Please change `${WORKSPACE}` as appropriate for your environment.
181200
```bash
182-
cd ${workspace}
201+
export WORKSPACE=${HOME}/ws_tflite
202+
mkdir -p ${WORKSPACE}
203+
cd ${WORKSPACE}
183204
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
184205
mkdir tflite_build
185206
cd tflite_build
@@ -192,42 +213,18 @@ cmake ../tensorflow_src/tensorflow/lite \
192213
-DCMAKE_BUILD_TYPE=Release
193214

194215
make -j"$(nproc)"
195-
``` -->
196-
197-
## Build
198-
199-
### OpenVINO
200-
201-
```bash
202-
# build with openvino
203-
source /opt/ros/humble/setup.bash
204-
source /opt/intel/openvino_2021/bin/setupvars.sh
205-
colcon build --cmake-args -DYOLOX_USE_OPENVINO=ON
206216
```
207217

208-
### TensorRT
209-
210218
```bash
211-
# build with tensorrt
212-
source /opt/ros/humble/setup.bash
213-
colcon build --cmake-args -DYOLOX_USE_TENSORRT=ON
219+
colcon build --cmake-args \
220+
-DYOLOX_USE_TFLITE=ON \
221+
-DTFLITE_LIB_PATH=${WORKSPACE}/tflite_build \
222+
-DTFLITE_INCLUDE_DIR=${WORKSPACE}/tensorflow_src/ \
223+
-DABSEIL_CPP_ICLUDE_DIR=${WORKSPACE}/tflite_build/abseil-cpp \
224+
-DFLATBUFFERS_INCLUDE_DIR=${WORKSPACE}/tflite_build/flatbuffers/include
214225
```
215226

216-
<!-- ##### build ros package with tflite
217-
218-
This is build script when tflite built as above.
219-
220-
```bash
221-
# build with tflite
222-
colcon build --symlink-install \
223-
--packages-up-to yolox_ros_cpp \
224-
--cmake-args \
225-
-DYOLOX_USE_TFLITE=ON \
226-
-DTFLITE_LIB_PATH=${workspace}/tflite_build/libtensorflow-lite.so \
227-
-DTFLITE_INCLUDE_DIR=${workspace}/tensorflow_src \
228-
-DABSEIL_CPP_ICLUDE_DIR=${workspace}/tflite_build/abseil-cpp \
229-
-DFLATBUFFERS_INCLUDE_DIR=${workspace}/tflite_build/flatbuffers/include
230-
``` -->
227+
<br>
231228

232229
## Run
233230

@@ -272,28 +269,24 @@ If you want to show image with bounding box drawn, subscribe from host jetson or
272269
# run yolox_tiny
273270
ros2 launch yolox_ros_cpp yolox_tensorrt_jetson.launch.py
274271
```
275-
<!--
276-
### ONNXRuntime
272+
273+
<!-- ### ONNXRuntime
277274
```bash
278275
# run yolox_tiny
279276
ros2 launch yolox_ros_cpp yolox_onnxruntime.launch.py
280-
```
277+
``` -->
281278

282279
### Tensorflow Lite
283280
```bash
284-
# add libtensorflow-lite.so directory path to `LD_LIBRARY_PATH`
285-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${workspace}/tflite_build
286-
287-
# run Person Detection Model
288281
ros2 launch yolox_ros_cpp yolox_tflite.launch.py
289282

290-
# run PINTO_model_zoo model
291-
ros2 launch yolox_ros_cpp yolox_tflite.launch.py \
292-
model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model_float32.tflite \
293-
model_version:=0.1.0 \
294-
num_classes:=80 \
295-
is_nchw:=false
296-
``` -->
283+
# # run PINTO_model_zoo model
284+
# ros2 launch yolox_ros_cpp yolox_tflite.launch.py \
285+
# model_path:=install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model_float32.tflite \
286+
# model_version:=0.1.0 \
287+
# num_classes:=80 \
288+
# is_nchw:=false
289+
```
297290

298291
### Parameter
299292

yolox_ros_cpp/yolox_cpp/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ if(YOLOX_USE_TENSORRT)
5353
set(TARGET_DPENDENCIES CUDA)
5454
endif()
5555

56+
# tflite
57+
if(YOLOX_USE_TFLITE)
58+
set(ENABLE_TFLITE ON)
59+
set(TARGET_SRC src/yolox_tflite.cpp)
60+
set(INCLUDES ${INCLUDES} ${TFLITE_INCLUDE_DIR})
61+
set(INCLUDES ${INCLUDES} ${ABSEIL_CPP_ICLUDE_DIR})
62+
set(INCLUDES ${INCLUDES} ${FLATBUFFERS_INCLUDE_DIR})
63+
endif()
5664

5765
configure_file(
5866
"${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h.in"
@@ -65,12 +73,14 @@ ament_export_dependencies(${TARGET_DPENDENCIES})
6573

6674

6775
if (YOLOX_USE_TENSORRT)
68-
target_link_libraries(yolox_cpp
69-
nvinfer
70-
nvinfer_plugin
71-
nvparsers
72-
nvonnxparser
73-
)
76+
target_link_libraries(yolox_cpp ${TARGET_LIBS})
77+
endif()
78+
79+
if (YOLOX_USE_TFLITE)
80+
target_include_directories(yolox_cpp PUBLIC ${INCLUDES})
81+
target_link_libraries(yolox_cpp ${TFLITE_LIB_PATH}/libtensorflow-lite.so)
82+
ament_export_include_directories(${INCLUDES})
83+
install(DIRECTORY ${TFLITE_LIB_PATH}/ DESTINATION lib)
7484
endif()
7585

7686

yolox_ros_cpp/yolox_param/src/yolox_parameters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ yolox_parameters:
66
model_path:
77
type: string
88
description: "Path to the model file."
9-
default_value: "./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model.tflite"
9+
default_value: "./src/YOLOX-ROS/weights/tflite/model.tflite"
1010
class_labels_path:
1111
type: string
1212
description: "Path to the class labels file."

yolox_ros_cpp/yolox_ros_cpp/launch/yolox_tflite.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def generate_launch_description():
1616
),
1717
DeclareLaunchArgument(
1818
"model_path",
19-
default_value="./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/tflite/model.tflite",
19+
default_value="./src/YOLOX-ROS/weights/tflite/model.tflite",
2020
description="yolox model path."
2121
),
2222
DeclareLaunchArgument(

yolox_ros_cpp/yolox_ros_cpp/src/yolox_ros_cpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace yolox_ros_cpp
8181
#ifdef ENABLE_TFLITE
8282
RCLCPP_INFO(this->get_logger(), "Model Type is tflite");
8383
this->yolox_ = std::make_unique<yolox_cpp::YoloXTflite>(
84-
this->params_.model_path, this->params_.tflite_num_threads_,
84+
this->params_.model_path, this->params_.tflite_num_threads,
8585
this->params_.nms, this->params_.conf, this->params_.model_version,
8686
this->params_.num_classes, this->params_.p6, this->params_.is_nchw);
8787
#else

0 commit comments

Comments
 (0)