ArcFace[2019-CVPR]

论文信息

  • ArcFace: Additive Angular Margin Loss for Deep Face Recognition[2019-CVPR]
  • Author   : Jiankang Deng, Jia Guo, Niannan Xue, Stefanos Zafeiriou
  • Citation : 280+
  • Github   : metricface-pytorch 

关键技术

                                                         

     

Arcface-pytorch

class Arcface(nn.Module):
    r"""Implement of large margin arc distance: :
        Args:
            in_features: size of each input sample
            out_features: size of each output sample
            s: norm of input feature
            m: margin

            cos(theta + m)
        """
    def __init__(self, in_features, out_features, s = 30.0, m = 0.50, easy_margin = False, use_gpu = False):

        super(Arcface, self).__init__()
        self.in_features  = in_features
        self.out_features = out_features
        self.s = s
        self.m = m
        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.easy_margin = easy_margin
        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) * m


    def forward(self, input, target):

        # cos(a+b) = cos(a)cos(b)-sin(a)sin(b)
        cosine = F.linear(F.normalize(input), F.normalize(self.weight))
        sine   = torch.sqrt((1.0 - torch.pow(cosine, 2)).clamp(0, 1))
        phi    = cosine * self.cos_m - sine * self.sin_m
        if self.easy_margin:
            phi = torch.where(cosine > 0, phi, cosine)  # enhance similar class
        else:
            phi = torch.where(cosine > self.th, phi, cosine - self.mm) # pull similar, push diff
        one_hot = torch.zeros(cosine.size(), device=input.device)
        one_hot.scatter_(1, target.view(-1, 1).long(), 1)
        output = (one_hot * phi) + ((1.0 - one_hot) * cosine)
        output *= self.s

        return output

Arcface vs (Sphereface, Cosface) ?

                                     

Experiment

                                                   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ReLuJie

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

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

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

打赏作者

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

抵扣说明:

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

余额充值