【源码注释】腾讯优图Tface开源项目中的人脸识别DDL理解

论文链接:https://arxiv.org/abs/2002.03662

import torch
import torch.nn.functional as F


class DDL(torch.nn.Module):
    """ Implented of  
    """
    def __init__(self, pos_kl_weight=0.1, neg_kl_weight=0.02,
                 order_loss_weight=0.5, positive_threshold=0.0):
        """ Args:
            pos_kl_weight: weight for positive kl loss
            neg_kl_weight: weight for negative kl loss
            order_loss_weight: weight for order loss
            positive_threshold:  threshold fo positive pair  
        """
        super(DDL, self).__init__()
        self.pos_kl_weight = pos_kl_weight
        self.neg_kl_weight = neg_kl_weight
        self.order_loss_weight = order_loss_weight
        self.positive_threshold = positive_threshold
        # register_buffer:在内存中定一个常量,同时,模型保存和加载的时候可以写入和读出。
        # 该方法的作用是定义一组参数,该组参数的特别之处在于:模型训练时不会更新(即调用 optimizer.step() 后该组参数不会变化,只可人为地改变它们的值)
        # 保存模型时,该组参数又作为模型参数不可或缺的一部分被保存。
        self.register_buffer('t', torch.arange(0, 1.0, 0.001).view(-1, 1).t()) # 分配直方图间隔

    def forward(self, neg_features, pos_pair_features_first, pos_pair_features_second):
    
        # 教师(简单样本)和学生(难分样本)均有b个正样本对(2b个样本)、b个不同身份的样本 
        # sample b positive pairs (i.e., 2b samples) and b samples with different identities
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值