Apollo 11.0
自动驾驶开放平台
rcnn_proposal_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 <vector>
20
23
24namespace apollo {
25namespace perception {
26namespace inference {
27
28// TODO(chenjiahao): complete member functions
30 public:
32 const BBoxRegParameter &bbox_reg_param,
33 const DetectionOutputSSDParameter &detection_output_ssd_param,
34 Dims *in_dims) {
35 num_rois_ = in_dims[2].d[0];
36
37 for (int i = 0; i < 4; ++i) {
38 bbox_mean_[i] = bbox_reg_param.bbox_mean(i);
39 bbox_std_[i] = bbox_reg_param.bbox_std(i);
40 }
41
42 min_size_mode_ =
43 static_cast<int>(detection_output_ssd_param.min_size_mode());
44 min_size_h_ = detection_output_ssd_param.min_size_h();
45 min_size_w_ = detection_output_ssd_param.min_size_w();
46
47 num_class_ = detection_output_ssd_param.num_class();
48 refine_out_of_map_bbox_ =
49 detection_output_ssd_param.refine_out_of_map_bbox();
50 regress_agnostic_ = detection_output_ssd_param.regress_agnostic();
51 rpn_proposal_output_score_ =
52 detection_output_ssd_param.rpn_proposal_output_score();
53
54 threshold_objectness_ = detection_output_ssd_param.threshold_objectness();
55 for (int i = 0; i < num_class_; ++i) {
56 thresholds_.push_back(detection_output_ssd_param.threshold(i));
57 }
58
59 NMSSSDParameter nms_param = detection_output_ssd_param.nms_param();
60 max_candidate_n_ = nms_param.max_candidate_n(0);
61 overlap_ratio_ = nms_param.overlap_ratio(0);
62 top_n_ = nms_param.top_n(0);
63
64 out_channel_ = rpn_proposal_output_score_ ? 9 : 5;
65 }
66
68
69 int initialize() override { return 0; }
70 void terminate() override {}
71 int getNbOutputs() const override { return 1; }
72
73 Dims getOutputDimensions(int index, const Dims *inputs,
74 int nbInputDims) override {
75 // TODO(chenjiahao): complete input dims assertion
76 // TODO(chenjiahao): batch size is hard coded to 1 here
77 return Dims4(top_n_ * 1, out_channel_, 1, 1);
78 }
79
80 void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims,
81 int nbOutputs, int maxBatchSize) override {}
82
83 size_t getWorkspaceSize(int maxBatchSize) const override { return 0; }
84
85 int enqueue(int batchSize, const void *const *inputs, void **outputs,
86 void *workspace, cudaStream_t stream) override;
87
88 size_t getSerializationSize() override { return 0; }
89
90 void serialize(void *buffer) override {
91 char *d = reinterpret_cast<char *>(buffer), *a = d;
92 size_t size = getSerializationSize();
93 CHECK_EQ(d, a + size);
94 }
95
96 private:
97 const int thread_size_ = 512;
98 bool refine_out_of_map_bbox_ = true;
99 // TODO(chenjiahao): implement class-agnostic regression option
100 bool regress_agnostic_ = false;
101 bool rpn_proposal_output_score_ = true;
102
103 float bbox_mean_[4];
104 float bbox_std_[4];
105 float min_size_h_;
106 float min_size_w_;
107 float threshold_objectness_;
108 float overlap_ratio_;
109 int num_class_;
110 int num_rois_;
111 int max_candidate_n_;
112 int min_size_mode_;
113 int top_n_;
114 int out_channel_;
115 int acc_box_num_;
116
117 std::vector<float> thresholds_{};
118};
119
120} // namespace inference
121} // namespace perception
122} // namespace apollo
Definition plugin.h:31
Definition plugin.h:24
int32_t d[MAX_DIMS]
Definition plugin.h:28
size_t getWorkspaceSize(int maxBatchSize) const override
void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims, int nbOutputs, int maxBatchSize) override
Dims getOutputDimensions(int index, const Dims *inputs, int nbInputDims) override
int enqueue(int batchSize, const void *const *inputs, void **outputs, void *workspace, cudaStream_t stream) override
RCNNProposalPlugin(const BBoxRegParameter &bbox_reg_param, const DetectionOutputSSDParameter &detection_output_ssd_param, Dims *in_dims)
class register implement
Definition arena_queue.h:37