Apollo 11.0
自动驾驶开放平台
apollo::perception::lidar::CenterPointDetection类 参考

#include <center_point_detection.h>

类 apollo::perception::lidar::CenterPointDetection 继承关系图:
apollo::perception::lidar::CenterPointDetection 的协作图:

Public 成员函数

 CenterPointDetection ()
 Construct a new Center Point Detection object
 
virtual ~CenterPointDetection ()=default
 Destroy the Center Point Detection object
 
bool Init (const LidarDetectorInitOptions &options=LidarDetectorInitOptions()) override
 Init of Center Point Detection module
 
bool Detect (const LidarDetectorOptions &options, LidarFrame *frame) override
 Detect foreground object using centerpoint
 
std::string Name () const
 Name of Center Point Detection module
 
- Public 成员函数 继承自 apollo::perception::lidar::BaseLidarDetector
 BaseLidarDetector ()=default
 Construct a new Base Lidar Detector object
 
virtual ~BaseLidarDetector ()=default
 Destroy the Base Lidar Detector object
 

详细描述

在文件 center_point_detection.h 第 41 行定义.

构造及析构函数说明

◆ CenterPointDetection()

apollo::perception::lidar::CenterPointDetection::CenterPointDetection ( )

Construct a new Center Point Detection object

在文件 center_point_detection.cc 第 56 行定义.

57 : x_min_range_(Params::kMinXRange),
58 x_max_range_(Params::kMaxXRange),
59 y_min_range_(Params::kMinYRange),
60 y_max_range_(Params::kMaxYRange),
61 z_min_range_(Params::kMinZRange),
62 z_max_range_(Params::kMaxZRange) {}
static constexpr float kMaxYRange
Definition params.h:36
static constexpr float kMinYRange
Definition params.h:33
static constexpr float kMaxZRange
Definition params.h:37
static constexpr float kMinXRange
Definition params.h:32
static constexpr float kMinZRange
Definition params.h:34
static constexpr float kMaxXRange
Definition params.h:35

◆ ~CenterPointDetection()

virtual apollo::perception::lidar::CenterPointDetection::~CenterPointDetection ( )
virtualdefault

Destroy the Center Point Detection object

成员函数说明

◆ Detect()

bool apollo::perception::lidar::CenterPointDetection::Detect ( const LidarDetectorOptions &  options,
LidarFrame *  frame 
)
overridevirtual

Detect foreground object using centerpoint

参数
optionslidar dectection options
framelidar frame
返回
true
false

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 center_point_detection.cc 第 180 行定义.

181 {
182 // check input
183 if (frame == nullptr) {
184 AERROR << "Input null frame ptr.";
185 return false;
186 }
187 if (frame->cloud == nullptr) {
188 AERROR << "Input null frame cloud.";
189 return false;
190 }
191 if (frame->cloud->size() == 0) {
192 AERROR << "Input none points.";
193 return false;
194 }
195
196 // record input cloud and lidar frame
197 original_cloud_ = frame->cloud;
198 original_world_cloud_ = frame->world_cloud;
199 lidar_frame_ref_ = frame;
200
201 // check output
202 frame->segmented_objects.clear();
203
204 if (cudaSetDevice(model_param_.preprocess().gpu_id()) != cudaSuccess) {
205 AERROR << "Failed to set device to gpu "
206 << model_param_.preprocess().gpu_id();
207 return false;
208 }
209
210 Timer timer;
211
212 int num_points;
213 cur_cloud_ptr_ = std::shared_ptr<base::PointFCloud>(
214 new base::PointFCloud(*original_cloud_));
215
216 if (model_param_.preprocess().enable_roi_outside_removal()) {
217 cur_cloud_ptr_->CopyPointCloud(*original_cloud_, frame->roi_indices);
218 }
219
220 // down sample the point cloud through filtering beams
221 if (model_param_.preprocess().enable_downsample_beams()) {
222 base::PointFCloudPtr downsample_beams_cloud_ptr(new base::PointFCloud());
224 cur_cloud_ptr_, downsample_beams_cloud_ptr,
225 model_param_.preprocess().downsample_beams_factor())) {
226 cur_cloud_ptr_ = downsample_beams_cloud_ptr;
227 } else {
228 AWARN << "Down-sample beams factor must be >= 1. Cancel down-sampling."
229 " Current factor: "
230 << model_param_.preprocess().downsample_beams_factor();
231 }
232 }
233
234 // down sample the point cloud through filtering voxel grid
235 if (model_param_.preprocess().enable_downsample_pointcloud()) {
236 DownSampleOptions down_sample_options;
237 ACHECK(down_sample_ != nullptr);
238 down_sample_->Process(down_sample_options, cur_cloud_ptr_);
239 }
240
241 downsample_time_ = timer.toc(true);
242 num_points = cur_cloud_ptr_->size();
243 AINFO << "num points before fusing: " << num_points;
244
245 // fuse clouds of preceding frames with current cloud
246 cur_cloud_ptr_->mutable_points_timestamp()->assign(cur_cloud_ptr_->size(),
247 0.0);
248 if (model_param_.preprocess().enable_fuse_frames() &&
249 model_param_.preprocess().num_fuse_frames() > 1) {
250 // before fusing
251 while (!prev_world_clouds_.empty() &&
252 frame->timestamp - prev_world_clouds_.front()->get_timestamp() >
253 model_param_.preprocess().fuse_time_interval()) {
254 prev_world_clouds_.pop_front();
255 }
256 // transform current cloud to world coordinate and save to a new ptr
257 base::PointDCloudPtr cur_world_cloud_ptr =
258 std::make_shared<base::PointDCloud>();
259 for (size_t i = 0; i < cur_cloud_ptr_->size(); ++i) {
260 auto &pt = cur_cloud_ptr_->at(i);
261 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
262 trans_point = lidar_frame_ref_->lidar2world_pose * trans_point;
263 PointD world_point;
264 world_point.x = trans_point(0);
265 world_point.y = trans_point(1);
266 world_point.z = trans_point(2);
267 world_point.intensity = pt.intensity;
268 cur_world_cloud_ptr->push_back(world_point);
269 }
270 cur_world_cloud_ptr->set_timestamp(frame->timestamp);
271
272 // fusing clouds
273 for (auto &prev_world_cloud_ptr : prev_world_clouds_) {
274 num_points += prev_world_cloud_ptr->size();
275 }
276 FuseCloud(cur_cloud_ptr_, prev_world_clouds_);
277
278 // after fusing
279 while (static_cast<int>(prev_world_clouds_.size()) >=
280 model_param_.preprocess().num_fuse_frames() - 1) {
281 prev_world_clouds_.pop_front();
282 }
283 prev_world_clouds_.emplace_back(cur_world_cloud_ptr);
284 }
285 fuse_time_ = timer.toc(true);
286
287 // shuffle points and cut off
288 if (model_param_.preprocess().enable_shuffle_points()) {
289 num_points =
290 std::min(num_points, model_param_.preprocess().max_num_points());
291 std::vector<int> point_indices = GenerateIndices(0, num_points, true);
292 base::PointFCloudPtr shuffle_cloud_ptr(
293 new base::PointFCloud(*cur_cloud_ptr_, point_indices));
294 cur_cloud_ptr_ = shuffle_cloud_ptr;
295 }
296 shuffle_time_ = timer.toc(true);
297
298 // points_array[x, y, z, i,timestampe, ......]
299 std::vector<float> points_data(num_points *
300 model_param_.preprocess().num_point_feature());
301
302 CloudToArray(cur_cloud_ptr_, points_data.data(),
303 model_param_.preprocess().normalizing_factor());
304 cloud_to_array_time_ = timer.toc(true);
305
306 auto input_data_blob = inference_->get_blob(input_blob_names_.at(0));
307 auto output_bbox_blob = inference_->get_blob(output_blob_names_.at(0));
308 auto output_score_blob = inference_->get_blob(output_blob_names_.at(1));
309 auto output_label_blob = inference_->get_blob(output_blob_names_.at(2));
310
311 std::vector<int> points_shape{num_points,
312 model_param_.preprocess().num_point_feature()};
313 input_data_blob->Reshape(points_shape);
314 float *data_ptr = input_data_blob->mutable_cpu_data();
315 memcpy(data_ptr, points_data.data(), points_data.size() * sizeof(float));
316
317 inference_->Infer();
318
319 inference_time_ = timer.toc(true);
320
321 // paddle inference
322 std::vector<float> out_detections;
323 std::vector<int64_t> out_labels;
324 std::vector<float> out_scores;
325
326 // FilterScore(output_bbox_blob, output_label_blob, output_score_blob,
327 // model_param_.postprocess().score_threshold(), &out_detections,
328 // &out_labels, &out_scores);
329
330 FilterDiffScore(output_bbox_blob, output_label_blob, output_score_blob,
331 &out_detections, &out_labels, &out_scores);
332
333 GetObjects(frame->lidar2world_pose, out_detections,
334 out_labels, out_scores, &frame->segmented_objects);
335
336 std::stringstream sstr;
337 sstr << "[CenterPointDetection BeforeNMS] "
338 << std::to_string(frame->timestamp)
339 << " objs: " << frame->segmented_objects.size() << std::endl;
340 for (auto obj : frame->segmented_objects) {
341 sstr << "id = " << obj->id << ": " << obj->center(0) << ", "
342 << obj->center(1) << ", " << obj->center(2) << ", "
343 << obj->size(0) << ", " << obj->size(1) << ", "
344 << obj->size(2) << ", " << obj->theta << ", "
345 << static_cast<int>(obj->type) << ", "
346 << obj->confidence << std::endl;
347 }
348 ADEBUG << sstr.str();
349
350 if (model_param_.filter_by_points()) {
351 FilterObjectsbyPoints(&frame->segmented_objects);
352 }
353
354 PERF_BLOCK("class_nms")
355 if (diff_class_nms_) {
356 FilterObjectsbyClassNMS(&frame->segmented_objects);
357 }
359 nms_time_ = timer.toc(true);
360
361 // filter semantic if it's not unknown
362 if (model_param_.filter_by_semantic_type()) {
363 FilterObjectsbySemanticType(&frame->segmented_objects);
364 }
365
366 FilterForegroundPoints(&frame->segmented_objects);
367
368 SetPointsInROI(&frame->segmented_objects);
369
370 postprocess_time_ = timer.toc(true);
371
372 AINFO << "CenterPoint: "
373 << "\n"
374 << "down sample: " << downsample_time_ << "\t"
375 << "fuse: " << fuse_time_ << "\t"
376 << "shuffle: " << shuffle_time_ << "\t"
377 << "cloud_to_array: " << cloud_to_array_time_ << "\t"
378 << "inference: " << inference_time_ << "\t"
379 << "postprocess: " << postprocess_time_ << "\t"
380 << "nms: " << nms_time_ << "\t";
381
382 std::stringstream ssstr;
383 ssstr << "[CenterPointDetection AfterNMS] "
384 << std::to_string(frame->timestamp)
385 << " objs: " << frame->segmented_objects.size() << std::endl;
386 for (auto obj : frame->segmented_objects) {
387 ssstr << "id = " << obj->id << ": " << obj->center(0) << ", "
388 << obj->center(1) << ", " << obj->center(2) << ", "
389 << obj->size(0) << ", " << obj->size(1) << ", "
390 << obj->size(2) << ", " << obj->theta << ", "
391 << static_cast<int>(obj->type) << std::endl;
392 }
393 ADEBUG << ssstr.str();
394
395 return true;
396}
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
bool DownSamplePointCloudBeams(base::PointFCloudPtr cloud_ptr, base::PointFCloudPtr out_cloud_ptr, int downsample_factor)
AttributePointCloud< PointF > PointFCloud
std::shared_ptr< PointDCloud > PointDCloudPtr
std::shared_ptr< PointFCloud > PointFCloudPtr
Point< double > PointD
Definition point.h:57
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52
std::vector< std::shared_ptr< base::Object > > segmented_objects
Definition lidar_frame.h:53
optional common::PointCloudPreProcess preprocess

◆ Init()

bool apollo::perception::lidar::CenterPointDetection::Init ( const LidarDetectorInitOptions &  options = LidarDetectorInitOptions())
overridevirtual

Init of Center Point Detection module

参数
optionslidar detection init options
返回
true
false

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 center_point_detection.cc 第 64 行定义.

64 {
65 std::string config_file =
66 GetConfigFile(options.config_path, options.config_file);
67 ACHECK(apollo::cyber::common::GetProtoFromFile(config_file, &model_param_));
68
69 const auto &model_info = model_param_.info();
70 std::string model_path = GetModelPath(model_info.name());
71 // Network files
72 std::string proto_file =
73 GetModelFile(model_path, model_info.proto_file().file());
74 std::string weight_file =
75 GetModelFile(model_path, model_info.weight_file().file());
76 // Network input and output names
77 input_blob_names_ = inference::GetBlobNames(model_info.inputs());
78 output_blob_names_ = inference::GetBlobNames(model_info.outputs());
79
80 inference_.reset(inference::CreateInferenceByName(
81 model_info.framework(), proto_file, weight_file, output_blob_names_,
82 input_blob_names_));
83
84 std::map<std::string, std::vector<int>> shape_map;
85 inference::AddShape(&shape_map, model_info.inputs());
86 inference::AddShape(&shape_map, model_info.outputs());
87
88 if (!inference_->Init(shape_map)) {
89 return false;
90 }
91
92 if (model_param_.preprocess().enable_ground_removal()) {
93 z_min_range_ = std::max(
94 z_min_range_,
95 static_cast<float>(model_param_.preprocess().ground_removal_height()));
96 }
97 nms_strategy_ = model_param_.nms_strategy();
98 diff_class_iou_ = model_param_.diff_class_iou();
99 diff_class_nms_ = model_param_.diff_class_nms();
100
101 cone_score_threshold_ = model_param_.postprocess().cone_score_threshold();
102 ped_score_threshold_ = model_param_.postprocess().ped_score_threshold();
103 cyc_score_threshold_ = model_param_.postprocess().cyc_score_threshold();
104 small_mot_score_threshold_ =
105 model_param_.postprocess().small_mot_score_threshold();
106 big_mot_score_threshold_ =
107 model_param_.postprocess().big_mot_score_threshold();
108
109 if (model_param_.has_plugins()) {
110 const auto &plugin = model_param_.plugins();
111 const auto &name = plugin.name();
113 ->CreateInstance<BaseDownSample>(
115 if (!down_sample_) {
116 AINFO << "Failed to find down_sample plugin: " << name << ", skipped";
117 return false;
118 }
119 DownSampleInitOptions option;
120 option.config_path = plugin.config_path();
121 option.config_file = plugin.config_file();
122 if (!down_sample_->Init(option)) {
123 AINFO << "Failed to init down_sample plugin: " << name << ", skipped";
124 return false;
125 }
126 }
127 // if (diff_class_nms_) {
128 // nms_strategy_table_ = {
129 // {base::ObjectType::BICYCLE, {base::ObjectType::PEDESTRIAN,
130 // base::ObjectType::UNKNOWN}},
131 // {base::ObjectType::PEDESTRIAN, {base::ObjectType::UNKNOWN}},
132 // {base::ObjectType::VEHICLE, {base::ObjectType::BICYCLE,
133 // base::ObjectType::PEDESTRIAN, base::ObjectType::UNKNOWN}}
134 // };
135 // }
136 return true;
137}
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
static std::string GetFullClassName(const std::string &class_name)
Given the class name of perception module, combine the namespace "apollo::perception::lidar::" with i...
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,...
Definition file.cc:132
std::vector< std::string > GetBlobNames(const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
Definition model_util.cc:23
void AddShape(std::map< std::string, std::vector< int > > *shape_map, const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
Definition model_util.cc:32
Inference * CreateInferenceByName(const std::string &frame_work, const std::string &proto_file, const std::string &weight_file, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const std::string &model_root)
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
Definition util.cc:55
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
Definition util.cc:44
optional common::PointCloudPostProcess postprocess

◆ Name()

std::string apollo::perception::lidar::CenterPointDetection::Name ( ) const
inlinevirtual

Name of Center Point Detection module

返回
std::string

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 center_point_detection.h 第 80 行定义.

80{ return "CenterPointDetection"; }

该类的文档由以下文件生成: