Apollo 11.0
自动驾驶开放平台
pointwise_unet.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <memory>
20#include <string>
21#include <vector>
22#include <map>
23#include <limits>
24#include <algorithm>
25
26#include "modules/perception/pointcloud_motion/parser/pointwise_unet/proto/motion_unet.pb.h"
27
32
33namespace apollo {
34namespace perception {
35namespace lidar {
36
37struct Unode {
38 int point_size = 0;
39 // gravity center
40 float sum_x = 0;
41 float sum_y = 0;
42 float sum_z = 0;
43 // geometric center
44 float geometric_x = 0;
45 float geometric_y = 0;
46 float geometric_z = 0;
47 // unet coord
48 int grid_x = -1;
49 int grid_y = -1;
50};
51
52
54public:
55 MotionUnet() = default;
56
58
60
61 bool Parse(const PointCloudParserOptions& options, LidarFrame* frame);
62
63 std::string Name() const {
64 return "MotionUnet";
65 }
66
67private:
68 bool InitModel();
69
70 void GetValidPointcloud(base::PointFCloudPtr cloud) {
71 // valid point index
72 valid_point_index_.clear();
73 valid_point_index_.reserve(cloud->size());
74 // grid index vector
75 grid_index_vec_.clear();
76 grid_index_vec_.reserve(cloud->size() * 2);
77 for (size_t i = 0; i < cloud->size(); i++) {
78 auto pt = cloud->at(i);
79 // check valid range
80 if (pt.x < min_x_ || pt.x > max_x_ || pt.y < min_y_ || pt.y > max_y_ || pt.z < min_height_
81 || pt.z > max_height_) {
82 continue;
83 }
84 // get coordinate of pointcloud bev
85 int grid_x = (pt.x - min_x_) / resolution_;
86 int grid_y = (pt.y - min_y_) / resolution_;
87 if (grid_x >= 0 && grid_x < unet_width_ && grid_y >= 0 && grid_y < unet_length_) {
88 // valid point index
89 valid_point_index_.push_back(i);
90 // valid grid_y, grid_x
91 grid_index_vec_.push_back(grid_y);
92 grid_index_vec_.push_back(grid_x);
93
94 // max point number
95 if (static_cast<int>(valid_point_index_.size()) >= max_point_number_) {
96 break;
97 }
98 }
99 }
100 }
101
102 // pfn feature generater
103 void GeneratePfnFeature(base::PointFCloudPtr cloud) {
104 if (use_gpu_) {
105 GeneratePfnFeatureGPU(cloud);
106 } else {
107 GeneratePfnFeatureCPU(cloud);
108 }
109 }
110 void GeneratePfnFeatureCPU(base::PointFCloudPtr cloud);
111 void GeneratePfnFeatureGPU(base::PointFCloudPtr cloud);
112
113 // backbone feature generater
114 void GenerateBackboneFeature(std::shared_ptr<base::Blob<float>> feature) {
115 if (use_gpu_) {
116 GenerateBackboneFeatureGPU(feature);
117 } else {
118 GenerateBackboneFeatureCPU(feature);
119 }
120 }
121 void GenerateBackboneFeatureCPU(std::shared_ptr<base::Blob<float>> feature);
122 void GenerateBackboneFeatureGPU(std::shared_ptr<base::Blob<float>> feature);
123
124 void LabelToPointCloud(LidarFrame* frame);
125
126 void TransformCloud(base::PointFCloudPtr &cloud_ptr,
127 const base::PointDCloudPtr &world_cloud_ptr);
128
129private:
130 // reference pointer of lidar frame
131 LidarFrame* lidar_frame_ref_ = nullptr;
132 base::PointFCloudPtr original_cloud_;
133 base::PointDCloudPtr original_world_cloud_;
134 // model params
135 bool use_gpu_;
136 motion_unet::MotionUnetModelParam model_param_;
137 std::shared_ptr<inference::Inference> pfn_inference_;
138 std::shared_ptr<inference::Inference> inference_;
139 // Unet params
140 float resolution_;
141 int unet_width_;
142 int unet_length_;
143 float min_height_;
144 float max_height_;
145 float min_x_;
146 float max_x_;
147 float min_y_;
148 float max_y_;
149 int max_point_number_;
150 float z_offset_ = 0.0;
151
152 // pfn model blobs
153 std::shared_ptr<base::Blob<float>> voxels_; // (point_size, 10)
154 std::shared_ptr<base::Blob<float>> pfn_point_feats_; // (point_size, 64)
155 // backbone model blobs
156 // (point_size, 4), pillar coordinate of point
157 std::shared_ptr<base::Blob<float>> coors_;
158 std::shared_ptr<base::Blob<float>> point_feats_; // (point_size, 64)
159 std::shared_ptr<base::Blob<float>> bev_feature_; // (1, 64, height, width)
160 std::shared_ptr<base::Blob<float>> prev_bev_feature_; // (1, 64, height, width)
161 std::shared_ptr<base::Blob<float>> seg_pred_blob_; // (point_size, 4)
162
163 // point to pillar mapping
164 std::vector<int> valid_point_index_;
165 std::vector<int> grid_index_vec_;
166 std::vector<int> valid_node_index_;
167 // unet nodes, used for feature generating in cpu
168 std::vector<Unode> unet_nodes_;
169
170 // segmantic class mapping
171 std::vector<uint8_t> motion_class_mapping_;
172
173 // use for gpu feature generate
174 base::PointF* pc_gpu_ = nullptr;
175 cudaStream_t stream_ = 0;
176 int kGPUThreadSize = 512;
177
178 // previous pointcloud info
179 std::deque<std::pair<double, base::PointDCloudPtr>> prev_world_clouds_;
180};
181
182} // namespace lidar
183} // namespace perception
184} // namespace apollo
bool Parse(const PointCloudParserOptions &options, LidarFrame *frame)
Detect foreground objects
bool Init(const PointCloudParserInitOptions &options=PointCloudParserInitOptions())
Init the Base PointCloud Parser object
std::string Name() const
Name of Base PointCloud Parser class
Point< float > PointF
Definition point.h:56
std::shared_ptr< PointDCloud > PointDCloudPtr
std::shared_ptr< PointFCloud > PointFCloudPtr
class register implement
Definition arena_queue.h:37