code: def quality_focal_loss_tensor_target(
      pred, target, beta=2.0, activated=False
  ):
      """`QualityFocal 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.
          beta (float): The beta parameter for calculating the modulating factor.
              Defaults to 2.0.
          activated (bool): Whether the input is activated.
              If True, it means the input has been activated and can be
              treated as probabilities. Else, it should be treated as logits.
              Defaults to False.
      """
      # pred and target should be of the same size
      assert pred.size() == target.size()
      if activated:
          pred_sigmoid = pred
          loss_function = F.binary_cross_entropy
      else:
          pred_sigmoid = pred.sigmoid()
          loss_function = F.binary_cross_entropy_with_logits
  
      scale_factor = pred_sigmoid
      target = target.type_as(pred)
  
      zerolabel = scale_factor.new_zeros(pred.shape)
      loss = loss_function(
          pred, zerolabel, reduction="none"
      ) * scale_factor.pow(beta)
  
      pos = target != 0
      scale_factor = target[pos] - pred_sigmoid[pos]
      loss[pos] = loss_function(
          pred[pos], target[pos], reduction="none"
      ) * scale_factor.abs().pow(beta)
  
      loss = loss.sum(dim=1, keepdim=False)
      return loss
  
file_path: mmdetection/mmdet/models/losses/gfocal_loss.py
imports: from functools import partial
  import torch
  import torch.nn
  import torch.nn.functional
  from mmdet.models.losses.utils import weighted_loss
  from mmdet.registry import MODELS
label_desc: Use image node_id 2 for calling a global function with example usage: quality_focal_loss_tensor_target(pred, target, beta, activated) and returns: loss