Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for

Dense Object Detection

一. 论文简介

将目标检测Loss和评价指标统一,提升检测精度。这是一篇挺好的论文,下面会将其拓展到其它领域。

主要做的贡献如下(可能之前有人已提出):

  1. 分类Loss+评价指标
  2. Regression分布推广到一般性

二. 模块详解

2.1 谈谈分布

  1. 什么是分布?表示一个数发生的概率,设 \(f=P(x)\) 表示分布函数,\(f\) 表示发生的概率,\(x\) 可能存在的数。1)显而易见,\(\int_{-\infty}^{+\infty}P(x)dx=1\),所有的数存在概率总和为1。 2)\(y=\int_{-\infty}^{+\infty}P(x)*xdx\) ,它的整体期望(平均值)肯定是等于目标值的。
  2. 什么是 \(Dirac\) 分布? reference ,\(f=\delta(x-\mu)\) , 当 \(x=\mu\) 概率为1,其它都是0。这是什么意思?此分布简称为绝对分布,只要是直接求目标的,都属于此分布。比如:1)直接计算 \(one-hot\) 交叉熵 \(label=[0,0,0,1],pred=[0.2,0.1,0.1,0.6]\),我们的目的就是两者相等,其它的值都是不存在的。你问我按照\(Delta\) 分布应该其他值为0才对啊,那loss=0(实际loss为什么不是0)怎么回传呢?记住Loss和分布不是一个概念,Loss是我们用一种方式使得结果达到理想分布,分布是一种理想的状态,简单点说 \(Loss \to Sample\)。2)那么直接进行BBox回归也是一种 \(Delta\) 分布,因为都是预测一个值,然后直接和Label进行smoothL1计算Loss。
  3. 什么是 \(Gaussian\) 分布,这个不多说大家都知道。\(Gaussian-YOLO\) 和 \(Heatmap\) 都是属于此分布。举个例子:刚开始做关键点(当前小模型人脸也是这样做的)直接使用坐标 \((x,y)\) 进行回归,显然这是属于 \(Delta\) 分布的,后面人们将其改进为 \(Heatmap\),这就是将分布改为 \(Gaussian\),所以称为\(Gaussian-Heatmap\) .
  4. 什么是任意分布?只满足分布的两个条件,没有具体的公式。直接使用期望和Label进行计算Loss即可。
  5. 进一步理解Loss和分布的关系,期望和Label计算Loss(前向推导使用期望做结果),中间概率和期望计算Loss(使得输出按照一定分布进行,容易收敛提高精度)。


2.2 分类Loss

笔者给出简短说明:

  • 先去看一下FCOS论文,其中使用 \(center-ness\) 计算预测框质量,两个作用:1)训练时抑制质量较差的框。2)前向计算时用于NMS操作指标。
  • 问题来了。。。训练阶段、前向计算、评价指标没有统一?
  • 论文魔改一下Focal-Loss、center-ness统一为一个Loss

  • 此部分比较简单,基本和FCOS类似

# 代码出自mmdetection
@weighted_loss
def quality_focal_loss(pred, target, beta=2.0):
"""Quality Focal Loss (QFL) is from
Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes
for Dense Object Detection
https://arxiv.org/abs/2006.04388 Args:
pred (torch.Tensor): Predicted joint representation of classification
and quality (IoU) estimation with shape (N, C), C is the number of
classes.
target (tuple([torch.Tensor])): Target category label with shape (N,)
and target quality label with shape (N,).
beta (float): The beta parameter for calculating the modulating factor.
Defaults to 2.0. Return:
torch.Tensor: Loss tensor with shape (N,).
"""
assert len(target) == 2, """target for QFL must be a tuple of two elements,
including category label and quality label, respectively"""
# label denotes the category id, score denotes the quality score
label, score = target # negatives are supervised by 0 quality score
pred_sigmoid = pred.sigmoid()
scale_factor = pred_sigmoid
zerolabel = scale_factor.new_zeros(pred.shape)
loss = F.binary_cross_entropy_with_logits(
pred, zerolabel, reduction='none') * scale_factor.pow(beta) # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
bg_class_ind = pred.size(1)
pos = ((label >= 0) & (label < bg_class_ind)).nonzero().squeeze(1)
pos_label = label[pos].long()
# positives are supervised by bbox quality (IoU) score
scale_factor = score[pos] - pred_sigmoid[pos, pos_label]
loss[pos, pos_label] = F.binary_cross_entropy_with_logits(
pred[pos, pos_label], score[pos],
reduction='none') * scale_factor.abs().pow(beta) loss = loss.sum(dim=1, keepdim=False)
return loss

2.3 回归Loss

主要包括两个部分:

  • \(Delta\) 分布推广到任意分布

    • 论文公式(3)是 \(Delta\) 分布的期望,公式(4)和(5)是任意分布的期望
    • 直接预测多个(论文设置为16)值,求期望得到最佳值
    • TIPS: 效果肯定比 \(Delta\) 分布好,但是计算量会增加。小模型一般不适用,大模型使用较多。
  • 限制任意分布

    • 任意分布会过于离散,实际真实的值距离label都不会太远
    • 限制分布范围,论文公式(6)
    • TIPS: 按照公式推导应该效果好(正在推广到关键点检测),使用任意分布的都可以加上试试。
# 代码出自mmdetection
@weighted_loss
def distribution_focal_loss(pred, label):
"""Distribution Focal Loss (DFL) is from
Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes
for Dense Object Detection
https://arxiv.org/abs/2006.04388 Args:
pred (torch.Tensor): Predicted general distribution of bounding boxes
(before softmax) with shape (N, n+1), n is the max value of the
integral set `{0, ..., n}` in paper.
label (torch.Tensor): Target distance label for bounding boxes with
shape (N,). Return:
torch.Tensor: Loss tensor with shape (N,).
"""
# 完全按照论文公式(6)所示,label是真实值(目标框和anchor之间的偏差,参考FCOS)
# pred的shape(偏差*分布),如果没有后面的分布,那就变成delta分布
dis_left = label.long() # label范围[0,正无穷],感觉这里应该-1然后限制一下范围最好。作者说long()向下取整,但是这解决不了对称问题。
dis_right = dis_left + 1
weight_left = dis_right.float() - label
weight_right = label - dis_left.float()
loss = F.cross_entropy(pred, dis_left, reduction='none') * weight_left \
+ F.cross_entropy(pred, dis_right, reduction='none') * weight_right
return loss

三. 参考文献

Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for Dense Object Detection的更多相关文章

  1. 目标检测 | RetinaNet:Focal Loss for Dense Object Detection

    论文分析了one-stage网络训练存在的类别不平衡问题,提出能根据loss大小自动调节权重的focal loss,使得模型的训练更专注于困难样本.同时,基于FPN设计了RetinaNet,在精度和速 ...

  2. focal loss for dense object detection

    温故知新 focal loss for dense object detection,知乎上一人的评论很经典.hard negative sampling, 就是只挑出来男神(还是最难追的),而foc ...

  3. [论文理解]Focal Loss for Dense Object Detection(Retina Net)

    Focal Loss for Dense Object Detection Intro 这又是一篇与何凯明大神有关的作品,文章主要解决了one-stage网络识别率普遍低于two-stage网络的问题 ...

  4. 论文阅读笔记四十四:RetinaNet:Focal Loss for Dense Object Detection(ICCV2017)

    论文原址:https://arxiv.org/abs/1708.02002 github代码:https://github.com/fizyr/keras-retinanet 摘要 目前,具有较高准确 ...

  5. Focal Loss for Dense Object Detection 论文阅读

    何凯明大佬 ICCV 2017 best student paper 作者提出focal loss的出发点也是希望one-stage detector可以达到two-stage detector的准确 ...

  6. 深度学习笔记(八)Focal Loss

    论文:Focal Loss for Dense Object Detection 论文链接:https://arxiv.org/abs/1708.02002 一. 提出背景 object detect ...

  7. Focal Loss 损失函数简述

    Focal Loss 摘要 Focal Loss目标是解决样本类别不平衡以及样本分类难度不平衡等问题,如目标检测中大量简单的background,很少量较难的foreground样本.Focal Lo ...

  8. 技术干货 | 基于MindSpore更好的理解Focal Loss

    [本期推荐专题]物联网从业人员必读:华为云专家为你详细解读LiteOS各模块开发及其实现原理. 摘要:Focal Loss的两个性质算是核心,其实就是用一个合适的函数去度量难分类和易分类样本对总的损失 ...

  9. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...

随机推荐

  1. Mysql-Innodb : 从一个字节到整个数据库表了解物理存储结构和逻辑存储结构

    首先要从Innodb怎么看待磁盘物理空间说起   一块原生的(Raw)物理磁盘,可以把他看成一个字节一个字节单元组成的物理存储介质   如果要在这块原生物理空间中插入一条记录,不能单单只插入数据,还需 ...

  2. Mysql的Windows安装

    1,安装包下载, 这里我们使用压缩包安装方式,先进入Oracle官网,搜搜MySQL8.0,下载完成后选择一个磁盘放置,我选择放在D盘   2.安装教程 (1)配置环境变量 (2)生成data文件 用 ...

  3. 学习篇:NodeJS中的模板引擎:jade

    NodeJS 模板引擎作用:生成页面 在node常用的模板引擎一般是 1.jade --破坏式的.侵入式.强依赖(对原有的html体系不友好,走自己的一套体系)2.ejs --温和的.非侵入式的.弱依 ...

  4. WPF DataGrid 复合表头 (实现表头合并,自定义表头)

    功能说明: 将 DataGrid嵌套在本控件内,使用Label自定义表头,如果需要上下左右滚动 需要在控件外围添加  ScrollViewer 并且设置  ScrollVisibility 为Auto ...

  5. VS2017 Xamarin开发Android时首次部署完成后直接闪退

    项目属性切换到Android选项,在打包属性上有一个[使用共享运行时]的选项要取消勾选,默认打钩时apk文件比较小,但程序无法运行起来. 取消后安装包一小变成几十M,这个目前好像没什么好的解决办法,毕 ...

  6. Python-变量-字符串

    str 字符串如何表示字符串? 单行 单引号 '' 如果字符串中有单引号就需要双引号表示,反之亦然 双引号 " " 换行表示 \ one_str = "简洁胜于优雅&qu ...

  7. 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.3)- 串行NOR Flash下载算法(J-Link工具篇)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是J-Link工具下i.MXRT的串行NOR Flash下载算法设计. 在i.MXRT硬件那些事系列之<在串行NOR Flash X ...

  8. Java知识系统回顾整理01基础04操作符02关系操作符

    一.关系操作符 关系操作符:比较两个变量之间的关系  > 大于 >= 大于或等于 < 小于 <= 小于或等于 == 是否相等 != 是否不等 public class Hell ...

  9. 03 ArcPython实战篇一

    1.自增计算 (字段计算器) total = 0 def accumulate(increment):        global total        if total:            ...

  10. JVM 常见线上问题 → CPU 100%、内存泄露 问题排查

    开心一刻 明明是个小 bug,但就是死活修不好,我特么心态崩了...... 前言 后文会从 Windows.Linux 两个系统来做示例展示,有人会有疑问了:为什么要说 Windows 版的 ? 目前 ...