Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_tensorrt_rtmdet): add tensorrt rtmdet model #8165

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
983b11e
feat: add tensorrt rtmdet model
StepTurtle Aug 21, 2024
8ff3e28
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
21f656c
fix: pre-commit.ci
StepTurtle Aug 21, 2024
10f7ded
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
c8e462e
chore: add prefix
StepTurtle Aug 21, 2024
7065303
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
972e4f9
chore: update with new message type
StepTurtle Aug 23, 2024
631dd3b
chore: update readme
StepTurtle Aug 23, 2024
914a876
fix: missing language specifier
StepTurtle Aug 25, 2024
7234478
style(pre-commit): autofix
pre-commit-ci[bot] Aug 25, 2024
e34ac64
chore: standard types
StepTurtle Aug 27, 2024
49cf057
chore: use ros 2 debug functions
StepTurtle Aug 27, 2024
92843e4
chore: use smart pointer
StepTurtle Aug 27, 2024
039d2b8
chore: update param names
StepTurtle Aug 29, 2024
58bddd5
chore: add comment to parameters
StepTurtle Aug 29, 2024
e92d985
chore: remove unused variables and functions
StepTurtle Aug 29, 2024
ee67386
chore: update param names
StepTurtle Aug 29, 2024
20b74ab
chore: use const
StepTurtle Aug 29, 2024
d91763b
chore: remove unused parameter
StepTurtle Aug 29, 2024
b79a01d
chore: use safe types
StepTurtle Aug 29, 2024
a3cf757
style(pre-commit): autofix
pre-commit-ci[bot] Aug 27, 2024
4651298
style(pre-commit): autofix
pre-commit-ci[bot] Aug 29, 2024
c2167c0
chore: remove unnecessary initialization
StepTurtle Aug 29, 2024
76d4512
chore: remove unused variables
StepTurtle Aug 29, 2024
4558059
fix: add missing header for mask object
StepTurtle Sep 3, 2024
6d02c76
refactor: replace [] index access with at() for safer bounds checking
StepTurtle Sep 3, 2024
05786a3
chore: change class array with objects classification type
StepTurtle Sep 7, 2024
2943726
style(pre-commit): autofix
pre-commit-ci[bot] Sep 7, 2024
2ee5174
fix: missing topic check
StepTurtle Sep 10, 2024
741d686
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2024
f9592bf
chore: remove two calibration option
StepTurtle Sep 10, 2024
40e5d61
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2024
dd8a8ae
fix: image encoding
StepTurtle Sep 11, 2024
d650e57
style(pre-commit): autofix
pre-commit-ci[bot] Sep 12, 2024
ccbd818
chore: remove unused properties
StepTurtle Sep 19, 2024
e6563b1
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
ec057e0
refactor: remove trt_batched_nms plugin code
StepTurtle Sep 19, 2024
dc4f93d
chore: update calibrator
StepTurtle Sep 19, 2024
ff19a19
docs: add comments
StepTurtle Sep 19, 2024
04d2233
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
d1f1588
chore: update erosion function
StepTurtle Sep 19, 2024
009ba01
Merge branch 'feat/add_tensorrt_rtmdet' of https://github.com/StepTur…
StepTurtle Sep 19, 2024
4b73cfd
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
080aa27
fix: scale issue with cpu pre-process
StepTurtle Sep 19, 2024
1083813
chore: update calibrator image stream
StepTurtle Sep 19, 2024
09a804a
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
b890ddb
feat: add unit test
StepTurtle Sep 23, 2024
862492a
style(pre-commit): autofix
pre-commit-ci[bot] Sep 23, 2024
eb12b97
chore: check linter
StepTurtle Sep 23, 2024
e83eae1
fix: json schema
StepTurtle Sep 23, 2024
602a5c8
fix: add enqueueV3 support
StepTurtle Sep 27, 2024
defd6be
chore: update trt multiplier
StepTurtle Oct 16, 2024
5af114b
Merge branch 'main' into feat/add_tensorrt_rtmdet
amadeuszsz Nov 22, 2024
bfc82be
fix: wrong prefixes
StepTurtle Nov 26, 2024
8189f46
chore: remove duplicated comments
StepTurtle Nov 26, 2024
8f9a2a2
chore: update description
StepTurtle Nov 26, 2024
1cf882e
refactor: remove cpu preprocess
StepTurtle Nov 26, 2024
8b704aa
chore: update test time limit
StepTurtle Nov 26, 2024
d7a1cc5
docs: data information
StepTurtle Nov 26, 2024
309b53f
style(pre-commit): autofix
pre-commit-ci[bot] Nov 26, 2024
feb9792
chore: update msgs type
StepTurtle Nov 26, 2024
f7d8088
fix: spellings
StepTurtle Nov 26, 2024
d94931f
Merge branch 'feat/add_tensorrt_rtmdet' of https://github.com/StepTur…
StepTurtle Nov 26, 2024
1ec2772
style(pre-commit): autofix
pre-commit-ci[bot] Nov 26, 2024
ecfb38b
fix: spelling
StepTurtle Nov 26, 2024
efe859a
chore: add build depend
StepTurtle Nov 27, 2024
116d904
fix: spell check
StepTurtle Nov 27, 2024
955ef6b
style(pre-commit): autofix
pre-commit-ci[bot] Nov 27, 2024
593f5ea
refactor: restructure includes
StepTurtle Nov 28, 2024
26b1528
refactor: remove unused includes
StepTurtle Nov 28, 2024
51e8646
refactor: remove unused variables
StepTurtle Nov 28, 2024
aaf8ef4
style(pre-commit): autofix
pre-commit-ci[bot] Nov 28, 2024
db45f29
refactor: remove redundant declarations
StepTurtle Nov 29, 2024
8b32c19
refactor: remove unused macro
StepTurtle Dec 3, 2024
88a42c1
refactor: use `#pragma unroll`
StepTurtle Dec 3, 2024
fc49031
style(pre-commit): autofix
pre-commit-ci[bot] Dec 3, 2024
a7baba9
refactor: use explicit cast
StepTurtle Dec 3, 2024
fcab262
Merge branch 'main' into feat/add_tensorrt_rtmdet
StepTurtle Dec 5, 2024
3fc38ee
chore: remove redundant cspell
StepTurtle Dec 5, 2024
7dc456f
Merge branch 'main' into feat/add_tensorrt_rtmdet
amadeuszsz Dec 6, 2024
aec027b
fix: pre-commit.ci
StepTurtle Dec 6, 2024
fd778da
refactor: update msg type
StepTurtle Dec 9, 2024
b994b72
fix: wrong topic type
StepTurtle Dec 9, 2024
6b1833c
style(pre-commit): autofix
pre-commit-ci[bot] Dec 9, 2024
e36df2d
refactor: msg type
StepTurtle Dec 12, 2024
d4f02ec
style(pre-commit): autofix
pre-commit-ci[bot] Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build_depends.repos
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ repositories:
type: git
url: https://github.com/autowarefoundation/ament_cmake.git
version: feat/faster_ament_libraries_deduplicate
universe/external/trt_batched_nms:
type: git
url: https://github.com/autowarefoundation/trt_batched_nms.git
version: main
102 changes: 102 additions & 0 deletions perception/autoware_tensorrt_rtmdet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
cmake_minimum_required(VERSION 3.8)
project(autoware_tensorrt_rtmdet)

find_package(autoware_tensorrt_common)
if(NOT ${autoware_tensorrt_common_FOUND})
message(WARNING "The autoware_tensorrt_common package is not found. Please check its dependencies.")
return()
endif()

find_package(autoware_cmake REQUIRED)
autoware_package()

find_package(OpenCV REQUIRED)

include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(WARNING "CUDA is not found. preprocess acceleration using CUDA will not be available.")
endif()

find_package(OpenMP)
if(OpenMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

# tensorrt_rtmdet
ament_auto_add_library(${PROJECT_NAME} SHARED
src/tensorrt_rtmdet.cpp
)

ament_target_dependencies(${PROJECT_NAME}
OpenCV
)

if(CMAKE_CUDA_COMPILER)
# preprocess
cuda_add_library(${PROJECT_NAME}_gpu_preprocess
SHARED
src/preprocess.cu
)

target_include_directories(${PROJECT_NAME}_gpu_preprocess PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

target_link_libraries(${PROJECT_NAME}
${autoware_tensorrt_common_LIBRARIES}
${PROJECT_NAME}_gpu_preprocess
)

else()
target_link_libraries(${PROJECT_NAME}
${autoware_tensorrt_common_LIBRARIES}
)
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE
TENSORRT_VERSION_MAJOR=${TENSORRT_VERSION_MAJOR}
)

# tensorrt_rtmdet_node
ament_auto_add_library(${PROJECT_NAME}_node SHARED
src/tensorrt_rtmdet_node.cpp
)

ament_target_dependencies(${PROJECT_NAME}_node
OpenCV
)

target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}
)

target_compile_definitions(${PROJECT_NAME}_node PRIVATE
TENSORRT_VERSION_MAJOR=${TENSORRT_VERSION_MAJOR}
)

rclcpp_components_register_node(${PROJECT_NAME}_node
PLUGIN "autoware::tensorrt_rtmdet::TrtRTMDetNode"
EXECUTABLE ${PROJECT_NAME}_node_exe
)

if(BUILD_TESTING)
find_package(ament_cmake_ros REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

ament_add_ros_isolated_gtest(test_rtmdet test/test_rtmdet.cpp)
set_tests_properties(test_rtmdet PROPERTIES TIMEOUT 60) # It could take a long time on the first run to create the engine
target_link_libraries(test_rtmdet ${PROJECT_NAME} ${PROJECT_NAME}_node)
target_include_directories(test_rtmdet PRIVATE include)
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
config
test/data
)
70 changes: 70 additions & 0 deletions perception/autoware_tensorrt_rtmdet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# autoware_tensorrt_rtmdet

## Purpose

RTMDet is a real-time instance segmentation model which can be used for detecting objects like cars, pedestrians,
bicycles, etc. in a scene. This package provides a ROS 2 interface for RTMDet using TensorRT.

## Inner-workings / Algorithms

## Inputs / Outputs

### Input

| Name | Type | Description |
| ---------- | ------------------- | --------------- |
| `in/image` | `sensor_msgs/Image` | The input image |

### Output

| Name | Type | Description |
| ----------------- | ---------------------------------------------------- | ------------------------------------------------------------------- |
| `out/objects` | `tier4_perception_msgs/DetectedObjectsWithFeature` | The detected objects with 2D bounding boxes and scores |
| `out/mask` | `autoware_internal_perception_msgs/SegmentationMask` | The instance segmentation mask |
| `out/color_mask` | `sensor_msgs/Image` | The colorized image of instance segmentation mask for visualization |
| `out/debug_image` | `sensor_msgs/Image` | The image with 2D bounding boxes for visualization |

## Parameters

{{ json_to_markdown("perception/autoware_tensorrt_rtmdet/schema/rtmdet.schema.json") }}

## Assumptions / Known limits

## Onnx model

A sample model is provided in `autoware_data` folder by ansible script on env preparation stage. If you cannot find the
model, you follow instructions from the
[link](https://github.com/autowarefoundation/autoware/tree/main/ansible/roles/artifacts) to download the model.

The shared model was trained by open-mmlab using the COCO dataset. For more details,
see [link](https://github.com/open-mmlab/mmdetection/tree/3.x/configs/rtmdet#instance-segmentation).

### Package acceptable model generation
StepTurtle marked this conversation as resolved.
Show resolved Hide resolved

Users can generate their own model using official RTMDet repository. Please refer to the
[official repository](https://github.com/open-mmlab/mmdetection/tree/3.x/configs/rtmdet#rtmdet-an-empirical-study-of-designing-real-time-object-detectors)

## Label file

A sample label file (named label.txt) and instance segmentation color map file (name color_map.csv) are also
downloaded automatically during env preparation process.

These files are used to map the class index to class name and color respectively.

## Reference repositories

- <https://github.com/open-mmlab/mmdetection/tree/3.x/configs/rtmdet#rtmdet-an-empirical-study-of-designing-real-time-object-detectors>

## Citation

```bibtex
@misc{lyu2022rtmdetempiricalstudydesigning,
title={RTMDet: An Empirical Study of Designing Real-Time Object Detectors},
author={Chengqi Lyu and Wenwei Zhang and Haian Huang and Yue Zhou and Yudong Wang and Yanyi Liu and Shilong Zhang and Kai Chen},
year={2022},
eprint={2212.07784},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2212.07784},
}
```
23 changes: 23 additions & 0 deletions perception/autoware_tensorrt_rtmdet/config/rtmdet.param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**:
StepTurtle marked this conversation as resolved.
Show resolved Hide resolved
ros__parameters:
is_publish_debug_image: false

is_publish_color_mask: false

# cspell: ignore libtrt
model_path: "$(var data_path)/tensorrt_rtmdet/$(var model_name).onnx"
color_map_path: "$(var data_path)/tensorrt_rtmdet/color_map.csv"
plugin_paths: [ "$(find-pkg-prefix trt_batched_nms)/lib/libtrt_batched_nms_plugin.so" ]
input_image_mean: [ 103.53, 116.28, 123.675 ]
input_image_std_dev: [ 57.375, 57.12, 58.395 ]
score_threshold: 0.3
nms_threshold: 0.3
mask_threshold: 0.7
precision: "fp16"
dla_core_id: -1
quantize_first_layer: false
quantize_last_layer: false
profile_per_layer: false
clip_value: 6.0
apply_erosion: false
calibration_image_list_path: ""
Loading
Loading