Apollo 11.0
自动驾驶开放平台
rpn_proposal_ssd_plugin.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 <algorithm>
20
23
24namespace apollo {
25namespace perception {
26namespace inference {
27
28// TODO(chenjiahao): complete member functions
29// Custom layer for RPNProposalSSD operation, i.e.
30// anchor generation and nms filtering
32 public:
34 const BBoxRegParameter &bbox_reg_param,
35 const DetectionOutputSSDParameter &detection_output_ssd_param,
36 Dims *in_dims) {
37 height_ = in_dims[0].d[1];
38 width_ = in_dims[0].d[2];
39
40 for (int i = 0; i < 4; ++i) {
41 bbox_mean_[i] = bbox_reg_param.bbox_mean(i);
42 bbox_std_[i] = bbox_reg_param.bbox_std(i);
43 }
44
45 GenAnchorParameter gen_anchor_param =
46 detection_output_ssd_param.gen_anchor_param();
47 num_anchor_per_point_ = std::min(gen_anchor_param.anchor_width().size(),
48 gen_anchor_param.anchor_height().size());
49 anchor_heights_ = new float[num_anchor_per_point_]();
50 anchor_widths_ = new float[num_anchor_per_point_]();
51 for (int i = 0; i < num_anchor_per_point_; ++i) {
52 anchor_heights_[i] = gen_anchor_param.anchor_height(i);
53 anchor_widths_[i] = gen_anchor_param.anchor_width(i);
54 }
55
56 heat_map_a_ = detection_output_ssd_param.heat_map_a();
57
58 min_size_mode_ =
59 static_cast<int>(detection_output_ssd_param.min_size_mode());
60 min_size_h_ = detection_output_ssd_param.min_size_h();
61 min_size_w_ = detection_output_ssd_param.min_size_w();
62
63 threshold_objectness_ = detection_output_ssd_param.threshold_objectness();
64 refine_out_of_map_bbox_ =
65 detection_output_ssd_param.refine_out_of_map_bbox();
66
67 NMSSSDParameter nms_param = detection_output_ssd_param.nms_param();
68 max_candidate_n_ = nms_param.max_candidate_n(0);
69 overlap_ratio_ = nms_param.overlap_ratio(0);
70 top_n_ = nms_param.top_n(0);
71 }
72
74
75 int initialize() override { return 0; }
76 void terminate() override {}
77 int getNbOutputs() const override { return 1; }
78
79 Dims getOutputDimensions(int index, const Dims *inputs,
80 int nbInputDims) override {
81 // TODO(chenjiahao): complete inputs dims assertion
82 // TODO(chenjiahao): batch size is hard coded to 1 here
83 return Dims4(top_n_ * 1, 5, 1, 1);
84 }
85
86 void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims,
87 int nbOutputs, int maxBatchSize) override {}
88
89 size_t getWorkspaceSize(int maxBatchSize) const override { return 0; }
90
91 int enqueue(int batchSize, const void *const *inputs, void **outputs,
92 void *workspace, cudaStream_t stream) override;
93
94 size_t getSerializationSize() override { return 0; }
95
96 void serialize(void *buffer) override {
97 char *d = reinterpret_cast<char *>(buffer), *a = d;
98 size_t size = getSerializationSize();
99 CHECK_EQ(d, a + size);
100 }
101
102 private:
103 const int thread_size_ = 512;
104 bool refine_out_of_map_bbox_ = true;
105 float bbox_mean_[4];
106 float bbox_std_[4];
107 float heat_map_a_;
108 float min_size_h_ = 0.0f;
109 float min_size_w_ = 0.0f;
110 float threshold_objectness_ = 0.2f;
111 float overlap_ratio_ = 0.7f;
112 int height_;
113 int width_;
114 int max_candidate_n_ = 3000;
115 int min_size_mode_ = 0;
116 int num_anchor_per_point_;
117 int top_n_ = 300;
118 int out_rois_num_;
119
120 float *anchor_heights_;
121 float *anchor_widths_;
122};
123
124} // namespace inference
125} // namespace perception
126} // namespace apollo
Definition plugin.h:31
Definition plugin.h:24
int32_t d[MAX_DIMS]
Definition plugin.h:28
Dims getOutputDimensions(int index, const Dims *inputs, int nbInputDims) override
RPNProposalSSDPlugin(const BBoxRegParameter &bbox_reg_param, const DetectionOutputSSDParameter &detection_output_ssd_param, Dims *in_dims)
int enqueue(int batchSize, const void *const *inputs, void **outputs, void *workspace, cudaStream_t stream) override
void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims, int nbOutputs, int maxBatchSize) override
size_t getWorkspaceSize(int maxBatchSize) const override
class register implement
Definition arena_queue.h:37