在R-CNN之前的传统方法都是利用滑动窗口提取大量可能存在 object 的 window,将 detection 变成了 classification。当然,这类方法的弊端也十分明显:由于需要提取大量 sub-window 且尽可能覆盖任意 object,需要提前设置大量不同 size 的 sliding window,接着在图像上不断的滑动,并输入到分类器中,所需时间太长;而且为了避免时间过长,往往分类器设置的较为简单,以减少计算时间,这也导致其 mAP 并不会很高。
R-CNN系列模型都属于two-stage,先用启发式算法提取Region Proposal,再用CNN提取特征进行分类与回归
- R-CNN 的核心是利用启发式算法 Selective Search 提取 Region Proposal,避免提取大量无用的 sub-window
- Fast R-CNN 的核心是先提取特征,在提取 Region Proposal
- Faster R-CNN 的核心是不再使用启发式算法提取Region Proposal,而是利用神经网络(Region Proposal Network, RPN)进行提取, 演变成 end-to-end model。
1. R-CNN
2. SPP-Net
3. Fast R-CNN
4. Faster R-CNN
论文题目:Rich feature hierarchies for accurate object detection and semantic segmentation
论文作者:Ross Girshick, Jeff Donahue, Trevor Darrell, Jitendra Malik
所属机构:UC Berkeley
论文链接:https://arxiv.org/pdf/1311.2524.pdf
(1) 摘要:
2013年,RBG 使用 Region Proposal + CNN + SVM (也就是 R-CNN 框架)代替传统目标检测使用的滑动窗口+手工设计特征,效果惊人:‘improves mean average precision (mAP) by more than 30% relative to the previous best result on VOC 2012—achieving a mAP of 53.3%’ 。
(2) 模型结构:
首先,模型利用 Selective Search 算法在输入图像上提取 2k 个左右的 Region Proposal。
接着,将每个Region Proposal 缩放(原文中为 warp)成统一大小(227 x 227),并将其输入到作者所构建的CNN 网络中,以此提取每个 Region Proposal 的特征。
最后,将所提取到的特征输入到 SVM 中,以此判断每个 Region Proposal 的类别。
此外,作者还应用了 Bouding-box regression,以此微调每个 Region Proposal 的位置参数,作者将加上这一部分后的总体框架称为 R-CNN BB。
以上是整篇文章的主要思路,现在我们来研究一下细节之处:
关于 Selective Search 算法:
作者在文章里说过了:SS 算法与 R-CNN 并无太大关系,这一部分是可以用其他候选区域搜索算法替代的(‘While R-CNN is agnostic to the particular region proposal method, we use selective search to enable a controlled comparison with prior detection work (e.g., [39, 41])’)。
关于 Warp Region Proposal :
虽然 Conv layer 和 Pooling layer 对输入图像的大小并无要求,但是论文中的网络框架包含 FC layer,所以该网络对输入图像的大小有所要求。作者在论文中指出:在直接对Region Proposal 进行 resize 之前,会将该候选区域的边界扩展 p 个像素(文中指出,p=16)(Prior to warping, we dilate the tight bounding box so that at the warped size there are exactly p pixels of warped image context around the original box (we use p = 16))。
关于 CNN :
论文中所用到的 CNN 网络实现为 ‘using the Caffe [24] implementation of the CNN described by Krizhevsky et al.[25]’,该网络将从候选区域中提取 4096 维的特征向量。
为确定以 CNN 中的哪一层输出作为所提取特征,作者做了实验:
最后,作者以 CNN 的 fc7 层的输出作为所提取特征进行输出。
论文一共提及了两个 CNN 框架实现:‘Krizhevsky et al.’s architecture (T-Net). Rows three and four use the recently proposed 16-layer architecture from Simonyan and Zisserman (O-Net) [43]’,测试结果如下:
关于 SVM:
作者训练 N +1个(N为所要识别物体的类别总数,额外的1代表‘背景’这一类别)SVM分类器(二分类),每个类别对应一个SVM,判断是不是属于这个类别,如果是这个对应的类别,即认为 Positive,反之,认为 Negative。
看到这里大部分人应该会有个疑问,为什么要费这么大劲去训练这么多个 SVM 而不是直接在 CNN 后面接一个softmax layer呢?作者在附录B作出了相关的解释,并且还解释了为何 fine-tuning CNN和 train SVM 时,对 Positive 和 Negative 的定义不一样(fine-tuning CNN时,Region Proposal 与 ground-truth instance 的 IOU 大于等于0.5,才被认为是 Positive,其余的为 Negative;train SVM 时,只将 ground-truth instance 作为 Positive, ground-truth instance 的 IOU 小于0.3的 Region Proposal 被认为是 Negative,剩余的 Region Proposal 将被忽略)。
关于 NMS:
论文中有使用非极大值抑制(NMS, non-maximum suppression),即:若同类别的两个候选区域的交并比(IOU,intersection-over-union)超过某个阈值(作者指出经过验证集的验证后,阈值集合{0,0.1,…,0.5}中,该阈值最好取0.3;若该阈值取到0.5,则 mAP 下降5%;若该阈值取到0,则mAP下降4%),则只保留置信度大的候选区域。
关于 Bouding-box regression:
作者在文中指出:‘Inspired by the bounding-box regression employed in DPM [17], we train a linear regression model to predict a new detection window given the pool5 features for a selective search region proposal. Full details are given in Appendix C’,注意,此处的输入为pool5层的特征。
作者指出,这一结构使得 mAP 提高了3~4%。这样一来,该模型即包含 Classification,又包含 Regression。
(3) 实验结果:
(4) 总结:
R-CNN: 输入图像 → \to →通过 Selective Search 得到2000个左右的 Region Proposal → \to →每个 Region Proposal 都缩放至 227 x 227,输入进 CNN 中,提取 4096 维的特征向量 → \to →将特征向量输入到各个类别的 SVM 中,进行分类识别,同时采用 non-maximum suppression 减少候选区域个数,提高精度 → \to →提取 CNN pool5 层的特征,输入到 bounding-box regression 中,对 Region Proposal 的位置参数进行微调
优点:
有待改进之处:
论文题目:Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition
论文作者:Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun
所属机构:Microsoft Research
论文链接:https://arxiv.org/pdf/1406.4729.pdf
(1) 摘要:
2014年,Kaiming He 受到 SPM(Spatial Pyramid Matching) 的启发,提出了 SPP layer(Spatial Pyramid Pooling Layer)这一结构,使得应用这一结构的网络(一般称为 SPP-Net)可以对任意大小的图片提取固定长度的特征。
作者指出,这一结构可以应用到 object detection 中基于 Region Proposal 的模型上,从而避免对每个候选区域提取一次特征这一重复的工作,以此大幅缩短所需时间。此外,作者提到, SPP-Net 的速度是 R-CNN 的24~102倍,且在 Pascal VOC 2007 的准确率也高于 R-CNN。
笔记:
SPM 的提出是受到了 BoW (Bag-of-Words)的启发,这两者应该算是传统模型框架了吧,都是在CNN 引起广泛关注前,大家所关注的热门模型。作者在文中也指出,这篇论文所提出的 SPP 可以看作是BoW model 的扩展:’ as an extension of the Bag-of-Words (BoW) model’。
(2) 模型结构:
对于任意大小的 feature map,SPP layer 分别将其划分为 4 ∗ 4 , 2 ∗ 2 , 1 ∗ 1 4*4,2*2,1*1 4∗4,2∗2,1∗1 的 local spatial bins,然后在这些 local spatial bins 上进行 pooling 操作(论文采用的是 max pooling),分别得到 16 维,4 维,1 维的向量(图中的之所以为 16 ∗ 256 , 4 ∗ 256 , 1 ∗ 256 16*256,4*256,1*256 16∗256,4∗256,1∗256是因为所输入的 feature map 有 256 个channel )。
(3) 实验结果:
(4) 总结:
这篇论文所提出的 SPP layer 解决了 CNN 因 FC layer 所引起的固定输入问题,至此,CNN 得以接受任意大小的输入,且输出固定 size 的输出。
论文题目:Fast R-CNN
论文作者:Ross Girshick
所属机构:Microsoft Research
论文链接:https://arxiv.org/pdf/1504.08083.pdf
(1) 摘要:
2015年,在受到 SPP-Net 的启发下,rbg 对 R-CNN 做出了一系列的改进,提出了新的框架,称为:Fast R-CNN。作者指出,Fast R-CNN 训练速度是 R-CNN 的9倍,测试速度是 R-CNN 的213倍(CNN 结构为VGG16);跟 SPP-Net 相比,fast R-CNN 的训练速度是其的3倍,测试速度是其的10倍(CNN 结构为 VGG16),且准确率更高。
其中,rbg 做出的改进如下:
(2) 模型结构:
首先,利用 Selective Search 提取固定数量的RoI,训练时的方式为:‘first by sampling N images and then by sampling R/N RoIs from each image’(作者指出,N=2,R=128的训练方式比从128张不同图片各提取一个RoI的训练方式快64倍)。
接着,将图像输入到CNN中得到 feature map,将 RoI 映射到 feature map 上,并对映射区域进行 RoI pooling,将得到的 RoI feature map 输入到 FC layer,以此得到固定大小的特征向量。
最后,将特征向量分别输入到 Classifier 和 Bounding box regressor,得到所判定的类别与精确的区域位置。
关于 RoI pooling layer:
作者采用 max pooling 去进行 RoI pooling :先将 RoI 映射到 feature map 上(也就是将各个坐标按照RoI与feature map 的大小之比进行同比映射即可),此时 RoI feature map 表示为 ( r , c , h , w ) (r,c,h,w) (r,c,h,w)(其中, ( r , c ) (r,c) (r,c)为 RoI 的左上角坐标, h , w h,w h,w为 RoI 的高度与宽度)。接着,将大小为 h ∗ w h*w h∗w 的 RoI feature map划分为 H ∗ W H*W H∗W个sub-windows(论文指出, H ∗ W = 7 ∗ 7 H*W=7*7 H∗W=7∗7) ,每个 sub-windows 大小为 h / H ∗ w / W h/H * w/W h/H∗w/W,对每个 sub-window 进行 max pooling 就可以得到大小为 H ∗ W H*W H∗W的 RoI feature map(当然,按照 pooling layer 的定义,需要对原先的 feature map 的每个 channel 进行一次 RoI pooling,最后的 RoI feature map 大小应为 n u m _ o f _ c h a n n e l ∗ H ∗ W num\_of\_channel * H * W num_of_channel∗H∗W)。
关于 Multi-task loss:
在 Fast R-CNN 中,作者将 Classifier 和 Regressor 一起训练(‘We use a multi-task loss L on each labeled RoI to jointly train for classification and bounding-box regression’):
L ( p , u , t u , v ) = L c l s ( p , u ) + λ [ u ≥ 1 ] L l o c ( t u , v ) L(p,u,t^u,v)=L_{cls}(p,u)+\lambda[u\geq1]L_{loc}(t^u,v) L(p,u,tu,v)=Lcls(p,u)+λ[u≥1]Lloc(tu,v)
其中, L c l s ( p , u ) L_{cls}(p,u) Lcls(p,u)用于计算分类的 loss, L l o c ( t u , v ) L_{loc}(t^u,v) Lloc(tu,v)用于计算回归的 loss; L c l s ( p , u ) = − log p u L_{cls}(p,u)=-\log p_u Lcls(p,u)=−logpu, p u p_u pu为正确类别的概率; v = ( v x , v y , v w , v h ) v=(v_x,v_y,v_w,v_h) v=(vx,vy,vw,vh), t u = ( t x u , t y u , t w u , t h u ) t^u=(t^u_x,t^u_y,t^u_w,t^u_h) tu=(txu,tyu,twu,thu), L l o c ( t u , v ) = ∑ i ∈ x , y , w , h s m o o t h L 1 ( t i u − v i ) L_{loc}(t^u,v)=\sum_{i\in{x,y,w,h}}^{} {smooth_{L1}(t^u_i-v_i)} Lloc(tu,v)=∑i∈x,y,w,hsmoothL1(tiu−vi); λ \lambda λ用于控制 two task loss 的平衡。
[ u ≥ 1 ] = { 1 , if u ≥ 1 0 , otherwise(即类别为背景时) [u\geq1]= \begin{cases} 1, & \text{if $u\geq1$} \\ 0, & \text{otherwise(即类别为背景时)} \end{cases} [u≥1]={1,0,if u≥1otherwise(即类别为背景时)
s m o o t h L 1 = { 0.5 x 2 , if ∣ x ∣ < 1 ∣ x ∣ − 0.5 , otherwise smooth_{L1}= \begin{cases} 0.5x^2, & \text{if $|x|<1$} \\ |x|-0.5, & \text{otherwise} \end{cases} smoothL1={0.5x2,∣x∣−0.5,if ∣x∣<1otherwise
关于 Truncated SVD:
作者提到,FC层的计算可以使用 Truncated SVD 进行加速:‘In this technique, a layer parameterized by the u ∗ v u*v u∗v weight matrix W is approximately factorized as W ≈ U Σ t V T W \approx UΣ_{t}V^{T} W≈UΣtVTusing SVD’。
其中, U U U的大小为 u ∗ t u*t u∗t, Σ t Σ_t Σt的大小为 t ∗ t t*t t∗t, V T V^T VT的大小为 t ∗ v t*v t∗v。这样一来将 u ∗ v u*v u∗v降到了 t ∗ ( u + v + t ) t*(u+v+t) t∗(u+v+t), t t t远小于 m i n ( u , v ) min(u,v) min(u,v)。
(3) 实验结果:
(4) 总结:
Fast R-CNN: 输入图像 → \to →利用 Selective Search 得到图像的 RoI (即Region of Interest) → \to →通过 CNN 得到图像的 feature map → \to →将每个RoI 映射到 feature map 上,并进行 RoI pooling以及输入到FCs中计算,得到固定size 的 RoI feature vector → \to →Classification(linear+softmax)+ Bouding box regression(linear)
优点:
有待改进之处:
论文题目:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
论文作者:Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun
所属机构:Microsoft Research
论文链接:https://arxiv.org/pdf/1506.01497.pdf
(1) 摘要:
2015年,rbg 和 Kaiming He 在 Fast R-CNN 的基础上,引进了 RPN(Region Proposal Network)以此替换 提取Region Proposal 部分的 Selective Search ,推出了新的框架:Faster R-CNN。至此,R-CNN系列模型已经逐步演变为了 end-to-end model。
作者在摘要部分,简单的提了一下 Faster R-CNN 的效果:'For the very deep VGG-16 model [3],our detection system has a frame rate of 5fps (including all steps) on a GPU, while achieving state-of-the-art object detection accuracy on PASCAL VOC 2007, 2012, and MS COCO datasets with only 300 proposals per image. In ILSVRC and COCO 2015 competitions, Faster R-CNN and RPN are the foundations of the 1st-place winning entries in several tracks. ’
(2) 模型结构:
首先,输入 CNN 提取 feature map,将 feature map 输入到 RPN 中,提取出 Region Proposal,接着将 Region Propossal 和 feature map 一同进行 RoI pooling ,将得到固定 size 的特征向量,将这一特征向量分别输入给分类器和回归器,便可以得到结果。
关于 RPN:
关于 Loss Function:
Faster R-CNN = RPN + Fast R-CNN,作者将两拆开来训练,一共有两个损失函数。其中,训练 Fast R-CNN 所用到的损失函数与之前 Fast R-CNN 所提到的一样。
训练 RPN 之前,作者对每个 anchor 做了 binary class label(即该 anchor 是不是个 object):对于‘与ground-truth box 有最高IOU’的 anchor 和 ‘与任意ground-truth box 的IOU超过0.7‘的anchor,即为 Positive;对于 ’与所有ground-truth box 的IOU低于0.3‘的anchor,即为 Negative。
为训练 RPN,作者对 RPN 这一部分提出了multi-task loss:
L ( p i , t i ) = 1 N c l s ∑ i L c l s ( p i ∗ , p i ) + λ ∑ i p i ∗ L r e g ( t i ∗ , t i ) L({p_i},{t_i})=\frac{1}{N_{cls}} \sum_{i}{L_{cls}(p^*_i,p_i)}+\lambda \sum_{i}{p^*_i L_{reg}(t^*_i,t_i)} L(pi,ti)=Ncls1i∑Lcls(pi∗,pi)+λi∑pi∗Lreg(ti∗,ti)
其中,当 anchor 是 positive 的时, p ∗ = 1 p^*=1 p∗=1,其余时候, p ∗ = 0 p^*=0 p∗=0; t ∗ t^* t∗为positive anchor 的位置参数; L c l s L_{cls} Lcls是 classification loss(‘The classification loss L c l s L_{cls} Lcls is log loss over tow classes(object vs not object)’); L r e g L_{reg} Lreg是 regression loss, L r e g ( t i ∗ , t i ) = R ( t i ∗ , t i ) L_{reg}(t^*_i,t_i)=R(t^*_i,t_i) Lreg(ti∗,ti)=R(ti∗,ti),R 是 robust loss function(smooth L1)。
(3) 实验结果:
(4) 总结:
Faster R-CNN: 输入图像 → \to →利用 conv layers 得到图像的 feature map → \to →将 feature map 输入 Region Proposal Network 里,从而提取出 Region Proposals → \to →将提取出来的 Region Proposals 映射到 feature map 上,并进行 RoI pooling,得到固定 size 的 RoI feature vector → \to →Classification + Bouding box regression
优点:
有待改进之处:
参考资料:
如果你看到了这篇文章的最后,并且觉得有帮助的话,麻烦你花几秒钟时间点个赞,或者受累在评论中指出我的错误。谢谢!
作者信息:
知乎:没头脑
LeetCode:Tao Pu
CSDN:Code_Mart
Github:Bojack-want-drink