Apollo 11.0
自动驾驶开放平台
dfmb_psroi_align_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 "cyber/common/log.h"
22
23namespace apollo {
24namespace perception {
25namespace inference {
26
27// TODO(chenjiahao): complete member functions
28// Custom layer for DFMBPSROIAlign operation,
29// i.e. DeForMaBle Position Sensitive ROI Align.
30// input0 dims: [C, H, W], input1 dims: [num_rois, 5, 1, 1]
31// input2 dims: [N, C2, H2, W2]
33 public:
35 const DFMBPSROIAlignParameter &dfmb_psroi_align_parameter, Dims *in_dims,
36 int nbInputs) {
37 heat_map_a_ = dfmb_psroi_align_parameter.heat_map_a();
38 output_channel_ = dfmb_psroi_align_parameter.output_dim();
39 group_height_ = dfmb_psroi_align_parameter.group_height();
40 group_width_ = dfmb_psroi_align_parameter.group_width();
41 pooled_height_ = dfmb_psroi_align_parameter.pooled_height();
42 pooled_width_ = dfmb_psroi_align_parameter.pooled_width();
43 pad_ratio_ = dfmb_psroi_align_parameter.pad_ratio();
44 sample_per_part_ = dfmb_psroi_align_parameter.sample_per_part();
45
46 trans_std_ = dfmb_psroi_align_parameter.trans_std();
47 part_height_ = dfmb_psroi_align_parameter.part_height();
48 part_width_ = dfmb_psroi_align_parameter.part_width();
49 heat_map_b_ = dfmb_psroi_align_parameter.heat_map_b();
50 no_trans_ = (nbInputs < 3);
51 num_classes_ = no_trans_ ? 1 : in_dims[2].d[1];
52
53 CHECK_GT(heat_map_a_, 0);
54 CHECK_GE(heat_map_b_, 0);
55 CHECK_GE(pad_ratio_, 0);
56 CHECK_GT(output_channel_, 0);
57 CHECK_GT(sample_per_part_, 0);
58 CHECK_GT(group_height_, 0);
59 CHECK_GT(group_width_, 0);
60 CHECK_GT(pooled_height_, 0);
61 CHECK_GT(pooled_width_, 0);
62 CHECK_GE(part_height_, 0);
63 CHECK_GE(part_width_, 0);
64
65 channels_ = in_dims[0].d[0];
66 height_ = in_dims[0].d[1];
67 width_ = in_dims[0].d[2];
68 output_dims_ =
69 Dims4(in_dims[1].d[0], output_channel_, pooled_height_, pooled_width_);
70 output_size_ =
71 in_dims[1].d[0] * output_channel_ * pooled_height_ * pooled_width_;
72
73 CHECK_EQ(channels_, output_channel_ * group_height_ * group_width_);
74 CHECK_EQ(in_dims[1].d[1], 5);
75 if (!no_trans_) {
76 CHECK_EQ(in_dims[2].d[1] % 2, 0);
77 int num_classes = in_dims[2].d[1] / 2;
78 CHECK_EQ(output_channel_ % num_classes, 0);
79 CHECK_EQ(part_height_, in_dims[2].d[2]);
80 CHECK_EQ(part_width_, in_dims[2].d[3]);
81 }
82 }
83
85
86 int initialize() override { return 0; }
87 void terminate() override {}
88 int getNbOutputs() const override { return 1; }
89
90 Dims getOutputDimensions(int index, const Dims *inputs,
91 int nbInputDims) override {
92 // TODO(chenjiahao): complete input dims assertion
93 return output_dims_;
94 }
95
96 void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims,
97 int nbOutputs, int maxBatchSize) override {}
98
99 size_t getWorkspaceSize(int maxBatchSize) const override { return 0; }
100
101 int enqueue(int batchSize, const void *const *inputs, void **outputs,
102 void *workspace, cudaStream_t stream) override;
103
104 size_t getSerializationSize() override { return 0; }
105
106 void serialize(void *buffer) override {
107 char *d = reinterpret_cast<char *>(buffer), *a = d;
108 size_t size = getSerializationSize();
109 CHECK_EQ(d, a + size);
110 }
111
112 private:
113 const int thread_size_ = 512;
114 float heat_map_a_;
115 float heat_map_b_;
116 float pad_ratio_;
117
118 int output_channel_;
119 bool no_trans_;
120 float trans_std_;
121 int sample_per_part_;
122 int group_height_;
123 int group_width_;
124 int pooled_height_;
125 int pooled_width_;
126 int part_height_;
127 int part_width_;
128 int num_classes_;
129
130 int channels_;
131 int height_;
132 int width_;
133 int output_size_;
134
135 Dims output_dims_;
136};
137
138} // namespace inference
139} // namespace perception
140} // namespace apollo
Definition plugin.h:31
Definition plugin.h:24
int32_t d[MAX_DIMS]
Definition plugin.h:28
DFMBPSROIAlignPlugin(const DFMBPSROIAlignParameter &dfmb_psroi_align_parameter, Dims *in_dims, int nbInputs)
size_t getWorkspaceSize(int maxBatchSize) const override
Dims getOutputDimensions(int index, const Dims *inputs, int nbInputDims) override
void configure(const Dims *inputDims, int nbInputs, const Dims *outputDims, int nbOutputs, int maxBatchSize) override
int enqueue(int batchSize, const void *const *inputs, void **outputs, void *workspace, cudaStream_t stream) override
class register implement
Definition arena_queue.h:37