文章目录

  • (一)、研究背景
  • (二)、论文详解
    • 1.1、Abstract
    • 1.2、Introduction
  • (三)、Arcface Loss代码详解

人脸识别中Softmax-based Loss的演化史
ArcFace: Additive Angular Margin Loss for Deep Face Recognition论文

(一)、研究背景

1、提出问题yellow

1、需要特征的discrimnationdiscrimnationdiscrimnation
2、之前提出的一些方法,如triplet loss,center loss, L-Softmax, A-Softmax, cosface, 但是都有缺陷。
3、需要找到一个更加有效的方法(Arcface)

2、之前主要方法的缺陷yellow

之前的主要方法:

1、Center Loss
2、Triplet loss
3、Sphereface(a-softmax)
4、CosFace

缺陷:

1、强制改变特征的内在分布,需要联合softmax一起训练,类别多的时候很难训练。
2、训练数据选择复杂度高,semi-hard样本的选择也很复杂,大大降低训练的效率。
3、计算复杂度高,需要辅助函数(保证单调性),以及计算cos(m*theta),并且训练很不稳定, 难收敛,需要很多策略,比如一开始要和softmax的loss做插值。

研究成果以及意义

1.代码修改简单
2.训练效率高,几乎没有额外的计算开销
3.有着直观的几何解释
4.性能取得很好的效果

(二)、论文详解

1.1、Abstract

  1. 用深度学习提取特征的主要挑战是设计好的具有区分性的损失函数
  2. 最近也有一些方法解决这个问题如center loss, sphereface等
  3. 提出arcface来获得高度具有区分性的特征用作人脸识别,并且有着清晰的几何解释
  4. 在很多人脸识别的任务上取得很好的效果
1、提出问题yellow

1.2、Introduction

  1. 用DCNN来学习人脸表示,把人脸图片映射到特征空间,使得类内距离小类间距离大
  2. 一般两条主线方法,代表分别为softmax loss和triplet loss,但是都有一些缺陷
  3. 一些方法用来加强特征的区分性,比如center loss,但是也有不足
  4. Sphereface 和cosface 的优点与缺点 5. 提出arcface,并给出它的算法框架,并且总结了其优势
Face recognition的DCNN训练主要有两种方法和他们的缺点

1、The Softmax Classifer
缺点如下:

(1) 线性变换矩阵的大小W∈Rd×n随着身份数的增加而线性增加n;
(2) 学习到的特征对于封闭集的分类问题是可分离的的分类问题是可分离的,但对于开放性的人脸识别问题来说,却没有足够的鉴别力。脸部识别的问题。

softmax损失函数并没有明确地对特征嵌入进行优化。特征嵌入,对类内样本执行更高的相似性,对类间样本执行更高的多样性。这导致了在大的类内外观变化(如姿势变化)下,深度人脸识别的性能差距。大的类内外观变化(例如:姿势变化 [28, 44]和年龄差距[19, 45])和大规模测试场景下的性能差距。(例如,百万[12, 37, 18]或万亿对[1])。

2、The Triplet Loss
缺点如下:

(1)脸的数量会出现组合式爆炸,特别是对于大规模的数据集来说。特别是对于大规模的数据集,会导致迭代步骤的显著增加;
(2)半硬样本挖掘是一个相当困难的问题,需要有效的模型训练是一个相当困难的问题。

Softmax Loss的一些变体,以提高softmax损失的判别能力。

1.the centre loss
具体细节可以查看我的这篇博客:CenterLoss原理详解(通透)
(1)、每个特征向量与其类中心之间的欧氏距离,以获得类内的紧凑性,而类间的分散性则由softmax损失的联合惩罚来保证。
(2)、Nevertheless, updating the actual centres during training is extremely difficult as the number of faceclasses available for training has recently dramatically increased.

2、Sphereface
θθθ乘以决策余量mmm,进行权重归一化,并将偏置项归零(∣∣Wi∣∣=1,bi=0||W_i||=1,b_i=0Wi=1bi=0

3、Cosface
CosFace [35, 33] directly adds cosine margin penalty to the target logit, which obtains better performance compared to SphereFace but admits much easier implementation and relieves the need for joint supervision from the softmax loss.

4、Arcface
性能:further improve the discriminative power of the face recognition model and to stabilise the trainingprocess。
如下图所示,DCNN特征与最后一个完全连接层之间的点积等于特征和权值归一化后的余弦距离。
论文中详细讲述的关于xix_ixiwww细节如下:
For simplicity, we fix the bias bj=0b_j = 0bj=0 as in [15]. Then,we transform the logit [24] as WjTxi=∣∣Wj∣∣∣∣xi∣∣cosθjW_j^T x_i = ||W_j|| ||x_i|| cosθ_jWjTxi=Wjxicosθj ,where θjθ_jθj is the angle between the weight WjW_jWj and the feature xix_ixi. Following [15, 35, 34], we fix the individual weight WjW_jWj = 1 by L2L_2L2 normalisation. Following [26, 35, 34, 33],we also fix the embedding feature xix_ixi by L2L_2L2 normalisation and re-scale it to sss. The normalisation step on features and weights makes the predictions only depend on the angle between the feature and the weight. The learned embedding features are thus distributed on a hypersphere with a radius of sss.
关于xix_ixiwww处理公式如下:

1、xi−−>xi∣∣xi∣∣−−>sxi∣∣xi∣∣x_i --> \frac{x_i}{||x_i||}-->s\frac{x_i}{||x_i||}xi>xixi>sxixi
2、∣∣sxi∣∣xi∣∣∣∣=s∣∣xi∣∣∣∣xi∣∣=s||s\frac{x_i}{||x_i||}|| = \frac{s}{||x_i||}||x_i|| = ssxixi=xisxi=s
3、xiTwyi=s∗cosθjx_i^T w_{y_i} = s*cosθ_jxiTwyi=scosθj
L2=−1N∑i=1Nloges∗cos(θyj+m)es(cos(θyi+m))+∑j=1,j≠yines∗cos(θj)L_2 = -\frac{1}{N}\sum_{i=1}^Nlog\frac{e^{s*cos(θ_{y_j + m})}}{e^{s(cos(θ_{y_i}+m))}+ \sum_{j=1,j\neq y_i}^n e^{s*cos(θ_j)}}L2=N1i=1Nloges(cos(θyi+m))+j=1,j=yinescos(θj)escos(θyj+m)

(三)、Arcface Loss代码详解

Arcface为什么很容易实现?

我们看看论文中是如何叙述的:
Easy: ArcFace only needs several lines of code as given in Algorithm 1 and is extremely easy to implement in thecomputational-graph-based deep learning frameworks, e.g. MxNet [5], Pytorch [23] and Tensorflow [2].

ArcfaceMarginProduct官方源码
class ArcMarginProduct(nn.Module):r"""Implement of large margin arc distance: :Args:in_features: size of each input sampleout_features: size of each output samples: norm of input featurem: margincos(theta + m)"""def __init__(self, in_features, out_features, s=30.0, m=0.50, easy_margin=False):super(ArcMarginProduct, self).__init__()self.in_features = in_featuresself.out_features = out_featuresself.s = sself.m = mself.weight = Parameter(torch.FloatTensor(out_features, in_features))nn.init.xavier_uniform_(self.weight)self.easy_margin = easy_marginself.cos_m = math.cos(m)self.sin_m = math.sin(m)self.th = math.cos(math.pi - m)self.mm = math.sin(math.pi - m) * mdef forward(self, input, label):# --------------------------- cos(theta) & phi(theta) ---------------------------# 对feature x 和权重w 分别归一化后,做点乘,也就是全连接操作,得到的就是cosθcosine = F.linear(F.normalize(input), F.normalize(self.weight))# 求sinθsine = torch.sqrt((1.0 - torch.pow(cosine, 2)).clamp(0, 1))# cos(θ+m) = cosθ*cosm - sinθ*sinmphi = cosine * self.cos_m - sine * self.sin_mif self.easy_margin:phi = torch.where(cosine > 0, phi, cosine)else:phi = torch.where(cosine > self.th, phi, cosine - self.mm)# --------------------------- convert label to one-hot ---------------------------# one_hot = torch.zeros(cosine.size(), requires_grad=True, device='cuda')one_hot = torch.zeros(cosine.size(), device='cuda')one_hot.scatter_(1, label.view(-1, 1).long(), 1)# -------------torch.where(out_i = {x_i if condition_i else y_i) -------------output = (one_hot * phi) + ((1.0 - one_hot) * cosine)  # you can use torch.where if your torch.__version__ is 0.4output *= self.s# print(output)return output
ArcfaceMarginProduct官方源码我在下图中做了详细的推导,方便理解。


下面的和源码差不多,但是比官方源码好跑通,不缺文件。
bubbliiiing/arcface-pytorch代码

class Arcface_Head(Module):def __init__(self, embedding_size=128, num_classes=10575, s=64., m=0.5):super(Arcface_Head, self).__init__()self.s = sself.m = mself.weight = Parameter(torch.FloatTensor(num_classes, embedding_size))nn.init.xavier_uniform_(self.weight)self.cos_m = math.cos(m)self.sin_m = math.sin(m)self.th = math.cos(math.pi - m)self.mm = math.sin(math.pi - m) * mdef forward(self, input, label):cosine  = F.linear(input, F.normalize(self.weight))   # 归一化后的x与w相乘就是cos(角度)sine    = torch.sqrt((1.0 - torch.pow(cosine, 2)).clamp(0, 1))phi     = cosine * self.cos_m - sine * self.sin_m   # 等于cos(角度+m)# torch.where(a>0,a,b)      # 满足条件返回a, 不满足条件返回bphi     = torch.where(cosine.float() > self.th, phi.float(), cosine.float() - self.mm)one_hot = torch.zeros(cosine.size()).type_as(phi).long()one_hot.scatter_(1, label.view(-1, 1).long(), 1)output  = (one_hot * phi) + ((1.0 - one_hot) * cosine) output  *= self.sreturn output

Arcface详解(通透、清晰)相关推荐

  1. 单线复用场景下,详解IPTV透传原理

    文章目录 一.使用路由器进行拨号上网 (一)修改光猫 1.获取宽带密码 2.获取光猫的超级管理员密码 3.把光猫的internet"网络连接"配置为"桥接"模式 ...

  2. 【人脸识别】arcface详解

    论文题目:<ArcFace Additive Angular Margin Loss for Deep Face Recognition > 论文地址:https://arxiv.org/ ...

  3. 【4.0】 数学建模中拟合算法详解|内附清晰图片和详细代码实现

    一.前言 与插值问题不同,在拟合问题中不需要曲线一定经过给定的点.拟合问题的目标是寻求一个函数(曲线),使得该曲线在某种准则下与所有的数据点最为接近,即曲线拟合的最好(最小损失函数) 插值和拟合的区别 ...

  4. 【详解!思路清晰】1095 解码PAT准考证 (25分)

    立志用最少的代码做最高效的表达 PAT乙级最优题解-->传送门 PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级:B 代表乙级: 第 2~4 位是考场编号,范 ...

  5. 详解Modbus通信协议---清晰易懂

    本文旨在让您对Modbus有一个很直观的了解,总结关于Modbus相关的知识,非常适合初学的同学,同时如有错误,欢迎修改意见和建议,将在第一时间修改 什么是协议 什么是RS-485 RS-232 Mo ...

  6. bootstraptable 加载完成回调函数_牛皮了!头一次见有大佬把「JavaScript中的回调函数」详解得如此清晰明了...

    前言 callback,大家都知道是回调函数的意思.但是你对这个概念应该是模模糊糊.比如Ajax,你只知道去调用返回函数,如果对callback没有理解清楚,估计你在学习Node.js后会崩溃,因为c ...

  7. Modbus调试软件--ModbusPoll、ModbusSlave使用详解

    软件下载链接: 链接: https://pan.baidu.com/s/1vQiGP-AIYxShcZhbxbctTg 提取码: dqeg Modbus基础知识讲解: 详解Modbus通信协议-清晰易 ...

  8. 小白也能接广告赚钱,实操月入3000+项目详解

    小白也能接广告赚钱,实操月入3000+项目详解 大家好,我是独孤思维.今天是原创日更134篇. 01 微头条接广告 自从上次分享了微头条的搬运项目,很多粉丝朋友已经开始实操了,有的甚至两天都涨粉破百, ...

  9. 高通平台msm8953 Linux DTS(Device Tree Source)设备树详解之二(DTS设备树匹配过程)

    本系列导航: 高通平台8953  Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇) 高通平台8953 Linux DTS(Device Tree Source ...

  10. python编程入门与案例详解pdf-Flutter技术入门与实战 PDF 清晰版

    给大家带来的一篇关于Flutter相关的电子书资源,介绍了关于Flutter入门.Flutter实战.Flutter技术方面的内容,本书是由机械工业出版社出版,格式为PDF,资源大小162.5 MB, ...

最新文章

  1. python ascii函数二进制_python模块介绍- binascii:二进制和ASCII互转以及其他进制转换...
  2. 在linux系统安装R及rstudio
  3. Android移动开发之【Android实战项目】渐变的TextView小漂亮代码
  4. Java8新特性-接口中的静态方法与默认方法
  5. node 获取表单数据 为空_数据结构与算法(python)单向链表篇
  6. 手机只能签荣耀!最忠诚代言人胡歌喊你去天猫超品日
  7. thinkphp5 router.php,ThinkPHP5 之route(路由)简述
  8. 《DSP using MATLAB》Problem 7.25
  9. linux内核移植过程问题总结
  10. 这些竟然是身体的求救信号!你看懂了吗?
  11. Android Timer和TimerTask解决IllegalStateException:Task already scheduled or cancelled
  12. ES6.x版本单机三节点配置discovery.zen.ping.unicast.hosts 错误
  13. Nide.js安装配置
  14. 开户功能遭入侵攻击,银行 App 数据安全如何保护?
  15. 对话奥比中光CV博士:今年三维重建与计算机视觉可以关注哪些热点?
  16. 推荐一款文件文档在线预览解决方案
  17. Edge浏览器默认主页被莫名修改,修复流程分享
  18. 一篇文章告诉你什么是量化的统计套利
  19. mysql取消用户授权
  20. 歌曲:精忠报国 歌手:屠洪刚

热门文章

  1. 细聊智能家居开发中必备的通信协议
  2. 微信视频强制分享观看源码 微信流量裂变源码吸粉变现源码
  3. sql server的增删改查语句
  4. java解决合并两个有序链表问题
  5. 超详细excel键盘快捷键大全
  6. 【历史上的今天】8 月 21 日:谷歌创始人诞生;百度 360 搜索大战
  7. ansys 服务器系统,云服务器 ansys
  8. 减小app大小的方法——iOS开发用ImageOptim压缩png图片
  9. ALSA音频架构 -- aplay播放流程分析
  10. 你还不知道Java异或运算符的妙用?