[paper reading] RetinaNet

GitHub:Notes of Classic Detection Papers

本来想放到GitHub的,结果GitHub不支持公式。
没办法只能放到CSDN,但是格式也有些乱
强烈建议去GitHub上下载源文件,来阅读学习!!!这样阅读体验才是最好的
当然,如果有用,希望能给个star

topic motivation technique key element math use yourself relativity
RetinaNet Problem to Solve
Negative ==> Easy
Focal Loss
RetinaNet
Class Imbalance
Feature Pyramid Network
ResNet-FPN Backbone
Classify & Regress FCN
Post Processing
Anchor Design
Anchor & GT Matching
prior π\piπ Initialization
Ablation Experiments
Cross Entropy Math
Focal Loss Math
Data Analysis
Feature Pyramid Network
More Scale ≠\not=​= Better
Related Work
Related Articles
Blogs

文章目录

  • [paper reading] RetinaNet
    • Motivation
      • Problem to Solve
      • Negative ==> Easy
    • Technique
      • Focal Loss
      • RetinaNet
    • Key Element
      • Class Imbalance
        • One-Stage
        • Two-Stage
        • Results
      • Feature Pyramid Network
        • Components
        • bottom up path
        • top-down pathway
        • lateral connection
      • ResNet-FPN Backbone
      • Classify & Regress FCN
        • Classification FCN
          • Output
          • Components
        • Regression FCN
          • Output
          • Components
      • Post Processing
      • Anchor Design
        • scale & ratio
        • Ground Truth
      • Anchor & GT Matching
      • prior π\piπ Initialization
      • Ablation Experiments
        • RetinaNet vs.vs.vs. SOTA
        • γ\gammaγ on Pos & Neg Loss
        • AP w.r.t αt\alpha_tαt​
        • AP w.r.t γ\gammaγ
        • FL vs.vs.vs. OHEM
        • AP w.r.t scale & ratio
        • Perform w.r.t depth/scale
    • Math
      • Cross Entropy Math
        • Standard Cross Entropy
        • Balanced Cross Entropy
      • Focal Loss Math
    • Use Yourself
      • Data Analysis
      • [Feature Pyramid Network](#Feature Pyramid Network)
      • More Scale $\not= $ Better
    • Related Work
      • Two-Stage Method
        • Characteristic
        • Input
        • Sampling Fashion
      • One-Stage Method
        • Characteristic
        • Input
        • Sampling Fashion
    • Related Articles
    • Blogs

Motivation

Problem to Solve

one-stage方法面对的极端的正负样本不均衡

Negative ==> Easy

正负样本不均衡中的减少负样本数量 ==> 降低负样本中简单样本的损失(原因:负易样本占了全部样本的绝大多数)

  • 对数量巨大的easy negative的loss进行大幅度的衰减,从loss的角度就平衡了正负样本的比重
  • 仅保留 hard positive 和 hard negative,其 learning signal 更有理由训练和优化

注意:是负样本中的简单样本,而不是全部的负样本。因为one-stage的classification本质是一个多分类的问题,而background作为其中的一类,不能将其全部消除。

这是从 one-stage detection 的场景出发的

关于样本的分类,按照正/负难/易可以分为下面四类:

正难( 正易,γ\gammaγ衰减
负难,α\alphaα衰减 负易,α\alphaα,γ\gammaγ衰减(

而 γ\gammaγ 是指数衰减,α\alphaα 是一次衰减,即γ\gammaγ衰减的效果要大于α\alphaα衰减。

也就是模型的专注度正难 > 负难 > 正易 > 负易

Technique

Focal Loss

  • Introduction

    是对于Cross Entropy Loss的dynamically scale,对well-classified的样本进行down-weight,以处理正负样本间的平衡

    其核心思想是:通过降低高置信度样本产生的损失,从而使模型更加专注于难分类 (即低置信度) 样本

  • Essence

    本质是对于inliers (easy) 的 down-weight

    robust loss function是对于outliers进行down-weight(这里并不详细阐述)

  • Result

    使用全部样本(不对样本进行采样)下,使得模型在稀疏的难样本上训练(sparse set of hard example)

  • Drawback

    仅仅告诉模型少去关注正确率的样本,但没有告诉模型要去保持这种正确率

其数学推导详见 [Focal Loss Math](#Focal Loss Math)

RetinaNet

由以下3个部分组成:

  • [ResNet-FPN backbone](#ResNet-FPN backbone)
  • [Classification SunNetwork](#Classification SunNetwork)
  • [Regression SubNetwork](#Regression SubNetwork)

Key Element

Class Imbalance

One-Stage

one-stage方法会在训练时面临极端的foreground/background的类别不平衡

数量上讲:one-stage 会产生 10k~100k 个 candidate location,其中 foreground: background ≈\approx≈ 1: 1000

Two-Stage

  • stage-1 ==> proposal

    可以将 candidate local 降低到 1~2k(滤除了绝大部分的easy negative)

  • biased minibatch sampling ==> fixed raios

    对样本进行采样,使得 foreground / background = 1: 3(可以看做是隐性的 α\alphaα-balancing

Results

fore/back的类别不平衡主要会产生2个问题:

  • 训练低效

    占比极大的easy negative不贡献learning signal

  • 模型退化

    easy negativeoverwhelm训练过程,导致训练困难,造成网络退化

Feature Pyramid Network

Feature Pyramid Networks for Object Detection

Feature Pyramid Network 的目的是:使得Feature Pyramid所有高低分辨率(all scale)上都有强语义信息(strong semantic)

Components

  • bottom up(standard CNN)
  • top-down pathway
  • lateral connection

上图为FPN论文的框架(RetinaNet中只有取3个stage的feature map)

bottom up path

使用CNN进行特征提取,空间分辨率逐渐下降,语义信息逐渐增强

在bottom up path中选取的feature map是每个stage中最后一层的输出,具有该stage中最强的语义信息(输出feature map的size相同的层,统称为一个stage)

top-down pathway

最后一层的feature map(具有最强的语义信息)进行stride=2上采样,论文中的上采样方式为最简单的最近邻

lateral connection

横向连接为 $1×1 $ Conv,用于对 {C2,C3,C4,C5}\{C_2, C_3, C_4, C_5\}{C2​,C3​,C4​,C5​} 的channel维度进行降维(论文中设定降维后的维度为 d=256d=256d=256)

注意:merged feature map 后面还需要进行 3×33×33×3 Conv,已降低上采样带来的混叠现象aliasing effect of upsampling

ResNet-FPN Backbone

  • ResNet

    使用ResNet计算多个scale的feature map

  • FPN

    构成 feature pyramid

    详见 [Feature Pyramid Network](#Feature Pyramid Network)

Classify & Regress FCN

Classification FCN

使用FCN,分别对Feature Pyramid的不同层的feature map进行object的classification

Output

W×H×KAW×H×KAW×H×KA 的vector

表示每个spatial location的每个anchor都有 KKK 个classprobability

Components
  • 4 个 3×33×33×3 Conv,CCC filters(输出channel为 CCC)

    CCC 为输入channel数(保持channel数不变)

    之后接 ReLU

  • 1 个 3×33×33×3 Conv,KAKAKA filters(输出channel为 KAKAKA)

  • Sigmoid

    输出每个spatial location(W×HW×HW×H)的 AAA 个anchor的 KKK 个类别的probability

参数共享

subnet的参数所有的pyramid level共享

Regression FCN

使用FCN,分别对Feature Pyramid的不同层的feature map进行bounding box的regression

Output

W×H×4AW×H×4AW×H×4A 的vector

表示每个spatial location的每个anchor都有 444 个 bounding box regression

Components

除了第5层卷积输出channel为 4A4A4A,其他与Classification FCN相同

Post Processing

Feature Pyramid的每个levelprediction进行merge,以0.5为阈值进行NMS

两个提速技巧:

  • 滤除confidence<0.5的box
  • 在每个Feature Pyramid Level上,只对1000个 top-scoring prediction进行decode

Anchor Design

scale & ratio

每个level的每个location,anchor选择3个scale,每个scale有3个ratios,共 3×3 = 9 个anchor

反应到原图上,可以覆盖32~813个pixel的范围

  • ratios

    1: 2、1: 1、2: 1

  • scale

    202^020、22/32^{2/3}22/3、21/32^{1/3}21/3

Ground Truth

每个anchor会带有2个向量

  • classification

    一个 KKK 维的 one-hot vector,作为classification target(KKK 为类别数)

  • regression

    一个 444 维的vector,作为box regression target

Anchor & GT Matching

根据anchor与ground-truth box的IOU进行匹配

  • IoU > 0.5

    anchor被视为foreground,被分配到对应的ground-truth box

    这会存在一个问题,即ground-truth box有可能对应不到anchor

  • 0.5 > IoU > 0.4

    忽略该anchor

  • IoU < 0.4

    anchor被视为background

prior π\piπ Initialization

训练初期频繁出现的类别会导致不稳定

使用 “prior” 将训练起始阶段rare class 的 ppp 设定为一个较低的值(比如0.01)

用于初始化Classification SubNet的**第5个卷积层(最后一个卷积层)**的 bbb
b=−log((1−π)/π)b=-\text{log}((1-\pi)/\pi) b=−log((1−π)/π)

Ablation Experiments

RetinaNet vs.vs.vs. SOTA

γ\gammaγ on Pos & Neg Loss

即:Focal loss 对于foreground的loss的衰减很小 (a),但对于background的loss衰减很大,从而避免了easy negative对于classification loss的overwhelming

AP w.r.t αt\alpha_tαt​

  • αt=0.5\alpha_t=0.5αt​=0.5 对应的结果最好
  • αt\alpha_tαt​ 的值也会大幅度地影响AP

AP w.r.t γ\gammaγ

  • γ=2\gamma=2γ=2 对应的结果最好
  • γ\gammaγ 的值也会大幅度地影响AP

FL vs.vs.vs. OHEM

  • FL性能明显优于OHEM

AP w.r.t scale & ratio

  • scale和ratio应该兼顾

  • 一味地堆高scale会引起效果的下降

    原因可能是,这些scale本身不适合进行detection的任务

Perform w.r.t depth/scale

  • 总体来说,depth和scale对performance均为正相关

    • depth越深语义信息越丰富 ==> 对small object的提升最小
    • scale越大分辨率越高位置和细节信息越丰富 ==> 对small object的提升最大

Math

Cross Entropy Math

Standard Cross Entropy

  • 使用 ppp 表示
    CE(p,y)={−log⁡(p)if y=1−log⁡(1−p)otherwise \mathrm{CE}(p, y)=\left\{\begin{array}{ll} -\log (p) & \text { if } y=1 \\ -\log (1-p) & \text { otherwise } \end{array}\right. CE(p,y)={−log(p)−log(1−p)​ if y=1 otherwise ​

    • y∈{−1,+1}y \in \{-1, +1\}y∈{−1,+1}:ground-truth的class
    • p∈{0,1}p \in \{ 0, 1\}p∈{0,1}:预测类别为 $ 1$ 的预测概率
  • 使用 ptp_tpt​ 表示
    pt={pif y=11−potherwise p_t=\left\{\begin{array}{ll} p& \text { if } y=1 \\ 1-p & \text { otherwise } \end{array}\right. pt​={p1−p​ if y=1 otherwise ​

    CE(p,y)=CE(pt)=−log(pt)\text{CE}(p,y) = \text{CE}(p_t) = -\text{log}(p_t) CE(p,y)=CE(pt​)=−log(pt​)

问题:尽管每个easy sample的损失小,但大量的easy sample依旧会主导loss和gradient

Balanced Cross Entropy

CE(pt)=−αtlog(pt)\text{CE}(p_t) = -\alpha_t \text{log}(p_t) CE(pt​)=−αt​log(pt​)

  • αt\alpha_tαt​:用于平衡正负样本

问题:仅仅是平衡正负样本,而不是难易样本,治标不治本

Focal Loss Math

FL(pt)=−αt⋅(1−pt)γ⋅log(pt)\text{FL}(p_t) = -\alpha_t·(1-p_t)^{\gamma} ·\text{log}(p_t) FL(pt​)=−αt​⋅(1−pt​)γ⋅log(pt​)

  • 归一化系数

    匹配到ground-truthanchor的数目

  • 使用位置

    Classification SubNetwork ==> 仅仅是分类任务的损失函数

  • ptp_tpt​ :被分类正确的概率。ptp_tpt​ 越大,loss被down-weight的程度越大
  • γ\gammaγ :控制down-weight的程度
    • 实验中 γ=2\gamma=2γ=2 最好
    • γ=0\gamma=0γ=0 时,FL Loss = CE Loss

求导:
dFLdx=y(1−pt)γ(γptlog⁡(pt)+pt−1)\frac{d\text{FL}}{d x}=y\left(1-p_{t}\right)^{\gamma}\left(\gamma p_{t} \log \left(p_{t}\right)+p_{t}-1\right) dxdFL​=y(1−pt​)γ(γpt​log(pt​)+pt​−1)

Use Yourself

Data Analysis

数据分析能力是至关重要的:“做机器学习首先要是数据科学家

面对一项任务,了解其数据的分布是至关重要的一环,这会建立起你对该任务面对的状况(尤其是困难)的直观的认识

良好的数据分布会给后续的操作带来良好的基础,在一些方面也具有优良的性质

Focal Loss就是数据分布上起作用

[Feature Pyramid Network](#Feature Pyramid Network)

Feature Pyramid Network 其实是一种将语义信息细节/位置信息结合的方式,处理了feature map结合时的size不符的问题,可以较好的结合不同scale的feature map的优点

Feature Pyramid Network 提取到的特征兼顾了多种分辨率强语义信息,可以广泛地用于后续的处理(特征工程?)

Feature Pyramid Network更广义上来讲,其实是给出了一种信息聚合的结构,可以结合带有不同属性同种信息

More Scale $\not= $ Better

详见 [Perform w.r.t depth/scale](#Perform w.r.t depth/scale)

一味地增加feature map的multi-scale不是总能带来性能的提升

feature map的level的选取,也需要合理去选择

并不是拉过来一个feature map就能用!!!

Related Work

Two-Stage Method

Characteristic

  • 精度高,速度慢

Input

  • 分类器的输入为稀疏的候选目标集sparse set of candidate object locations

Sampling Fashion

  • stage-1 ==> proposal stage

    生成稀疏的候选目标集sparse set of candidate object locations

    滤除绝大部分的 background samples

  • stage-2 ==> classification stage

    使用分类器进行分类,最终结果为 foreground classes / background

    在这阶段会采用 sampling heuristics,老保持foreground和background的平衡

    • fixed foreground-to-background ratio (1: 3)
    • Hard Negative Mining ==> Online Hard Example Mining

One-Stage Method

Characteristic

  • 速度高、精度略差

Input

  • 对object的location、scale、ratio的 regular & dense 采样

    regular, dense sampling of object locations, scales, and aspect ratios

Sampling Fashion

对输入图片进行网格式的密集采样

fixed sample grid

Related Articles

  • Generalized Focal Loss

    对应博客:大白话 Generalized Focal Loss

  • Gradient Harmonized Single-stage Detector

Blogs

  • 样本不平衡、Focal Loss、GHM:5分钟理解Focal Loss与GHM——解决样本不平衡利器

  • GHM(待核对博客):AAAI 2019:把Cross Entropy梯度分布拉‘平’,就能轻松超越Focal Loss

[paper reading] RetinaNet相关推荐

  1. [paper reading] CenterNet (Object as Points)

    [paper reading] CenterNet (Object as Points) GitHub:Notes of Classic Detection Papers 2020.11.09更新:更 ...

  2. [paper reading] SSD

    [paper reading] SSD GitHub:Notes of Classic Detection Papers 本来想放到GitHub的,结果GitHub不支持公式. 没办法只能放到CSDN ...

  3. [paper reading] CornerNet

    [paper reading] CornerNet GitHub:Notes of Classic Detection Papers 本来想放到GitHub的,结果GitHub不支持公式. 没办法只能 ...

  4. cvpr2019/cvpr2018/cvpr2017(Papers/Codes/Project/Paper reading)

    cvpr2019/cvpr2018/cvpr2017(Papers/Codes/Project/Paper reading) Source:https://mp.weixin.qq.com/s/SmS ...

  5. [paper reading] FCOS

    [paper reading] FCOS GitHub:Notes of Classic Detection Papers 2020.11.09更新:更新了Use Yourself,即对于本文的理解和 ...

  6. [paper reading] CenterNet (Triplets)

    [paper reading] CenterNet (Triplets) GitHub:Notes of Classic Detection Papers 2020.11.09更新:更新了Use Yo ...

  7. [paper reading] YOLO v1

    [paper reading] YOLO v1 GitHub:Notes of Classic Detection Papers 本来想放到GitHub的,结果GitHub不支持公式. 没办法只能放到 ...

  8. [paper reading] Faster RCNN

    [paper reading] Faster RCNN GitHub:Notes of Classic Detection Papers 本来想放到GitHub的,结果GitHub不支持公式. 没办法 ...

  9. [paper reading] DenseNet

    [paper reading] DenseNet GitHub:Notes of Classic Detection Papers 本来想放到GitHub的,结果GitHub不支持公式. 没办法只能放 ...

最新文章

  1. sql查询返回xml数据之应用【转载】
  2. Oracle在线重定义
  3. java指导手册,Java 注解指导手册 – 终极向导
  4. 天地伟业tiandy如何连手机_关注 | 天地盖手工盒裱纸选铜版纸还是白牛皮纸?
  5. C# 中数据缓存总结
  6. asp.net MVC2 初探十五
  7. 学计算机比学农好吗,学农教育效果如何?学生:“做农活比打游戏有意义”
  8. 三星关闭在华最后一家电脑厂 约850名员工受影响
  9. SQLServer之深度分析Select
  10. 阮兄弟的致远OAa8v5移动端增加功能和OEM实例
  11. js监听中文拼音输入开始输入和输入完成的事件,用input事件用拼音输入法的大坑,由这两个事件来解决
  12. 从算法学起C语言--费氏数列
  13. 从阿里云下载centos的步骤
  14. Speedoffice(word)如何设置分栏
  15. matlab求三维图形表面积,基于MATLAB的不规则平面立体表面积计算
  16. php花朵飘落特效,【新年气象】WordPress 主题添加花瓣飘落特效
  17. 关于oracle数据库死锁的解决 以及产生的原因
  18. 【CF375C】Circling Round Treasures【XSY1176】大包子环绕宝藏【状压dp】
  19. 倍福端子用直径2.4mm的螺丝刀
  20. 来酷新生态 抢滩元宇宙:首发数码类数字藏品

热门文章

  1. python和java选择哪个-python和java哪个学起来更简单
  2. 解密车载语音识别架构 车载系统能听懂人说话?
  3. 百度地图api vue集成模板收录
  4. docker php7 mysql分开,Docker nginx+php74+mysql57, 并安装gd和mysql扩展
  5. PYTHON笔记 面向对象程序设计
  6. 安卓 mysql读取图片路径_android开发之数据库存取图片
  7. 表必须要有主键吗_玄关隔断什么材质好?玄关隔断必须要做吗
  8. 如何选择漏电保护器规格型号_电涌保护器(SPD)选择有哪几个关键的参数?SPD如何使用和安装?...
  9. 苹果air3安兔兔html5是什么,iPad Air3什么时候上市?我们期待的苹果iPad Air3是什么样?(2)...
  10. 【考研】考研5大分数线——国家线、院校线、自划线、单科线、录取线的区别