Skip to content

Commit

Permalink
style(pre-commit): autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Aug 23, 2024
1 parent 9d3936d commit 132ff68
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions perception/autoware_tensorrt_rtmdet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ bicycles, etc. in a scene. This package provides a ROS2 interface for RTMDet usi
### 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_msgs/SegmentationMask` | The instance segmentation mask |
| `out/color_mask` | `sensor_msgs/Image` | The colorized image of instance segmentation mask for visualization |
Expand Down Expand Up @@ -64,4 +64,4 @@ archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2212.07784},
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ class TrtRTMDet

~TrtRTMDet();

bool doInference(const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids);
bool doInference(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids);

bool doInferenceWithRoi(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids,
const std::vector<cv::Rect> & roi);
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids, const std::vector<cv::Rect> & roi);

bool doMultiScaleInference(
const cv::Mat & image, ObjectArrays & objects, const std::vector<cv::Rect> & roi);
Expand All @@ -109,7 +111,9 @@ class TrtRTMDet

bool multiScaleFeedforward(const cv::Mat & image, int batch_size, ObjectArrays & objects);

bool feedforward(const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids);
bool feedforward(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids);

void readColorMap(const std::string & color_map_path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <image_transport/image_transport.hpp>
#include <rclcpp/rclcpp.hpp>

#include "autoware_internal_msgs/msg/segmentation_mask.hpp"
#include "autoware_internal_msgs/msg/segmentation_config.hpp"
#include "autoware_internal_msgs/msg/segmentation_mask.hpp"
#include "tier4_perception_msgs/msg/detected_object_with_feature.hpp"
#include "tier4_perception_msgs/msg/detected_objects_with_feature.hpp"
#include "tier4_perception_msgs/msg/feature.hpp"
Expand Down
2 changes: 1 addition & 1 deletion perception/autoware_tensorrt_rtmdet/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<buildtool_export_depend>cudnn_cmake_module</buildtool_export_depend>
<buildtool_export_depend>tensorrt_cmake_module</buildtool_export_depend>

<depend>autoware_perception_msgs</depend>
<depend>autoware_internal_msgs</depend>
<depend>autoware_perception_msgs</depend>
<depend>cuda_utils</depend>
<depend>cv_bridge</depend>
<depend>image_transport</depend>
Expand Down
16 changes: 8 additions & 8 deletions perception/autoware_tensorrt_rtmdet/src/tensorrt_rtmdet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ void TrtRTMDet::preprocess(const std::vector<cv::Mat> & images)
}

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

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

TrtRTMDet::preprocess 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.

bool TrtRTMDet::doInference(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids)
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids)
{
if (!trt_common_->isInitialized()) {
return false;
Expand Down Expand Up @@ -549,8 +550,8 @@ void TrtRTMDet::multiScalePreprocess(const cv::Mat & image, const std::vector<cv
}

bool TrtRTMDet::doInferenceWithRoi(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids,
const std::vector<cv::Rect> & rois)
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids, const std::vector<cv::Rect> & rois)
{
if (!trt_common_->isInitialized()) {
return false;
Expand Down Expand Up @@ -579,7 +580,8 @@ bool TrtRTMDet::doMultiScaleInference(
}

bool TrtRTMDet::feedforward(
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask, std::vector<uint8_t> &class_ids)
const std::vector<cv::Mat> & images, ObjectArrays & objects, cv::Mat & mask,
std::vector<uint8_t> & class_ids)
{
std::vector<void *> buffers = {
input_d_.get(), out_dets_d_.get(), out_labels_d_.get(), out_masks_d_.get()};
Expand Down Expand Up @@ -635,7 +637,7 @@ bool TrtRTMDet::feedforward(
// The intensity of each pixel corresponds to the index of the class_array,
// which stores the class IDs.
mask = cv::Mat(model_input_height_, model_input_width_, CV_8UC3, cv::Scalar(0, 0, 0));
uint8_t pixel_intensity = 1; // 0 is reserved for background
uint8_t pixel_intensity = 1; // 0 is reserved for background
for (size_t batch = 0; batch < batch_size; ++batch) {
for (const auto & object : objects[batch]) {
cv::Mat object_mask(
Expand All @@ -653,9 +655,7 @@ bool TrtRTMDet::feedforward(
int j = position[1];

if (object_mask.at<uchar>(i, j) > static_cast<int>(255 * mask_threshold_)) {
cv::Vec3b color(
pixel_intensity, pixel_intensity,
pixel_intensity);
cv::Vec3b color(pixel_intensity, pixel_intensity, pixel_intensity);
pixel = color;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ TrtRTMDetNode::TrtRTMDetNode(const rclcpp::NodeOptions & node_options)

objects_pub_ = this->create_publisher<tier4_perception_msgs::msg::DetectedObjectsWithFeature>(
"~/out/objects", 1);
mask_pub_ = this->create_publisher<autoware_internal_msgs::msg::SegmentationMask>("~/out/mask", 1);
mask_pub_ =
this->create_publisher<autoware_internal_msgs::msg::SegmentationMask>("~/out/mask", 1);

color_mask_pub_ = image_transport::create_publisher(this, "~/out/color_mask");
debug_image_pub_ = image_transport::create_publisher(this, "~/out/debug_image");
Expand All @@ -97,7 +98,8 @@ void TrtRTMDetNode::onConnect()
{
using std::placeholders::_1;
if (
debug_image_pub_.getNumSubscribers() == 0 && mask_pub_->get_intra_process_subscription_count() == 0 &&
debug_image_pub_.getNumSubscribers() == 0 &&
mask_pub_->get_intra_process_subscription_count() == 0 &&
color_mask_pub_.getNumSubscribers() == 0 && objects_pub_->get_subscription_count() == 0 &&

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

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

TrtRTMDetNode::onConnect has 1 complex conditionals with 4 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();
Expand Down

0 comments on commit 132ff68

Please sign in to comment.