具体的计算公式可能因具体实现而异,但通常可以表示为: python import torch import torch.nn.functional as F def distribution_focal_loss(preds, targets, gamma=2.0, alpha=0.25): """ 计算DFL损失 Args: - preds: 模型预测的概率分布,形状为 (N, C),其中 N 是样本数,C 是类别数。 - targets: 真实标...
但是这两个整数,距离真实值的距离又是不同的,所以就给8一个大一点的权重0.7(9-8.3=0.7,对应于公式中的yi+1-y),给9一个小一点的权重0.3(8.3-8=0.3,对应于公式中的y-yi). def _df_loss(pred_dist, target): """Return sum of left and right DFL losses.""" # target向下取整,作为目标的左侧整数...