Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 18 additions & 12 deletions perception/autoware_traffic_light_classifier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
${CUDA_INCLUDE_DIRS}
)

ament_auto_add_library(traffic_light_classifier_nodelet SHARED
ament_auto_add_library(${PROJECT_NAME} SHARED
src/classifier/color_classifier.cpp
src/classifier/cnn_classifier.cpp
src/traffic_light_classifier_node.cpp
src/traffic_light_classifier_process.cpp
)
target_link_libraries(traffic_light_classifier_nodelet
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBRARIES}
${NVINFER}
${NVONNXPARSER}
Expand All @@ -92,7 +93,7 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
${CUDNN_LIBRARY}
stdc++fs
)
rclcpp_components_register_node(traffic_light_classifier_nodelet
rclcpp_components_register_node(${PROJECT_NAME}
PLUGIN "autoware::traffic_light::TrafficLightClassifierNodelet"
EXECUTABLE traffic_light_classifier_node
)
Expand All @@ -101,6 +102,7 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
src/classifier/cnn_classifier.cpp
src/classifier/color_classifier.cpp
src/traffic_light_classifier_node.cpp
src/traffic_light_classifier_process.cpp
src/single_image_debug_inference_node.cpp
)
target_link_libraries(single_image_debug_inference_node
Expand All @@ -120,11 +122,6 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
EXECUTABLE single_image_debug_inference
)

ament_auto_package(INSTALL_TO_SHARE
launch
config
)

else()
message(STATUS "CUDA and/or TensorRT were not found. build only color classifier")

Expand All @@ -135,6 +132,7 @@ else()
ament_auto_add_library(${PROJECT_NAME} SHARED
src/classifier/color_classifier.cpp
src/traffic_light_classifier_node.cpp
src/traffic_light_classifier_process.cpp
)
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBRARIES}
Expand All @@ -145,9 +143,17 @@ else()
EXECUTABLE traffic_light_classifier_node
)

ament_auto_package(INSTALL_TO_SHARE
launch
config
)
endif()

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_auto_add_gtest(test_utils
test/test_utils.cpp
)
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
config
test/test_data
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
precision: fp16
mean: [123.675, 116.28, 103.53]
std: [58.395, 57.12, 57.375]
backlight_threshold: 0.85
over_exposure_threshold: 0.85
under_exposure_threshold: -0.83
classifier_type: 1
traffic_light_type: 0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
precision: fp16
mean: [123.675, 116.28, 103.53]
std: [58.395, 57.12, 57.375]
backlight_threshold: 0.85
over_exposure_threshold: 0.85
under_exposure_threshold: -0.83
classifier_type: 1
traffic_light_type: 1
2 changes: 2 additions & 0 deletions perception/autoware_traffic_light_classifier/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>wget</buildtool_depend>

<build_depend>ament_cmake_gtest</build_depend>
<build_depend>autoware_cmake</build_depend>

<depend>autoware_cuda_dependency_meta</depend>
<depend>autoware_cuda_utils</depend>
<depend>autoware_tensorrt_classifier</depend>
<depend>autoware_tensorrt_common</depend>
<depend>autoware_traffic_light_utils</depend>
<depend>autoware_utils</depend>
<depend>cv_bridge</depend>
<depend>image_transport</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
},
"default": [58.395, 57.12, 57.375]
},
"backlight_threshold": {
"over_exposure_threshold": {
"type": "number",
"description": "If the intensity get grater than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much higher, the node only overwrites in the harsher backlight situations. Therefore, If you wouldn't like to use this feature set this value to `1.0`. The value can be `[0.0, 1.0]`. The confidence of overwritten signal is set to `0.0`.",
"description": "If the intensity get grater than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much higher, the node only overwrites in the over exposure situations. Therefore, If you wouldn't like to use this feature set this value to `1.0`. The value can be `[0.0, 1.0]`. The confidence of overwritten signal is set to `0.0`.",
"default": 0.85
},
"under_exposure_threshold": {
"type": "number",
"description": "If the intensity get lesser than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much lesser, the node only overwrites in the under exposure situations. Therefore, If you wouldn't like to use this feature set this value to `-1.0`. The confidence of overwritten signal is set to `0.0`.",
"default": -0.83
},
"classifier_type": {
"type": "integer",
"description": "Type of classifier used. {0: hsv_filter, 1: cnn}.",
Expand All @@ -53,7 +58,8 @@
"precision",
"mean",
"std",
"backlight_threshold",
"over_exposure_threshold",
"under_exposure_threshold",
"classifier_type",
"traffic_light_type"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
},
"default": [58.395, 57.12, 57.375]
},
"backlight_threshold": {
"over_exposure_threshold": {
"type": "number",
"description": "If the intensity get grater than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much higher, the node only overwrites in the harsher backlight situations. Therefore, If you wouldn't like to use this feature set this value to `1.0`. The value can be `[0.0, 1.0]`. The confidence of overwritten signal is set to `0.0`.",
"description": "If the intensity get grater than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much higher, the node only overwrites in the over exposure situations. Therefore, If you wouldn't like to use this feature set this value to `1.0`. The value can be `[0.0, 1.0]`. The confidence of overwritten signal is set to `0.0`.",
"default": 0.85
},
"under_exposure_threshold": {
"type": "number",
"description": "If the intensity get lesser than this overwrite with UNKNOWN in corresponding RoI. Note that, if the value is much lesser, the node only overwrites in the under exposure situations. Therefore, If you wouldn't like to use this feature set this value to `-1.0`. The confidence of overwritten signal is set to `0.0`.",
"default": -0.83
},
"classifier_type": {
"type": "integer",
"description": "Type of classifier used. {0: hsv_filter, 1: cnn}.",
Expand All @@ -53,7 +58,8 @@
"precision",
"mean",
"std",
"backlight_threshold",
"over_exposure_threshold",
"under_exposure_threshold",
"classifier_type",
"traffic_light_type"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "cnn_classifier.hpp"

#include "../traffic_light_classifier_process.hpp"

#include <ament_index_cpp/get_package_share_directory.hpp>

#include <boost/algorithm/string/classification.hpp>
Expand Down Expand Up @@ -104,7 +106,8 @@ void CNNClassifier::outputDebugImage(
std::string label;
for (std::size_t i = 0; i < traffic_signal.elements.size(); i++) {
auto light = traffic_signal.elements.at(i);
const auto light_label = state2label_[light.color] + "-" + state2label_[light.shape];
const auto light_label =
utils::convertColorT4toString(light.color) + "-" + utils::convertShapeT4toString(light.shape);
label += light_label;
// all lamp confidence are the same
probability = light.confidence;
Expand All @@ -130,7 +133,7 @@ void CNNClassifier::outputDebugImage(
}

void CNNClassifier::postProcess(
int class_index, float prob, tier4_perception_msgs::msg::TrafficLight & traffic_signal)
int class_index, float prob, tier4_perception_msgs::msg::TrafficLight & traffic_signal) const
{
std::string match_label = labels_[class_index];

Expand All @@ -143,28 +146,24 @@ void CNNClassifier::postProcess(
std::vector<std::string> split_label;
boost::algorithm::split(split_label, match_label, boost::is_any_of(","));
for (auto label : split_label) {
if (label2state_.find(label) == label2state_.end()) {
RCLCPP_DEBUG(
node_ptr_->get_logger(), "cnn_classifier does not have a key [%s]", label.c_str());
continue;
}
tier4_perception_msgs::msg::TrafficLightElement element;
if (label.find("-") != std::string::npos) {
// found "-" delimiter in label string
std::vector<std::string> color_and_shape;
boost::algorithm::split(color_and_shape, label, boost::is_any_of("-"));
element.color = label2state_[color_and_shape.at(0)];
element.shape = label2state_[color_and_shape.at(1)];
element.color = utils::convertColorStringtoT4(color_and_shape.at(0));
element.shape = utils::convertShapeStringtoT4(color_and_shape.at(1));
} else {
if (label == state2label_[tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN]) {
if (label == std::string("unknown")) {
// if label is unknown, set UNKNOWN to color and shape
element.color = tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN;
element.shape = tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN;
} else if (isColorLabel(label)) {
element.color = label2state_[label];
} else if (utils::isColorLabel(label)) {
element.color = utils::convertColorStringtoT4(label);
element.shape = tier4_perception_msgs::msg::TrafficLightElement::CIRCLE;
} else {
element.color = tier4_perception_msgs::msg::TrafficLightElement::GREEN;
element.shape = label2state_[label];
element.shape = utils::convertShapeStringtoT4(label);
}
}
element.confidence = prob;
Expand All @@ -186,17 +185,4 @@ bool CNNClassifier::readLabelfile(std::string filepath, std::vector<std::string>
return true;
}

bool CNNClassifier::isColorLabel(const std::string & label)
{
using tier4_perception_msgs::msg::TrafficLight;
if (
label == state2label_[tier4_perception_msgs::msg::TrafficLightElement::GREEN] ||
label == state2label_[tier4_perception_msgs::msg::TrafficLightElement::AMBER] ||
label == state2label_[tier4_perception_msgs::msg::TrafficLightElement::RED] ||
label == state2label_[tier4_perception_msgs::msg::TrafficLightElement::WHITE]) {
return true;
}
return false;
}

} // namespace autoware::traffic_light
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,12 @@ class CNNClassifier : public ClassifierInterface

private:
void postProcess(
int class_index, float prob, tier4_perception_msgs::msg::TrafficLight & traffic_signal);
int class_index, float prob, tier4_perception_msgs::msg::TrafficLight & traffic_signal) const;
bool readLabelfile(std::string filepath, std::vector<std::string> & labels);
bool isColorLabel(const std::string & label);
void outputDebugImage(
cv::Mat & debug_image, const tier4_perception_msgs::msg::TrafficLight & traffic_signal);

private:
std::map<int, std::string> state2label_{
// color
{tier4_perception_msgs::msg::TrafficLightElement::RED, "red"},
{tier4_perception_msgs::msg::TrafficLightElement::AMBER, "yellow"},
{tier4_perception_msgs::msg::TrafficLightElement::GREEN, "green"},
{tier4_perception_msgs::msg::TrafficLightElement::WHITE, "white"},
// shape
{tier4_perception_msgs::msg::TrafficLightElement::CIRCLE, "circle"},
{tier4_perception_msgs::msg::TrafficLightElement::LEFT_ARROW, "left"},
{tier4_perception_msgs::msg::TrafficLightElement::RIGHT_ARROW, "right"},
{tier4_perception_msgs::msg::TrafficLightElement::UP_ARROW, "straight"},
{tier4_perception_msgs::msg::TrafficLightElement::UP_LEFT_ARROW, "up_left"},
{tier4_perception_msgs::msg::TrafficLightElement::UP_RIGHT_ARROW, "up_right"},
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_ARROW, "down"},
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_LEFT_ARROW, "down_left"},
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_RIGHT_ARROW, "down_right"},
{tier4_perception_msgs::msg::TrafficLightElement::CROSS, "cross"},
// other
{tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN, "unknown"},
};

std::map<std::string, int> label2state_{
// color
{"red", tier4_perception_msgs::msg::TrafficLightElement::RED},
{"yellow", tier4_perception_msgs::msg::TrafficLightElement::AMBER},
{"green", tier4_perception_msgs::msg::TrafficLightElement::GREEN},
{"white", tier4_perception_msgs::msg::TrafficLightElement::WHITE},
// shape
{"circle", tier4_perception_msgs::msg::TrafficLightElement::CIRCLE},
{"left", tier4_perception_msgs::msg::TrafficLightElement::LEFT_ARROW},
{"right", tier4_perception_msgs::msg::TrafficLightElement::RIGHT_ARROW},
{"straight", tier4_perception_msgs::msg::TrafficLightElement::UP_ARROW},
{"up_left", tier4_perception_msgs::msg::TrafficLightElement::UP_LEFT_ARROW},
{"up_right", tier4_perception_msgs::msg::TrafficLightElement::UP_RIGHT_ARROW},
{"down", tier4_perception_msgs::msg::TrafficLightElement::DOWN_ARROW},
{"down_left", tier4_perception_msgs::msg::TrafficLightElement::DOWN_LEFT_ARROW},
{"down_right", tier4_perception_msgs::msg::TrafficLightElement::DOWN_RIGHT_ARROW},
{"cross", tier4_perception_msgs::msg::TrafficLightElement::CROSS},
// other
{"unknown", tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN},
};

rclcpp::Node * node_ptr_;
int batch_size_;
std::unique_ptr<autoware::tensorrt_classifier::TrtClassifier> classifier_;
Expand Down
Loading
Loading