code: def varifocal_loss(
      pred,
      target,
      weight=None,
      alpha=0.75,
      gamma=2.0,
      iou_weighted=True,
      reduction="mean",
      avg_factor=None,
  ):
      """`Varifocal Loss <https://arxiv.org/abs/2008.13367>`_
  
      Args:
          pred (torch.Tensor): The prediction with shape (N, C), C is the
              number of classes
          target (torch.Tensor): The learning target of the iou-aware
              classification score with shape (N, C), C is the number of classes.
          weight (torch.Tensor, optional): The weight of loss for each
              prediction. Defaults to None.
          alpha (float, optional): A balance factor for the negative part of
              Varifocal Loss, which is different from the alpha of Focal Loss.
              Defaults to 0.75.
          gamma (float, optional): The gamma for calculating the modulating
              factor. Defaults to 2.0.
          iou_weighted (bool, optional): Whether to weight the loss of the
              positive example with the iou target. Defaults to True.
          reduction (str, optional): The method used to reduce the loss into
              a scalar. Defaults to 'mean'. Options are "none", "mean" and
              "sum".
          avg_factor (int, optional): Average factor that is used to average
              the loss. Defaults to None.
      """
      # pred and target should be of the same size
      assert pred.size() == target.size()
      pred_sigmoid = pred.sigmoid()
      target = target.type_as(pred)
      if iou_weighted:
          focal_weight = (
              target * (target > 0.0).float()
              + alpha
              * (pred_sigmoid - target).abs().pow(gamma)
              * (target <= 0.0).float()
          )
      else:
          focal_weight = (target > 0.0).float() + alpha * (
              pred_sigmoid - target
          ).abs().pow(gamma) * (target <= 0.0).float()
      loss = (
          F.binary_cross_entropy_with_logits(
              pred, target, reduction="none"
          )
          * focal_weight
      )
      loss = weight_reduce_loss(loss, weight, reduction, avg_factor)
      return loss
  
file_path: insightface/detection/scrfd/mmdet/models/losses/varifocal_loss.py
imports: import torch.nn
  import torch.nn.functional
  from ..builder import LOSSES
  from .utils import weight_reduce_loss
label_desc: Use image node_id 1 for calling a global function with example usage: varifocal_loss(pred, target, weight, alpha, gamma, iou_weighted, reduction, avg_factor) and returns: loss