Bounding box regression RCNN我的理解
0. bounding-box regression
bouding-box regression 在R-CNN论文附录C中有详细的介绍,在后续的论文Fast-RCNN、Faster-RCNN、Mask-RCNN、SSD系列、yolo系列中都没有仔细介绍.
本文使用RCNN论文来介绍bounding box regression原理,同时利用faster rcnn代码来分析理论公式在代码中是如何实现的
R-CNN 论文地址: https://arxiv.org/pdf/1311.2524v3.pdf
faster r-cnn地址 : https://github.com/ShaoqingRen/faster_rcnn
1. bouding-box参数解释
RPN网络层与分类cls层并列的bbox层,其网络权重值是 Ground Truth与 预测值P之间的参数,其网络输出值W*P是 proposal(rpn层的anchor, 或者是 fast rcnn层的proposal)到 GT坐标值的四个变化系数
训练过程学习什么参数
学习的参数是bbox层的网络权重,因为bbox层有四个通道,分别对应四个输出值,可以将每个通道对应的卷积参数称之为wx,wy,ww,whw_x,w_y,w_w,w_hwx,wy,ww,wh, 图像经过这层卷积之后就是 四个值dx(P),dy(P),dw(P),dh(P)d_x(P), d_y(P), d_w(P), d_h(P)dx(P),dy(P),dw(P),dh(P)了,为了方便表示,将这四个数字或者说函数的结果表示为tx′,ty′,tw′,th′t_x',t_y',t_w',t_h'tx′,ty′,tw′,th′,也就是RPN网络中bbox层的输出。
2. 网络训练过程
理论公式
一方面将bbox层的输出tx′,ty′,tw′,th′t_x',t_y',t_w',t_h'tx′,ty′,tw′,th′作为预测值,另一方面将 tx=(Gx−Px)/Pwt_x=(G_x - P_x)/ P_wtx=(Gx−Px)/Pw tx=(Gx−Px)/Pwt_x=(G_x - P_x)/ P_wtx=(Gx−Px)/Pw tx=(Gx−Px)/Pwt_x=(G_x - P_x)/ P_wtx=(Gx−Px)/Pw tx=(Gx−Px)/Pwt_x=(G_x - P_x)/ P_wtx=(Gx−Px)/Pw
作为label,于是求使label与预测值最小的网络权重偏移参数wx,wy,ww,whw_x,w_y,w_w,w_hwx,wy,ww,wh…这便是bbox层网络权重的更新过程。
其中 GGG是实际值,那么PPP要怎么求解出来呢?
- R-CNN的预测框是由 selective search方法得到的,称之为 proposal.于是这个proposal的x,y,w,h就用于和ground truth作比较。
- RPN网络中 P是 9个anchor中的被保留下来的那个anchor, anchor经过上面的公式得到第一次优化的bounding-box,称为proposal。
- Fast RCNN中将RPN的输出proposal作为P,再次寻求P到G之间的变换函数。
实际代码
function [regression_label] = fast_rcnn_bbox_transform(ex_boxes, gt_boxes)
% [regression_label] = fast_rcnn_bbox_transform(ex_boxes, gt_boxes)
% --------------------------------------------------------
% Fast R-CNN
% Reimplementation based on Python Fast R-CNN (https://github.com/rbgirshick/fast-rcnn)
% Copyright (c) 2015, Shaoqing Ren
% Licensed under The MIT License [see LICENSE for details]
% --------------------------------------------------------ex_widths = ex_boxes(:, 3) - ex_boxes(:, 1) + 1;ex_heights = ex_boxes(:, 4) - ex_boxes(:, 2) + 1;ex_ctr_x = ex_boxes(:, 1) + 0.5 * (ex_widths - 1);ex_ctr_y = ex_boxes(:, 2) + 0.5 * (ex_heights - 1);gt_widths = gt_boxes(:, 3) - gt_boxes(:, 1) + 1;gt_heights = gt_boxes(:, 4) - gt_boxes(:, 2) + 1;gt_ctr_x = gt_boxes(:, 1) + 0.5 * (gt_widths - 1);gt_ctr_y = gt_boxes(:, 2) + 0.5 * (gt_heights - 1);targets_dx = (gt_ctr_x - ex_ctr_x) ./ (ex_widths+eps);targets_dy = (gt_ctr_y - ex_ctr_y) ./ (ex_heights+eps);targets_dw = log(gt_widths ./ ex_widths);targets_dh = log(gt_heights ./ ex_heights);regression_label = [targets_dx, targets_dy, targets_dw, targets_dh];
end
迁移到RPN网络中的做法
其中上面的代码中ex_boxes即为faster rcnn论文中说到的筛选方法之后被选中的9个anchor中的一个,一个anchor有四个参数
在Fast RCNN的训练过程中,也就是Faster RCNN第二个bounding-box regression过程中,RPN网络产生的anchor经过RPN层后得到第一次优化的bounding-box,称为proposal,因为有NMS步骤,所以对于一个物体,最多有一个proposal框,拿这个proposal的四个参数再次和ground truth来运算,形成了Fast RCNN层的tx,ty,tw,tzt_x,t_y,t_w,t_ztx,ty,tw,tz。于是就将proposal按照tx,ty,tw,tzt_x,t_y,t_w,t_ztx,ty,tw,tz去调整为最终的输出。
- 在RPN网络训练过程中,anchor的四个数字认为是公式中的P。
- 在Fast-RCNN网络训练部分,P不再是anchor,而是由RPN网络得到的proposal框的四个值。
anchor生成过程可以参看这篇博客
3. 预测过程
理论公式
G^x=Pwdx(P)+Px\hat{G}_x= P_wd_x(P) + P_xG^x=Pwdx(P)+Px G^y=Phdy(P)+Py\hat{G}_y = P_hd_y(P) + P_yG^y=Phdy(P)+Py G^w=Pwexp(dw(P))\hat{G}_w = P_wexp(d_w(P))G^w=Pwexp(dw(P)) G^h=Phexp(dh(P))\hat{G}_h = P_hexp(d_h(P))G^h=Phexp(dh(P))
代码框架
for j = 1:2 % we warm up 2 timesim = uint8(ones(375, 500, 3)*128);if opts.use_gpuim = gpuArray(im);end% proposal_im_detect是RPN网络输出结果的过程[boxes, scores] = proposal_im_detect(proposal_detection_model.conf_proposal, rpn_net, im);% aboxes是经过NMS等过程后,挑选出合适的boxesaboxes = boxes_filter([boxes, scores], opts.per_nms_topN, opts.nms_overlap_thres, opts.after_nms_topN, opts.use_gpu);if proposal_detection_model.is_share_feature %用于RPN层的卷积和Fast RCNN的卷积层共享参数, 要达到这个功能,需要按照论文那样四步走训练网络[boxes, scores] = fast_rcnn_conv_feat_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, rpn_net.blobs(proposal_detection_model.last_shared_output_blob_name), aboxes(:, 1:4), opts.after_nms_topN);else[boxes, scores] = fast_rcnn_im_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, aboxes(:, 1:4), opts.after_nms_topN);end
end
公式在代码中的应用
% 在RPN网络中使用anchor来预测第一次的boxesbox_deltas = output_blobs{1}; % 从rpn层的输出%获取到的anchors,经过NMS等操作处理anchors = proposal_locate_anchors(conf, size(im), conf.test_scales, featuremap_size); % 利用anchor和 box_deltas求取预测框输出的过程 ,也是下面论文中的公式pred_boxes = fast_rcnn_bbox_transform_inv(anchors, box_deltas);
%Faster RCNN中第二次bounding-box regression即Fast RCNN中的回归过程box_deltas = output_blobs{1};box_deltas = squeeze(box_deltas)';% 这里使用的是上一步产生的boxespred_boxes = fast_rcnn_bbox_transform_inv(boxes, box_deltas);
4. R-CNN论文Bounding-box regression内容
另外不得不感叹R-CNN的附录图片真的超级漂亮!检测效果、美观程度兼备!
Bounding box regression RCNN我的理解相关推荐
- Bounding box regression RCNN系列网络中矩形框的计算
0. bounding-box regression bouding-box regression 在R-CNN论文附录C中有详细的介绍,在后续的论文Fast-RCNN.Faster-RCNN.Mas ...
- Bounding box regression详解
Bounding box regression详解 转载 http://blog.csdn.net/u011534057/article/details/51235964 Reference link ...
- 感知算法论文(八):Generalized Intersection over Union:A Metric and A Loss for Bounding Box Regression(2019)
文章目录 摘要 引言 2. 相关工作 3. Generalized Intersection over Union 3.1 GIoU as Loss for Bounding Box Regressi ...
- softer-nms论文学习详解(Bounding Box Regression with Uncertainty for Accurate Object Detection)
<Bounding Box Regression with Uncertainty for Accurate Object Detection> 论文地址: https://arxiv.o ...
- 论文阅读:Softer-NMS: Rethinking Bounding Box Regression for Accurate Object Detection
Softer-NMS 文章 和之前同样出自Megvii的一篇论文IoU-Net一样,这篇论文的出发点也是,two-stage detector进行NMS时用到的score仅仅是classifica ...
- 【目标检测】Bounding Box Regression
Bounding Box是目标检测中一个重要概念.常见格式是边界框左上角坐标.右下角坐标,即[xmin,ymin,xmax,ymax]:或者边界框中心坐标,宽高,即[x_center,y_center ...
- Bounding Box Regression
这篇博客主要讲解为什么可以用线性模型去做Bounding Box Regression,在讲解之前先明确几个先决条件: (1)Bounding Box由包含四个参数的坐标组成,即 其中Gx,Gy表示B ...
- MNS、IOU、bounding box regression详解
IOU 非极大值抑制(MNS) 边框回归(bounding box regression)
- 边框回归(Bounding Box Regression)算法解释
文章目录 一.为什么需要边框回归 二.边框回归的调整策略 三.论文里怎么说 3.1 平移量与缩放量定义 3.2 损失函数 3.3 为什么是线性回归 四.论文中为什么这样定义平移量和缩放量 4.1 平移 ...
最新文章
- 数据库2.0 -- 数据类型和数据表的基本操作
- Kotlin, Android的Swift
- 三维视觉传感器的类型
- Linux的Page Cache
- Python Django 装饰器模式之二阶装饰器
- oracle sql 输出,将数据从Oracle SQL Developer导出到Excel .xlsx
- Luogu P2827 蚯蚓
- Centos7下载和安装教程
- WPS Excel+windows批处理批量重排序文件夹
- Windows更新错误代码0x8007000e
- 数据库SQL 某字段按首字母排序
- 利用三轴加速器的计步测算方法
- 青龙面板安装搭建详细教程
- python抓取视频真实地址_快手批量获取真实地址python
- 数字社会案例集(1.0版本) 附下载
- ThingsBoard接入阿里ALink协议的网关设备探讨
- c语言关键词中英翻译机编程,课程设计--C语言关键字中英翻译机
- UWB定位matlab代码及详细解析(附github下载链接)
- c mvc mysql_c mvc 连接数据库
- 云数据中心安全设计要点