CenterLoss - A Discriminative Feature Learning Approach for Deep Face Recognition

[Paper]

[Caffe-Code]

摘要:

Center Loss For Face Recognition - 提高CNN学习的特征的判别能力.

Center Loss 通过学习每一类的深度特征的中心,同时惩罚深度特征与对应的类别中心的距离.

Softmax Loss + Center Loss,可以同时增加类间分散程度(inter-class dispension)与类内紧凑程度(intra-class compactness).

由于CNNs模型采用SGD方法以 mini-batch 的方式进行优化,难以很好的反应深度新特征的全局分布. 且对于大规模训练集,也很难将所有的训练样本一次性的输入到每次迭代.

contrastive loss 和 triplet loss 存在图像 pairs 和 triplets 构建的问题,训练样本的图像采样较为复杂.

基于 CNN 网络的典型框架:
这里写图片描述

将人脸图片输入到 CNN 网络,进行特征学习以得到深度特征,包括可区分特征和判别特征,然后进行 label 预测.

对于深度特征分布情况的分析:

以 MNIST 数据集, 采用 LeNets 网络,Softmax Loss,提取最后一层网络输出的 2 维特征,并进行可视化.
这里写图片描述
Figure 2. 深度学习特征分布的可视化. (a) 训练集 (b) 测试集.

网络的最后一个全连接层相当于线性分类器,不同类的深度特征通过决策边界(decision boundaries)被区分.

由 Figure 2 可知,

  • 基于 Softmax Loss 监督学习的深度特征是可区分的;
  • 由于特征显著的类内变化,深度特征的判别能力不够. 某些类内距离大于类间距离.

1. Softmax Loss

这里写图片描述

xiRd x i ∈ R d <script type="math/tex" id="MathJax-Element-41">\mathbf{x}_i \in R^d</script> - 属于第 yi y i <script type="math/tex" id="MathJax-Element-42">y_i</script> 类的第 i i <script type="math/tex" id="MathJax-Element-43">i</script> 个深度特征;

d<script type="math/tex" id="MathJax-Element-44">d</script> - 特征维度;

WjRd W j ∈ R d <script type="math/tex" id="MathJax-Element-45">W_j \in R^d</script> - 最后全连接层的权重 WRd×n W ∈ R d × n <script type="math/tex" id="MathJax-Element-46">W \in R^{d×n} </script> 的第 j j <script type="math/tex" id="MathJax-Element-47">j</script> 列;

bRn<script type="math/tex" id="MathJax-Element-48">\mathbf{b} \in R^n</script> - bias 项;

m m <script type="math/tex" id="MathJax-Element-49">m</script> - mini-batch 大小;

n<script type="math/tex" id="MathJax-Element-50">n</script> - 类别数.

2. Center Loss

提升深度特征的判别能力:

最小化类内距离,同时保持不同类别特征的可区分性. [Intuitively, minimizing the intra-class variations while keeping the features of different classes separable is the key. ]

这里写图片描述

cyiRd c y i ∈ R d <script type="math/tex" id="MathJax-Element-204">\mathbf{c}_{y_i} \in R^d</script> - 深度特征的第 yi y i <script type="math/tex" id="MathJax-Element-205">y_i</script> 个类别中心.

理想情况下, cyi c y i <script type="math/tex" id="MathJax-Element-206">c_{y_i}</script> 随着深度特征的学习而进行更新. 也就是说,需要在每次迭代中将整个训练集都考虑在内,并对每一类的特征进行取平均. 但这是不可行,甚至不切实际的.

这里进行两处必要的改进:

  • 对 mini-batch 内的训练样本进行更新,而不是对整个训练集的各类别中心进行更新;每次迭代过程中,只对对应类别的特征进行平均计算,(某些类别中心可能不进行更新.)
  • 为了避免少样本类别造成的较大干扰,采用一个因子 α α <script type="math/tex" id="MathJax-Element-207">\alpha</script> 来控制类别中心的学习率.

Lc L c <script type="math/tex" id="MathJax-Element-208">L_c</script> 关于 xi x i <script type="math/tex" id="MathJax-Element-209">\mathbf{x} _i</script> 的梯度和 cyi c y i <script type="math/tex" id="MathJax-Element-210">\mathbf{c}_{y_i}</script> 的更新计算为:
这里写图片描述

δ(condition)=1if condition,else,δ(condition)=0 δ ( c o n d i t i o n ) = 1 , i f   c o n d i t i o n , e l s e , δ ( c o n d i t i o n ) = 0 <script type="math/tex" id="MathJax-Element-211">\delta(condition) = 1, if \ condition, else, \delta(condition)=0</script>;

α[0,1] α ∈ [ 0 , 1 ] <script type="math/tex" id="MathJax-Element-212">\alpha \in [0, 1]</script>.

采用 Softmax Loss + Center Loss 来进行判别特征学习:
这里写图片描述

其中, λ λ <script type="math/tex" id="MathJax-Element-213">\lambda</script> 为控制两个损失函数的 balance 因子,如果 λ=0 λ = 0 <script type="math/tex" id="MathJax-Element-214">\lambda = 0</script> ,即是 Softmax Loss.

SGD 优化过程:
这里写图片描述

λ λ <script type="math/tex" id="MathJax-Element-215">\lambda</script> 对于特征分布的影响如图:
这里写图片描述
Figure 3. 基于 Softmax Loss 和 Center Loss 联合监督所学习深度特征的分布情况. 不同颜色的点表示不同类别的特征. 不同的 λ λ <script type="math/tex" id="MathJax-Element-216">\lambda</script> 值对应不同的深度特征分布( α=0.5 α = 0.5 <script type="math/tex" id="MathJax-Element-217">\alpha = 0.5</script>). 白色的圆点( c0,c1,...,c9 c 0 , c 1 , . . . , c 9 <script type="math/tex" id="MathJax-Element-218">\mathbf{c}_0, \mathbf{c}_1, ..., \mathbf{c}_9</script>) 分别表示 10 类深度特征的类别中心.

合适的 λ λ <script type="math/tex" id="MathJax-Element-219">\lambda</script> 值能够明显提高深度特征的判别能力. 而且,在一个较大范围内的 λ λ <script type="math/tex" id="MathJax-Element-220">\lambda</script> 值,特征均具有可区分性. 这对于人脸识别是很有帮助的.

3. Discussion

3.1. Softmax Loss + Center Loss 联合训练的必要性

如果只采用 Softmax Loss,深度特征类内离散度较大.

如果只采用 Center Loss,深度特征和类别中心将趋近于 0(此时,Center Loss 非常小.)

单独的采用一个 Loss,难以达到判别性特征学习的目的. 因此,需要进行联合训练.
这里写图片描述
Figure . (左) 基于 Softmax Loss 的特征; (右) 基于 Center Loss 的特征. Center Loss 是使得任意红色特征点之间的距离小于红色特征点与蓝色特征点之间的距离,以确保最好的不同特征类别的划分.

3.2 对比 ContrastIve Loss 和 Triplet Loss

ContrastIve Loss 和 Triplet Loss 均是被用来提高深度特征的判别能力. 但是,基于大规模数据集时,需要面对庞大的样本对和样本 triplets 采样的问题.

Center Loss 与 Softmax Loss 采用相同的训练数据格式,不需要复杂的训练样本重采样.

因此,Center Loss 易于实现,效率更高;Center Loss 通过直接学习类间的紧凑度,更有利于判别性特征学习.

4. Center Loss for Face Recognition

  • 网络结构
    这里写图片描述
    Figure 4. 人脸识别的 CNN 网络. 基于 Center Loss + Softmax Loss.

  • 数据

    首先检测所有的人脸图片及对应的 landmarks. 采用 5 个landmarks(2 eyes, nose 和 mouth corners) 来进行相似度变换.

    如果训练图片的人脸和 landmarks 检测失败 ,则丢弃该图片;但如果是测试图片,则仍采用提供的 landmarks.

    人脸图片裁剪为 112×96 112 × 96 <script type="math/tex" id="MathJax-Element-222">112×96</script> 的 RGB 图片. 每个像素值减去 127.5 的均值(中心化),并乘以 1/128=0.0078125 的尺度.

    • 数据集
      CASIAWebFace
      CACD2000
      Celebrity+

    • 数据增广 —— 水平翻转

  • CNNs 网络设置

    • 基于 Caffe

    • models - batchsize = 256 / 2 GPUs(Titan X)
      model A - Softmax Loss
      model B - Softmax Loss + Contrastive Loss
      model C - Softmax Loss + Center Loss

  • 测试设置

    将第一个 FC 层的输出作为深度特征.

    提取每张图片和其翻转图片的特征,一起作为图像特征. 然后进行PCA 降维.

    计算降维后的两个特征间的 Cos 距离,得到最终的 Score.

参考

[1] - Center Loss - A Discriminative Feature Learning Approach for Deep Face Recognition 论文理解

[2] - 人脸识别之caffe-face

更多推荐