losses.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:mean-teacher 作者: CuriousAI 项目源码 文件源码
def softmax_kl_loss(input_logits, target_logits):
    """Takes softmax on both sides and returns KL divergence

    Note:
    - Returns the sum over all examples. Divide by the batch size afterwards
      if you want the mean.
    - Sends gradients to inputs but not the targets.
    """
    assert input_logits.size() == target_logits.size()
    input_log_softmax = F.log_softmax(input_logits, dim=1)
    target_softmax = F.softmax(target_logits, dim=1)
    return F.kl_div(input_log_softmax, target_softmax, size_average=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号