Fast RCNN: RoI Pooling 原理及代码
RoI Pooling 层 初始化参数 pooled_weight_ RoI池化层宽网格数(即论文中W=7) pooled_height_ RoI池化层高网格数(即论文中H=7) spatial_scale_ 从输入图像的坐标到特征图像坐标的缩放值 Forward函数流程 输入:(特征图data,位置信息rois) * Batch个 从Batch中取一张特征图datas的一个通道data,从此图对应的rois中取一个roi,得到(id,x,y,w,h) 缩放roi使其对应到特征图中位置(四舍五入为整数)得到(Rx,Ry,Rw,Rh) round(roi * spatial_scale_) 通过Rw,Rh得到每个bin的长宽BINw,BINh(四舍五入为整数) round(Rw / pooled_weight_) 遍历BIN中的特征值,将最大值作为输出,并记录此值对应在特征图的位置 示意图 Caffe代码 摘自 jiongnima //cpu前传函数 template <typename Dtype> void ROIPoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0][/latex]gt;cpu_data();//bottom_data表示共享卷积层输出的特征图 const Dtype* bottom_rois = bottom[1][/latex]gt;cpu_data();//bottom_rois表示rois的信息,一共5维,第一维表示rois在训练batch中的图片索引,后四维表示rois的坐标信息 // Number of ROIs int num_rois = bottom[1][/latex]gt;num();//roi的总数 int batch_size = bottom[0][/latex]gt;num();//batch_size表示一次训练中输入的图片数量,因为roi并不是都存在于同一张图片上 int top_count = top[0][/latex]gt;count();//top_count表示top[0]的全部容量(N*C*H*W) Dtype* top_data = top[0][/latex]gt;mutable_cpu_data();//使用top_data指针索引top[0] caffe_set(top_count, Dtype(-FLT_MAX), top_data);//初始化top_data(即top[0]),将其初始值(共top_count个)置为最小值(-FLT_MAX) int* argmax_data = max_idx_.mutable_cpu_data();//使用argmax_data指针索引max_idx_ caffe_set(top_count, -1, argmax_data);//初始化argmax_data(即max_idx_),将其初始值(共top_count个)置为-1 // For each ROI R = [batch_index x1 y1 x2 y2]: max pool over R (rois的五维数据的说明) for (int n =...