SphereFace[2017-CVPR]

Paper-info

  • title : SphereFace: Deep Hypersphere Embedding for Face Recognition[CVPR-2017]
  • author : Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj, Le Song.
  • insight : angular softmax (A-Softmax) loss.
  • github : metricface-pytorch

Motivation

  • prior : 人脸位于流行结构上.
  • 基于角度的softmax损失函数本质是:在超球面上加入了区分约束,这与先验知识非常匹配!

 

Details

                                          

  • 归一化W,同时让bias置零

                                                           

  1. 优化内积 --> 优化角度
  2. decision boundary更为简洁明了,人脸分布于空间超球面上!
  • cos(mθ1)>cos(θ2)

                                     

     1. 为了保证cos(m*theta)单调递减,需要对theta的取值范围加以约束,为了消除这种约束,采用如下的方式来替代cos:

                                        

# 根据m*theta的取值范围,找到对应的k,使得cos(m*theta)在对应的区间单调
theta = cos_theta.data.acos()
k = (self.m * theta / 3.14159265).floor()   # k.shape == theta.shape

Sphereface-pytorch

class Sphereface(nn.Module):
  
    def __init__(self, in_features, out_features, m = 4, use_gpu = False):

        super(Sphereface, self).__init__()

        self.in_features  = in_features
        self.out_features = out_features
        self.m     = m
        self.base  = 1000.0
        self.gamma = 0.12
        self.power = 1
        self.LambdaMin = 5.0
        self.iter   = 0
        self.weight = torch.FloatTensor(out_features, in_features)
        if use_gpu:
            self.weight = self.weight.cuda()
        self.weight = Parameter(self.weight)
        nn.init.xavier_uniform_(self.weight)
        
        self.mlambda = [
            lambda x: x ** 0,
            lambda x: x ** 1,
            lambda x: 2 * x ** 2 - 1,
            lambda x: 4 * x ** 3 - 3 * x,
            lambda x: 8 * x ** 4 - 8 * x ** 2 + 1,
            lambda x: 16 * x ** 5 - 20 * x ** 3 + 5 * x
        ]

    def forward(self, input, target):

        self.iter += 1
        self.lamb = max(self.LambdaMin, self.base * (1 + self.gamma * self.iter) ** (-1 * self.power))

        cos_theta = F.linear(F.normalize(input), F.normalize(self.weight))
        cos_theta = cos_theta.clamp(-1, 1)
        cos_m_theta = self.mlambda[self.m](cos_theta)
        theta = cos_theta.data.acos()
        k = (self.m * theta / 3.14159265).floor()
        phi_theta = ((-1.0) ** k) * cos_m_theta - 2 * k
        NormOfFeature = torch.norm(input, 2, 1)

        one_hot = torch.zeros(cos_theta.size(), device=input.device)
        one_hot.scatter_(1, target.view(-1, 1), 1)

        output = (one_hot * (phi_theta - cos_theta) / (1 + self.lamb)) + cos_theta
        output *= NormOfFeature.view(-1, 1)

        return output

Experiments

  • Sphere-3D-CASIA_WebFace         

              

  • LFW/YTF

           

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ReLuJie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值