docstr: `Equalization Loss v2 <https://arxiv.org/abs/2012.08548>`_
  
  Args:
      cls_score (Tensor): The prediction with shape (N, C), C is the
          number of classes.
      label (Tensor): The ground truth label of the predicted target with
          shape (N, C), C is the number of classes.
      weight (Tensor, optional): The weight of loss for each prediction.
          Defaults to None.
      avg_factor (int, optional): Average factor that is used to average
          the loss. Defaults to None.
      reduction_override (str, optional): The reduction method used to
          override the original reduction method of the loss.
          Options are "none", "mean" and "sum".
  
  Returns:
     Tensor: The calculated loss
docstr_tok: ["`","Equalization","Loss","v2","<","https",":","\/\/arxiv.org\/abs\/2012.08548",">","`","_","Args",":","cls_score","(","Tensor",")",":","The","prediction","with","shape","(","N",",","C",")",",","C","is","the","number","of","classes",".","label","(","Tensor",")",":","The","ground","truth","label","of","the","predicted","target","with","shape","(","N",",","C",")",",","C","is","the","number","of","classes",".","weight","(","Tensor",",","optional",")",":","The","weight","of","loss","for","each","prediction",".","Defaults","to","None",".","avg_factor","(","int",",","optional",")",":","Average","factor","that","is","used","to","average","the","loss",".","Defaults","to","None",".","reduction_override","(","str",",","optional",")",":","The","reduction","method","used","to","override","the","original","reduction","method","of","the","loss",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","Returns",":","Tensor",":","The","calculated","loss"]
code: def forward(
      self,
      cls_score: Tensor,
      label: Tensor,
      weight: Optional[Tensor] = None,
      avg_factor: Optional[int] = None,
      reduction_override: Optional[Tensor] = None,
  ) -> Tensor:
      """`Equalization Loss v2 <https://arxiv.org/abs/2012.08548>`_
  
      Args:
          cls_score (Tensor): The prediction with shape (N, C), C is the
              number of classes.
          label (Tensor): The ground truth label of the predicted target with
              shape (N, C), C is the number of classes.
          weight (Tensor, optional): The weight of loss for each prediction.
              Defaults to None.
          avg_factor (int, optional): Average factor that is used to average
              the loss. Defaults to None.
          reduction_override (str, optional): The reduction method used to
              override the original reduction method of the loss.
              Options are "none", "mean" and "sum".
  
      Returns:
         Tensor: The calculated loss
      """
      self.n_i, self.n_c = cls_score.size()
      self.gt_classes = label
      self.pred_class_logits = cls_score
  
      def expand_label(pred, gt_classes):
          target = pred.new_zeros(self.n_i, self.n_c)
          target[torch.arange(self.n_i), gt_classes] = 1
          return target
  
      target = expand_label(cls_score, label)
  
      pos_w, neg_w = self.get_weight(cls_score)
  
      weight = pos_w * target + neg_w * (1 - target)
  
      cls_loss = F.binary_cross_entropy_with_logits(
          cls_score, target, reduction="none"
      )
      cls_loss = torch.sum(cls_loss * weight) / self.n_i
  
      self.collect_grad(
          cls_score.detach(), target.detach(), weight.detach()
      )
  
      return self.loss_weight * cls_loss
  
file_path: mmdetection/mmdet/models/losses/eqlv2_loss.py
imports: import logging
  from functools import partial
  from typing import Optional
  import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
  from mmengine.logging import print_log
  from torch import Tensor
  from mmdet.registry import MODELS
label_desc: Use image node_id 2 for calling the EQLV2Loss obj's underlying member method code with example usage: obj.forward(cls_score, label, weight, avg_factor, reduction_override) and returns: unknown, target