class_docstr: LovaszLoss.
  
  This loss is proposed in `The Lovasz-Softmax loss: A tractable surrogate
  for the optimization of the intersection-over-union measure in neural
  networks <https://arxiv.org/abs/1705.08790>`_.
  
  Args:
      loss_type (str, optional): Binary or multi-class loss.
          Default: 'multi_class'. Options are "binary" and "multi_class".
      classes (str | list[int], optional): Classes chosen to calculate loss.
          'all' for all classes, 'present' for classes present in labels, or
          a list of classes to average. Default: 'present'.
      per_image (bool, optional): If per_image is True, compute the loss per
          image instead of per batch. Default: False.
      reduction (str, optional): The method used to reduce the loss. Options
          are "none", "mean" and "sum". This parameter only works when
          per_image is True. Default: 'mean'.
      class_weight (list[float] | str, optional): Weight of each class. If in
          str format, read them from a file. Defaults to None.
      loss_weight (float, optional): Weight of the loss. Defaults to 1.0.
class_docstr_tok: ["LovaszLoss",".","This","loss","is","proposed","in","`","The","Lovasz-Softmax","loss",":","A","tractable","surrogate","for","the","optimization","of","the","intersection-over-union","measure","in","neural","networks","<","https",":","\/\/arxiv.org\/abs\/1705.08790",">","`","_",".","Args",":","loss_type","(","str",",","optional",")",":","Binary","or","multi-class","loss",".","Default",":","'multi_class","'",".","Options","are","``","binary","''","and","``","multi_class","''",".","classes","(","str","|","list","[","int","]",",","optional",")",":","Classes","chosen","to","calculate","loss",".","'all","'","for","all","classes",",","'present","'","for","classes","present","in","labels",",","or","a","list","of","classes","to","average",".","Default",":","'present","'",".","per_image","(","bool",",","optional",")",":","If","per_image","is","True",",","compute","the","loss","per","image","instead","of","per","batch",".","Default",":","False",".","reduction","(","str",",","optional",")",":","The","method","used","to","reduce","the","loss",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","This","parameter","only","works","when","per_image","is","True",".","Default",":","'mean","'",".","class_weight","(","list","[","float","]","|","str",",","optional",")",":","Weight","of","each","class",".","If","in","str","format",",","read","them","from","a","file",".","Defaults","to","None",".","loss_weight","(","float",",","optional",")",":","Weight","of","the","loss",".","Defaults","to","1.0","."]
docstr: Forward function.
docstr_tok: ["Forward","function","."]
code: def forward(
      self,
      cls_score,
      label,
      weight=None,
      avg_factor=None,
      reduction_override=None,
      **kwargs,
  ):
      """Forward function."""
      assert reduction_override in (None, "none", "mean", "sum")
      reduction = (
          reduction_override if reduction_override else self.reduction
      )
      if self.class_weight is not None:
          class_weight = cls_score.new_tensor(self.class_weight)
      else:
          class_weight = None
  
      # if multi-class loss, transform logits to probs
      if self.cls_criterion == lovasz_softmax:
          cls_score = F.softmax(cls_score, dim=1)
  
      loss_cls = self.loss_weight * self.cls_criterion(
          cls_score,
          label,
          self.classes,
          self.per_image,
          class_weight=class_weight,
          reduction=reduction,
          avg_factor=avg_factor,
          **kwargs,
      )
      return loss_cls
  
file_path: lavis/lavis/common/annotator/uniformer/mmseg/models/losses/lovasz_loss.py
imports: import annotator.uniformer.mmcv
  import torch
  import torch.nn
  import torch.nn.functional
  from ..builder import LOSSES
  from .utils import get_class_weight, weight_reduce_loss
label_desc: Use image node_id 2 for calling the LovaszLoss obj's underlying member method code with example usage: obj.forward(cls_score, label, weight, avg_factor, reduction_override) and returns: loss_cls