class_docstr: Seesaw Loss for Long-Tailed Instance Segmentation (CVPR 2021)
  arXiv: https://arxiv.org/abs/2008.10032
  
  Args:
      use_sigmoid (bool, optional): Whether the prediction uses sigmoid
           of softmax. Only False is supported.
      p (float, optional): The ``p`` in the mitigation factor.
           Defaults to 0.8.
      q (float, optional): The ``q`` in the compenstation factor.
           Defaults to 2.0.
      num_classes (int, optional): The number of classes.
           Default to 1203 for LVIS v1 dataset.
      eps (float, optional): The minimal value of divisor to smooth
           the computation of compensation factor
      reduction (str, optional): The method that reduces the loss to a
           scalar. Options are "none", "mean" and "sum".
      loss_weight (float, optional): The weight of the loss. Defaults to 1.0
      return_dict (bool, optional): Whether return the losses as a dict.
           Default to True.
class_docstr_tok: ["Seesaw","Loss","for","Long-Tailed","Instance","Segmentation","(","CVPR","2021",")","arXiv",":","https",":","\/\/arxiv.org\/abs\/2008.10032","Args",":","use_sigmoid","(","bool",",","optional",")",":","Whether","the","prediction","uses","sigmoid","of","softmax",".","Only","False","is","supported",".","p","(","float",",","optional",")",":","The","``","p","``","in","the","mitigation","factor",".","Defaults","to","0.8.","q","(","float",",","optional",")",":","The","``","q","``","in","the","compenstation","factor",".","Defaults","to","2.0.","num_classes","(","int",",","optional",")",":","The","number","of","classes",".","Default","to","1203","for","LVIS","v1","dataset",".","eps","(","float",",","optional",")",":","The","minimal","value","of","divisor","to","smooth","the","computation","of","compensation","factor","reduction","(","str",",","optional",")",":","The","method","that","reduces","the","loss","to","a","scalar",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","loss_weight","(","float",",","optional",")",":","The","weight","of","the","loss",".","Defaults","to","1.0","return_dict","(","bool",",","optional",")",":","Whether","return","the","losses","as","a","dict",".","Default","to","True","."]
docstr: Forward function.
  
  Args:
      cls_score (Tensor): The prediction with shape (N, C + 2).
      labels (Tensor): The learning label of the prediction.
      label_weights (Tensor, optional): Sample-wise loss weight.
      avg_factor (int, optional): Average factor that is used to average
           the loss. Defaults to None.
      reduction (str, optional): The method used to reduce the loss.
           Options are "none", "mean" and "sum".
  
  Returns:
      Tensor | Dict [str, Tensor]:
           if return_dict == False: The calculated loss |
           if return_dict == True: The dict of calculated losses
           for objectness and classes, respectively.
docstr_tok: ["Forward","function",".","Args",":","cls_score","(","Tensor",")",":","The","prediction","with","shape","(","N",",","C","+","2",")",".","labels","(","Tensor",")",":","The","learning","label","of","the","prediction",".","label_weights","(","Tensor",",","optional",")",":","Sample-wise","loss","weight",".","avg_factor","(","int",",","optional",")",":","Average","factor","that","is","used","to","average","the","loss",".","Defaults","to","None",".","reduction","(","str",",","optional",")",":","The","method","used","to","reduce","the","loss",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","Returns",":","Tensor","|","Dict","[","str",",","Tensor","]",":","if","return_dict","==","False",":","The","calculated","loss","|","if","return_dict","==","True",":","The","dict","of","calculated","losses","for","objectness","and","classes",",","respectively","."]
code: def forward(
      self,
      cls_score: Tensor,
      labels: Tensor,
      label_weights: Optional[Tensor] = None,
      avg_factor: Optional[int] = None,
      reduction_override: Optional[str] = None,
  ) -> Union[Tensor, Dict[str, Tensor]]:
      """Forward function.
  
      Args:
          cls_score (Tensor): The prediction with shape (N, C + 2).
          labels (Tensor): The learning label of the prediction.
          label_weights (Tensor, optional): Sample-wise loss weight.
          avg_factor (int, optional): Average factor that is used to average
               the loss. Defaults to None.
          reduction (str, optional): The method used to reduce the loss.
               Options are "none", "mean" and "sum".
  
      Returns:
          Tensor | Dict [str, Tensor]:
               if return_dict == False: The calculated loss |
               if return_dict == True: The dict of calculated losses
               for objectness and classes, respectively.
      """
      assert reduction_override in (None, "none", "mean", "sum")
      reduction = (
          reduction_override if reduction_override else self.reduction
      )
      assert cls_score.size(-1) == self.num_classes + 2
      pos_inds = labels < self.num_classes
      # 0 for pos, 1 for neg
      obj_labels = (labels == self.num_classes).long()
  
      # accumulate the samples for each category
      unique_labels = labels.unique()
      for u_l in unique_labels:
          inds_ = labels == u_l.item()
          self.cum_samples[u_l] += inds_.sum()
  
      if label_weights is not None:
          label_weights = label_weights.float()
      else:
          label_weights = labels.new_ones(
              labels.size(), dtype=torch.float
          )
  
      cls_score_classes, cls_score_objectness = self._split_cls_score(
          cls_score
      )
      # calculate loss_cls_classes (only need pos samples)
      if pos_inds.sum() > 0:
          loss_cls_classes = self.loss_weight * self.cls_criterion(
              cls_score_classes[pos_inds],
              labels[pos_inds],
              label_weights[pos_inds],
              self.cum_samples[: self.num_classes],
              self.num_classes,
              self.p,
              self.q,
              self.eps,
              reduction,
              avg_factor,
          )
      else:
          loss_cls_classes = cls_score_classes[pos_inds].sum()
      # calculate loss_cls_objectness
      loss_cls_objectness = self.loss_weight * cross_entropy(
          cls_score_objectness,
          obj_labels,
          label_weights,
          reduction,
          avg_factor,
      )
  
      if self.return_dict:
          loss_cls = dict()
          loss_cls["loss_cls_objectness"] = loss_cls_objectness
          loss_cls["loss_cls_classes"] = loss_cls_classes
      else:
          loss_cls = loss_cls_classes + loss_cls_objectness
      return loss_cls
  
file_path: mmdetection/mmdet/models/losses/seesaw_loss.py
imports: from typing import Dict, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from mmdet.registry import MODELS
  from .accuracy import accuracy
  from .cross_entropy_loss import cross_entropy
  from .utils import weight_reduce_loss
label_desc: Use image node_id 6 for calling the SeesawLoss obj's underlying member method code with example usage: obj.forward(cls_score, labels, label_weights, avg_factor, reduction_override) and returns: loss_cls