语义分割:Mask R-CNN原理



  • Mask R-CNN原理

    0_1551058627577_Screenshot from 2019-02-22 19-44-24.png

    R-CNN对由FCN得到的两个分支--分类与框,运用RolPool,为每个Rol产生一样大小的Rol feature vector。缺点:在overlapping instance上可能会产生系统错误和伪边。
    MASK R-CNN额外地在产生class和box offset的同时,并行产生a binary mask for each RoI。对每个RoI,都定义一个multi-task loss L = Lcls + Lbox + Lmask。其中Lcls和Lbox都和fast r-cnn一样。输出mask的分支,对于每一个RoI,都会输出Km^2维度的输出,其中包括K个binary masks,每个mask都对应一个类(这个mxm应该不是指原图的proposal的分辨率,因为RoIAlign后得到的vector是一样大小的。应该是可以通过这个mxm计算对应原图中的哪些像素)。(For an RoI associated with ground-truth class k, Lmask is only defined on the k-th mask (other mask outputs do not contribute to the loss)我们这样定义Lmask可以使网络为每个类别产生masks,并且每个类之间没有竞争。classification branch可以产生class label,而mask branch不用产生class label,它可直接用分类分支产生的class label。
    0_1551058711465_Screenshot from 2019-02-24 21-34-42.png
    0_1551058776109_Screenshot from 2019-02-22 19-46-45.png

    RoIAlign: we avoid any quantization of the RoI boundariesor bins (i.e., we use x/16 instead of [x/16]). We use bilinear features at four regularly sampled locations in each RoI bin,and aggregate the result (using max or average).总得来说就是:为了更精确地划分,直接提取RoI减少量化.

    0_1551058642569_Screenshot from 2019-02-25 09-20-39.png
    原文:RoIPool是如何从一个RoI+特征图得到a small feature map的呢?两个量化过程就能得到了。RoIPool首先将a floating-number RoI量化到离散粒度的feature map上,然后这个quantized RoI就被分为spatial bins;这些bins再量化;最后每个bin覆盖的feature map上的区域就被合并(例如使用max pooling合并),最终就得到一个7X7的small feature map。这种量化方式,会使RoI和the extracted features之间不能对准。虽然这可能不会影响分类,因为分类对小的平移是鲁棒的,但这对predict pixel-accurate masks有很大的副作用。(其实,由原图proposal到RoI需要经过变换,RoI是对应最后一层特征图的。我们为什么提取proposal?不如直接提取RoI?所以,由proposal到RoI是由程序计算出来的,可能是个浮点数值,需要把RoI具体到占feature map的哪些个像素点,即离散化。离散化过程中,肯定不可能正好整除,会有四舍五入之类的,但舍去一个特征图中的点可能就是舍去原图中的一大片呀。以上是第一步量化。第二部量化就是把RoI占特征图的离散化的点分为7 X 7部分,这也不可能都正好整除!所以这一步量化可能也会造成translation。)为了解决这个副作用,我们避免RoI boundaries or bins的任何量化(不量化了,不求约数了,直接从浮点RoI到浮点bins,然后在求small feature map时,插值!)。使用双线性插值来计算每个bin中四个采样位置的输入特征的精确值,然后合并。使用双线性插值,让不能整除变能整除。(应该是把特征图插值成可以整除的大小。)

    细节:

    (a)消除decouples mask与class prediction之间的竞争关系(once the instance has been classified as a whole by the box branch,建议在预测mask时,不考虑category),可以提高准确率,论文中通过对比a per-pixel sigmoid and a binary loss与 a per-pixel softmax and a multinomial loss的使用效果得到此结论。

    (b)Class-Specific与 Class-Agnostic Masks效果前者略好于后者,大致相当。

    (c)RoIAlign largely resolves the long-standing challenge of using large-stride features for detection and segmentation.

    training:在Fast R-CNN中,RoI有正有负。IoU大于0.5为正,否则为负。而Lmask是在正RoI上定义的。The mask target is the intersection between an RoI and its associated ground-truth mask(所以,Lmask,在RoI为正时,是用预测出来的mask - mask target,如果RoI为负,则为0)。

    testing:The mask branch can predict K masks per RoI, but we only use the k-th mask,where k is the predicted class by the classification branch.The m×m floating-number mask output is then resized tothe RoI size, and binarized at a threshold of 0.5.

    注:双线性差值:0_1551059611006_Screenshot from 2019-02-25 09-52-31.png



  • 提升训练速度tip :Mini Mask
    训练高分辨率的图片时,表示每个目标的二值mask也会非常大。例如,训练一张1024×1024的图片,其目标物体对应的mask需要1MB的内存(用boolean变量表示单点),如果1张图片有100个目标物体就需要100MB。讲道理,如果是五颜六色就算了,但实际上表示mask的图像矩阵上大部分都是0,很浪费空间。

    为了节省空间同时提升训练速度,我们优化mask的表示方式,不直接存储那么多0,而是通过存储有值坐标的相对位置来压缩表示数据的内存,原理和压缩算法差类似。

    我们存储在对象边界框内(bbox内)的mask像素,而不是存储整张图片的mask像素,大多数物体相对比于整张图片是较小的,节省存储空间是通过少存储目标周围的0实现的。
    将mask调整到小尺寸56×56,对于大尺寸的物体会丢失一些精度,但是大多数对象的注解并不是很准确,所以大多数情况下这些损失是可以忽略的。(可以在config类中设置mini mask的size。)
    说白了就是在处理数据的时候,我们先利用标注的mask信息计算出对应的bbox框,而后利用计算的bbox框反过来改变mask的表示方法,目的就是操作规范化,同时降低存储空间和计算复杂度。



  • anchors:

    • Sort by pyramid level first.
    • Within each level, sort anchors by feature map processing sequence. Typically, a convolution layer processes a feature map starting from top-left and moving right row by row.
    • For each feature map cell, pick any sorting order for the anchors of different ratios. Here we match the order of ratios passed to the function.
      Anchor Stride:略

    RPN中anchor生成机制
    相关超参数设置:
    base_size=16
    ratios=[0.5, 1, 2]
    scales== [8 16 32]
    第一步:s=1616=256      zero_base的坐标体系里对应的中心点坐标为(7.5,7.5)
    第二步:s/ratios =>256/[0.5, 1, 2]=[512,256,128]
    第三步:根据第二步得到三种尺寸的anchors
                     h/w= ratios        ①
                     w.h=s                 ②   
           ②/①=> w^2= s/ratios =[512,256,128]  
    w=[512,256,128]的算术平方根四舍五入= [23 16 11]
     根据①式有            h=w
    ratios  = [12 16 22]
    得到三种尺寸的anchors [(23,12),(16,16),(11,22)]
    第四步:根据中心点(7.5,7.5)不变原则得到对应尺寸的anchors=(xmin,ymin,xmax,ymax)
    固anchor:[[-3.5 2 18.5 13]  [0  0  15  15]   [2.5  -3  12.5 18]]
    第五步:每种anchor对应scales进行扩大,3*3=9种anchors,这里不再依依列出


 

Copyright © 2018 bbs.dian.org.cn All rights reserved.

与 Dian 的连接断开,我们正在尝试重连,请耐心等待