def distribution_focal_loss(pred, label):
    """Distribution Focal Loss (DFL) is from `Generalized Focal Loss: Learning
    Qualified and Distributed Bounding Boxes for Dense Object Detection
    <https://arxiv.org/abs/2006.04388>`_.
    Args:
        pred (Tensor): Predicted general distribution of bounding boxes
            (before softmax) with shape (N, n+1), n is the max value of the
            integral set `{0, ..., n}` in paper.
        label (Tensor): Target distance label for bounding boxes with
            shape (N,).
    Returns:
        Tensor: Loss tensor with shape (N,).
    """
    dis_left = label.cast('int64')
    dis_right = dis_left + 1
    weight_left = dis_right.cast('float32') - label
    weight_right = label - dis_left.cast('float32')
    loss = F.cross_entropy(pred, dis_left, reduction='none') * weight_left \
        + F.cross_entropy(pred, dis_right, reduction='none') * weight_right
    return loss
Distribution Focal Loss (DFL) is from `Generalized Focal Loss: Learning
    Qualified and Distributed Bounding Boxes for Dense Object Detection
    <https://arxiv.org/abs/2006.04388>`_.
    Args:
        pred (Tensor): Predicted general distribution of bounding boxes
            (before softmax) with shape (N, n+1), n is the max value of the
            integral set `{0, ..., n}` in paper.
        label (Tensor): Target distance label for bounding boxes with
            shape (N,).
    Returns:
        Tensor: Loss tensor with shape (N,).
    
ppdet/modeling/losses/gfocal_loss.py