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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: use explicit cast
Signed-off-by: Barış Zeren <baris@leodrive.ai>
StepTurtle committed Dec 3, 2024
commit a7baba91e453f965dde364e3a7cabb69784ea549
6 changes: 3 additions & 3 deletions perception/autoware_tensorrt_rtmdet/src/preprocess.cu
Original file line number Diff line number Diff line change
@@ -51,10 +51,10 @@ __device__ float lerp2d(int f00, int f01, int f10, int f11, float centroid_h, fl
centroid_h = (1 + lroundf(centroid_h) - centroid_h) / 2;

float r0, r1, r;
r0 = lerp1d(f00, f01, centroid_w);
r1 = lerp1d(f10, f11, centroid_w);
r0 = (float)lround(lerp1d(f00, f01, centroid_w));
r1 = (float)lround(lerp1d(f10, f11, centroid_w));

r = lerp1d(r0, r1, centroid_h); //+ 0.00001
r = lerp1d((int)r0, (int)r1, centroid_h);
return r;
}


Unchanged files with check annotations Beta

// Copyright 2024 TIER IV, Inc.

Check warning on line 1 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Overall Code Complexity

This module has a mean cyclomatic complexity of 4.88 across 8 functions. The mean complexity threshold is 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
trt_common_->printProfiling();
}
void TrtRTMDet::preprocess_gpu(const std::vector<cv::Mat> & images)
{
const auto batch_size = images.size();
auto input_dims = trt_common_->getBindingDimensions(0);
input_dims.d[0] = static_cast<int32_t>(batch_size);
for (const auto & image : images) {
// if size of source input has been changed...
int width = image.cols;
int height = image.rows;
if (src_width_ != -1 || src_height_ != -1) {
if (width != src_width_ || height != src_height_) {
// Free cuda memory to reallocate
if (image_buf_h_) {
image_buf_h_.reset();
}
if (image_buf_d_) {
image_buf_d_.reset();
}
}
}
src_width_ = width;
src_height_ = height;
}
if (!image_buf_h_) {
trt_common_->setBindingDimensions(0, input_dims);
scale_width_ = 0;
scale_height_ = 0;
}
const auto input_height = static_cast<float>(input_dims.d[2]);
const auto input_width = static_cast<float>(input_dims.d[3]);
int b = 0;
for (const auto & image : images) {
if (!image_buf_h_) {
scale_width_ = input_width / static_cast<float>(image.cols);
scale_height_ = input_height / static_cast<float>(image.rows);
image_buf_h_ = autoware::cuda_utils::make_unique_host<unsigned char[]>(
image.cols * image.rows * 3 * batch_size, cudaHostAllocWriteCombined);
image_buf_d_ = autoware::cuda_utils::make_unique<unsigned char[]>(
image.cols * image.rows * 3 * batch_size);
}
int index = b * image.cols * image.rows * 3;
// Copy into pinned memory
memcpy(
image_buf_h_.get() + index, &image.data[0],
image.cols * image.rows * 3 * sizeof(unsigned char));
b++;
}
// Copy into device memory
CHECK_CUDA_ERROR(cudaMemcpyAsync(
image_buf_d_.get(), image_buf_h_.get(),
images[0].cols * images[0].rows * 3 * batch_size * sizeof(unsigned char),
cudaMemcpyHostToDevice, *stream_));
// Preprocess on GPU
resize_bilinear_letterbox_nhwc_to_nchw32_batch_gpu(
input_d_.get(), image_buf_d_.get(), static_cast<int32_t>(input_width),
static_cast<int32_t>(input_height), images[0].cols, images[0].rows,
static_cast<int32_t>(batch_size), mean_.data(), std_.data(), *stream_);
}

Check warning on line 216 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

TrtRTMDet::preprocess_gpu has a cyclomatic complexity of 11, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 216 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

TrtRTMDet::preprocess_gpu has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 216 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Deep, Nested Complexity

TrtRTMDet::preprocess_gpu has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
bool TrtRTMDet::do_inference(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
return feedforward(images, objects, mask, class_ids);
}
bool TrtRTMDet::feedforward(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids)
{
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8050
trt_common_->enqueueV3(*stream_);
#else
std::vector<void *> buffers = {
input_d_.get(), out_detections_d_.get(), out_labels_d_.get(), out_masks_d_.get()};
trt_common_->enqueueV2(buffers.data(), *stream_, nullptr);
#endif
const auto batch_size = images.size();
out_detections_h_.reset(new float[batch_size_ * max_detections_ * 5]);
out_labels_h_.reset(new int32_t[batch_size_ * max_detections_]);
out_masks_h_.reset(new float[batch_size_ * 20 * model_input_width_ * model_input_height_]);
CHECK_CUDA_ERROR(cudaMemcpyAsync(
out_detections_h_.get(), out_detections_d_.get(),
sizeof(float) * batch_size_ * max_detections_ * 5, cudaMemcpyDeviceToHost, *stream_));
CHECK_CUDA_ERROR(cudaMemcpyAsync(
out_labels_h_.get(), out_labels_d_.get(), sizeof(int32_t) * batch_size_ * max_detections_,
cudaMemcpyDeviceToHost, *stream_));
CHECK_CUDA_ERROR(cudaMemcpyAsync(
out_masks_h_.get(), out_masks_d_.get(),
sizeof(float) * batch_size_ * 20 * model_input_width_ * model_input_height_,
cudaMemcpyDeviceToHost, *stream_));
cudaStreamSynchronize(*stream_);
// POST PROCESSING
objects.clear();
for (size_t batch = 0; batch < batch_size; ++batch) {
ObjectArray object_array;
for (uint32_t index = 0; index < max_detections_; ++index) {
if (out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 4)] < score_threshold_) {
break;
}
Object object{};
object.mask_index = index;
object.class_id = out_labels_h_[(batch * max_detections_) + index];
object.x1 = static_cast<uint32_t>(
out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 0)] / scale_width_);
object.y1 = static_cast<uint32_t>(
out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 1)] / scale_height_);
object.x2 = static_cast<uint32_t>(
out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 2)] / scale_width_);
object.y2 = static_cast<uint32_t>(
out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 3)] / scale_height_);
object.score = out_detections_h_[(batch * max_detections_ * 5) + ((5 * index) + 4)];
object_array.push_back(object);
}
ObjectArray nms_objects;
nms_sorted_bboxes(object_array, nms_objects, nms_threshold_);
objects.push_back(nms_objects);
}
// Create an instance segmentation mask.
// The mask is an image with the same dimensions as the model input image,
// where each pixel represents the class intensity.
// The intensity of each pixel corresponds to the index of the class_array,
// which stores the class IDs.
mask = cv::Mat(
static_cast<int32_t>(model_input_height_), static_cast<int32_t>(model_input_width_), CV_8UC1,
cv::Scalar(0, 0, 0));
uint8_t pixel_intensity = 1; // 0 is reserved for background
for (size_t batch = 0; batch < batch_size; ++batch) {
for (const auto & object : objects.at(batch)) {
cv::Mat object_mask(
static_cast<int32_t>(model_input_height_), static_cast<int32_t>(model_input_width_), CV_32F,
&out_masks_h_
[(batch * 100 * model_input_width_ * model_input_height_) +
(object.mask_index * model_input_width_ * model_input_height_)]);
double min_val = 0;
double max_val = 0;
cv::minMaxLoc(object_mask, &min_val, &max_val);
object_mask.convertTo(
object_mask, CV_8U, 255.0 / (max_val - min_val), -min_val * 255.0 / (max_val - min_val));
auto process_pixel = [&]([[maybe_unused]] cv::Vec3b & pixel, const int * position) -> void {
int i = position[0];
int j = position[1];
if (object_mask.at<uchar>(i, j) > static_cast<int>(255 * mask_threshold_)) {
mask.at<uint8_t>(i, j) = pixel_intensity;
}
};
mask.forEach<cv::Vec3b>(process_pixel);
class_ids.push_back(color_map_.at(object.class_id).label_id);
pixel_intensity++;
}
}
return true;
}

Check warning on line 326 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Large Method

TrtRTMDet::feedforward has 81 lines, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.

Check warning on line 326 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

TrtRTMDet::feedforward has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
float TrtRTMDet::intersection_over_union(const Object & a, const Object & b)
{
return intersection_area / (a_area + b_area - intersection_area);
}
void TrtRTMDet::nms_sorted_bboxes(
const ObjectArray & input_objects, ObjectArray & output_objects, const float & nms_threshold)
{
std::vector<bool> suppressed(input_objects.size(), false);
for (size_t i = 0; i < input_objects.size(); ++i) {
if (suppressed.at(i)) continue;
const Object & a = input_objects.at(i);
output_objects.push_back(a);
for (size_t j = i + 1; j < input_objects.size(); ++j) {
if (suppressed.at(j)) continue;
const Object & b = input_objects.at(j);
if (intersection_over_union(a, b) > nms_threshold) {
suppressed.at(j) = true;
}
}
}
}

Check warning on line 366 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

TrtRTMDet::nms_sorted_bboxes has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
} // namespace autoware::tensorrt_rtmdet
void TrtRTMDetNode::on_connect()
{
using std::placeholders::_1;
if (
debug_image_pub_.getNumSubscribers() == 0 && mask_pub_->get_subscription_count() == 0 &&
mask_pub_->get_intra_process_subscription_count() == 0 &&
color_mask_pub_.getNumSubscribers() == 0 && objects_pub_->get_subscription_count() == 0 &&

Check warning on line 104 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet_node.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

TrtRTMDetNode::on_connect has 1 complex conditionals with 5 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
objects_pub_->get_intra_process_subscription_count() == 0) {
image_sub_.shutdown();
} else if (!image_sub_) {
}
}
void TrtRTMDetNode::on_image(const sensor_msgs::msg::Image::ConstSharedPtr msg)
{
stop_watch_ptr_->toc("processing_time", true);
cv_bridge::CvImagePtr in_image_ptr;
try {
in_image_ptr = cv_bridge::toCvCopy(msg, msg->encoding);
} catch (cv_bridge::Exception & e) {
RCLCPP_ERROR(this->get_logger(), "cv_bridge exception: %s", e.what());
return;
}
tensorrt_rtmdet::ObjectArrays objects;
cv::Mat mask;
std::vector<uint8_t> class_ids;
if (!trt_rtmdet_->do_inference({in_image_ptr->image}, objects, mask, class_ids)) {
RCLCPP_WARN(this->get_logger(), "Fail to inference");
return;
}
tier4_perception_msgs::msg::DetectedObjectsWithFeature detected_objects_with_feature;
for (const auto & object : objects.at(0)) {
tier4_perception_msgs::msg::DetectedObjectWithFeature detected_object_with_feature;
detected_object_with_feature.feature.roi.width = object.x2 - object.x1;
detected_object_with_feature.feature.roi.height = object.y2 - object.y1;
detected_object_with_feature.feature.roi.x_offset = object.x1;
detected_object_with_feature.feature.roi.y_offset = object.y1;
autoware_perception_msgs::msg::ObjectClassification classification;
classification.label = color_map_[object.class_id].label_id;
classification.probability = object.score;
detected_object_with_feature.object.classification =
std::vector<autoware_perception_msgs::msg::ObjectClassification>{classification};
detected_objects_with_feature.feature_objects.push_back(detected_object_with_feature);
}
detected_objects_with_feature.header = msg->header;
objects_pub_->publish(detected_objects_with_feature);
if (!mask.empty() && !class_ids.empty()) {
if (is_apply_erosion_) apply_erosion(mask, 3);
sensor_msgs::msg::Image::SharedPtr mask_image =
cv_bridge::CvImage(std_msgs::msg::Header(), sensor_msgs::image_encodings::MONO8, mask)
.toImageMsg();
std::vector<autoware_perception_msgs::msg::ObjectClassification> classification;
for (uint8_t class_id : class_ids) {
autoware_perception_msgs::msg::ObjectClassification object_classification;
object_classification.label = class_id;
object_classification.probability = 1.0;
classification.push_back(object_classification);
}
autoware_internal_msgs::msg::SegmentationMask mask_msg;
mask_msg.classification = classification;
mask_msg.image = *mask_image;
mask_msg.header = msg->header;
mask_pub_->publish(mask_msg);
}
if (is_publish_color_mask_) {
cv::Mat color_mask = cv::Mat::zeros(mask.rows, mask.cols, CV_8UC3);
get_colorized_mask(color_map_, mask, color_mask);
sensor_msgs::msg::Image::SharedPtr color_mask_msg =
cv_bridge::CvImage(std_msgs::msg::Header(), sensor_msgs::image_encodings::BGR8, color_mask)
.toImageMsg();
color_mask_msg->header = msg->header;
color_mask_pub_.publish(color_mask_msg);
}
if (is_publish_debug_image_) {
cv::Mat debug_image = in_image_ptr->image.clone();
draw_debug_image(debug_image, mask, objects, color_map_);
sensor_msgs::msg::Image::SharedPtr debug_image_msg =
cv_bridge::CvImage(std_msgs::msg::Header(), sensor_msgs::image_encodings::BGR8, debug_image)
.toImageMsg();
debug_image_msg->header = msg->header;
debug_image_pub_.publish(debug_image_msg);
}
if (debug_publisher_) {
const double processing_time_ms = stop_watch_ptr_->toc("processing_time", true);
const double cyclic_time_ms = stop_watch_ptr_->toc("cyclic_time", true);
const double pipeline_latency_ms =
std::chrono::duration<double, std::milli>(
std::chrono::nanoseconds((this->get_clock()->now() - msg->header.stamp).nanoseconds()))
.count();
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/cyclic_time_ms", cyclic_time_ms);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", processing_time_ms);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/pipeline_latency_ms", pipeline_latency_ms);
}
}

Check warning on line 205 in perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet_node.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

TrtRTMDetNode::on_image has a cyclomatic complexity of 11, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
ColorMap TrtRTMDetNode::read_color_map_file(const std::string & color_map_path)
{
template <typename T>
T get_pixel_value(const cv::Mat & image, int x, int y)
{
if (x < 0 || x >= image.cols || y < 0 || y >= image.rows) {

Check warning on line 36 in perception/autoware_tensorrt_rtmdet/test/test_rtmdet.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

get_pixel_value has 1 complex conditionals with 3 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
throw std::out_of_range("Coordinates are out of image bounds");
}