58const int PointPillars::kGridXSize =
59 static_cast<int>((kMaxXRange - kMinXRange) / kPillarXSize);
60const int PointPillars::kGridYSize =
61 static_cast<int>((kMaxYRange - kMinYRange) / kPillarYSize);
62const int PointPillars::kGridZSize =
63 static_cast<int>((kMaxZRange - kMinZRange) / kPillarZSize);
64const int PointPillars::kRpnInputSize = 64 * kGridXSize * kGridYSize;
67const int PointPillars::kRpnBoxOutputSize = kNumAnchor * kNumOutputBoxFeature;
68const int PointPillars::kRpnClsOutputSize = kNumAnchor * kNumClass;
69const int PointPillars::kRpnDirOutputSize = kNumAnchor * 2;
79const std::vector<int> PointPillars::kAnchorRanges{
84 static_cast<int>(kGridXSize * 0.25),
85 static_cast<int>(kGridXSize * 0.75),
86 static_cast<int>(kGridYSize * 0.25),
87 static_cast<int>(kGridYSize * 0.75)};
89const std::vector<std::vector<float>> PointPillars::kAnchorDxSizes =
91const std::vector<std::vector<float>> PointPillars::kAnchorDySizes =
93const std::vector<std::vector<float>> PointPillars::kAnchorDzSizes =
95const std::vector<std::vector<float>> PointPillars::kAnchorZCoors =
97const std::vector<std::vector<int>> PointPillars::kNumAnchorRo =
99const std::vector<std::vector<float>> PointPillars::kAnchorRo =
103 const float score_threshold,
104 const float nms_overlap_threshold,
105 const common::Framework& model_type,
106 const std::string& model_file)
107 : reproduce_result_mode_(reproduce_result_mode),
108 score_threshold_(score_threshold),
109 nms_overlap_threshold_(nms_overlap_threshold),
110 model_type_(model_type),
111 model_file_(model_file) {
112 if (reproduce_result_mode_) {
114 kMaxNumPillars, kMaxNumPointsPerPillar, kNumPointFeature, kGridXSize,
115 kGridYSize, kGridZSize, kPillarXSize, kPillarYSize, kPillarZSize,
116 kMinXRange, kMinYRange, kMinZRange, kNumIndsForScan));
119 kNumThreads, kMaxNumPillars, kMaxNumPointsPerPillar, kNumPointFeature,
120 kNumIndsForScan, kGridXSize, kGridYSize, kGridZSize, kPillarXSize,
121 kPillarYSize, kPillarZSize, kMinXRange, kMinYRange, kMinZRange));
125 kNumThreads, kNumIndsForScan, kNumAnchor, kMinXRange, kMinYRange,
126 kPillarXSize, kPillarYSize, kGridXSize, kGridYSize));
128 const float float_min = std::numeric_limits<float>::lowest();
129 const float float_max = std::numeric_limits<float>::max();
130 postprocess_cuda_ptr_.reset(
132 score_threshold_, kNumThreads, nms_overlap_threshold_,
133 kNumBoxCorners, kNumOutputBoxFeature));
135 DeviceMemoryMalloc();
141 delete[] anchors_px_;
142 delete[] anchors_py_;
143 delete[] anchors_pz_;
144 delete[] anchors_dx_;
145 delete[] anchors_dy_;
146 delete[] anchors_dz_;
147 delete[] anchors_ro_;
148 delete[] box_anchors_min_x_;
149 delete[] box_anchors_min_y_;
150 delete[] box_anchors_max_x_;
151 delete[] box_anchors_max_y_;
155 GPU_CHECK(cudaFree(dev_num_points_per_pillar_));
156 GPU_CHECK(cudaFree(dev_sparse_pillar_map_));
157 GPU_CHECK(cudaFree(dev_pillar_point_feature_));
160 GPU_CHECK(cudaFree(dev_cumsum_along_x_));
161 GPU_CHECK(cudaFree(dev_cumsum_along_y_));
163 GPU_CHECK(cudaFree(dev_box_anchors_min_x_));
164 GPU_CHECK(cudaFree(dev_box_anchors_min_y_));
165 GPU_CHECK(cudaFree(dev_box_anchors_max_x_));
166 GPU_CHECK(cudaFree(dev_box_anchors_max_y_));
178 GPU_CHECK(cudaFree(dev_scattered_feature_));
188 GPU_CHECK(cudaFree(dev_filtered_score_));
189 GPU_CHECK(cudaFree(dev_filtered_label_));
195void PointPillars::DeviceMemoryMalloc() {
196 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_x_coors_),
197 kMaxNumPillars *
sizeof(
int)));
198 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_y_coors_),
199 kMaxNumPillars *
sizeof(
int)));
200 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_num_points_per_pillar_),
201 kMaxNumPillars *
sizeof(
float)));
202 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_sparse_pillar_map_),
203 kNumIndsForScan * kNumIndsForScan *
sizeof(
int)));
205 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_pillar_point_feature_),
206 kMaxNumPillars * kMaxNumPointsPerPillar *
207 kNumPointFeature *
sizeof(
float)));
208 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_pillar_coors_),
209 kMaxNumPillars * 4 *
sizeof(
float)));
211 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_cumsum_along_x_),
212 kNumIndsForScan * kNumIndsForScan *
sizeof(
int)));
213 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_cumsum_along_y_),
214 kNumIndsForScan * kNumIndsForScan *
sizeof(
int)));
217 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_box_anchors_min_x_),
218 kNumAnchor *
sizeof(
float)));
219 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_box_anchors_min_y_),
220 kNumAnchor *
sizeof(
float)));
221 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_box_anchors_max_x_),
222 kNumAnchor *
sizeof(
float)));
223 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_box_anchors_max_y_),
224 kNumAnchor *
sizeof(
float)));
225 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchor_mask_),
226 kNumAnchor *
sizeof(
int)));
231 cudaMalloc(&pfe_buffers_[0], kMaxNumPillars * kMaxNumPointsPerPillar *
232 kNumPointFeature *
sizeof(
float)));
233 GPU_CHECK(cudaMalloc(&pfe_buffers_[1], kMaxNumPillars *
sizeof(
float)));
234 GPU_CHECK(cudaMalloc(&pfe_buffers_[2], kMaxNumPillars * 4 *
sizeof(
float)));
236 GPU_CHECK(cudaMalloc(&rpn_buffers_[0], kRpnInputSize *
sizeof(
float)));
237 GPU_CHECK(cudaMalloc(&rpn_buffers_[1], kRpnBoxOutputSize *
sizeof(
float)));
238 GPU_CHECK(cudaMalloc(&rpn_buffers_[2], kRpnClsOutputSize *
sizeof(
float)));
239 GPU_CHECK(cudaMalloc(&rpn_buffers_[3], kRpnDirOutputSize *
sizeof(
float)));
242 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_scattered_feature_),
243 kNumThreads * kGridYSize * kGridXSize *
sizeof(
float)));
246 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_px_),
247 kNumAnchor *
sizeof(
float)));
248 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_py_),
249 kNumAnchor *
sizeof(
float)));
250 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_pz_),
251 kNumAnchor *
sizeof(
float)));
252 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_dx_),
253 kNumAnchor *
sizeof(
float)));
254 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_dy_),
255 kNumAnchor *
sizeof(
float)));
256 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_dz_),
257 kNumAnchor *
sizeof(
float)));
258 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_anchors_ro_),
259 kNumAnchor *
sizeof(
float)));
260 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_filtered_box_),
261 kNumAnchor * kNumOutputBoxFeature *
sizeof(
float)));
262 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_filtered_score_),
263 kNumAnchor *
sizeof(
float)));
264 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_filtered_label_),
265 kNumAnchor *
sizeof(
int)));
266 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_filtered_dir_),
267 kNumAnchor *
sizeof(
int)));
268 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_box_for_nms_),
269 kNumAnchor * kNumBoxCorners *
sizeof(
float)));
271 cudaMalloc(
reinterpret_cast<void**
>(&dev_filter_count_),
sizeof(
int)));
274void PointPillars::InitAnchors() {
276 anchors_px_ =
new float[kNumAnchor]();
277 anchors_py_ =
new float[kNumAnchor]();
278 anchors_pz_ =
new float[kNumAnchor]();
279 anchors_dx_ =
new float[kNumAnchor]();
280 anchors_dy_ =
new float[kNumAnchor]();
281 anchors_dz_ =
new float[kNumAnchor]();
282 anchors_ro_ =
new float[kNumAnchor]();
283 box_anchors_min_x_ =
new float[kNumAnchor]();
284 box_anchors_min_y_ =
new float[kNumAnchor]();
285 box_anchors_max_x_ =
new float[kNumAnchor]();
286 box_anchors_max_y_ =
new float[kNumAnchor]();
289 GenerateAnchors(anchors_px_, anchors_py_, anchors_pz_, anchors_dx_,
290 anchors_dy_, anchors_dz_, anchors_ro_);
292 ConvertAnchors2BoxAnchors(anchors_px_, anchors_py_, box_anchors_min_x_,
293 box_anchors_min_y_, box_anchors_max_x_,
296 PutAnchorsInDeviceMemory();
299void PointPillars::GenerateAnchors(
float* anchors_px_,
float* anchors_py_,
300 float* anchors_pz_,
float* anchors_dx_,
301 float* anchors_dy_,
float* anchors_dz_,
302 float* anchors_ro_) {
303 for (
int i = 0; i < kNumAnchor; ++i) {
311 box_anchors_min_x_[i] = 0;
312 box_anchors_min_y_[i] = 0;
313 box_anchors_max_x_[i] = 0;
314 box_anchors_max_y_[i] = 0;
318 for (
size_t head = 0; head < kNumAnchorSets.size(); ++head) {
319 float x_stride = kPillarXSize * kAnchorStrides[head];
320 float y_stride = kPillarYSize * kAnchorStrides[head];
321 int x_ind_start = kAnchorRanges[head * 4 + 0] / kAnchorStrides[head];
322 int x_ind_end = kAnchorRanges[head * 4 + 1] / kAnchorStrides[head];
323 int y_ind_start = kAnchorRanges[head * 4 + 2] / kAnchorStrides[head];
324 int y_ind_end = kAnchorRanges[head * 4 + 3] / kAnchorStrides[head];
326 float x_offset = kMinXRange + x_stride / 2.0;
327 float y_offset = kMinYRange + y_stride / 2.0;
329 std::vector<float> anchor_x_count, anchor_y_count;
330 for (
int i = x_ind_start; i < x_ind_end; ++i) {
331 float anchor_coor_x =
static_cast<float>(i) * x_stride + x_offset;
332 anchor_x_count.push_back(anchor_coor_x);
334 for (
int i = y_ind_start; i < y_ind_end; ++i) {
335 float anchor_coor_y =
static_cast<float>(i) * y_stride + y_offset;
336 anchor_y_count.push_back(anchor_coor_y);
339 for (
int y = 0; y < y_ind_end - y_ind_start; ++y) {
340 for (
int x = 0; x < x_ind_end - x_ind_start; ++x) {
342 for (
size_t c = 0; c < kNumAnchorRo[head].size(); ++c) {
343 for (
int i = 0; i < kNumAnchorRo[head][c]; ++i) {
344 anchors_px_[ind] = anchor_x_count[x];
345 anchors_py_[ind] = anchor_y_count[y];
346 anchors_ro_[ind] = kAnchorRo[head][ro_count];
347 anchors_pz_[ind] = kAnchorZCoors[head][c];
348 anchors_dx_[ind] = kAnchorDxSizes[head][c];
349 anchors_dy_[ind] = kAnchorDySizes[head][c];
350 anchors_dz_[ind] = kAnchorDzSizes[head][c];
360void PointPillars::PutAnchorsInDeviceMemory() {
361 GPU_CHECK(cudaMemcpy(dev_box_anchors_min_x_, box_anchors_min_x_,
362 kNumAnchor *
sizeof(
float), cudaMemcpyHostToDevice));
363 GPU_CHECK(cudaMemcpy(dev_box_anchors_min_y_, box_anchors_min_y_,
364 kNumAnchor *
sizeof(
float), cudaMemcpyHostToDevice));
365 GPU_CHECK(cudaMemcpy(dev_box_anchors_max_x_, box_anchors_max_x_,
366 kNumAnchor *
sizeof(
float), cudaMemcpyHostToDevice));
367 GPU_CHECK(cudaMemcpy(dev_box_anchors_max_y_, box_anchors_max_y_,
368 kNumAnchor *
sizeof(
float), cudaMemcpyHostToDevice));
370 GPU_CHECK(cudaMemcpy(dev_anchors_px_, anchors_px_, kNumAnchor *
sizeof(
float),
371 cudaMemcpyHostToDevice));
372 GPU_CHECK(cudaMemcpy(dev_anchors_py_, anchors_py_, kNumAnchor *
sizeof(
float),
373 cudaMemcpyHostToDevice));
374 GPU_CHECK(cudaMemcpy(dev_anchors_pz_, anchors_pz_, kNumAnchor *
sizeof(
float),
375 cudaMemcpyHostToDevice));
376 GPU_CHECK(cudaMemcpy(dev_anchors_dx_, anchors_dx_, kNumAnchor *
sizeof(
float),
377 cudaMemcpyHostToDevice));
378 GPU_CHECK(cudaMemcpy(dev_anchors_dy_, anchors_dy_, kNumAnchor *
sizeof(
float),
379 cudaMemcpyHostToDevice));
380 GPU_CHECK(cudaMemcpy(dev_anchors_dz_, anchors_dz_, kNumAnchor *
sizeof(
float),
381 cudaMemcpyHostToDevice));
382 GPU_CHECK(cudaMemcpy(dev_anchors_ro_, anchors_ro_, kNumAnchor *
sizeof(
float),
383 cudaMemcpyHostToDevice));
386void PointPillars::ConvertAnchors2BoxAnchors(
float* anchors_px,
388 float* box_anchors_min_x_,
389 float* box_anchors_min_y_,
390 float* box_anchors_max_x_,
391 float* box_anchors_max_y_) {
393 float* flipped_anchors_dx =
new float[kNumAnchor]();
394 float* flipped_anchors_dy =
new float[kNumAnchor]();
397 for (
size_t head = 0; head < kNumAnchorSets.size(); ++head) {
399 (kAnchorRanges[head * 4 + 1] - kAnchorRanges[head * 4 + 0]) /
400 kAnchorStrides[head];
402 (kAnchorRanges[head * 4 + 3] - kAnchorRanges[head * 4 + 2]) /
403 kAnchorStrides[head];
406 for (
int x = 0; x < num_x_inds; ++x) {
407 for (
int y = 0; y < num_y_inds; ++y) {
409 for (
size_t c = 0; c < kNumAnchorRo[head].size(); ++c) {
410 for (
int i = 0; i < kNumAnchorRo[head][c]; ++i) {
411 if (kAnchorRo[head][ro_count] <= 0.78) {
412 flipped_anchors_dx[base_ind] = kAnchorDxSizes[head][c];
413 flipped_anchors_dy[base_ind] = kAnchorDySizes[head][c];
415 flipped_anchors_dx[base_ind] = kAnchorDySizes[head][c];
416 flipped_anchors_dy[base_ind] = kAnchorDxSizes[head][c];
425 for (
int x = 0; x < num_x_inds; ++x) {
426 for (
int y = 0; y < num_y_inds; ++y) {
427 for (
size_t i = 0; i < kAnchorRo[head].size(); ++i) {
428 box_anchors_min_x_[ind] =
429 anchors_px[ind] - flipped_anchors_dx[ind] / 2.0f;
430 box_anchors_min_y_[ind] =
431 anchors_py[ind] - flipped_anchors_dy[ind] / 2.0f;
432 box_anchors_max_x_[ind] =
433 anchors_px[ind] + flipped_anchors_dx[ind] / 2.0f;
434 box_anchors_max_y_[ind] =
435 anchors_py[ind] + flipped_anchors_dy[ind] / 2.0f;
442 delete[] flipped_anchors_dx;
443 delete[] flipped_anchors_dy;
446void PointPillars::InitTorch() {
449 model_type_, model_file_,
"", output_blob_names_, input_blob_names_));
450 CHECK_NOTNULL(inference_.get());
452 std::map<std::string, std::vector<int>> shape_map;
453 shape_map.emplace(std::pair<std::string, std::vector<int>>(
454 input_blob_names_[0],
455 {kMaxNumPillars, kMaxNumPointsPerPillar, kNumPointFeature}));
456 shape_map.emplace(std::pair<std::string, std::vector<int>>(
457 input_blob_names_[1], {kMaxNumPillars}));
458 shape_map.emplace(std::pair<std::string, std::vector<int>>(
459 input_blob_names_[2], {kMaxNumPillars, 4}));
461 shape_map.emplace(std::pair<std::string, std::vector<int>>(
462 output_blob_names_[0],
463 {1, kGridSize, kGridSize, kNumAnchorPerGrid * kNumClass}));
464 shape_map.emplace(std::pair<std::string, std::vector<int>>(
465 output_blob_names_[1],
466 {1, kGridSize, kGridSize, kNumAnchorPerGrid * 7}));
467 shape_map.emplace(std::pair<std::string, std::vector<int>>(
468 output_blob_names_[2],
469 {1, kGridSize, kGridSize, kNumAnchorPerGrid * 2}));
471 ACHECK(inference_->Init(shape_map)) <<
"Failed to init inference.";
474void PointPillars::InitTRT() {
475#if GPU_PLATFORM == NVIDIA
477 OnnxToTRTModel(pfe_onnx_file_, &pfe_engine_);
478 OnnxToTRTModel(rpn_onnx_file_, &rpn_engine_);
479 if (pfe_engine_ ==
nullptr || rpn_engine_ ==
nullptr) {
480 AERROR <<
"Failed to load ONNX file.";
484 pfe_context_ = pfe_engine_->createExecutionContext();
485 rpn_context_ = rpn_engine_->createExecutionContext();
486 if (pfe_context_ ==
nullptr || rpn_context_ ==
nullptr) {
487 AERROR <<
"Failed to create TensorRT Execution Context.";
489#elif GPU_PLATFORM == AMD
490 assert(0 &&
"PointPillars::InitTRT() is not implemented yet");
494void PointPillars::OnnxToTRTModel(
495 const std::string& model_file,
496 nvinfer1::ICudaEngine** engine_ptr) {
497#if GPU_PLATFORM == NVIDIA
498 int verbosity =
static_cast<int>(nvinfer1::ILogger::Severity::kWARNING);
501 const auto explicit_batch =
502 static_cast<uint32_t
>(kBatchSize) <<
static_cast<uint32_t
>(
503 nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
504 nvinfer1::IBuilder* builder = nvinfer1::createInferBuilder(g_logger_);
505 nvinfer1::INetworkDefinition* network =
506 builder->createNetworkV2(explicit_batch);
509 auto parser = nvonnxparser::createParser(*network, g_logger_);
510 if (!parser->parseFromFile(model_file.c_str(), verbosity)) {
511 std::string msg(
"failed to parse onnx file");
512 g_logger_.
log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
517 builder->setMaxBatchSize(kBatchSize);
518 nvinfer1::IBuilderConfig* config = builder->createBuilderConfig();
519 config->setMaxWorkspaceSize(1 << 20);
520 nvinfer1::ICudaEngine* engine =
521 builder->buildEngineWithConfig(*network, *config);
523 *engine_ptr = engine;
528#elif GPU_PLATFORM == AMD
529 assert(0 &&
"PointPillars::OnnxToTRTModel is not implemented yet");
533void PointPillars::PreprocessCPU(
const float* in_points_array,
534 const int in_num_points) {
535 int x_coors[kMaxNumPillars] = {};
536 int y_coors[kMaxNumPillars] = {};
537 float num_points_per_pillar[kMaxNumPillars] = {};
539 float* pillar_point_feature =
540 new float[kMaxNumPillars * kMaxNumPointsPerPillar * kNumPointFeature];
541 float* pillar_coors =
new float[kMaxNumPillars * 4];
542 float* sparse_pillar_map =
new float[kNumIndsForScan * kNumIndsForScan];
544 preprocess_points_ptr_->Preprocess(in_points_array, in_num_points, x_coors,
545 y_coors, num_points_per_pillar,
546 pillar_point_feature, pillar_coors,
547 sparse_pillar_map, host_pillar_count_);
549 GPU_CHECK(cudaMemset(dev_x_coors_, 0, kMaxNumPillars *
sizeof(
int)));
550 GPU_CHECK(cudaMemset(dev_y_coors_, 0, kMaxNumPillars *
sizeof(
int)));
551 GPU_CHECK(cudaMemset(dev_pillar_point_feature_, 0,
552 kMaxNumPillars * kMaxNumPointsPerPillar *
553 kNumPointFeature *
sizeof(
float)));
555 cudaMemset(dev_pillar_coors_, 0, kMaxNumPillars * 4 *
sizeof(
float)));
556 GPU_CHECK(cudaMemset(dev_num_points_per_pillar_, 0,
557 kMaxNumPillars *
sizeof(
float)));
558 GPU_CHECK(cudaMemset(dev_sparse_pillar_map_, 0,
559 kNumIndsForScan * kNumIndsForScan *
sizeof(
int)));
561 GPU_CHECK(cudaMemcpy(dev_x_coors_, x_coors, kMaxNumPillars *
sizeof(
int),
562 cudaMemcpyHostToDevice));
563 GPU_CHECK(cudaMemcpy(dev_y_coors_, y_coors, kMaxNumPillars *
sizeof(
int),
564 cudaMemcpyHostToDevice));
565 GPU_CHECK(cudaMemcpy(dev_pillar_point_feature_, pillar_point_feature,
566 kMaxNumPillars * kMaxNumPointsPerPillar *
567 kNumPointFeature *
sizeof(
float),
568 cudaMemcpyHostToDevice));
569 GPU_CHECK(cudaMemcpy(dev_pillar_coors_, pillar_coors,
570 kMaxNumPillars * 4 *
sizeof(
float),
571 cudaMemcpyHostToDevice));
572 GPU_CHECK(cudaMemcpy(dev_num_points_per_pillar_, num_points_per_pillar,
573 kMaxNumPillars *
sizeof(
float), cudaMemcpyHostToDevice));
574 GPU_CHECK(cudaMemcpy(dev_sparse_pillar_map_, sparse_pillar_map,
575 kNumIndsForScan * kNumIndsForScan *
sizeof(
float),
576 cudaMemcpyHostToDevice));
578 delete[] pillar_point_feature;
579 delete[] pillar_coors;
580 delete[] sparse_pillar_map;
583void PointPillars::PreprocessGPU(
const float* in_points_array,
584 const int in_num_points) {
586 GPU_CHECK(cudaMalloc(
reinterpret_cast<void**
>(&dev_points),
587 in_num_points * kNumPointFeature *
sizeof(
float)));
588 GPU_CHECK(cudaMemcpy(dev_points, in_points_array,
589 in_num_points * kNumPointFeature *
sizeof(
float),
590 cudaMemcpyHostToDevice));
592 GPU_CHECK(cudaMemset(dev_x_coors_, 0, kMaxNumPillars *
sizeof(
int)));
593 GPU_CHECK(cudaMemset(dev_y_coors_, 0, kMaxNumPillars *
sizeof(
int)));
594 GPU_CHECK(cudaMemset(dev_num_points_per_pillar_, 0,
595 kMaxNumPillars *
sizeof(
float)));
596 GPU_CHECK(cudaMemset(dev_pillar_point_feature_, 0,
597 kMaxNumPillars * kMaxNumPointsPerPillar *
598 kNumPointFeature *
sizeof(
float)));
600 cudaMemset(dev_pillar_coors_, 0, kMaxNumPillars * 4 *
sizeof(
float)));
601 GPU_CHECK(cudaMemset(dev_sparse_pillar_map_, 0,
602 kNumIndsForScan * kNumIndsForScan *
sizeof(
int)));
603 host_pillar_count_[0] = 0;
605 GPU_CHECK(cudaMemset(dev_anchor_mask_, 0, kNumAnchor *
sizeof(
int)));
607 preprocess_points_cuda_ptr_->DoPreprocessPointsCuda(
608 dev_points, in_num_points, dev_x_coors_, dev_y_coors_,
609 dev_num_points_per_pillar_, dev_pillar_point_feature_, dev_pillar_coors_,
610 dev_sparse_pillar_map_, host_pillar_count_);
615void PointPillars::Preprocess(
const float* in_points_array,
616 const int in_num_points) {
617 if (reproduce_result_mode_) {
618 PreprocessCPU(in_points_array, in_num_points);
620 PreprocessGPU(in_points_array, in_num_points);
625 const int in_num_points,
626 std::vector<float>* out_detections,
627 std::vector<int>* out_labels) {
628 if (device_id_ < 0) {
629 AERROR <<
"Torch is not using GPU!";
633 Preprocess(in_points_array, in_num_points);
635 anchor_mask_cuda_ptr_->DoAnchorMaskCuda(
636 dev_sparse_pillar_map_, dev_cumsum_along_x_, dev_cumsum_along_y_,
637 dev_box_anchors_min_x_, dev_box_anchors_min_y_, dev_box_anchors_max_x_,
638 dev_box_anchors_max_y_, dev_anchor_mask_);
641 auto pillar_point_feature = inference_->get_blob(input_blob_names_.at(0));
642 auto points_per_pillar = inference_->get_blob(input_blob_names_.at(1));
643 auto pillar_coors = inference_->get_blob(input_blob_names_.at(2));
646 GPU_CHECK(cudaMemcpyAsync(pillar_point_feature->mutable_gpu_data(),
647 dev_pillar_point_feature_,
648 kMaxNumPillars * kMaxNumPointsPerPillar *
649 kNumPointFeature *
sizeof(
float),
650 cudaMemcpyDeviceToDevice, stream));
651 GPU_CHECK(cudaMemcpyAsync(points_per_pillar->mutable_gpu_data(),
652 dev_num_points_per_pillar_,
653 kMaxNumPillars *
sizeof(
float),
654 cudaMemcpyDeviceToDevice, stream));
655 GPU_CHECK(cudaMemcpyAsync(pillar_coors->mutable_gpu_data(),
657 kMaxNumPillars * 4 *
sizeof(
float),
658 cudaMemcpyDeviceToDevice, stream));
661 auto cls_score = inference_->get_blob(output_blob_names_.at(0));
662 auto bbox_pred = inference_->get_blob(output_blob_names_.at(1));
663 auto dir_cls_preds = inference_->get_blob(output_blob_names_.at(2));
665 GPU_CHECK(cudaMemset(dev_filter_count_, 0,
sizeof(
int)));
666 postprocess_cuda_ptr_->DoPostprocessCuda(
667 bbox_pred->gpu_data(),
668 cls_score->gpu_data(),
669 dir_cls_preds->gpu_data(),
670 dev_anchor_mask_, dev_anchors_px_, dev_anchors_py_, dev_anchors_pz_,
671 dev_anchors_dx_, dev_anchors_dy_, dev_anchors_dz_, dev_anchors_ro_,
672 dev_filtered_box_, dev_filtered_score_, dev_filtered_label_,
673 dev_filtered_dir_, dev_box_for_nms_, dev_filter_count_, out_detections,
677 cudaStreamDestroy(stream);
void log(Severity severity, const char *msg) noexcept override
static std::vector< std::vector< float > > AnchorDySizes()
static constexpr float kMaxYRange
static constexpr float kPillarYSize
static constexpr int kNumAnchor
static constexpr int kNumClass
static constexpr float kPillarXSize
static constexpr int kNumThreads
static constexpr float kMinYRange
static std::vector< std::vector< float > > AnchorRo()
static constexpr int kNumIndsForScan
static constexpr int kMaxNumPillars
static constexpr int kBatchSize
static constexpr float kMaxZRange
static constexpr int kNumAnchorPerGrid
static constexpr int kMaxNumPointsPerPillar
static constexpr int kGridSize
static std::vector< std::vector< float > > AnchorDzSizes()
static constexpr float kMinXRange
static constexpr float kPillarZSize
static std::vector< int > NumAnchorSets()
static std::vector< int > AnchorStrides()
static constexpr int kNumBoxCorners
static std::vector< std::vector< float > > AnchorDxSizes()
static std::vector< std::vector< int > > NumAnchorRo()
static constexpr int kNumOutputBoxFeature
static constexpr float kMinZRange
static constexpr int kNumPointFeature
static constexpr float kMaxXRange
static std::vector< std::vector< float > > AnchorZCoors()
~PointPillars()
Destroy the Point Pillars object
PointPillars(const bool reproduce_result_mode, const float score_threshold, const float nms_overlap_threshold, const common::Framework &model_type, const std::string &model_file)
Constructor
void DoInference(const float *in_points_array, const int in_num_points, std::vector< float > *out_detections, std::vector< int > *out_labels)
Call PointPillars for the inference
Algorithm for PointPillars
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)