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 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
60bb4e1
feat: add tensorrt rtmdet model
StepTurtle Aug 21, 2024
0cadb80
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
2c468a1
fix: pre-commit.ci
StepTurtle Aug 21, 2024
f26073e
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
cc44e4e
chore: add prefix
StepTurtle Aug 21, 2024
8ac7f21
style(pre-commit): autofix
pre-commit-ci[bot] Aug 21, 2024
7645aed
chore: update with new message type
StepTurtle Aug 23, 2024
f50f19c
chore: update readme
StepTurtle Aug 23, 2024
a65eb73
fix: missing language specifier
StepTurtle Aug 25, 2024
4dc5802
style(pre-commit): autofix
pre-commit-ci[bot] Aug 25, 2024
ee14ad1
chore: standard types
StepTurtle Aug 27, 2024
1f46a6d
chore: use ros 2 debug functions
StepTurtle Aug 27, 2024
a8f9b66
chore: use smart pointer
StepTurtle Aug 27, 2024
6fb088d
chore: update param names
StepTurtle Aug 29, 2024
69a43ee
chore: add comment to parameters
StepTurtle Aug 29, 2024
ff2cfd0
chore: remove unused variables and functions
StepTurtle Aug 29, 2024
0508dff
chore: update param names
StepTurtle Aug 29, 2024
7e545a9
chore: use const
StepTurtle Aug 29, 2024
5e36db2
chore: remove unused parameter
StepTurtle Aug 29, 2024
0ccca7b
chore: use safe types
StepTurtle Aug 29, 2024
8f8a20a
style(pre-commit): autofix
pre-commit-ci[bot] Aug 27, 2024
7120220
style(pre-commit): autofix
pre-commit-ci[bot] Aug 29, 2024
d36f1ec
chore: remove unnecessary initialization
StepTurtle Aug 29, 2024
ff112eb
chore: remove unused variables
StepTurtle Aug 29, 2024
d8bcc16
fix: add missing header for mask object
StepTurtle Sep 3, 2024
4802802
refactor: replace [] index access with at() for safer bounds checking
StepTurtle Sep 3, 2024
08e0883
chore: change class array with objects classification type
StepTurtle Sep 7, 2024
f1cc27b
style(pre-commit): autofix
pre-commit-ci[bot] Sep 7, 2024
7ba0e29
fix: missing topic check
StepTurtle Sep 10, 2024
63e7f1d
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2024
6ca58cd
chore: remove two calibration option
StepTurtle Sep 10, 2024
71a891c
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2024
498feba
fix: image encoding
StepTurtle Sep 11, 2024
1a0b884
style(pre-commit): autofix
pre-commit-ci[bot] Sep 12, 2024
d123b22
chore: remove unused properties
StepTurtle Sep 19, 2024
24593e9
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
6eea661
refactor: remove trt_batched_nms plugin code
StepTurtle Sep 19, 2024
9be3558
chore: update calibrator
StepTurtle Sep 19, 2024
8cb7b59
docs: add comments
StepTurtle Sep 19, 2024
a69193e
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
8b47d32
chore: update erosion function
StepTurtle Sep 19, 2024
7006e89
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
941d393
fix: scale issue with cpu pre-process
StepTurtle Sep 19, 2024
7f52795
chore: update calibrator image stream
StepTurtle Sep 19, 2024
553a41b
style(pre-commit): autofix
pre-commit-ci[bot] Sep 19, 2024
22936b7
feat: add unit test
StepTurtle Sep 23, 2024
b2669bd
style(pre-commit): autofix
pre-commit-ci[bot] Sep 23, 2024
c08a619
chore: check linter
StepTurtle Sep 23, 2024
61f2e22
fix: json schema
StepTurtle Sep 23, 2024
43a02ef
fix: add enqueueV3 support
StepTurtle Sep 27, 2024
e48ac97
chore: update trt multiplier
StepTurtle Oct 16, 2024
4d0256b
fix: wrong prefixes
StepTurtle Nov 26, 2024
2827dcb
chore: remove duplicated comments
StepTurtle Nov 26, 2024
6bd81f1
chore: update description
StepTurtle Nov 26, 2024
3e356ec
refactor: remove cpu preprocess
StepTurtle Nov 26, 2024
0c84c27
chore: update test time limit
StepTurtle Nov 26, 2024
cfa8777
docs: data information
StepTurtle Nov 26, 2024
d8c207c
style(pre-commit): autofix
pre-commit-ci[bot] Nov 26, 2024
512175c
chore: update msgs type
StepTurtle Nov 26, 2024
2660c1a
fix: spellings
StepTurtle Nov 26, 2024
47c2498
style(pre-commit): autofix
pre-commit-ci[bot] Nov 26, 2024
cec1209
fix: spelling
StepTurtle Nov 26, 2024
521713f
chore: add build depend
StepTurtle Nov 27, 2024
b1b3508
fix: spell check
StepTurtle Nov 27, 2024
1ae6cb5
style(pre-commit): autofix
pre-commit-ci[bot] Nov 27, 2024
7a6620a
refactor: restructure includes
StepTurtle Nov 28, 2024
99d13fc
refactor: remove unused includes
StepTurtle Nov 28, 2024
b9772aa
refactor: remove unused variables
StepTurtle Nov 28, 2024
4f645ee
style(pre-commit): autofix
pre-commit-ci[bot] Nov 28, 2024
d59f2de
refactor: remove redundant declarations
StepTurtle Nov 29, 2024
646cf9b
refactor: remove unused macro
StepTurtle Dec 3, 2024
c774677
refactor: use `#pragma unroll`
StepTurtle Dec 3, 2024
0ff8805
style(pre-commit): autofix
pre-commit-ci[bot] Dec 3, 2024
72ad4d4
refactor: use explicit cast
StepTurtle Dec 3, 2024
fb13a8e
chore: remove redundant cspell
StepTurtle Dec 5, 2024
a8c8d47
fix: pre-commit.ci
StepTurtle Dec 6, 2024
cc96771
refactor: update msg type
StepTurtle Dec 9, 2024
01ee1a6
fix: wrong topic type
StepTurtle Dec 9, 2024
f573b7e
style(pre-commit): autofix
pre-commit-ci[bot] Dec 9, 2024
d881c3a
refactor: msg type
StepTurtle Dec 12, 2024
b1b0ad5
style(pre-commit): autofix
pre-commit-ci[bot] Dec 12, 2024
f744a8a
refactor(autoware_tensorrt_rtmdet): upgrade to new autoware_tensorrt_…
amadeuszsz Jan 27, 2025
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
105 changes: 105 additions & 0 deletions perception/autoware_tensorrt_rtmdet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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()

# TODO(amadeuszsz): Remove -Wno-deprecated-declarations once removing implicit quantization
add_compile_options(-Wno-deprecated-declarations)

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