Skip to content

Commit

Permalink
feat(lidar_centerpoint): implemented a class remapping according to t…
Browse files Browse the repository at this point in the history
…he detections shape (autowarefoundation#1876)

* Implemented a small package to remap detection classes depending on their shape

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>

* Update perception/detection_class_adapter/include/detection_class_adapter/detection_class_adapter.hpp

Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com>

* Removed the hardcoded mapping from centerpoint and pointfusion. Fixed the description of the config file

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>

* Deleted the new package and moved the logic to centerpoint

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>

* Update perception/lidar_centerpoint/config/detection_class_adapter.param.yaml

Co-authored-by: Yusuke Muramatsu <yukke42@users.noreply.github.com>

* Changed: adapter->remapper

* Update perception/lidar_centerpoint/lib/detection_class_remapper.cpp

Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com>

* Delted duplicated file

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>

* Modified the parameters to match autowarefoundation#1710
Now we do not map cars to buses no mather the size

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>

* Update perception/lidar_centerpoint/config/detection_class_remapper.param.yaml

Co-authored-by: Yusuke Muramatsu <yukke42@users.noreply.github.com>

Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>
Co-authored-by: Yukihiro Saito <yukky.saito@gmail.com>
Co-authored-by: Yusuke Muramatsu <yukke42@users.noreply.github.com>
Signed-off-by: tomoya.kimura <tomoya.kimura@tier4.jp>
  • Loading branch information
3 people authored and tkimura4 committed Oct 14, 2022
1 parent 0cef0d7 commit 32d1ce9
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**:
ros__parameters:
class_names: ["CAR", "PEDESTRIAN", "BICYCLE"]
rename_car_to_truck_and_bus: true
point_feature_size: 6 # x, y, z and car, pedestrian, bicycle
max_voxel_size: 40000
point_cloud_range: [-76.8, -76.8, -3.0, 76.8, 76.8, 5.0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <image_projection_based_fusion/utils/geometry.hpp>
#include <image_projection_based_fusion/utils/utils.hpp>
#include <lidar_centerpoint/centerpoint_trt.hpp>
#include <lidar_centerpoint/detection_class_remapper.hpp>

#include <map>
#include <memory>
Expand Down Expand Up @@ -52,9 +53,10 @@ class PointpaintingFusionNode : public FusionNode<sensor_msgs::msg::PointCloud2,
float score_threshold_{0.0};
std::vector<std::string> class_names_;
std::vector<double> pointcloud_range;
bool rename_car_to_truck_and_bus_{false};
bool has_twist_{false};

centerpoint::DetectionClassRemapper detection_class_remapper_;

std::unique_ptr<image_projection_based_fusion::PointPaintingTRT> detector_ptr_{nullptr};

bool out_of_scope(const DetectedObjects & obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<arg name="model_name" default="pointpainting" description="options: `pointpainting`"/>
<arg name="model_path" default="$(find-pkg-share image_projection_based_fusion)/data"/>
<arg name="model_param_path" default="$(find-pkg-share image_projection_based_fusion)/config/$(var model_name).param.yaml"/>
<arg name="class_remapper_param_path" default="$(find-pkg-share lidar_centerpoint)/config/detection_class_remapper.param.yaml"/>

<!-- for eval variable-->
<arg name="input_rois_number" default="$(var input/rois_number)"/>
Expand Down Expand Up @@ -74,6 +75,7 @@
<param name="head_onnx_path" value="$(var model_path)/pts_backbone_neck_head_$(var model_name).onnx"/>
<param name="head_engine_path" value="$(var model_path)/pts_backbone_neck_head_$(var model_name).engine"/>
<param from="$(var model_param_path)"/>
<param from="$(var class_remapper_param_path)"/>
<param name="rois_number" value="$(var input/rois_number)"/>

<!-- debug -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ PointpaintingFusionNode::PointpaintingFusionNode(const rclcpp::NodeOptions & opt
const std::string head_onnx_path = this->declare_parameter("head_onnx_path", "");
const std::string head_engine_path = this->declare_parameter("head_engine_path", "");
class_names_ = this->declare_parameter<std::vector<std::string>>("class_names");
rename_car_to_truck_and_bus_ = this->declare_parameter("rename_car_to_truck_and_bus", false);
has_twist_ = this->declare_parameter("has_twist", false);
const std::size_t point_feature_size =
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("point_feature_size"));
Expand All @@ -59,6 +58,13 @@ PointpaintingFusionNode::PointpaintingFusionNode(const rclcpp::NodeOptions & opt
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("downsample_factor"));
const std::size_t encoder_in_feature_size =
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("encoder_in_feature_size"));
const auto allow_remapping_by_area_matrix =
this->declare_parameter<std::vector<int64_t>>("allow_remapping_by_area_matrix");
const auto min_area_matrix = this->declare_parameter<std::vector<double>>("min_area_matrix");
const auto max_area_matrix = this->declare_parameter<std::vector<double>>("max_area_matrix");

detection_class_remapper_.setParameters(
allow_remapping_by_area_matrix, min_area_matrix, max_area_matrix);

centerpoint::NetworkParam encoder_param(encoder_onnx_path, encoder_engine_path, trt_precision);
centerpoint::NetworkParam head_param(head_onnx_path, head_engine_path, trt_precision);
Expand Down Expand Up @@ -240,11 +246,12 @@ void PointpaintingFusionNode::postprocess(sensor_msgs::msg::PointCloud2 & painte
continue;
}
autoware_auto_perception_msgs::msg::DetectedObject obj;
centerpoint::box3DToDetectedObject(
box3d, class_names_, rename_car_to_truck_and_bus_, has_twist_, obj);
centerpoint::box3DToDetectedObject(box3d, class_names_, has_twist_, obj);
output_obj_msg.objects.emplace_back(obj);
}

detection_class_remapper_.mapClasses(output_obj_msg);

obj_pub_ptr_->publish(output_obj_msg);
}

Expand Down
1 change: 1 addition & 0 deletions perception/lidar_centerpoint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
### centerpoint ###
ament_auto_add_library(centerpoint_lib SHARED
lib/centerpoint_trt.cpp
lib/detection_class_remapper.cpp
lib/utils.cpp
lib/ros_utils.cpp
lib/network/network_trt.cpp
Expand Down
2 changes: 1 addition & 1 deletion perception/lidar_centerpoint/config/aip_x2.param.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**:
ros__parameters:
class_names: ["CAR", "TRUCK", "BUS", "BICYCLE", "PEDESTRIAN"]
class_names: ["CAR", "PEDESTRIAN", "BICYCLE"]
rename_car_to_truck_and_bus: false
point_feature_size: 4
max_voxel_size: 40000
Expand Down
1 change: 0 additions & 1 deletion perception/lidar_centerpoint/config/default.param.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**:
ros__parameters:
class_names: ["CAR", "PEDESTRIAN", "BICYCLE"]
rename_car_to_truck_and_bus: true
point_feature_size: 4
max_voxel_size: 40000
point_cloud_range: [-89.6, -89.6, -3.0, 89.6, 89.6, 5.0]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**:
ros__parameters:
allow_remapping_by_area_matrix:
# NOTE(kl): We turn all vehicles into trailers if they go over 3x12 [m^2].
# NOTE(kl): We turn cars into trucks if they have an area between 2.2 x 5.5 and 3.0 * 12.0 [m^2]
# row: original class. column: class to remap to
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE,PEDESTRIAN
[0, 0, 0, 0, 0, 0, 0, 0, #UNKNOWN
0, 0, 1, 0, 1, 0, 0, 0, #CAR
0, 0, 0, 0, 1, 0, 0, 0, #TRUCK
0, 0, 0, 0, 1, 0, 0, 0, #BUS
0, 0, 0, 0, 0, 0, 0, 0, #TRAILER
0, 0, 0, 0, 0, 0, 0, 0, #MOTORBIKE
0, 0, 0, 0, 0, 0, 0, 0, #BICYCLE
0, 0, 0, 0, 0, 0, 0, 0] #PEDESTRIAN

min_area_matrix:
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE, PEDESTRIAN
[ 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #UNKNOWN
0.000, 0.000, 12.100, 0.000, 36.000, 0.000, 0.000, 0.000, #CAR
0.000, 0.000, 0.000, 0.000, 36.000, 0.000, 0.000, 0.000, #TRUCK
0.000, 0.000, 0.000, 0.000, 36.000, 0.000, 0.000, 0.000, #BUS
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #TRAILER
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #MOTORBIKE
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #BICYCLE
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000] #PEDESTRIAN


max_area_matrix:
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE, PEDESTRIAN
[ 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #UNKNOWN
0.000, 0.000, 36.000, 0.000, inf, 0.000, 0.000, 0.000, #CAR
0.000, 0.000, 0.000, 0.000, inf, 0.000, 0.000, 0.000, #TRUCK
0.000, 0.000, 0.000, 0.000, inf, 0.000, 0.000, 0.000, #BUS
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #TRAILER
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #MOTORBIKE
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, #BICYCLE
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000] #PEDESTRIAN
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef LIDAR_CENTERPOINT__DETECTION_CLASS_REMAPPER_HPP_
#define LIDAR_CENTERPOINT__DETECTION_CLASS_REMAPPER_HPP_

#include <Eigen/Core>

#include <autoware_auto_perception_msgs/msg/detected_object_kinematics.hpp>
#include <autoware_auto_perception_msgs/msg/detected_objects.hpp>
#include <autoware_auto_perception_msgs/msg/object_classification.hpp>
#include <autoware_auto_perception_msgs/msg/shape.hpp>

#include <vector>

namespace centerpoint
{

class DetectionClassRemapper
{
public:
void setParameters(
const std::vector<int64_t> & allow_remapping_by_area_matrix,
const std::vector<double> & min_area_matrix, const std::vector<double> & max_area_matrix);
void mapClasses(autoware_auto_perception_msgs::msg::DetectedObjects & msg);

protected:
Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic> allow_remapping_by_area_matrix_;
Eigen::MatrixXd min_area_matrix_;
Eigen::MatrixXd max_area_matrix_;
int num_labels_;
};

} // namespace centerpoint

#endif // LIDAR_CENTERPOINT__DETECTION_CLASS_REMAPPER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define LIDAR_CENTERPOINT__NODE_HPP_

#include <lidar_centerpoint/centerpoint_trt.hpp>
#include <lidar_centerpoint/detection_class_remapper.hpp>
#include <rclcpp/rclcpp.hpp>
#include <tier4_autoware_utils/ros/debug_publisher.hpp>
#include <tier4_autoware_utils/system/stop_watch.hpp>
Expand Down Expand Up @@ -49,9 +50,10 @@ class LidarCenterPointNode : public rclcpp::Node

float score_threshold_{0.0};
std::vector<std::string> class_names_;
bool rename_car_to_truck_and_bus_{false};
bool has_twist_{false};

DetectionClassRemapper detection_class_remapper_;

std::unique_ptr<CenterPointTRT> detector_ptr_{nullptr};

// debugger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ namespace centerpoint
{

void box3DToDetectedObject(
const Box3D & box3d, const std::vector<std::string> & class_names,
const bool rename_car_to_truck_and_bus, const bool has_twist,
const Box3D & box3d, const std::vector<std::string> & class_names, const bool has_twist,
autoware_auto_perception_msgs::msg::DetectedObject & obj);

uint8_t getSemanticType(const std::string & class_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<arg name="model_name" default="default" description="options: `default` or `aip_x2`"/>
<arg name="model_path" default="$(find-pkg-share lidar_centerpoint)/data"/>
<arg name="model_param_path" default="$(find-pkg-share lidar_centerpoint)/config/$(var model_name).param.yaml"/>
<arg name="score_threshold" default="0.45"/>
<arg name="yaw_norm_threshold" default="0.5"/>
<arg name="class_remapper_param_path" default="$(find-pkg-share lidar_centerpoint)/config/detection_class_remapper.param.yaml"/>
<arg name="score_threshold" default="0.35"/>
<arg name="yaw_norm_threshold" default="0.0"/>
<arg name="has_twist" default="false"/>

<node pkg="lidar_centerpoint" exec="lidar_centerpoint_node" name="lidar_centerpoint" output="screen">
Expand All @@ -22,5 +23,6 @@
<param name="head_onnx_path" value="$(var model_path)/pts_backbone_neck_head_$(var model_name).onnx"/>
<param name="head_engine_path" value="$(var model_path)/pts_backbone_neck_head_$(var model_name).engine"/>
<param from="$(var model_param_path)"/>
<param from="$(var class_remapper_param_path)"/>
</node>
</launch>
70 changes: 70 additions & 0 deletions perception/lidar_centerpoint/lib/detection_class_remapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2022 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <lidar_centerpoint/detection_class_remapper.hpp>

namespace centerpoint
{

void DetectionClassRemapper::setParameters(
const std::vector<int64_t> & allow_remapping_by_area_matrix,
const std::vector<double> & min_area_matrix, const std::vector<double> & max_area_matrix)
{
assert(allow_remapping_by_area_matrix.size() == min_area_matrix.size());
assert(allow_remapping_by_area_matrix.size() == max_area_matrix.size());
assert(std::pow(std::sqrt(min_area_matrix.size()), 2) == std::sqrt(min_area_matrix.size()));

num_labels_ = static_cast<int>(std::sqrt(min_area_matrix.size()));

Eigen::Map<const Eigen::Matrix<int64_t, Eigen::Dynamic, Eigen::Dynamic>>
allow_remapping_by_area_matrix_tmp(
allow_remapping_by_area_matrix.data(), num_labels_, num_labels_);
allow_remapping_by_area_matrix_ = allow_remapping_by_area_matrix_tmp.transpose()
.cast<bool>(); // Eigen is column major by default

Eigen::Map<const Eigen::MatrixXd> min_area_matrix_tmp(
min_area_matrix.data(), num_labels_, num_labels_);
min_area_matrix_ = min_area_matrix_tmp.transpose(); // Eigen is column major by default

Eigen::Map<const Eigen::MatrixXd> max_area_matrix_tmp(
max_area_matrix.data(), num_labels_, num_labels_);
max_area_matrix_ = max_area_matrix_tmp.transpose(); // Eigen is column major by default

min_area_matrix_ = min_area_matrix_.unaryExpr(
[](double v) { return std::isfinite(v) ? v : std::numeric_limits<double>::max(); });
max_area_matrix_ = max_area_matrix_.unaryExpr(
[](double v) { return std::isfinite(v) ? v : std::numeric_limits<double>::max(); });
}

void DetectionClassRemapper::mapClasses(autoware_auto_perception_msgs::msg::DetectedObjects & msg)
{
for (auto & object : msg.objects) {
const float bev_area = object.shape.dimensions.x * object.shape.dimensions.y;

for (auto & classification : object.classification) {
auto & label = classification.label;

for (int i = 0; i < num_labels_; ++i) {
if (
allow_remapping_by_area_matrix_(label, i) && bev_area >= min_area_matrix_(label, i) &&
bev_area <= max_area_matrix_(label, i)) {
label = i;
break;
}
}
}
}
}

} // namespace centerpoint
14 changes: 1 addition & 13 deletions perception/lidar_centerpoint/lib/ros_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace centerpoint
using Label = autoware_auto_perception_msgs::msg::ObjectClassification;

void box3DToDetectedObject(
const Box3D & box3d, const std::vector<std::string> & class_names,
const bool rename_car_to_truck_and_bus, const bool has_twist,
const Box3D & box3d, const std::vector<std::string> & class_names, const bool has_twist,
autoware_auto_perception_msgs::msg::DetectedObject & obj)
{
// TODO(yukke42): the value of classification confidence of DNN, not probability.
Expand All @@ -41,17 +40,6 @@ void box3DToDetectedObject(
rclcpp::get_logger("lidar_centerpoint"), "Unexpected label: UNKNOWN is set.");
}

float l = box3d.length;
float w = box3d.width;
if (classification.label == Label::CAR && rename_car_to_truck_and_bus) {
// Note: object size is referred from multi_object_tracker
if ((w * l > 2.2 * 5.5) && (w * l <= 2.5 * 7.9)) {
classification.label = Label::TRUCK;
} else if (w * l > 2.5 * 7.9) {
classification.label = Label::BUS;
}
}

if (isCarLikeVehicleLabel(classification.label)) {
obj.kinematics.orientation_availability =
autoware_auto_perception_msgs::msg::DetectedObjectKinematics::SIGN_UNKNOWN;
Expand Down
12 changes: 10 additions & 2 deletions perception/lidar_centerpoint/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
const std::string head_onnx_path = this->declare_parameter<std::string>("head_onnx_path");
const std::string head_engine_path = this->declare_parameter<std::string>("head_engine_path");
class_names_ = this->declare_parameter<std::vector<std::string>>("class_names");
rename_car_to_truck_and_bus_ = this->declare_parameter("rename_car_to_truck_and_bus", false);
has_twist_ = this->declare_parameter("has_twist", false);
const std::size_t point_feature_size =
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("point_feature_size"));
Expand All @@ -64,6 +63,13 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("downsample_factor"));
const std::size_t encoder_in_feature_size =
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("encoder_in_feature_size"));
const auto allow_remapping_by_area_matrix =
this->declare_parameter<std::vector<int64_t>>("allow_remapping_by_area_matrix");
const auto min_area_matrix = this->declare_parameter<std::vector<double>>("min_area_matrix");
const auto max_area_matrix = this->declare_parameter<std::vector<double>>("max_area_matrix");

detection_class_remapper_.setParameters(
allow_remapping_by_area_matrix, min_area_matrix, max_area_matrix);

NetworkParam encoder_param(encoder_onnx_path, encoder_engine_path, trt_precision);
NetworkParam head_param(head_onnx_path, head_engine_path, trt_precision);
Expand Down Expand Up @@ -127,10 +133,12 @@ void LidarCenterPointNode::pointCloudCallback(
output_msg.header = input_pointcloud_msg->header;
for (const auto & box3d : det_boxes3d) {
autoware_auto_perception_msgs::msg::DetectedObject obj;
box3DToDetectedObject(box3d, class_names_, rename_car_to_truck_and_bus_, has_twist_, obj);
box3DToDetectedObject(box3d, class_names_, has_twist_, obj);
output_msg.objects.emplace_back(obj);
}

detection_class_remapper_.mapClasses(output_msg);

if (objects_sub_count > 0) {
objects_pub_->publish(output_msg);
}
Expand Down

0 comments on commit 32d1ce9

Please sign in to comment.