Apollo  6.0
Open source self driving car software
rcnn_proposal_plugin.h
Go to the documentation of this file.
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 
22 
23 namespace apollo {
24 namespace perception {
25 namespace inference {
26 
27 // TODO(chenjiahao): complete member functions
28 class RCNNProposalPlugin : public nvinfer1::IPlugin {
29  public:
31  const BBoxRegParameter &bbox_reg_param,
32  const DetectionOutputSSDParameter &detection_output_ssd_param,
33  nvinfer1::Dims *in_dims) {
34  num_rois_ = in_dims[2].d[0];
35 
36  for (int i = 0; i < 4; ++i) {
37  bbox_mean_[i] = bbox_reg_param.bbox_mean(i);
38  bbox_std_[i] = bbox_reg_param.bbox_std(i);
39  }
40 
41  min_size_mode_ =
42  static_cast<int>(detection_output_ssd_param.min_size_mode());
43  min_size_h_ = detection_output_ssd_param.min_size_h();
44  min_size_w_ = detection_output_ssd_param.min_size_w();
45 
46  num_class_ = detection_output_ssd_param.num_class();
47  refine_out_of_map_bbox_ =
48  detection_output_ssd_param.refine_out_of_map_bbox();
49  regress_agnostic_ = detection_output_ssd_param.regress_agnostic();
50  rpn_proposal_output_score_ =
51  detection_output_ssd_param.rpn_proposal_output_score();
52 
53  threshold_objectness_ = detection_output_ssd_param.threshold_objectness();
54  for (int i = 0; i < num_class_; ++i) {
55  thresholds_.push_back(detection_output_ssd_param.threshold(i));
56  }
57 
58  NMSSSDParameter nms_param = detection_output_ssd_param.nms_param();
59  max_candidate_n_ = nms_param.max_candidate_n(0);
60  overlap_ratio_ = nms_param.overlap_ratio(0);
61  top_n_ = nms_param.top_n(0);
62 
63  out_channel_ = rpn_proposal_output_score_ ? 9 : 5;
64  }
65 
66  virtual ~RCNNProposalPlugin() {}
67 
68  virtual int initialize() { return 0; }
69  virtual void terminate() {}
70  int getNbOutputs() const override { return 1; }
71 
72  nvinfer1::Dims getOutputDimensions(int index, const nvinfer1::Dims *inputs,
73  int nbInputDims) override {
74  // TODO(chenjiahao): complete input dims assertion
75  // TODO(chenjiahao): batch size is hard coded to 1 here
76  return nvinfer1::Dims4(top_n_ * 1, out_channel_, 1, 1);
77  }
78 
79  void configure(const nvinfer1::Dims *inputDims, int nbInputs,
80  const nvinfer1::Dims *outputDims, int nbOutputs,
81  int maxBatchSize) override {}
82 
83  size_t getWorkspaceSize(int maxBatchSize) const override { return 0; }
84 
85  virtual int enqueue(int batchSize, const void *const *inputs, void **outputs,
86  void *workspace, cudaStream_t stream);
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
void serialize(void *buffer) override
Definition: rcnn_proposal_plugin.h:90
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void configure(const nvinfer1::Dims *inputDims, int nbInputs, const nvinfer1::Dims *outputDims, int nbOutputs, int maxBatchSize) override
Definition: rcnn_proposal_plugin.h:79
virtual ~RCNNProposalPlugin()
Definition: rcnn_proposal_plugin.h:66
virtual void terminate()
Definition: rcnn_proposal_plugin.h:69
virtual int initialize()
Definition: rcnn_proposal_plugin.h:68
nvinfer1::Dims getOutputDimensions(int index, const nvinfer1::Dims *inputs, int nbInputDims) override
Definition: rcnn_proposal_plugin.h:72
virtual int enqueue(int batchSize, const void *const *inputs, void **outputs, void *workspace, cudaStream_t stream)
size_t getSerializationSize() override
Definition: rcnn_proposal_plugin.h:88
int getNbOutputs() const override
Definition: rcnn_proposal_plugin.h:70
RCNNProposalPlugin(const BBoxRegParameter &bbox_reg_param, const DetectionOutputSSDParameter &detection_output_ssd_param, nvinfer1::Dims *in_dims)
Definition: rcnn_proposal_plugin.h:30
size_t getWorkspaceSize(int maxBatchSize) const override
Definition: rcnn_proposal_plugin.h:83
Definition: rcnn_proposal_plugin.h:28