Apollo 11.0
自动驾驶开放平台
feature_generator.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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#pragma once
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#include "gtest/gtest_prod.h"
23
24#include "modules/perception/lidar_detection/detector/cnn_segmentation/proto/model_param.pb.h"
25
28
29namespace apollo {
30namespace perception {
31namespace lidar {
32
34 public:
40#if USE_GPU == 1
41 pc_gpu_size_ = kMaxPointCloudGPUSize;
42 BASE_GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&pc_gpu_),
43 pc_gpu_size_ * sizeof(base::PointF)));
44 BASE_GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&point2grid_gpu_),
45 pc_gpu_size_ * sizeof(int)));
46#endif
47 }
48
54#if USE_GPU == 1
55 ReleaseGPUMemory();
56#endif
57 }
58
67 bool Init(const cnnseg::FeatureParam& feature_param,
68 base::Blob<float>* out_blob);
69
76 void Generate(const base::PointFCloudPtr& pc_ptr,
77 const std::vector<int>& point2grid) {
78#if USE_GPU == 1
79 GenerateGPU(pc_ptr, point2grid);
80#else
81 GenerateCPU(pc_ptr, point2grid);
82#endif
83 }
84
90 inline std::string Name() const { return "FeatureGenerator"; }
91
92 private:
93#if USE_GPU == 1
94 void GenerateGPU(const base::PointFCloudPtr& pc_ptr,
95 const std::vector<int>& point2grid);
96 void ReleaseGPUMemory();
97#endif
98 void GenerateCPU(const base::PointFCloudPtr& pc_ptr,
99 const std::vector<int>& point2grid);
100
101 float LogCount(int count) {
102 if (count < static_cast<int>(log_table_.size())) {
103 return log_table_[count];
104 }
105 return logf(static_cast<float>(1 + count));
106 }
107
108 // log table for CPU, with std::vector type
109 std::vector<float> log_table_;
110 // log table for GPU, with base::Blob type
111 std::shared_ptr<base::Blob<float>> log_blob_;
112 const int kMaxLogNum = 256;
113
114 // feature param
115 int width_ = 0;
116 int height_ = 0;
117 float range_ = 0.0f;
118 float min_height_ = 0.0f;
119 float max_height_ = 0.0f;
120 bool use_intensity_feature_ = false;
121 bool use_constant_feature_ = false;
122
123 // raw feature data
124 float* max_height_data_ = nullptr;
125 float* mean_height_data_ = nullptr;
126 float* count_data_ = nullptr;
127 float* direction_data_ = nullptr;
128 float* top_intensity_data_ = nullptr;
129 float* mean_intensity_data_ = nullptr;
130 float* distance_data_ = nullptr;
131 float* nonempty_data_ = nullptr;
132
133 // 1-d index in feature map of each point
134 std::vector<int> map_idx_;
135
136 // output feature blob
137 base::Blob<float>* out_blob_ = nullptr;
138
139 // param for managing gpu memory, only for cuda code
140 base::PointF* pc_gpu_ = nullptr;
141 int* point2grid_gpu_ = nullptr;
142 int pc_gpu_size_ = 0;
143 const int kMaxPointCloudGPUSize = 120000;
144 const int kGPUThreadSize = 512;
145
146 // for TEST only
147 FRIEND_TEST(FeatureGeneratorTest, basic_test);
149};
150
151} // namespace lidar
152} // namespace perception
153} // namespace apollo
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
Definition blob.h:88
void Generate(const base::PointFCloudPtr &pc_ptr, const std::vector< int > &point2grid)
Generate features for cnnseg
std::string Name() const
Name of Feature Generator
virtual ~FeatureGenerator()
Destroy the Feature Generator object
FeatureGenerator()
Construct a new Feature Generator object
bool Init(const cnnseg::FeatureParam &feature_param, base::Blob< float > *out_blob)
Init the Feature Generator
Point< float > PointF
Definition point.h:56
std::shared_ptr< PointFCloud > PointFCloudPtr
class register implement
Definition arena_queue.h:37