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

#include <cnn_segmentation.h>

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

Public 成员函数

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

详细描述

在文件 cnn_segmentation.h 第 37 行定义.

构造及析构函数说明

◆ CNNSegmentation()

apollo::perception::lidar::CNNSegmentation::CNNSegmentation ( )
default

Construct a new CNNSegmentation object

◆ ~CNNSegmentation()

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

Destroy the CNNSegmentation object

成员函数说明

◆ Detect()

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

Detect foreground objects using CNNSegmentation

参数
optionslidar detection options
framelidar frame
返回
true
false

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

在文件 cnn_segmentation.cc 第 184 行定义.

185 {
186 // check input
187 if (frame == nullptr) {
188 AERROR << "Input null frame ptr.";
189 return false;
190 }
191 if (frame->cloud == nullptr) {
192 AERROR << "Input null frame cloud.";
193 return false;
194 }
195 if (frame->world_cloud == nullptr) {
196 AERROR << "Input null frame world cloud.";
197 return false;
198 }
199 if (frame->cloud->size() == 0) {
200 AERROR << "Input none points.";
201 return false;
202 }
203 if (frame->cloud->size() != frame->world_cloud->size()) {
204 AERROR << "Cloud size and world cloud size not consistent.";
205 return false;
206 }
207 // record input cloud and lidar frame
208 original_cloud_ = frame->cloud;
209 original_world_cloud_ = frame->world_cloud;
210 lidar_frame_ref_ = frame;
211
212 // roi cloud
213 roi_cloud_->CopyPointCloud(*lidar_frame_ref_->cloud,
214 lidar_frame_ref_->roi_indices);
215 roi_world_cloud_->CopyPointCloud(*lidar_frame_ref_->world_cloud,
216 lidar_frame_ref_->roi_indices);
217
218 // check output
219 frame->segmented_objects.clear();
220
221 // note we should use origninal cloud here, frame->cloud may be exchanged
222 Timer timer;
223 // map 3d points to 2d image grids
224 MapPointToGrid(original_cloud_);
225 mapping_time_ = timer.toc(true);
226
227 if (cudaSetDevice(gpu_id_) != cudaSuccess) {
228 AERROR << "Failed to set device to " << gpu_id_;
229 return false;
230 }
231
232 // generate features
233 feature_generator_->Generate(original_cloud_, point2grid_);
234 feature_time_ = timer.toc(true);
235
236 // model inference
237 inference_->Infer();
238 infer_time_ = timer.toc(true);
239
240 // processing clustering
241 GetObjectsFromSppEngine(&frame->segmented_objects);
242
243 AINFO << "CNNSEG: mapping: " << mapping_time_ << "\t"
244 << " feature: " << feature_time_ << "\t"
245 << " infer: " << infer_time_ << "\t"
246 << " fg-seg: " << fg_seg_time_ << "\t"
247 << " collect: " << collect_time_;
248 return true;
249}
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::shared_ptr< base::AttributePointCloud< base::PointD > > world_cloud
Definition lidar_frame.h:37
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud
Definition lidar_frame.h:35

◆ Init()

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

Init of CNNSegmentation object

参数
optionslidar detection init options
返回
true
false

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

在文件 cnn_segmentation.cc 第 41 行定义.

41 {
42 sensor_name_ = options.sensor_name;
43 std::string config_file =
44 GetConfigFile(options.config_path, options.config_file);
45 ACHECK(apollo::cyber::common::GetProtoFromFile(config_file, &model_param_));
46
47 // init feature parameters
48 const cnnseg::FeatureParam& feature_param = model_param_.feature_param();
49 range_ = feature_param.point_cloud_range();
50 width_ = feature_param.width();
51 height_ = feature_param.height();
52 min_height_ = feature_param.min_height();
53 max_height_ = feature_param.max_height();
54
55 const auto& model_info = model_param_.info();
56 std::string model_path = GetModelPath(model_info.name());
57 std::string proto_file =
58 GetModelFile(model_path, model_info.proto_file().file());
59 std::string weight_file =
60 GetModelFile(model_path, model_info.weight_file().file());
61
62 // init inference model
63 std::vector<std::string> input_names =
64 inference::GetBlobNames(model_info.inputs());
65 std::vector<std::string> output_names =
66 inference::GetBlobNames(model_info.outputs());
67
68 inference_.reset(inference::CreateInferenceByName(
69 model_param_.info().framework(), proto_file, weight_file, output_names,
70 input_names));
71 CHECK_NOTNULL(inference_.get());
72
73 gpu_id_ = model_param_.preprocess().has_gpu_id()
74 ? model_param_.preprocess().gpu_id()
75 : -1;
76 BASE_GPU_CHECK(cudaSetDevice(gpu_id_));
77 inference_->set_gpu_id(gpu_id_); // inference sets CPU mode when -1
78
79 std::map<std::string, std::vector<int>> input_shapes;
80 inference::AddShape(&input_shapes, model_info.inputs());
81 auto& input_shape = input_shapes[input_names.at(0)];
82 if (!feature_param.use_intensity_feature()) {
83 input_shape[1] -= 2;
84 }
85 if (!feature_param.use_constant_feature()) {
86 input_shape[1] -= 2;
87 }
88 ACHECK(inference_->Init(input_shapes)) << "Failed to init inference.";
89
90 // init blobs
91 instance_pt_blob_ = inference_->get_blob(output_names.at(0));
92 CHECK_NOTNULL(instance_pt_blob_.get());
93 category_pt_blob_ = inference_->get_blob(output_names.at(1));
94 CHECK_NOTNULL(category_pt_blob_.get());
95 confidence_pt_blob_ = inference_->get_blob(output_names.at(2));
96 CHECK_NOTNULL(confidence_pt_blob_.get());
97 height_pt_blob_ = inference_->get_blob(output_names.at(3));
98 CHECK_NOTNULL(height_pt_blob_.get());
99 feature_blob_ = inference_->get_blob(input_names.at(0));
100 CHECK_NOTNULL(feature_blob_.get());
101 if (model_param_.do_classification()) {
102 classify_pt_blob_ = inference_->get_blob(output_names.at(5));
103 CHECK_NOTNULL(classify_pt_blob_.get());
104 }
105 if (model_param_.do_heading()) {
106 heading_pt_blob_ = inference_->get_blob(output_names.at(4));
107 CHECK_NOTNULL(heading_pt_blob_.get());
108 }
109
110 // init feature generator
111 feature_generator_.reset(new FeatureGenerator);
112 ACHECK(feature_generator_->Init(feature_param, feature_blob_.get()))
113 << "Failed to init feature generator.";
114
115 point2grid_.reserve(kDefaultPointCloudSize);
116
117 // init cluster and background segmentation methods
118 ACHECK(InitClusterAndBackgroundSegmentation());
119
120 return true;
121}
#define ACHECK(cond)
Definition log.h:80
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::PointCloudPreProcess preprocess

◆ Name()

std::string apollo::perception::lidar::CNNSegmentation::Name ( ) const
inlineoverridevirtual

Name of CNNSegmentation module

返回
std::string

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

在文件 cnn_segmentation.h 第 76 行定义.

76{ return "CNNSegmentation"; }

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