Apollo 11.0
自动驾驶开放平台
apollo::perception::inference::ROIPoolingLayer< Dtype > 模板类 参考

#include <roipooling_layer.h>

类 apollo::perception::inference::ROIPoolingLayer< Dtype > 继承关系图:
apollo::perception::inference::ROIPoolingLayer< Dtype > 的协作图:

Public 成员函数

 ROIPoolingLayer (int pooled_h, int pooled_w, bool use_floor, float spatial_scale, int channels, int max_objs=1000)
 
void ForwardGPU (const std::vector< std::shared_ptr< base::Blob< Dtype > > > &bottom, const std::vector< std::shared_ptr< base::Blob< Dtype > > > &top)
 
void ForwardCPU (const std::vector< std::shared_ptr< base::Blob< Dtype > > > &bottom, const std::vector< std::shared_ptr< base::Blob< Dtype > > > &top)
 
- Public 成员函数 继承自 apollo::perception::inference::Layer< Dtype >
 Layer ()=default
 
virtual ~Layer ()=default
 
void set_gpu_id (const int &gpu_id)
 

额外继承的成员函数

- Protected 属性 继承自 apollo::perception::inference::Layer< Dtype >
int gpu_id_ = 0
 

详细描述

template<typename Dtype>
class apollo::perception::inference::ROIPoolingLayer< Dtype >

在文件 roipooling_layer.h 第 77 行定义.

构造及析构函数说明

◆ ROIPoolingLayer()

template<typename Dtype >
apollo::perception::inference::ROIPoolingLayer< Dtype >::ROIPoolingLayer ( int  pooled_h,
int  pooled_w,
bool  use_floor,
float  spatial_scale,
int  channels,
int  max_objs = 1000 
)
inline

在文件 roipooling_layer.h 第 79 行定义.

81 : channels_(0),
82 height_(0),
83 width_(0),
84 pooled_height_(pooled_h),
85 pooled_width_(pooled_w),
86 use_floor_(use_floor),
87 float_max_(std::numeric_limits<float>::max()),
88 spatial_scale_(spatial_scale) {
89 max_idx_.Reshape(max_objs, channels, pooled_height_, pooled_width_);
90 }
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
Definition blob.cc:72

成员函数说明

◆ ForwardCPU()

template<typename Dtype >
void apollo::perception::inference::ROIPoolingLayer< Dtype >::ForwardCPU ( const std::vector< std::shared_ptr< base::Blob< Dtype > > > &  bottom,
const std::vector< std::shared_ptr< base::Blob< Dtype > > > &  top 
)
virtual

实现了 apollo::perception::inference::Layer< Dtype >.

在文件 roipooling_layer.cc 第 75 行定义.

77 {
78 channels_ = bottom[0]->channels();
79 height_ = bottom[0]->height();
80 width_ = bottom[0]->width();
81 top[0]->Reshape(bottom[1]->num(), channels_, pooled_height_, pooled_width_);
82 auto feat_bottom = bottom[0];
83 auto roi_bottom = bottom[1];
84 const Dtype *bottom_data = feat_bottom->cpu_data();
85 const Dtype *bottom_rois = roi_bottom->cpu_data();
86 // Number of ROIs
87 int num_rois = roi_bottom->num();
88 int batch_size = feat_bottom->num();
89 int top_count = top[0]->count();
90 Dtype *top_data = top[0]->mutable_cpu_data();
91 memset(top_data, -1, static_cast<size_t>(float_max_ * sizeof(Dtype)));
92 int *argmax_data = max_idx_.mutable_cpu_data();
93 memset(argmax_data, -1, top_count * sizeof(int));
94 // For each ROI R = [batch_index x1 y1 x2 y2]: max pool over R
95 for (int n = 0; n < num_rois; ++n) {
96 int roi_batch_ind = static_cast<int>(bottom_rois[0]);
97 int roi_start_w = 0;
98 int roi_start_h = 0;
99 int roi_end_w = 0;
100 int roi_end_h = 0;
101 if (use_floor_) {
102 roi_start_w = static_cast<int>(floor(bottom_rois[1] * spatial_scale_));
103 roi_start_h = static_cast<int>(floor(bottom_rois[2] * spatial_scale_));
104 roi_end_w = static_cast<int>(floor(bottom_rois[3] * spatial_scale_));
105 roi_end_h = static_cast<int>(floor(bottom_rois[4] * spatial_scale_));
106 } else {
107 roi_start_w = static_cast<int>(round(bottom_rois[1] * spatial_scale_));
108 roi_start_h = static_cast<int>(round(bottom_rois[2] * spatial_scale_));
109 roi_end_w = static_cast<int>(round(bottom_rois[3] * spatial_scale_));
110 roi_end_h = static_cast<int>(round(bottom_rois[4] * spatial_scale_));
111 }
112 CHECK_GE(roi_batch_ind, 0);
113 CHECK_LT(roi_batch_ind, batch_size);
114
115 int roi_height = std::max(roi_end_h - roi_start_h + 1, 1);
116 int roi_width = std::max(roi_end_w - roi_start_w + 1, 1);
117 const Dtype bin_size_h =
118 static_cast<Dtype>(roi_height) / static_cast<Dtype>(pooled_height_);
119 const Dtype bin_size_w =
120 static_cast<Dtype>(roi_width) / static_cast<Dtype>(pooled_width_);
121
122 const Dtype *batch_data = bottom_data + bottom[0]->offset(roi_batch_ind);
123
124 for (int c = 0; c < channels_; ++c) {
125 for (int ph = 0; ph < pooled_height_; ++ph) {
126 for (int pw = 0; pw < pooled_width_; ++pw) {
127 // Compute pooling region for this output unit:
128 int hstart =
129 static_cast<int>(floor(static_cast<Dtype>(ph) * bin_size_h));
130 int wstart =
131 static_cast<int>(floor(static_cast<Dtype>(pw) * bin_size_w));
132 int hend =
133 static_cast<int>(ceil(static_cast<Dtype>(ph + 1) * bin_size_h));
134 int wend =
135 static_cast<int>(ceil(static_cast<Dtype>(pw + 1) * bin_size_w));
136
137 hstart = std::min(std::max(hstart + roi_start_h, 0), height_);
138 hend = std::min(std::max(hend + roi_start_h, 0), height_);
139 wstart = std::min(std::max(wstart + roi_start_w, 0), width_);
140 wend = std::min(std::max(wend + roi_start_w, 0), width_);
141
142 bool is_empty = (hend <= hstart) || (wend <= wstart);
143 const int pool_index = ph * pooled_width_ + pw;
144 if (is_empty) {
145 top_data[pool_index] = 0;
146 argmax_data[pool_index] = -1;
147 }
148
149 for (int h = hstart; h < hend; ++h) {
150 for (int w = wstart; w < wend; ++w) {
151 const int index = h * width_ + w;
152 if (batch_data[index] > top_data[pool_index]) {
153 top_data[pool_index] = batch_data[index];
154 argmax_data[pool_index] = index;
155 }
156 }
157 }
158 }
159 }
160 // Increment all data pointers by one channel
161 batch_data += feat_bottom->offset(0, 1);
162 top_data += top[0]->offset(0, 1);
163 argmax_data += max_idx_.offset(0, 1);
164 }
165 // Increment ROI data pointer
166 bottom_rois += roi_bottom->offset(1);
167 }
168}
int offset(const int n, const int c=0, const int h=0, const int w=0) const
Definition blob.h:231

◆ ForwardGPU()

template<typename Dtype >
void apollo::perception::inference::ROIPoolingLayer< Dtype >::ForwardGPU ( const std::vector< std::shared_ptr< base::Blob< Dtype > > > &  bottom,
const std::vector< std::shared_ptr< base::Blob< Dtype > > > &  top 
)
virtual

该类的文档由以下文件生成: