code: def quality_focal_loss(pred, target, beta=2.0):
      r"""Quality Focal Loss (QFL) is from `Generalized Focal Loss: Learning
      Qualified and Distributed Bounding Boxes for Dense Object Detection
      <https://arxiv.org/abs/2006.04388>`_.
  
      Args:
          pred (torch.Tensor): Predicted joint representation of classification
              and quality (IoU) estimation with shape (N, C), C is the number of
              classes.
          target (tuple([torch.Tensor])): Target category label with shape (N,)
              and target quality label with shape (N,).
          beta (float): The beta parameter for calculating the modulating factor.
              Defaults to 2.0.
  
      Returns:
          torch.Tensor: Loss tensor with shape (N,).
      """
      assert (
          len(target) == 2
      ), """target for QFL must be a tuple of two elements,
          including category label and quality label, respectively"""
      # label denotes the category id, score denotes the quality score
      label, score = target
  
      # negatives are supervised by 0 quality score
      pred_sigmoid = pred.sigmoid()
      scale_factor = pred_sigmoid
      zerolabel = scale_factor.new_zeros(pred.shape)
      loss = F.binary_cross_entropy_with_logits(
          pred, zerolabel, reduction="none"
      ) * scale_factor.pow(beta)
  
      # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
      bg_class_ind = pred.size(1)
      pos = ((label >= 0) & (label < bg_class_ind)).nonzero().squeeze(1)
      pos_label = label[pos].long()
      # positives are supervised by bbox quality (IoU) score
      scale_factor = score[pos] - pred_sigmoid[pos, pos_label]
      loss[pos, pos_label] = F.binary_cross_entropy_with_logits(
          pred[pos, pos_label], score[pos], reduction="none"
      ) * scale_factor.abs().pow(beta)
  
      loss = loss.sum(dim=1, keepdim=False)
      return loss
  
file_path: insightface/detection/scrfd/mmdet/models/losses/gfocal_loss.py
imports: import torch.nn
  import torch.nn.functional
  from ..builder import LOSSES
  from .utils import weighted_loss
label_desc: Use image node_id 1 for calling a global function with example usage: quality_focal_loss(pred, target, beta) and returns: loss