57 std::string conf_file =
61 LoadParams(cpdet_config_);
64 AERROR <<
"Init CPDetection Model Failed";
69 cudaStreamCreate(&stream_);
70 pfn_inference_->SetStream(stream_);
71 backbone_inference_->SetStream(stream_);
74 point2grid_blob_.reset(
new base::Blob<int>(std::vector<int>{max_voxel_num_}));
75 grid2pointnum_blob_.reset(
new base::Blob<int>(std::vector<int>{map_size_}));
77 if (use_gpu_generate_feature_) {
78 voxels_blob_->mutable_gpu_data();
79 canvas_feature_blob_->mutable_gpu_data();
80 point2grid_blob_->mutable_gpu_data();
81 grid2pointnum_blob_->mutable_gpu_data();
83 voxels_blob_->mutable_cpu_data();
84 canvas_feature_blob_->mutable_cpu_data();
85 point2grid_blob_->mutable_cpu_data();
86 grid2pointnum_blob_->mutable_cpu_data();
89 int channel_index = pillar_feature_dim_;
90 feature_offset_[
"canvas_feature"] = canvas_feature_blob_->offset(0, 0);
91 if (use_cnnseg_features_) {
92 feature_offset_[
"max_height"] = canvas_feature_blob_->offset(0, channel_index++);
93 feature_offset_[
"mean_height"] = canvas_feature_blob_->offset(0, channel_index++);
94 feature_offset_[
"top_intensity"] = canvas_feature_blob_->offset(0, channel_index++);
95 feature_offset_[
"mean_intensity"] = canvas_feature_blob_->offset(0, channel_index++);
96 feature_offset_[
"count"] = canvas_feature_blob_->offset(0, channel_index++);
97 feature_offset_[
"nonempty"] = canvas_feature_blob_->offset(0, channel_index++);
98 feature_offset_[
"height_bin"] = canvas_feature_blob_->offset(0, channel_index);
101 max_candidate_num_ = num_tasks_ * nms_pre_max_size_;
102 all_res_box_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_, kBoxBlockSize}));
103 all_res_conf_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_}));
104 all_res_cls_blob_.reset(
new base::Blob<int>(std::vector<int>{max_candidate_num_}));
107 res_box_blob_.reset(
new base::Blob<float>(std::vector<int>{nms_pre_max_size_, kBoxBlockSize}));
108 res_conf_blob_.reset(
new base::Blob<float>(std::vector<int>{nms_pre_max_size_}));
109 res_cls_blob_.reset(
new base::Blob<int>(std::vector<int>{nms_pre_max_size_}));
111 score_class_map_blob_.reset(
new base::Blob<float>(std::vector<int>{num_classes_}));
113 res_sorted_indices_blob_.reset(
new base::Blob<int>(std::vector<int>{nms_pre_max_size_}));
114 box_for_nms_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_, 4}));
115 box_corner_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_, 8}));
116 remain_conf_blob_.reset(
new base::Blob<float>(std::vector<int>{nms_pre_max_size_}));
117 rotate_overlapped_blob_.reset(
new base::Blob<bool>(std::vector<int>{nms_pre_max_size_, nms_pre_max_size_}));
118 kept_indices_blob_.reset(
new base::Blob<int>(std::vector<int>{num_tasks_ * nms_post_max_size_}));
120 box_corners_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_, 8}));
121 box_rects_blob_.reset(
new base::Blob<float>(std::vector<int>{max_candidate_num_, 4}));
123 valid_point_indices_blob_.reset(
new base::Blob<int>(std::vector<int>{max_valid_point_size_}));
124 valid_point2boxid_blob_.reset(
new base::Blob<int>(std::vector<int>{max_valid_point_size_}));
126 res_box_num_blob_->mutable_gpu_data();
127 res_box_blob_->mutable_gpu_data();
128 res_conf_blob_->mutable_gpu_data();
129 res_cls_blob_->mutable_gpu_data();
130 all_res_box_blob_->mutable_gpu_data();
131 all_res_conf_blob_->mutable_gpu_data();
132 all_res_cls_blob_->mutable_gpu_data();
133 score_class_map_blob_->mutable_gpu_data();
134 remain_conf_blob_->mutable_gpu_data();
135 rotate_overlapped_blob_->mutable_gpu_data();
136 kept_indices_blob_->mutable_gpu_data();
137 box_corners_blob_->mutable_gpu_data();
138 box_rects_blob_->mutable_gpu_data();
139 valid_point_num_blob_->mutable_gpu_data();
140 valid_point_indices_blob_->mutable_gpu_data();
141 valid_point2boxid_blob_->mutable_gpu_data();
143 res_box_num_blob_->mutable_cpu_data();
144 all_res_box_blob_->mutable_cpu_data();
145 all_res_conf_blob_->mutable_cpu_data();
146 all_res_cls_blob_->mutable_cpu_data();
147 rotate_overlapped_blob_->mutable_cpu_data();
148 box_corners_blob_->mutable_cpu_data();
149 box_rects_blob_->mutable_cpu_data();
150 valid_point_num_blob_->mutable_cpu_data();
151 valid_point_indices_blob_->mutable_cpu_data();
152 valid_point2boxid_blob_->mutable_cpu_data();
154 if (cpdet_config_.has_plugins()) {
155 const auto &plugin = cpdet_config_.
plugins();
156 const auto &name = plugin.
name();
160 AINFO <<
"Failed to find down_sample plugin: " << name <<
", skipped";
166 if (!down_sample_->Init(option)) {
167 AINFO <<
"Failed to init down_sample plugin: " << name <<
", skipped";
185 x_offset_ = (voxel_x_size_) / 2 + x_min_range_;
186 y_offset_ = (voxel_y_size_) / 2 + y_min_range_;
187 z_offset_ = (voxel_z_size_) / 2 + z_min_range_;
188 float x_range = x_max_range_ - x_min_range_;
189 float y_range = y_max_range_ - y_min_range_;
190 float z_range = z_max_range_ - z_min_range_;
191 grid_x_size_ =
static_cast<int>(x_range / voxel_x_size_);
192 grid_y_size_ =
static_cast<int>(y_range / voxel_y_size_);
193 grid_z_size_ =
static_cast<int>(z_range / voxel_z_size_);
194 map_size_ = grid_x_size_ * grid_y_size_;
199 max_point_number_ = 160000;
202 cnnseg_feature_dim_ = 0;
203 if (use_cnnseg_features_) {
208 height_bin_dim_ =
static_cast<int>((height_bin_max_height_
209 - height_bin_min_height_) / height_bin_voxel_size_);
221 head_x_size_ =
static_cast<int>(grid_x_size_ / downsample_size_);
222 head_y_size_ =
static_cast<int>(grid_y_size_ / downsample_size_);
223 head_map_size_ = head_x_size_ * head_y_size_;
230 for (
size_t i = 0; i < cpdet_config.
post_process().det_head_size(); ++i) {
234 for (
size_t i = 0; i < num_tasks_; i++) {
235 num_classes_in_task_.push_back(cpdet_config.
post_process().
task(i).sub_task_size());
236 for (
size_t j = 0; j < cpdet_config.
post_process().
task(i).sub_task_size(); j++) {
242 for (
size_t i = 0; i < num_classes_; i++) {
243 score_thresh_map_.push_back(score_thresh_per_class_.at(i).second);
246 max_valid_point_size_);
264 for (
int i = 0; i < cpdet_config.
filter_param().fore_semantic_filter_size(); i++) {
268 fore_semantic_filter_map_[semantic_type] = pair;
274bool CPDetection::InitModel(
const cpdet::CPDetModelParam &model_param) {
276 std::map<std::string, std::vector<int>> pfn_blob_maps;
278 auto pfn_model_info = model_param.pfn_model_info();
279 auto preprocess = model_param.preprocess();
280 std::string model_path =
GetModelPath(pfn_model_info.name());
283 pfn_model_info.proto_file().file());
284 std::vector<std::string> pfn_input_names =
286 std::vector<std::string> pfn_output_names =
289 "apollo::perception::inference::" + pfn_model_info.infer_plugin());
290 pfn_inference_->set_model_info(pfn_proto_file,
291 pfn_input_names, pfn_output_names);
292 pfn_inference_->set_gpu_id(preprocess.gpu_id());
293 pfn_inference_->set_max_batch_size(max_point_number_ * 2);
298 pfn_inference_->Init(pfn_blob_maps);
300 if (pfn_input_names.size() == 1) {
301 voxels_blob_ = pfn_inference_->get_blob(pfn_input_names.at(0));
302 CHECK_NOTNULL(voxels_blob_.get());
304 AERROR <<
"Init cpdet_pfn_inference input blob error.";
308 if (pfn_output_names.size() == 1) {
309 pfn_pillar_feature_blob_ = pfn_inference_->get_blob(pfn_output_names.at(0));
310 CHECK_NOTNULL(pfn_pillar_feature_blob_.get());
312 AERROR <<
"Init cpdet_pfn_inference output blob error.";
315 AINFO <<
"Init cpdet pfn model success.";
318 std::map<std::string, std::vector<int>> backbone_blob_maps;
320 auto backbone_model_info = model_param.backbone_model_info();
323 model_path, backbone_model_info.proto_file().file());
324 std::vector<std::string> backbone_input_names =
326 std::vector<std::string> backbone_output_names =
329 "apollo::perception::inference::" + backbone_model_info.infer_plugin());
330 backbone_inference_->set_model_info(backbone_proto_file,
331 backbone_input_names, backbone_output_names);
332 backbone_inference_->set_gpu_id(preprocess.gpu_id());
333 backbone_inference_->set_max_batch_size(max_point_number_ * 2);
338 backbone_inference_->Init(backbone_blob_maps);
340 if (backbone_input_names.size() == 1) {
341 canvas_feature_blob_ = backbone_inference_->get_blob(backbone_input_names.at(0));
342 CHECK_NOTNULL(canvas_feature_blob_.get());
344 AERROR <<
"Init cpdet_backbone_inference input blob error.";
347 if (backbone_output_names.size() == 3) {
348 output_box_blob_ = backbone_inference_->get_blob(backbone_output_names.at(0));
349 output_cls_blob_ = backbone_inference_->get_blob(backbone_output_names.at(1));
350 output_dir_blob_ = backbone_inference_->get_blob(backbone_output_names.at(2));
351 CHECK_NOTNULL(output_box_blob_.get());
352 CHECK_NOTNULL(output_cls_blob_.get());
353 CHECK_NOTNULL(output_dir_blob_.get());
355 AERROR <<
"Init cpdet_backbone_inference output blobs error.";
358 AINFO <<
"Init cpdet backbone model Success.";
362void CPDetection::PointCloudPreprocess() {
363 if (!enable_downsample_) {
366 DownSampleOptions down_sample_options;
367 ACHECK(down_sample_ !=
nullptr);
368 down_sample_->Process(down_sample_options, cur_cloud_ptr_);
387void CPDetection::GenerateObjects(LidarFrame* frame) {
389 std::vector<base::ObjectPtr> fore_objects;
390 size_t size = res_outputs_.size();
391 for (
size_t i = 0; i < size; ++i) {
392 auto cluster = res_outputs_[i];
393 if (cluster.point_ids.size() <= min_pts_num_fg_) {
398 object.lidar_supplement.on_use =
true;
399 object.lidar_supplement.is_in_roi =
true;
400 object.lidar_supplement.is_background =
false;
401 object.lidar_supplement.is_clustered =
false;
403 for (
auto idx : cluster.point_ids) {
404 object.lidar_supplement.point_ids.push_back(
static_cast<int>(idx));
406 object.lidar_supplement.num_points_in_roi = cluster.point_ids.size();
407 object.lidar_supplement.cloud.CopyPointCloud(*original_cloud_, cluster.point_ids);
408 object.lidar_supplement.cloud_world.CopyPointCloud(*original_world_cloud_, cluster.point_ids);
411 object.lidar_supplement.detections.resize(7);
412 object.lidar_supplement.detections[0] = cluster.x;
413 object.lidar_supplement.detections[1] = cluster.y;
414 object.lidar_supplement.detections[2] = cluster.z;
415 object.lidar_supplement.detections[3] = cluster.l;
416 object.lidar_supplement.detections[4] = cluster.w;
417 object.lidar_supplement.detections[5] = cluster.h;
418 object.lidar_supplement.detections[6] = cluster.yaw;
421 object.center(0) = cluster.x;
422 object.center(1) = cluster.y;
423 object.center(2) = cluster.z;
424 object.size(0) = cluster.l;
425 object.size(1) = cluster.w;
426 object.size(2) = cluster.h;
429 object.theta = cluster.yaw;
430 object.direction[0] = cosf(cluster.yaw);
431 object.direction[1] = sinf(cluster.yaw);
432 object.direction[2] = 0;
433 object.lidar_supplement.is_orientation_ready =
true;
436 object.confidence = cluster.confidence;
440 object.lidar_supplement.raw_probs.push_back(std::vector<float>(
442 object.lidar_supplement.raw_classification_methods.push_back(
Name());
443 object.sub_type = GetObjectSubType(cluster.model_type_index);
449 object.lidar_supplement.raw_probs.back()[
static_cast<int>(
object.type)] = 1.0f;
451 object.type_probs.assign(
object.lidar_supplement.raw_probs.back().begin(),
452 object.lidar_supplement.raw_probs.back().end());
454 std::shared_ptr<base::Object> obj(
new base::Object);
456 fore_objects.push_back(std::move(obj));
459 frame->segmented_objects.insert(frame->segmented_objects.end(), fore_objects.begin(), fore_objects.end());
462void CPDetection::SetPointsInROI(std::vector<base::ObjectPtr> *objects) {
464 roi_mask_.Set(original_cloud_->size(), 0);
465 roi_mask_.AddIndices(lidar_frame_ref_->
roi_indices, 1);
466 for (uint32_t i = 0; i < objects->size(); ++i) {
467 auto &
object = objects->at(i);
468 object->lidar_supplement.num_points_in_roi =
469 roi_mask_.ValidIndicesCount(object->lidar_supplement.point_ids);
473void CPDetection::RemoveForePoints(std::vector<base::ObjectPtr> *objects) {
475 mask.Set(original_cloud_->size(), 0);
476 mask.AddIndicesOfIndices(lidar_frame_ref_->
roi_indices,
478 for (uint32_t i = 0; i < objects->size(); ++i) {
479 auto &
object = objects->at(i);
480 base::PointIndices ind;
481 ind.indices =
object->lidar_supplement.point_ids;
482 mask.RemoveIndices(ind);
487void CPDetection::MapPointsToGridCpu(
int* point2grid_data) {
488 auto Pc2Pixel = [&](
float pc_axis,
float voxel_size,
float start_range) {
489 float fpixel = (pc_axis - start_range) / voxel_size;
490 return fpixel < 0 ? -1 :
static_cast<int>(fpixel);
495 for (
int i = 0; i < model_cloud_size_; ++i) {
496 auto pt = original_cloud_->at(i);
500 if (enable_rotate_45degree_) {
501 px = 0.707107 * pt.x - 0.707107 * pt.y;
502 py = 0.707107 * pt.x + 0.707107 * pt.y;
504 pos_x =
Pc2Pixel(px, voxel_x_size_, x_min_range_);
505 pos_y =
Pc2Pixel(py, voxel_y_size_, y_min_range_);
506 if (pos_y < 0 || pos_y >= grid_y_size_ || pos_x < 0 || pos_x >= grid_x_size_) {
507 point2grid_data[i] = -1;
510 point2grid_data[i] = pos_y * grid_x_size_ + pos_x;
514void CPDetection::GeneratePfnFeatureCPU() {
518 voxels_blob_->mutable_cpu_data();
520 float* voxels_cluster_data = canvas_feature_blob_->mutable_cpu_data();
521 int* grid2pointnum_data = grid2pointnum_blob_->mutable_cpu_data();
522 memset(voxels_cluster_data, 0, map_size_ * 3 *
sizeof(
float));
523 memset(grid2pointnum_data, 0, map_size_ *
sizeof(
int));
525 point2grid_blob_->Reshape(std::vector<int>{model_cloud_size_});
526 voxels_blob_->Reshape(std::vector<int>{model_cloud_size_, 1, voxel_feature_dim_, 1});
527 int* point2grid_data = point2grid_blob_->mutable_cpu_data();
528 float* voxels_data = voxels_blob_->mutable_cpu_data();
529 memset(point2grid_data, 0, model_cloud_size_ *
sizeof(
int));
530 memset(voxels_data, 0.f, (model_cloud_size_) * voxel_feature_dim_ *
sizeof(
float));
532 MapPointsToGridCpu(point2grid_data);
534 if (use_cnnseg_features_) {
535 float* out_data = canvas_feature_blob_->mutable_cpu_data();
536 max_height_data_ = out_data + feature_offset_[
"max_height"];
537 mean_height_data_ = out_data + feature_offset_[
"mean_height"];
538 top_intensity_data_ = out_data + feature_offset_[
"top_intensity"];
539 mean_intensity_data_ = out_data + feature_offset_[
"mean_intensity"];
540 count_data_ = out_data + feature_offset_[
"count"];
541 nonempty_data_ = out_data + feature_offset_[
"nonempty"];
542 height_bin_data_ = out_data + feature_offset_[
"height_bin"];
544 memset(mean_height_data_, 0, map_size_ *
sizeof(
float));
545 memset(max_height_data_, -5.0, map_size_ *
sizeof(
float));
546 memset(top_intensity_data_, 0, map_size_ *
sizeof(
float));
547 memset(mean_intensity_data_, 0, map_size_ *
sizeof(
float));
548 memset(count_data_, 0, map_size_ *
sizeof(
float));
549 memset(nonempty_data_, 0, map_size_ *
sizeof(
float));
550 memset(height_bin_data_, 0, map_size_ * height_bin_dim_ *
sizeof(
float));
554 for (
int i = 0; i < model_cloud_size_; ++i) {
555 int idx = point2grid_data[i];
559 auto pt = original_cloud_->at(i);
563 if (enable_rotate_45degree_) {
564 px = 0.707107 * pt.x - 0.707107 * pt.y;
565 py = 0.707107 * pt.x + 0.707107 * pt.y;
568 voxels_cluster_data[map_size_ * 0 + idx] += px;
569 voxels_cluster_data[map_size_ * 1 + idx] += py;
570 voxels_cluster_data[map_size_ * 2 + idx] += pz;
571 grid2pointnum_data[idx] += 1;
574 for (
int i = 0; i < model_cloud_size_; ++i) {
575 int grid_idx = point2grid_data[i];
576 if (grid_idx == -1) {
579 auto pt = original_cloud_->at(i);
583 if (enable_rotate_45degree_) {
584 px = 0.707107 * pt.x - 0.707107 * pt.y;
585 py = 0.707107 * pt.x + 0.707107 * pt.y;
587 int coord_y = grid_idx / grid_x_size_;
588 int coord_x = grid_idx % grid_x_size_;
589 int voxel_data_idx = i * voxel_feature_dim_;
590 float point_num = std::max(1.f,
static_cast<float>(grid2pointnum_data[grid_idx]));
592 voxels_data[voxel_data_idx + 4] = px - voxels_cluster_data[map_size_ * 0 + grid_idx] / point_num;
593 voxels_data[voxel_data_idx + 5] = py - voxels_cluster_data[map_size_ * 1 + grid_idx] / point_num;
594 voxels_data[voxel_data_idx + 6] = pz - voxels_cluster_data[map_size_ * 2 + grid_idx] / point_num;
595 voxels_data[voxel_data_idx + 7] = px - (
static_cast<float>(coord_x) * voxel_x_size_ + x_offset_);
596 voxels_data[voxel_data_idx + 8] = py - (
static_cast<float>(coord_y) * voxel_y_size_ + y_offset_);
597 if (use_input_norm_) {
598 voxels_data[voxel_data_idx + 0] = px / x_max_range_;
599 voxels_data[voxel_data_idx + 1] = py / y_max_range_;
600 voxels_data[voxel_data_idx + 2] = pz / z_max_range_;
601 voxels_data[voxel_data_idx + 3] = pt.intensity / 255.0;
603 voxels_data[voxel_data_idx + 0] = pt.x;
604 voxels_data[voxel_data_idx + 1] = pt.y;
605 voxels_data[voxel_data_idx + 2] = pt.z;
606 voxels_data[voxel_data_idx + 3] = pt.intensity;
608 if (use_cnnseg_features_) {
609 if (max_height_data_[grid_idx] < pz) {
610 max_height_data_[grid_idx] = pz;
611 top_intensity_data_[grid_idx] = pt.intensity / 255.0;
613 mean_height_data_[grid_idx] +=
static_cast<float>(pz);
614 mean_intensity_data_[grid_idx] +=
static_cast<float>(
615 pt.intensity / 255.0);
616 count_data_[grid_idx] += 1.f;
617 int height_bin_index =
static_cast<int>(
618 (pz - height_bin_min_height_) / height_bin_voxel_size_);
619 height_bin_index = height_bin_index < 0 ? 0 : height_bin_index;
620 height_bin_index = height_bin_index >= height_bin_dim_ ?
621 (height_bin_dim_ - 1) : height_bin_index;
622 height_bin_data_[height_bin_index * map_size_ + grid_idx] = 1.f;
626 if (use_cnnseg_features_) {
627 for (
int i = 0; i < map_size_; ++i) {
628 if (count_data_[i] <= std::numeric_limits<float>::epsilon()) {
629 max_height_data_[i] = 0.f;
631 mean_height_data_[i] /= count_data_[i];
632 mean_intensity_data_[i] /= count_data_[i];
633 nonempty_data_[i] = 1.f;
635 count_data_[i] =
static_cast<int>(log(
static_cast<float>(1 + count_data_[i])));
639 pfn_pillar_feature_blob_->Reshape({model_cloud_size_, pillar_feature_dim_});
642void CPDetection::GenerateBackboneFeatureCPU(
const base::Blob<float>* pillar_feature_blob) {
646 canvas_feature_blob_->mutable_cpu_data();
648 const float* pillar_feat_data = pillar_feature_blob->cpu_data();
649 const int* point2grid_data = point2grid_blob_->cpu_data();
650 const int* grid2pointnum_data = grid2pointnum_blob_->cpu_data();
653 int shape = pillar_feature_dim_ + cnnseg_feature_dim_;
654 canvas_feature_blob_->Reshape({1, shape, grid_x_size_, grid_y_size_});
655 float* canvas_feat_data = canvas_feature_blob_->mutable_cpu_data() + feature_offset_[
"canvas_feature"];
656 memset(canvas_feat_data, 0.f, map_size_ * pillar_feature_dim_ *
sizeof(
float));
659 for (
int i = 0; i < model_cloud_size_; ++i) {
660 int grid_idx = point2grid_data[i];
661 if (grid_idx == -1) {
664 int y = grid_idx / grid_x_size_;
665 int x = grid_idx % grid_x_size_;
666 for (
int c_idx = 0; c_idx < pillar_feature_dim_; c_idx++) {
667 int canvas_idx = c_idx * map_size_ + y * grid_x_size_ + x;
668 int pillar_idx = i * pillar_feature_dim_ + c_idx;
669 canvas_feat_data[canvas_idx] = std::max(
670 canvas_feat_data[canvas_idx], pillar_feat_data[pillar_idx]);
675float CPDetection::CalculateUnionArea(
const float *corners1,
const float *corners2) {
676 auto trangle_area_cpu = [&](
float* a,
float* b,
float* c) {
677 return ((a[0] - c[0]) * (b[1] - c[1]) - (a[1] - c[1]) * (b[0] - c[0])) / 2.f;
680 auto sort_vertex_in_convex_polygon_cpu = [&](
float* int_pts,
int num_of_inter) {
681 if (num_of_inter == 0) {
684 float center_x = 0.f;
685 float center_y = 0.f;
686 for (
int i = 0; i < num_of_inter; i++) {
687 center_x += int_pts[2 * i];
688 center_y += int_pts[2 * i + 1];
690 center_x /= num_of_inter;
691 center_y /= num_of_inter;
695 for (
int i = 0; i < num_of_inter; i++) {
696 v0 = int_pts[2 * i] - center_x;
697 v1 = int_pts[2 * i + 1] - center_y;
698 float d = sqrt(v0 * v0 + v1 * v1);
708 for (
int i = 0; i < num_of_inter; i++) {
709 if (vs[i - 1] > vs[i]) {
711 float tx = int_pts[2 * i];
712 float ty = int_pts[2 * i + 1];
714 while (j > 0 && vs[j - 1] > temp) {
716 int_pts[j * 2] = int_pts[j * 2 - 2];
717 int_pts[j * 2 + 1] = int_pts[j * 2 - 1];
722 int_pts[j * 2 + 1] = ty;
727 auto line_segment_intersection_cpu = [&](
const float* pts1,
const float* pts2,
int i,
int j,
float* temp_pts) {
728 float A0 = pts1[2 * i];
729 float A1 = pts1[2 * i + 1];
731 float B0 = pts1[2 * ((i + 1) % 4)];
732 float B1 = pts1[2 * ((i + 1) % 4) + 1];
734 float C0 = pts2[2 * j];
735 float C1 = pts2[2 * j + 1];
737 float D0 = pts2[2 * ((j + 1) % 4)];
738 float D1 = pts2[2 * ((j + 1) % 4) + 1];
745 bool acd = DA1 * CA0 > CA1 * DA0;
746 bool bcd = (D1 - B1) * (C0 - B0) > (C1 - B1) * (D0 - B0);
748 bool abc = CA1 * BA0 > BA1 * CA0;
749 bool abd = DA1 * BA0 > BA1 * DA0;
753 float ABBA = A0 * B1 - B0 * A1;
754 float CDDC = C0 * D1 - D0 * C1;
755 float DH = BA1 * DC0 - BA0 * DC1;
756 float Dx = ABBA * DC0 - BA0 * CDDC;
757 float Dy = ABBA * DC1 - BA1 * CDDC;
758 temp_pts[0] = Dx / DH;
759 temp_pts[1] = Dy / DH;
766 auto point_in_quadrilateral_cpu = [&](
float pt_x,
float pt_y,
const float* corners) {
767 float ab0 = corners[2] - corners[0];
768 float ab1 = corners[3] - corners[1];
769 float ad0 = corners[6] - corners[0];
770 float ad1 = corners[7] - corners[1];
771 float ap0 = pt_x - corners[0];
772 float ap1 = pt_y - corners[1];
773 float abab = ab0 * ab0 + ab1 * ab1;
774 float abap = ab0 * ap0 + ab1 * ap1;
775 float adad = ad0 * ad0 + ad1 * ad1;
776 float adap = ad0 * ap0 + ad1 * ap1;
777 return abab >= abap && abap >= 0 && adad >= adap && adap >= 0;
780 float intersection_corners[16];
782 int num_of_inter = 0;
783 for (
int i = 0; i < 4; i++) {
784 if (point_in_quadrilateral_cpu(corners1[2 * i], corners1[2 * i + 1], corners2)) {
785 intersection_corners[num_of_inter * 2] = corners1[2 * i];
786 intersection_corners[num_of_inter * 2 + 1] = corners1[2 * i + 1];
789 if (point_in_quadrilateral_cpu(corners2[2 * i], corners2[2 * i + 1], corners1)) {
790 intersection_corners[num_of_inter * 2] = corners2[2 * i];
791 intersection_corners[num_of_inter * 2 + 1] = corners2[2 * i + 1];
795 for (
int i = 0; i < 4; i++) {
796 for (
int j = 0; j < 4; j++) {
797 if (line_segment_intersection_cpu(corners1, corners2, i, j, intersection_corners + num_of_inter * 2)) {
802 sort_vertex_in_convex_polygon_cpu(intersection_corners, num_of_inter);
804 float area_val = 0.f;
805 for (
int i = 0; i < num_of_inter - 2; i++) {
806 area_val +=
abs(trangle_area_cpu(intersection_corners,
807 intersection_corners + 2 * (i + 1),
808 intersection_corners + 2 * (i + 2)));
813std::vector<ResultsOutput> CPDetection::ApplyNMSCPU(std::vector<ResultsOutput>& boxes) {
814 auto get_res_corners = [&](ResultsOutput& o) {
815 std::vector<float> box_corner;
816 box_corner.resize(8);
828 float cos_r =
cos(r);
829 float sin_r =
sin(r);
832 float x1 = (-hl) * cos_r - (-hw) * sin_r + x;
833 float y1 = (-hl) * sin_r + (-hw) * cos_r + y;
834 float x2 = ( hl) * cos_r - (-hw) * sin_r + x;
835 float y2 = ( hl) * sin_r + (-hw) * cos_r + y;
836 float x3 = ( hl) * cos_r - ( hw) * sin_r + x;
837 float y3 = ( hl) * sin_r + ( hw) * cos_r + y;
838 float x4 = (-hl) * cos_r - ( hw) * sin_r + x;
839 float y4 = (-hl) * sin_r + ( hw) * cos_r + y;
991 auto BBoxIoU = [&](ResultsOutput& o1, ResultsOutput& o2) {
992 std::vector<float> box_corner1 = get_res_corners(o1);
993 std::vector<float> box_corner2 = get_res_corners(o2);
994 float area_inter = CalculateUnionArea(box_corner1.data(), box_corner2.data());
995 float overlap = area_inter / std::max(o1.l * o1.w + o2.l * o2.w - area_inter, 0.001f);
1000 auto NmsCompare = [&](
const ResultsOutput& a,
const ResultsOutput& b) {
1001 if (a.confidence == b.confidence) {
1002 return a.model_type_index < b.model_type_index;
1004 return a.confidence > b.confidence;
1007 std::vector<ResultsOutput> res;
1008 std::sort(boxes.begin(), boxes.end(), NmsCompare);
1009 while (boxes.size() > 0) {
1010 res.push_back(boxes[0]);
1012 while (index < boxes.size()) {
1013 float iou = BBoxIoU(boxes[0], boxes[index]);
1014 if (iou > nms_overlap_thresh_) {
1015 boxes.erase(boxes.begin() + index);
1020 boxes.erase(boxes.begin());
1025void CPDetection::GetObjectsCPU() {
1029 int box_range = head_map_[
"reg"] + head_map_[
"hei"] + head_map_[
"dim"];
1030 std::vector<int> cls_range {0};
1033 float* all_res_box_data = all_res_box_blob_->mutable_cpu_data();
1034 float* all_res_conf_data = all_res_conf_blob_->mutable_cpu_data();
1035 int* all_res_cls_data = all_res_cls_blob_->mutable_cpu_data();
1036 memset(all_res_box_data, 0.f,
sizeof(
float) * max_candidate_num_ * kBoxBlockSize);
1037 memset(all_res_conf_data, 0.f,
sizeof(
float) * max_candidate_num_);
1038 memset(all_res_cls_data, -1,
sizeof(
int) * max_candidate_num_);
1040 res_outputs_.clear();
1041 std::vector<ResultsOutput> total_results;
1042 total_results.clear();
1043 for (
int i = 0; i < num_tasks_; ++i) {
1044 std::vector<ResultsOutput> task_results;
1045 task_results.clear();
1047 const float* reg = output_box_blob_->cpu_data() + output_box_blob_->offset(0, box_range * i);
1048 const float* hei = output_box_blob_->cpu_data() + output_box_blob_->offset(0, box_range * i + head_map_[
"reg"]);
1049 const float* dim = output_box_blob_->cpu_data() + output_box_blob_->offset(0, box_range * i + head_map_[
"reg"] + head_map_[
"hei"]);
1050 const float* cls = output_cls_blob_->cpu_data() + output_cls_blob_->offset(0, cls_range[i]);
1051 const float* rot = output_dir_blob_->cpu_data() + output_dir_blob_->offset(0, head_map_[
"rot"] * i);
1052 cls_range.push_back(cls_range[i] + num_classes_in_task_[i]);
1061 for (
int idx = 0; idx < head_map_size_; idx++) {
1062 float max_score = cls[idx];
1063 int label = cls_range[i];
1064 for (
int index = 1; index < num_classes_in_task_[i]; ++index) {
1065 float cur_score = cls[idx + index * head_map_size_];
1066 if (cur_score > max_score) {
1067 max_score = cur_score;
1068 label = index + cls_range[i];
1071 int coor_x = idx % head_x_size_;
1072 int coor_y = idx / head_x_size_;
1073 float conf = 1.0 / (1.0 + exp(-max_score));
1074 if (conf > score_thresh_map_[label]) {
1076 if (box_num >= nms_pre_max_size_) {
1079 float x = (reg[idx + 0 * head_map_size_] + coor_x) * downsample_size_ * voxel_x_size_ + x_min_range_;
1080 float y = (reg[idx + 1 * head_map_size_] + coor_y) * downsample_size_ * voxel_y_size_ + y_min_range_;
1082 float l = expf(dim[idx + 0 * head_map_size_]);
1083 float w = expf(dim[idx + 1 * head_map_size_]);
1084 float h = expf(dim[idx + 2 * head_map_size_]);
1085 float theta = atan2f(rot[idx], rot[idx + head_map_size_]);
1096 ResultsOutput output;
1104 output.model_type_index = type;
1105 output.confidence = conf;
1106 output.point_ids.clear();
1107 task_results.push_back(output);
1112 std::vector<ResultsOutput> nms_results = ApplyNMSCPU(task_results);
1113 for (
int j = 0; j < nms_results.size(); j++) {
1123 ResultsOutput output;
1124 output.x = nms_results[j].x;
1125 output.y = nms_results[j].y;
1126 output.z = nms_results[j].z;
1127 output.l = nms_results[j].l;
1128 output.w = nms_results[j].w;
1129 output.h = nms_results[j].h;
1130 output.yaw = nms_results[j].yaw;
1131 output.model_type_index = nms_results[j].model_type_index;
1132 output.confidence = nms_results[j].confidence;
1133 output.point_ids.clear();
1134 total_results.push_back(output);
1139 const int total_box = total_results.size();
1140 res_outputs_.resize(total_box);
1141 for (
int i = 0; i < total_box; i++) {
1148 float x = total_results[i].x;
1149 float y = total_results[i].y;
1150 float r = total_results[i].yaw;
1151 if (enable_rotate_45degree_) {
1152 x = 0.707107 * total_results[i].x + 0.707107 * total_results[i].y;
1153 y = -0.707107 * total_results[i].x + 0.707107 * total_results[i].y;
1156 r += (r <= -M_PI ? M_PI : 0.0);
1157 r -= (r >= M_PI ? M_PI : 0.0);
1158 res_outputs_.at(i).clear();
1159 res_outputs_.at(i).x = x;
1160 res_outputs_.at(i).y = y;
1161 res_outputs_.at(i).z = total_results[i].z - total_results[i].h / 2;
1162 res_outputs_.at(i).l = total_results[i].l;
1163 res_outputs_.at(i).w = total_results[i].w;
1164 res_outputs_.at(i).h = total_results[i].h;
1165 res_outputs_.at(i).yaw = r;
1166 res_outputs_.at(i).confidence = total_results[i].confidence;
1167 res_outputs_.at(i).model_type_index = total_results[i].model_type_index;
1169 total_results.clear();
1170 double get_time = timer.toc(
true);
1171 ADEBUG <<
"[GetObjectsCPU] time: " << get_time;
1174void CPDetection::AssignPointsCPU() {
1175 const int num_objects = res_outputs_.size();
1176 const float quantize = voxel_x_size_;
1178 std::vector<float> box_corner(num_objects * 8);
1179 std::vector<float> box_rectangular(num_objects * 4);
1180 for (
int i = 0; i < num_objects; ++i) {
1181 float xx = res_outputs_[i].x;
1182 float yy = res_outputs_[i].y;
1183 float l = res_outputs_[i].l;
1184 float w = res_outputs_[i].w;
1185 float a = res_outputs_[i].yaw;
1189 if (enable_rotate_45degree_) {
1190 x = 0.707107 * xx - 0.707107 * yy;
1191 y = 0.707107 * xx + 0.707107 * yy;
1195 w = ceil(w / quantize) * quantize;
1196 l = ceil(l / quantize) * quantize;
1198 if (width_enlarge_value_ > 0) {
1199 w = w + width_enlarge_value_;
1201 if (length_enlarge_value_ > 0) {
1202 l = l + length_enlarge_value_;
1204 float cos_a =
cos(a);
1205 float sin_a =
sin(a);
1209 float x1 = (-hl) * cos_a - (-hw) * sin_a + x;
1210 float y1 = (-hl) * sin_a + (-hw) * cos_a + y;
1211 float x2 = ( hl) * cos_a - (-hw) * sin_a + x;
1212 float y2 = ( hl) * sin_a + (-hw) * cos_a + y;
1213 float x3 = ( hl) * cos_a - ( hw) * sin_a + x;
1214 float y3 = ( hl) * sin_a + ( hw) * cos_a + y;
1215 float x4 = (-hl) * cos_a - ( hw) * sin_a + x;
1216 float y4 = (-hl) * sin_a + ( hw) * cos_a + y;
1217 box_corner[i * 8 + 0] = x1;
1218 box_corner[i * 8 + 1] = y1;
1219 box_corner[i * 8 + 2] = x2;
1220 box_corner[i * 8 + 3] = y2;
1221 box_corner[i * 8 + 4] = x3;
1222 box_corner[i * 8 + 5] = y3;
1223 box_corner[i * 8 + 6] = x4;
1224 box_corner[i * 8 + 7] = y4;
1225 box_rectangular[i * 4 + 0] = std::min(std::min(std::min(x1, x2), x3), x4);
1226 box_rectangular[i * 4 + 1] = std::min(std::min(std::min(y1, y2), y3), y4);
1227 box_rectangular[i * 4 + 2] = std::max(std::max(std::max(x1, x2), x3), x4);
1228 box_rectangular[i * 4 + 3] = std::max(std::max(std::max(y1, y2), y3), y4);
1230 double nms_time = timer.toc(
true);
1232 for (
int point_idx = 0; point_idx < original_cloud_->size(); ++point_idx) {
1234 original_cloud_->points_semantic_label(point_idx) & 15) ==
1236 bool raw_flag = (original_cloud_->points_label(point_idx) ==
1238 if ((remove_semantic_ground_ && semantic_flag) ||
1239 (remove_raw_ground_ && raw_flag)) {
1242 const auto &point = original_cloud_->at(point_idx);
1246 if (enable_rotate_45degree_) {
1247 px = 0.707107 * point.x - 0.707107 * point.y;
1248 py = 0.707107 * point.x + 0.707107 * point.y;
1250 for (
int i = 0; i < num_objects; i++) {
1251 if (px < box_rectangular[i * 4 + 0] || px > box_rectangular[i * 4 + 2]) {
1254 if (py < box_rectangular[i * 4 + 1] || py > box_rectangular[i * 4 + 3]) {
1257 float z = res_outputs_[i].z;
1258 float h = res_outputs_[i].h;
1260 if (pz < (z - h / 2 - bottom_enlarge_value_) || pz > (z + h / 2 + top_enlarge_value_)) {
1263 float x1 = box_corner[i * 8 + 0];
1264 float x2 = box_corner[i * 8 + 2];
1265 float x3 = box_corner[i * 8 + 4];
1266 float x4 = box_corner[i * 8 + 6];
1267 float y1 = box_corner[i * 8 + 1];
1268 float y2 = box_corner[i * 8 + 3];
1269 float y3 = box_corner[i * 8 + 5];
1270 float y4 = box_corner[i * 8 + 7];
1271 double angl1 = (px - x1) * (x2 - x1) + (py - y1) * (y2 - y1);
1272 double angl2 = (px - x2) * (x3 - x2) + (py - y2) * (y3 - y2);
1273 double angl3 = (px - x3) * (x4 - x3) + (py - y3) * (y4 - y3);
1274 double angl4 = (px - x4) * (x1 - x4) + (py - y4) * (y1 - y4);
1275 if ((angl1 < 0 && angl2 < 0 && angl3 < 0 && angl4 < 0) ||
1276 (angl1 > 0 && angl2 > 0 && angl3 > 0 && angl4 > 0)) {
1277 res_outputs_.at(i).point_ids.push_back(point_idx);
1281 double assign_point_time = timer.toc(
true);
1282 ADEBUG <<
"[AssignPointsCPU] total_point size " << original_cloud_->size()
1283 <<
" nms_box_time: " << nms_time
1284 <<
" assign point time: " << assign_point_time;
1287void CPDetection::FilterObjectsbyClassNMS(
1288 std::vector<std::shared_ptr<base::Object>> *objects) {
1289 auto ordinary_nms_strategy = [&](
size_t i,
size_t j,
1290 bool use_strategy =
false) {
1292 size_t type_i =
static_cast<size_t>(objects->at(i)->type);
1293 size_t type_j =
static_cast<size_t>(objects->at(j)->type);
1294 size_t filter_index =
1295 (objects->at(i)->confidence < objects->at(j)->confidence) ? i : j;
1297 if (nms_strategy_ || use_strategy) {
1298 return type_i > type_j ? j : i;
1300 return filter_index;
1303 auto special_nms_strategy = [&](
size_t keep_index,
1306 if (nms_strategy_) {
1309 objects->at(keep_index)->lidar_supplement.raw_probs.clear();
1310 objects->at(keep_index)->type_probs.clear();
1312 objects->at(keep_index)->lidar_supplement.raw_probs.push_back(
1313 std::vector<float>(
static_cast<int>(
1315 float sum_confidence = objects->at(keep_index)->confidence +
1316 objects->at(filter_index)->confidence;
1317 float filter_prob = 1.0 * (objects->at(filter_index)->confidence
1318 + conf_buffer) / (sum_confidence + conf_buffer);
1319 float keep_prob = 1.0 * objects->at(keep_index)->confidence /
1320 (sum_confidence + conf_buffer);
1321 objects->at(keep_index)->lidar_supplement.raw_probs.back()[
1322 static_cast<int>(filter_type)] = filter_prob;
1323 objects->at(keep_index)->lidar_supplement.raw_probs.back()[
1324 static_cast<int>(keep_type)] = keep_prob;
1325 objects->at(keep_index)->type_probs.assign(
1326 objects->at(keep_index)->lidar_supplement.raw_probs.back().begin(),
1327 objects->at(keep_index)->lidar_supplement.raw_probs.back().end());
1331 std::vector<float> box_corner;
1332 box_corner.resize(8);
1333 float x = obj->center(0);
1334 float y = obj->center(1);
1335 float l = obj->size(0);
1336 float w = obj->size(1);
1337 float r = obj->theta;
1344 float cos_r =
cos(r);
1345 float sin_r =
sin(r);
1348 float x1 = (-hl) * cos_r - (-hw) * sin_r + x;
1349 float y1 = (-hl) * sin_r + (-hw) * cos_r + y;
1350 float x2 = ( hl) * cos_r - (-hw) * sin_r + x;
1351 float y2 = ( hl) * sin_r + (-hw) * cos_r + y;
1352 float x3 = ( hl) * cos_r - ( hw) * sin_r + x;
1353 float y3 = ( hl) * sin_r + ( hw) * cos_r + y;
1354 float x4 = (-hl) * cos_r - ( hw) * sin_r + x;
1355 float y4 = (-hl) * sin_r + ( hw) * cos_r + y;
1368 std::vector<float> box_corner1 = get_obj_corners(obj1);
1369 std::vector<float> box_corner2 = get_obj_corners(obj2);
1370 float area_inter = CalculateUnionArea(box_corner1.data(), box_corner2.data());
1371 float overlap = area_inter / std::max(obj1->size(0) * obj1->size(1) + obj2->size(0) * obj2->size(1) - area_inter, 0.001f);
1375 std::vector<bool> delete_array(objects->size(),
false);
1376 std::vector<bool> nms_visited(objects->size(),
false);
1377 std::vector<std::vector<size_t>> nms_pairs;
1378 nms_pairs.resize(objects->size());
1380 for (
size_t i = 0; i < objects->size(); i++) {
1381 auto &obj_i = objects->at(i);
1382 if (!obj_i || nms_visited[i]) {
1385 for (
size_t j = i + 1; j < objects->size(); j++) {
1386 auto &obj_j = objects->at(j);
1390 if (calculate_nms(obj_i, obj_j) <= class_nms_iou_thres_) {
1393 if (
static_cast<int>(obj_i->type) ==
static_cast<int>(obj_j->type)) {
1396 nms_visited[j] =
true;
1397 nms_pairs[i].push_back(j);
1401 for (
size_t i = 0; i < objects->size(); i++) {
1402 if (nms_pairs[i].size() == 0) {
1405 if (nms_pairs[i].size() == 1) {
1406 size_t filter_index = ordinary_nms_strategy(i, nms_pairs[i][0]);
1407 size_t keep_index = filter_index == i ? nms_pairs[i][0] : i;
1409 delete_array[keep_index] =
false;
1410 delete_array[filter_index] =
true;
1413 auto filter_type = objects->at(filter_index)->type;
1414 auto reserve_type = objects->at(keep_index)->type;
1439 ADEBUG <<
"Only Two NMS: reserve " << keep_index
1440 <<
" filter " << filter_index;
1442 if (nms_pairs[i].size() >= 2) {
1444 bool have_car =
false;
1448 for (
size_t k = 0; k < nms_pairs[i].size() && !have_car; k++) {
1449 auto type = objects->at(nms_pairs[i][k])->type;
1458 auto keep_conf = objects->at(i)->confidence;
1459 auto keep_index = i;
1460 for (
size_t k = 0; k < nms_pairs[i].size(); k++) {
1461 if (objects->at(nms_pairs[i][k])->confidence > keep_conf) {
1462 delete_array[keep_index] =
true;
1463 keep_conf = objects->at(nms_pairs[i][k])->confidence;
1464 keep_index = nms_pairs[i][k];
1466 delete_array[nms_pairs[i][k]] =
true;
1467 ADEBUG <<
"NMS filter_index: " << nms_pairs[i][k];
1471 auto keep_type =
static_cast<size_t>(objects->at(i)->type);
1472 auto keep_index = i;
1473 for (
size_t k = 0; k < nms_pairs[i].size(); k++) {
1474 if (
static_cast<size_t>(
1475 objects->at(nms_pairs[i][k])->type) > keep_type) {
1476 delete_array[keep_index] =
true;
1477 keep_type =
static_cast<size_t>(
1478 objects->at(nms_pairs[i][k])->type);
1479 keep_index = nms_pairs[i][k];
1481 delete_array[nms_pairs[i][k]] =
true;
1482 ADEBUG <<
"NMS filter_index: " << nms_pairs[i][k];
1488 size_t valid_num = 0;
1489 for (
size_t i = 0; i < objects->size(); i++) {
1490 auto &
object = objects->at(i);
1491 if (!delete_array[i]) {
1492 objects->at(valid_num) = object;
1496 objects->resize(valid_num);
1499void CPDetection::FilterObjectsbySemanticType(
1500 std::vector<std::shared_ptr<base::Object>> *objects) {
1501 std::vector<bool> filter_flag(objects->size(),
false);
1502 for (
size_t i = 0; i < objects->size(); i++) {
1503 auto object = objects->at(i);
1505 for (
size_t k = 0; k <
object->lidar_supplement.cloud.size(); k++) {
1508 int index =
static_cast<int>(
GetSemanticLabel(object->lidar_supplement.cloud.points_semantic_label(k)));
1510 type_count[index]++;
1516 for (
size_t j = 0; j < type_count.size(); j++) {
1517 if (type_count.at(j) > max_value) {
1518 max_value = type_count.at(j);
1522 if (fore_semantic_filter_map_.find(max_index) == fore_semantic_filter_map_.end()) {
1526 float ratio =
static_cast<float>(
object->lidar_supplement.num_points_in_roi * 1.0f /
1527 object->lidar_supplement.cloud.size());
1529 float range = sqrt(object->center(0) * object->center(0) + object->center(1) * object->center(1));
1530 if (ratio >= fore_semantic_filter_map_.at(max_index).first &&
1531 range <= fore_semantic_filter_map_.at(max_index).second) {
1532 ADEBUG <<
"id = " <<
object->id <<
": total_size: " <<
object->lidar_supplement.cloud.size() <<
", roi_size: "
1533 <<
object->lidar_supplement.num_points_in_roi <<
", out_ratio: " << ratio
1534 <<
", semantic_type: " << max_index;
1535 filter_flag.at(i) =
true;
1540 for (
size_t i = 0; i < objects->size(); i++) {
1541 if (filter_flag.at(i)) {
1544 objects->at(valid_size) = objects->at(i);
1547 AINFO <<
"Filter " << (objects->size() - valid_size) <<
" objects from " << objects->size() <<
" objects.";
1548 objects->resize(valid_size);
1553 if (frame ==
nullptr) {
1554 AERROR <<
"Input null frame ptr.";
1557 if (frame->
cloud ==
nullptr) {
1558 AERROR <<
"Input null frame cloud.";
1561 if (frame->
cloud->size() == 0) {
1562 AERROR <<
"Input none points.";
1566 original_cloud_ = frame->
cloud;
1568 lidar_frame_ref_ = frame;
1569 cur_cloud_ptr_ = std::shared_ptr<base::PointFCloud>(
1574 AERROR <<
"Failed to set device to "
1580 PointCloudPreprocess();
1581 AINFO <<
"Downsample PointCloud from " << original_cloud_->size() <<
" to " << cur_cloud_ptr_->size();
1582 double pointcloud_pre_time = timer.
toc(
true);
1584 model_cloud_size_ =
static_cast<int>(cur_cloud_ptr_->size());
1585 total_cloud_size_ =
static_cast<int>(original_cloud_->size());
1587 double pfn_feature_generate_time = timer.
toc(
true);
1590 pfn_inference_->Infer();
1592 double pfn_inference_time = timer.
toc(
true);
1596 double backbone_feature_generate_time = timer.
toc(
true);
1599 backbone_inference_->Infer();
1601 double backbone_inference_time = timer.
toc(
true);
1604 double get_objects_and_assign_time = timer.
toc(
true);
1606 GenerateObjects(frame);
1607 std::stringstream sstr;
1608 sstr <<
"[CPDetection BeforeNMS] "
1612 sstr <<
"id = " << obj->id <<
": " << obj->center(0) <<
", "
1613 << obj->center(1) <<
", " << obj->center(2) <<
", "
1614 << obj->size(0) <<
", " << obj->size(1) <<
", "
1615 << obj->size(2) <<
", " << obj->theta <<
", "
1616 <<
static_cast<int>(obj->type) <<
", "
1617 << obj->confidence << std::endl;
1621 if (num_tasks_ > 1 && inter_class_nms_) {
1624 std::stringstream ssstr;
1625 ssstr <<
"[CenterPointDetection AfterNMS] "
1629 ssstr <<
"id = " << obj->id <<
": " << obj->center(0) <<
", "
1630 << obj->center(1) <<
", " << obj->center(2) <<
", "
1631 << obj->size(0) <<
", " << obj->size(1) <<
", "
1632 << obj->size(2) <<
", " << obj->theta <<
", "
1633 <<
static_cast<int>(obj->type) << std::endl;
1639 if (filter_by_semantic_type_) {
1644 res_outputs_.clear();
1645 double post_process_time = timer.
toc(
true);
1647 double total_time = pointcloud_pre_time + pfn_feature_generate_time +
1648 pfn_inference_time + backbone_feature_generate_time +
1649 backbone_inference_time + get_objects_and_assign_time + post_process_time;
1651 <<
", pointcloud preprocess: " << pointcloud_pre_time
1652 <<
", pfn feature generate: " << pfn_feature_generate_time
1653 <<
", pfn inference: " << pfn_inference_time
1654 <<
", backbone feature generate: " << backbone_feature_generate_time
1655 <<
", backbone inference: " << backbone_inference_time
1656 <<
", getObjects and assignPoints: " << get_objects_and_assign_time
1657 <<
", postProcess: " << post_process_time
1658 <<
", Total: " << total_time;
#define PERCEPTION_REGISTER_LIDARDETECTOR(name)
static PluginManager * Instance()
get singleton instance of PluginManager
std::shared_ptr< Base > CreateInstance(const std::string &derived_class)
create plugin instance of derived class based on Base
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
void GetObjectsAndAssignPoints()
bool Init(const CPDetectorInitOptions &options=CPDetectorInitOptions()) override
Init the Base Lidar Detector object
bool Detect(const CPDetectorOptions &options, LidarFrame *frame) override
Detect foreground objects
std::string Name() const
Name of Base Lidar Detector class
void GenerateBackboneFeature(const base::Blob< float > *pillar_feature_blob)
void GeneratePfnFeature()
static std::string GetFullClassName(const std::string &class_name)
Given the class name of perception module, combine the namespace "apollo::perception::lidar::" with i...
double toc(bool reset=false)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
const std::map< ObjectSubType, ObjectType > kSubType2TypeMap
ObjectSubType mapping
std::shared_ptr< Object > ObjectPtr
std::vector< std::string > GetBlobNames(const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
void AddShape(std::map< std::string, std::vector< int > > *shape_map, const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
PointSemanticLabel GetSemanticLabel(uint8_t value)
int Pc2Pixel(float in_pc, float in_range, float out_size)
T abs(const T &x)
Get absolute value of x
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
base::PointIndices roi_indices
std::shared_ptr< base::AttributePointCloud< base::PointD > > world_cloud
base::PointIndices non_ground_indices
std::vector< std::shared_ptr< base::Object > > segmented_objects
base::PointIndices secondary_indices
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud
optional CPDetModelParam model_param
optional CPDetPostProcessParam post_process
optional CPDetPreProcessParam pre_process
optional CPDetFilter filter_param
optional PluginParam plugins
optional float roi_out_ratio
optional int32 semantic_type
optional float filter_range
optional bool nms_strategy
optional bool inter_class_nms
optional bool remove_raw_ground
optional bool point_unique
optional float class_nms_iou_thres
optional bool filter_by_semantic_type
repeated ForeSemanticFilter fore_semantic_filter
optional bool remove_semantic_ground
optional int32 min_points_threshold
optional common::PointCloudPreProcess preprocess
optional int32 head_shape
optional string head_name
repeated subTask sub_task
optional string class_name
optional float score_thresh
optional int32 class_index
optional float top_enlarge_height
optional int32 nms_post_max_size
optional float bottom_enlarge_height
optional float score_thresh
optional bool use_cpu_assign_points
optional bool use_cpu_get_objects
optional float length_enlarge_value
optional float nms_overlap_thresh
optional int32 downsample_size
optional float width_enlarge_value
optional int32 nms_pre_max_size
optional float height_bin_min_height
optional bool enable_downsample_pointcloud
optional float voxel_y_size
optional float voxel_x_size
optional bool enable_rotate_45degree
optional float min_z_range
optional int32 pillar_feature_dim
optional int32 voxel_feature_dim
optional float height_bin_max_height
optional float min_x_range
optional bool use_gpu_generate_feature
optional float voxel_z_size
optional int32 num_classes
optional uint32 cnnseg_feature_dim
optional int32 max_voxel_num
optional float min_y_range
optional int32 max_points_in_voxel
optional float max_x_range
optional float max_z_range
optional float height_bin_voxel_size
optional float max_y_range
optional bool use_cnnseg_features
optional bool use_input_norm