Skip to content

Commit cf5a2ed

Browse files
tzhong518pre-commit-ci[bot]YoshiRitechnolojin
authored
feat(lidar_centerpoint): output the covariance of pose and twist (#6573)
* feat: postprocess variance Signed-off-by: tzhong518 <sworgun@gmail.com> * feat: output variance Signed-off-by: tzhong518 <sworgun@gmail.com> * feat: add has_variance to config Signed-off-by: tzhong518 <sworgun@gmail.com> * fix: single_inference node Signed-off-by: tzhong518 <sworgun@gmail.com> * style(pre-commit): autofix * fix: add to pointpainting param Signed-off-by: tzhong518 <sworgun@gmail.com> * Update perception/lidar_centerpoint/src/node.cpp Co-authored-by: Yoshi Ri <yoshiyoshidetteiu@gmail.com> * Update perception/image_projection_based_fusion/src/pointpainting_fusion/node.cpp Co-authored-by: Yoshi Ri <yoshiyoshidetteiu@gmail.com> * Update perception/lidar_centerpoint/src/node.cpp Co-authored-by: Yoshi Ri <yoshiyoshidetteiu@gmail.com> * fix: add options Signed-off-by: tzhong518 <sworgun@gmail.com> * fix: avoid powf Signed-off-by: tzhong518 <sworgun@gmail.com> * Update launch/tier4_perception_launch/launch/object_recognition/detection/detector/lidar_dnn_detector.launch.xml Co-authored-by: Taekjin LEE <technolojin@gmail.com> --------- Signed-off-by: tzhong518 <sworgun@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yoshi Ri <yoshiyoshidetteiu@gmail.com> Co-authored-by: Taekjin LEE <technolojin@gmail.com>
1 parent 729cbc6 commit cf5a2ed

File tree

16 files changed

+137
-17
lines changed

16 files changed

+137
-17
lines changed

launch/tier4_perception_launch/launch/object_recognition/detection/detector/lidar_dnn_detector.launch.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<arg name="lidar_detection_model" default="centerpoint" description="options: `centerpoint`, `apollo`, `clustering`"/>
66

77
<!-- Lidar detector centerpoint parameters -->
8-
<arg name="centerpoint_model_name" default="centerpoint_tiny"/>
8+
<arg name="centerpoint_model_name" default="centerpoint_tiny" description="options: `centerpoint`, `centerpoint_tiny` or `centerpoint_sigma`"/>
99
<arg name="centerpoint_model_path" default="$(var data_path)/lidar_centerpoint"/>
1010
<arg name="lidar_model_param_path" default="$(find-pkg-share lidar_centerpoint)/config"/>
1111

launch/tier4_perception_launch/launch/perception.launch.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<arg name="traffic_light_arbiter_param_path"/>
3737

3838
<!-- CenterPoint model parameters -->
39-
<arg name="centerpoint_model_name" default="centerpoint_tiny" description="options: `centerpoint` or `centerpoint_tiny`"/>
39+
<arg name="centerpoint_model_name" default="centerpoint_tiny" description="options: `centerpoint`, `centerpoint_tiny` or `centerpoint_sigma`"/>
4040
<arg name="centerpoint_model_path" default="$(var data_path)/lidar_centerpoint"/>
4141

4242
<!-- PointPainting model parameters -->

perception/image_projection_based_fusion/config/pointpainting.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
downsample_factor: 1
1717
encoder_in_feature_size: 12
1818
yaw_norm_thresholds: [0.3, 0.3, 0.3, 0.3, 0.0]
19+
has_variance: false
1920
has_twist: false
2021
densification_params:
2122
world_frame_id: "map"

perception/image_projection_based_fusion/include/image_projection_based_fusion/pointpainting_fusion/node.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PointPaintingFusionNode
6060
std::map<std::string, float> class_index_;
6161
std::map<std::string, std::function<bool(int)>> isClassTable_;
6262
std::vector<double> pointcloud_range;
63+
bool has_variance_{false};
6364
bool has_twist_{false};
6465

6566
centerpoint::NonMaximumSuppression iou_bev_nms_;

perception/image_projection_based_fusion/schema/pointpainting.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
"minimum": 0.0,
6161
"maximum": 1.0
6262
},
63+
"has_variance": {
64+
"type": "boolean",
65+
"description": "Indicates whether the model outputs variance value.",
66+
"default": false
67+
},
6368
"has_twist": {
6469
"type": "boolean",
6570
"description": "Indicates whether the model outputs twist value.",

perception/image_projection_based_fusion/src/pointpainting_fusion/node.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ PointPaintingFusionNode::PointPaintingFusionNode(const rclcpp::NodeOptions & opt
140140
isClassTable_.erase(cls);
141141
}
142142
}
143+
has_variance_ = this->declare_parameter<bool>("has_variance");
143144
has_twist_ = this->declare_parameter<bool>("model_params.has_twist");
144145
const std::size_t point_feature_size = static_cast<std::size_t>(
145146
this->declare_parameter<std::int64_t>("model_params.point_feature_size"));
@@ -189,7 +190,7 @@ PointPaintingFusionNode::PointPaintingFusionNode(const rclcpp::NodeOptions & opt
189190
centerpoint::CenterPointConfig config(
190191
class_names_.size(), point_feature_size, max_voxel_size, pointcloud_range, voxel_size,
191192
downsample_factor, encoder_in_feature_size, score_threshold, circle_nms_dist_threshold,
192-
yaw_norm_thresholds);
193+
yaw_norm_thresholds, has_variance_);
193194

194195
// create detector
195196
detector_ptr_ = std::make_unique<image_projection_based_fusion::PointPaintingTRT>(
@@ -401,7 +402,7 @@ void PointPaintingFusionNode::postprocess(sensor_msgs::msg::PointCloud2 & painte
401402
raw_objects.reserve(det_boxes3d.size());
402403
for (const auto & box3d : det_boxes3d) {
403404
autoware_auto_perception_msgs::msg::DetectedObject obj;
404-
box3DToDetectedObject(box3d, class_names_, has_twist_, obj);
405+
box3DToDetectedObject(box3d, class_names_, has_twist_, has_variance_, obj);
405406
raw_objects.emplace_back(obj);
406407
}
407408

perception/lidar_centerpoint/config/centerpoint.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
iou_nms_threshold: 0.1
1515
yaw_norm_thresholds: [0.3, 0.3, 0.3, 0.3, 0.0]
1616
score_threshold: 0.35
17+
has_variance: false
1718
has_twist: false
1819
trt_precision: fp16
1920
densification_num_past_frames: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**:
2+
ros__parameters:
3+
class_names: ["CAR", "TRUCK", "BUS", "BICYCLE", "PEDESTRIAN"]
4+
point_feature_size: 4
5+
max_voxel_size: 40000
6+
point_cloud_range: [-76.8, -76.8, -4.0, 76.8, 76.8, 6.0]
7+
voxel_size: [0.32, 0.32, 10.0]
8+
downsample_factor: 1
9+
encoder_in_feature_size: 9
10+
# post-process params
11+
circle_nms_dist_threshold: 0.5
12+
iou_nms_target_class_names: ["CAR"]
13+
iou_nms_search_distance_2d: 10.0
14+
iou_nms_threshold: 0.1
15+
yaw_norm_thresholds: [0.3, 0.3, 0.3, 0.3, 0.0]
16+
score_threshold: 0.35
17+
has_variance: true
18+
has_twist: true
19+
trt_precision: fp16
20+
densification_num_past_frames: 1
21+
densification_world_frame_id: map
22+
23+
# weight files
24+
encoder_onnx_path: "$(var model_path)/pts_voxel_encoder_$(var model_name).onnx"
25+
encoder_engine_path: "$(var model_path)/pts_voxel_encoder_$(var model_name).engine"
26+
head_onnx_path: "$(var model_path)/pts_backbone_neck_head_$(var model_name).onnx"
27+
head_engine_path: "$(var model_path)/pts_backbone_neck_head_$(var model_name).engine"

perception/lidar_centerpoint/config/centerpoint_tiny.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
iou_nms_threshold: 0.1
1515
yaw_norm_thresholds: [0.3, 0.3, 0.3, 0.3, 0.0]
1616
score_threshold: 0.35
17+
has_variance: false
1718
has_twist: false
1819
trt_precision: fp16
1920
densification_num_past_frames: 1

perception/lidar_centerpoint/include/lidar_centerpoint/centerpoint_config.hpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CenterPointConfig
2828
const std::vector<double> & point_cloud_range, const std::vector<double> & voxel_size,
2929
const std::size_t downsample_factor, const std::size_t encoder_in_feature_size,
3030
const float score_threshold, const float circle_nms_dist_threshold,
31-
const std::vector<double> yaw_norm_thresholds)
31+
const std::vector<double> yaw_norm_thresholds, const bool has_variance)
3232
{
3333
class_size_ = class_size;
3434
point_feature_size_ = point_feature_size;
@@ -49,6 +49,15 @@ class CenterPointConfig
4949
downsample_factor_ = downsample_factor;
5050
encoder_in_feature_size_ = encoder_in_feature_size;
5151

52+
if (has_variance) {
53+
has_variance_ = true;
54+
head_out_offset_size_ = 4;
55+
head_out_z_size_ = 2;
56+
head_out_dim_size_ = 6;
57+
head_out_rot_size_ = 4;
58+
head_out_vel_size_ = 4;
59+
}
60+
5261
if (score_threshold > 0 && score_threshold < 1) {
5362
score_threshold_ = score_threshold;
5463
}
@@ -97,11 +106,12 @@ class CenterPointConfig
97106
std::size_t encoder_in_feature_size_{9};
98107
const std::size_t encoder_out_feature_size_{32};
99108
const std::size_t head_out_size_{6};
100-
const std::size_t head_out_offset_size_{2};
101-
const std::size_t head_out_z_size_{1};
102-
const std::size_t head_out_dim_size_{3};
103-
const std::size_t head_out_rot_size_{2};
104-
const std::size_t head_out_vel_size_{2};
109+
bool has_variance_{false};
110+
std::size_t head_out_offset_size_{2};
111+
std::size_t head_out_z_size_{1};
112+
std::size_t head_out_dim_size_{3};
113+
std::size_t head_out_rot_size_{2};
114+
std::size_t head_out_vel_size_{2};
105115

106116
// post-process params
107117
float score_threshold_{0.35f};

perception/lidar_centerpoint/include/lidar_centerpoint/node.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class LidarCenterPointNode : public rclcpp::Node
5353

5454
float score_threshold_{0.0};
5555
std::vector<std::string> class_names_;
56+
bool has_variance_{false};
5657
bool has_twist_{false};
5758

5859
NonMaximumSuppression iou_bev_nms_;

perception/lidar_centerpoint/include/lidar_centerpoint/ros_utils.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ namespace centerpoint
3232

3333
void box3DToDetectedObject(
3434
const Box3D & box3d, const std::vector<std::string> & class_names, const bool has_twist,
35-
autoware_auto_perception_msgs::msg::DetectedObject & obj);
35+
const bool has_variance, autoware_auto_perception_msgs::msg::DetectedObject & obj);
3636

3737
uint8_t getSemanticType(const std::string & class_name);
3838

39+
std::array<double, 36> convertPoseCovarianceMatrix(const Box3D & box3d);
40+
41+
std::array<double, 36> convertTwistCovarianceMatrix(const Box3D & box3d);
42+
3943
bool isCarLikeVehicleLabel(const uint8_t label);
4044

4145
} // namespace centerpoint

perception/lidar_centerpoint/include/lidar_centerpoint/utils.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ struct Box3D
3333
float yaw;
3434
float vel_x;
3535
float vel_y;
36+
37+
// variance
38+
float x_variance;
39+
float y_variance;
40+
float z_variance;
41+
float length_variance;
42+
float width_variance;
43+
float height_variance;
44+
float yaw_variance;
45+
float vel_x_variance;
46+
float vel_y_variance;
3647
};
3748

3849
// cspell: ignore divup

perception/lidar_centerpoint/lib/postprocess/postprocess_kernel.cu

+30-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ __global__ void generateBoxes3D_kernel(
5858
const float * out_rot, const float * out_vel, const float voxel_size_x, const float voxel_size_y,
5959
const float range_min_x, const float range_min_y, const std::size_t down_grid_size_x,
6060
const std::size_t down_grid_size_y, const std::size_t downsample_factor, const int class_size,
61-
const float * yaw_norm_thresholds, Box3D * det_boxes3d)
61+
const bool has_variance, const float * yaw_norm_thresholds, Box3D * det_boxes3d)
6262
{
6363
// generate boxes3d from the outputs of the network.
6464
// shape of out_*: (N, DOWN_GRID_SIZE_Y, DOWN_GRID_SIZE_X)
@@ -107,6 +107,34 @@ __global__ void generateBoxes3D_kernel(
107107
det_boxes3d[idx].yaw = atan2f(yaw_sin, yaw_cos);
108108
det_boxes3d[idx].vel_x = vel_x;
109109
det_boxes3d[idx].vel_y = vel_y;
110+
111+
if (has_variance) {
112+
const float offset_x_variance = out_offset[down_grid_size * 2 + idx];
113+
const float offset_y_variance = out_offset[down_grid_size * 3 + idx];
114+
const float z_variance = out_z[down_grid_size * 1 + idx];
115+
const float w_variance = out_dim[down_grid_size * 3 + idx];
116+
const float l_variance = out_dim[down_grid_size * 4 + idx];
117+
const float h_variance = out_dim[down_grid_size * 5 + idx];
118+
const float yaw_sin_log_variance = out_rot[down_grid_size * 2 + idx];
119+
const float yaw_cos_log_variance = out_rot[down_grid_size * 3 + idx];
120+
const float vel_x_variance = out_vel[down_grid_size * 2 + idx];
121+
const float vel_y_variance = out_vel[down_grid_size * 3 + idx];
122+
123+
det_boxes3d[idx].x_variance = voxel_size_x * downsample_factor * expf(offset_x_variance);
124+
det_boxes3d[idx].y_variance = voxel_size_x * downsample_factor * expf(offset_y_variance);
125+
det_boxes3d[idx].z_variance = expf(z_variance);
126+
det_boxes3d[idx].length_variance = expf(l_variance);
127+
det_boxes3d[idx].width_variance = expf(w_variance);
128+
det_boxes3d[idx].height_variance = expf(h_variance);
129+
const float yaw_sin_sq = yaw_sin * yaw_sin;
130+
const float yaw_cos_sq = yaw_cos * yaw_cos;
131+
const float yaw_norm_sq = (yaw_sin_sq + yaw_cos_sq) * (yaw_sin_sq + yaw_cos_sq);
132+
det_boxes3d[idx].yaw_variance =
133+
(yaw_cos_sq * expf(yaw_sin_log_variance) + yaw_sin_sq * expf(yaw_cos_log_variance)) /
134+
yaw_norm_sq;
135+
det_boxes3d[idx].vel_x_variance = expf(vel_x_variance);
136+
det_boxes3d[idx].vel_y_variance = expf(vel_y_variance);
137+
}
110138
}
111139

112140
PostProcessCUDA::PostProcessCUDA(const CenterPointConfig & config) : config_(config)
@@ -131,7 +159,7 @@ cudaError_t PostProcessCUDA::generateDetectedBoxes3D_launch(
131159
out_heatmap, out_offset, out_z, out_dim, out_rot, out_vel, config_.voxel_size_x_,
132160
config_.voxel_size_y_, config_.range_min_x_, config_.range_min_y_, config_.down_grid_size_x_,
133161
config_.down_grid_size_y_, config_.downsample_factor_, config_.class_size_,
134-
thrust::raw_pointer_cast(yaw_norm_thresholds_d_.data()),
162+
config_.has_variance_, thrust::raw_pointer_cast(yaw_norm_thresholds_d_.data()),
135163
thrust::raw_pointer_cast(boxes3d_d_.data()));
136164

137165
// suppress by score

perception/lidar_centerpoint/lib/ros_utils.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using Label = autoware_auto_perception_msgs::msg::ObjectClassification;
2525

2626
void box3DToDetectedObject(
2727
const Box3D & box3d, const std::vector<std::string> & class_names, const bool has_twist,
28-
autoware_auto_perception_msgs::msg::DetectedObject & obj)
28+
const bool has_variance, autoware_auto_perception_msgs::msg::DetectedObject & obj)
2929
{
3030
// TODO(yukke42): the value of classification confidence of DNN, not probability.
3131
obj.existence_probability = box3d.score;
@@ -58,6 +58,10 @@ void box3DToDetectedObject(
5858
obj.shape.type = autoware_auto_perception_msgs::msg::Shape::BOUNDING_BOX;
5959
obj.shape.dimensions =
6060
tier4_autoware_utils::createTranslation(box3d.length, box3d.width, box3d.height);
61+
if (has_variance) {
62+
obj.kinematics.has_position_covariance = has_variance;
63+
obj.kinematics.pose_with_covariance.covariance = convertPoseCovarianceMatrix(box3d);
64+
}
6165

6266
// twist
6367
if (has_twist) {
@@ -68,6 +72,10 @@ void box3DToDetectedObject(
6872
twist.angular.z = 2 * (std::atan2(vel_y, vel_x) - yaw);
6973
obj.kinematics.twist_with_covariance.twist = twist;
7074
obj.kinematics.has_twist = has_twist;
75+
if (has_variance) {
76+
obj.kinematics.has_twist_covariance = has_variance;
77+
obj.kinematics.twist_with_covariance.covariance = convertTwistCovarianceMatrix(box3d);
78+
}
7179
}
7280
}
7381

@@ -92,4 +100,24 @@ uint8_t getSemanticType(const std::string & class_name)
92100
}
93101
}
94102

103+
std::array<double, 36> convertPoseCovarianceMatrix(const Box3D & box3d)
104+
{
105+
using POSE_IDX = tier4_autoware_utils::xyzrpy_covariance_index::XYZRPY_COV_IDX;
106+
std::array<double, 36> pose_covariance{};
107+
pose_covariance[POSE_IDX::X_X] = box3d.x_variance;
108+
pose_covariance[POSE_IDX::Y_Y] = box3d.y_variance;
109+
pose_covariance[POSE_IDX::Z_Z] = box3d.z_variance;
110+
pose_covariance[POSE_IDX::YAW_YAW] = box3d.yaw_variance;
111+
return pose_covariance;
112+
}
113+
114+
std::array<double, 36> convertTwistCovarianceMatrix(const Box3D & box3d)
115+
{
116+
using POSE_IDX = tier4_autoware_utils::xyzrpy_covariance_index::XYZRPY_COV_IDX;
117+
std::array<double, 36> twist_covariance{};
118+
twist_covariance[POSE_IDX::X_X] = box3d.vel_x_variance;
119+
twist_covariance[POSE_IDX::Y_Y] = box3d.vel_y_variance;
120+
return twist_covariance;
121+
}
122+
95123
} // namespace centerpoint

perception/lidar_centerpoint/src/node.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
5555
const std::string head_onnx_path = this->declare_parameter<std::string>("head_onnx_path");
5656
const std::string head_engine_path = this->declare_parameter<std::string>("head_engine_path");
5757
class_names_ = this->declare_parameter<std::vector<std::string>>("class_names");
58-
has_twist_ = this->declare_parameter("has_twist", false);
58+
has_variance_ = this->declare_parameter<bool>("has_variance");
59+
has_twist_ = this->declare_parameter<bool>("has_twist");
5960
const std::size_t point_feature_size =
6061
static_cast<std::size_t>(this->declare_parameter<std::int64_t>("point_feature_size"));
6162
const std::size_t max_voxel_size =
@@ -102,7 +103,7 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
102103
CenterPointConfig config(
103104
class_names_.size(), point_feature_size, max_voxel_size, point_cloud_range, voxel_size,
104105
downsample_factor, encoder_in_feature_size, score_threshold, circle_nms_dist_threshold,
105-
yaw_norm_thresholds);
106+
yaw_norm_thresholds, has_variance_);
106107
detector_ptr_ =
107108
std::make_unique<CenterPointTRT>(encoder_param, head_param, densification_param, config);
108109

@@ -152,7 +153,7 @@ void LidarCenterPointNode::pointCloudCallback(
152153
raw_objects.reserve(det_boxes3d.size());
153154
for (const auto & box3d : det_boxes3d) {
154155
autoware_auto_perception_msgs::msg::DetectedObject obj;
155-
box3DToDetectedObject(box3d, class_names_, has_twist_, obj);
156+
box3DToDetectedObject(box3d, class_names_, has_twist_, has_variance_, obj);
156157
raw_objects.emplace_back(obj);
157158
}
158159

0 commit comments

Comments
 (0)