目标检测算法中ROI提取方法比较+源码分析

本文主要介绍ROI提取结构在目标检测框架中的作用,并结合源码,理解它的实现方式。包含的算法有:ROI-pooling,ROI-align,Deformable-psroi-pooling。
目前,主流的目标检测算法大致分为2种,one-stage和two-stage方法。

  • one-stage:典型代表为SSD,相当于two-stage中的rpn结构,先通过基本的特征提取网络如resnet或vggnet得到特征图,再通过5层的卷积得到目标位置和类别。这种方法计算速度快,但是精度较two-stage方法差一些
  • two-stage:典型代表为Faster-rcnn。其结构分为RPN(Region Proposal Network)和RCNN(Region Convolution Neural Network)两个部分。RPN的特征通过ROI-Pooling层传递到RCNN中。

本文介绍的方法,仅出现在two-stage的方法中。顾名思义,该层的作用就是将RPN中提取的位置,截取特征图中特征用于进一步的分类和定位。


ROI-Pooling

Roi-pooling是Faster-rcnn原版使用的特征提取方式,论文在此。这里用动图来说明roi-pooling的过程(动图来源)
在这里插入图片描述
从上图看出,ROI-Pooling层的输入有两个:RPN层得到的位置和特征提取网络得到的特征。参数有pooling结果的宽高。
好了,下面结合图片来理解ROI-pooling代码,代码来源是pytorch-fasterrcnn项目,由于是cuda代码,所以如果你看了另外支持自定义operation的框架(如caffe,mxnet等)的roipooling实现方式,就会发现它们是完全一致的。
在这里插入图片描述
代码的注释中,增加了上图实例中各个变量的实际值,以便于读者理解。

_global__ void ROIPoolForward(const int nthreads, const float* bottom_data,
    const float spatial_scale, const int height, const int width,
    const int channels, const int pooled_height, const int pooled_width,
    const float* bottom_rois, float* top_data, int* argmax_data)
{
    CUDA_KERNEL_LOOP(index, nthreads)
    {
    	//index是gpu并行时块的计数
        int pw = index % pooled_width;//pooled_width=2,用户设置的参数,控制pooling输出大小
        int ph = (index / pooled_width) % pooled_height;//pooled_height=2,用户设置的参数,控制pooling输出大小
        int c  = (index / pooled_width / pooled_height) % channels;
        int n  = index / pooled_width / pooled_height / channels;

        // bottom_rois += n * 5;
        int roi_batch_ind = bottom_rois[n * 5 + 0];
        int roi_start_w = round(bottom_rois[n * 5 + 1] * spatial_scale);//rsw=0,左上角点横坐标,来自RPN
        int roi_start_h = round(bottom_rois[n * 5 + 2] * spatial_scale);//rsh=3,左上角点纵坐标,来自RPN
        int roi_end_w = round(bottom_rois[n * 5 + 3] * spatial_scale);//rew=7,右下角点横坐标,来自RPN
        int roi_end_h = round(bottom_rois[n * 5 + 4] * spatial_scale);//reh=8,
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值