深度学习: RPN (区域候选网络)

深度学习: RPN (区域候选网络)Overview绿框内为RPN所在的位置:放大之后是这样:庖丁解牛RPN由以下三部分构成:在RPN头部,通过以下结构生成anchor(其实就是一堆有编号有坐标的bbox):论文中的这幅插图对应的就是RPN头部:(曾经以为这张图就是整个RPN,于是百思不得其解,走了不少弯路。。。)在RPN中部,分类分支(cls)和边框回归分支(b…

大家好,又见面了,我是你们的朋友全栈君。

Overview

RPN的本质是 “ 基于滑窗的无类别object检测器 ” :
这里写图片描述

RPN所在的位置:
这里写图片描述

Note

  • 只有在train时,cls+reg才能得到强监督信息(来源于ground truth)。即ground truth会告诉cls+reg结构,哪些才是真的前景,从而引导cls+reg结构学得正确区分前后景的能力;在inference阶段,就要靠cls+reg自力更生了。
  • 在train阶段,会输出约2000个proposal,但只会抽取其中256个proposal来训练RPN的cls+reg结构(其中,128个前景proposal用来训练cls+reg,128个背景proposal用来只训练cls);到了inference阶段,则直接输出最高score的300个proposal。此时由于没有了监督信息,所有RPN并不知道这些proposal是否为前景,整个过程只是惯性地推送一波无tag的proposal给后面的Fast R-CNN。
  • RPN的运用使得region proposal的额外开销就只有一个两层网络

放大之后是这样:
这里写图片描述

庖丁解牛

RPN由以下三部分构成:

  1. RPN头部 ,通过以下结构生成 anchor(其实就是一堆有编号有坐标的bbox):
    这里写图片描述

    论文中的这幅插图对应的就是 RPN头部
    这里写图片描述
    (曾经以为这张图就是整个RPN,于是百思不得其解,走了不少弯路。。。)

  2. RPN中部分类分支(cls)边框回归分支(bbox reg) 分别对这堆anchor进行各种计算:
    这里写图片描述
    Note: two stage型的检测算法在RPN 之后 还会进行 再一次分类任务边框回归任务,以进一步提升检测精度。

  3. RPN末端,通过对 两个分支的结果进行汇总,来实现对anchor的 初步筛除(先剔除越界的anchor,再根据cls结果通过NMS算法去重)和 初步偏移(根据bbox reg结果),此时输出的都改头换面叫 Proposal 了:
    这里写图片描述

后话

RPN之后,proposal 成为 RoI (感兴趣区域) ,被输入 RoIPooling 或 RoIAlign 中进行 size上的归一化。当然,这些都是 RPN网络 之后 的操作了,严格来说并 不属于 RPN 的范围 了。

图中 绿框内RPN红圈内RoI 以及其对应的 Pooling 操作
这里写图片描述

Note

  • 如果只在最后一层 feature map 上映射回原图像,且初始产生的anchor被限定了尺寸下限,那么低于最小anchor尺寸的小目标虽然被anchor圈入,在后面的过程中依然容易被漏检。
  • 但是FPN的出现,大大降低了小目标的漏检率,使得RPN如虎添翼。
  • 关于RPN的具体结构,我自己也画了一张图解。有兴趣的可以看一下:论文阅读: Faster R-CNN

Source Code

作者的源码

#========= RPN ============

layer { 
   
  name: "rpn_conv/3x3"
  type: "Convolution"
  bottom: "conv5"
  top: "rpn/output"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  convolution_param { 
   
    num_output: 256
    kernel_size: 3 pad: 1 stride: 1
    weight_filler { 
    type: "gaussian" std: 0.01 }
    bias_filler { 
    type: "constant" value: 0 }
  }
}
layer { 
   
  name: "rpn_relu/3x3"
  type: "ReLU"
  bottom: "rpn/output"
  top: "rpn/output"
}
layer { 
   
  name: "rpn_cls_score"
  type: "Convolution"
  bottom: "rpn/output"
  top: "rpn_cls_score"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  convolution_param { 
   
    num_output: 18   # 2(bg/fg) * 9(anchors)
    kernel_size: 1 pad: 0 stride: 1
    weight_filler { 
    type: "gaussian" std: 0.01 }
    bias_filler { 
    type: "constant" value: 0 }
  }
}
layer { 
   
  name: "rpn_bbox_pred"
  type: "Convolution"
  bottom: "rpn/output"
  top: "rpn_bbox_pred"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  convolution_param { 
   
    num_output: 36   # 4 * 9(anchors)
    kernel_size: 1 pad: 0 stride: 1
    weight_filler { 
    type: "gaussian" std: 0.01 }
    bias_filler { 
    type: "constant" value: 0 }
  }
}
layer { 
   
   bottom: "rpn_cls_score"
   top: "rpn_cls_score_reshape"
   name: "rpn_cls_score_reshape"
   type: "Reshape"
   reshape_param { 
    shape { 
    dim: 0 dim: 2 dim: -1 dim: 0 } }
}
layer { 
   
  name: 'rpn-data'
  type: 'Python'
  bottom: 'rpn_cls_score'
  bottom: 'gt_boxes'
  bottom: 'im_info'
  bottom: 'data'
  top: 'rpn_labels'
  top: 'rpn_bbox_targets'
  top: 'rpn_bbox_inside_weights'
  top: 'rpn_bbox_outside_weights'
  python_param { 
   
    module: 'rpn.anchor_target_layer'
    layer: 'AnchorTargetLayer'
    param_str: "'feat_stride': 16"
  }
}
layer { 
   
  name: "rpn_loss_cls"
  type: "SoftmaxWithLoss"
  bottom: "rpn_cls_score_reshape"
  bottom: "rpn_labels"
  propagate_down: 1
  propagate_down: 0
  top: "rpn_cls_loss"
  loss_weight: 1
  loss_param { 
   
    ignore_label: -1
    normalize: true
  }
}
layer { 
   
  name: "rpn_loss_bbox"
  type: "SmoothL1Loss"
  bottom: "rpn_bbox_pred"
  bottom: "rpn_bbox_targets"
  bottom: 'rpn_bbox_inside_weights'
  bottom: 'rpn_bbox_outside_weights'
  top: "rpn_loss_bbox"
  loss_weight: 1
  smooth_l1_loss_param { 
    sigma: 3.0 }
}

#========= RoI Proposal ============

layer { 
   
  name: "rpn_cls_prob"
  type: "Softmax"
  bottom: "rpn_cls_score_reshape"
  top: "rpn_cls_prob"
}
layer { 
   
  name: 'rpn_cls_prob_reshape'
  type: 'Reshape'
  bottom: 'rpn_cls_prob'
  top: 'rpn_cls_prob_reshape'
  reshape_param { 
    shape { 
    dim: 0 dim: 18 dim: -1 dim: 0 } }
}
layer { 
   
  name: 'proposal'
  type: 'Python'
  bottom: 'rpn_cls_prob_reshape'
  bottom: 'rpn_bbox_pred'
  bottom: 'im_info'
  top: 'rpn_rois'
# top: 'rpn_scores'
  python_param { 
   
    module: 'rpn.proposal_layer'
    layer: 'ProposalLayer'
    param_str: "'feat_stride': 16"
  }
}
layer { 
   
  name: 'roi-data'
  type: 'Python'
  bottom: 'rpn_rois'
  bottom: 'gt_boxes'
  top: 'rois'
  top: 'labels'
  top: 'bbox_targets'
  top: 'bbox_inside_weights'
  top: 'bbox_outside_weights'
  python_param { 
   
    module: 'rpn.proposal_target_layer'
    layer: 'ProposalTargetLayer'
    param_str: "'num_classes': 21"
  }
}

#========= RCNN ============

layer { 
   
  name: "roi_pool_conv5"
  type: "ROIPooling"
  bottom: "conv5"
  bottom: "rois"
  top: "roi_pool_conv5"
  roi_pooling_param { 
   
    pooled_w: 6
    pooled_h: 6
    spatial_scale: 0.0625 # 1/16
  }
}
layer { 
   
  name: "fc6"
  type: "InnerProduct"
  bottom: "roi_pool_conv5"
  top: "fc6"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  inner_product_param { 
   
    num_output: 4096
  }
}
layer { 
   
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
}
layer { 
   
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param { 
   
    dropout_ratio: 0.5
    scale_train: false
  }
}
layer { 
   
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6"
  top: "fc7"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  inner_product_param { 
   
    num_output: 4096
  }
}
layer { 
   
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
}
layer { 
   
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param { 
   
    dropout_ratio: 0.5
    scale_train: false
  }
}
layer { 
   
  name: "cls_score"
  type: "InnerProduct"
  bottom: "fc7"
  top: "cls_score"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  inner_product_param { 
   
    num_output: 21
    weight_filler { 
   
      type: "gaussian"
      std: 0.01
    }
    bias_filler { 
   
      type: "constant"
      value: 0
    }
  }
}
layer { 
   
  name: "bbox_pred"
  type: "InnerProduct"
  bottom: "fc7"
  top: "bbox_pred"
  param { 
    lr_mult: 1.0 }
  param { 
    lr_mult: 2.0 }
  inner_product_param { 
   
    num_output: 84
    weight_filler { 
   
      type: "gaussian"
      std: 0.001
    }
    bias_filler { 
   
      type: "constant"
      value: 0
    }
  }
}
layer { 
   
  name: "loss_cls"
  type: "SoftmaxWithLoss"
  bottom: "cls_score"
  bottom: "labels"
  propagate_down: 1
  propagate_down: 0
  top: "cls_loss"
  loss_weight: 1
  loss_param { 
   
    ignore_label: -1
    normalize: true
  }
}
layer { 
   
  name: "loss_bbox"
  type: "SmoothL1Loss"
  bottom: "bbox_pred"
  bottom: "bbox_targets"
  bottom: 'bbox_inside_weights'
  bottom: 'bbox_outside_weights'
  top: "bbox_loss"
  loss_weight: 1
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152319.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月23日 下午2:46
下一篇 2022年6月23日 下午2:46


相关推荐

  • Windows server 2003 安装vs2005 sp1补丁包报1718错误的解决方法

    Windows server 2003 安装vs2005 sp1补丁包报1718错误的解决方法收藏于2012-03-30迁移自个人的百度空间——————————–解决步骤如下1.在控制面板中打开“管理工具“。2.双击“本地安全策略”。 3.单击“软件限制策略”。(注意:如果未列出软件限制,请右击“软件限制策略”,然后单击“新建策略”。)4.在“对象类型”下,双击“强制”。 5.单击“除本地管理员以外的所有用户”…

    2022年10月5日
    5
  • 限流算法对比

    限流算法对比计数器优点 简单 易实现缺点 先到先得 先到的请求可执行概率为 100 后到的请求可执行概率小一些 每个请求获得执行的机会是不平等的 临界点问题 滑动窗口是计数器的升级版 解决了临界点问题 但计数多复杂已有实现 Sentinel 滑动窗口的格子划分的越多 那么滑动窗口的滚动就越平滑 限流的统计就会越精确 漏桶算法比如 rabbitmq 等 都属于漏桶算法原理优点 流量控制

    2026年3月16日
    4
  • 克莱姆法则应用_克莱姆和克拉默法则

    克莱姆法则应用_克莱姆和克拉默法则克莱姆法则(由线性方程组的系数确定方程组解的表达式)是线性代数中一个关于求解线性方程组的定理,它适用于变量和方程数目相等的线性方程组。概念含有n个未知数的线性方程组称为n元线性方程组。1)当其右端的常数项b1,b2,…,bn不全为零时,称为非齐次线性方程组:其中,A是线性方程组的系数矩阵,X是由未知数组成的列向量,β是由常数项组成的列向量。非齐次线性方程组的矩阵形式:2)当常数项全为零…

    2025年11月3日
    5
  • CodeForces 191C 树链剖分 第4遍「建议收藏」

    CodeForces 191C 树链剖分 第4遍

    2022年1月26日
    50
  • 端口状态 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT详解,以及三次握手,滑动窗口

    端口状态 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT详解,以及三次握手,滑动窗口网上查了一下端口状态的资料 我下面总结了一下 自己学习学习 TCP 状态转移要点 TCP 协议规定 对于已经建立的连接 网络双方要进行四次握手才能成功断开连接 如果缺少了其中某个步骤 将会使连接处于假死状态 连接本身占用的资源不会被释放 网络服务器程序要同时管理大量连接 所以很有必要保证无用连接完全断开 否则大量僵死的连接会浪费许多服务器资源 在众多 TCP 状态中 最值得注意的状态有两个 C

    2026年3月16日
    3
  • 0703-APP-Notification-statue-bar

    0703-APP-Notification-statue-bar

    2021年11月23日
    56

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号