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","."]
code: def __init__(
      self,
      loss_type="multi_class",
      classes="present",
      per_image=False,
      reduction="mean",
      class_weight=None,
      loss_weight=1.0,
  ):
      super(LovaszLoss, self).__init__()
      assert loss_type in (
          "binary",
          "multi_class",
      ), "loss_type should be \
                                                      'binary' or 'multi_class'."
  
      if loss_type == "binary":
          self.cls_criterion = lovasz_hinge
      else:
          self.cls_criterion = lovasz_softmax
      assert classes in ("all", "present") or mmcv.is_list_of(
          classes, int
      )
      if not per_image:
          assert (
              reduction == "none"
          ), "reduction should be 'none' when \
                                                          per_image is False."
  
      self.classes = classes
      self.per_image = per_image
      self.reduction = reduction
      self.loss_weight = loss_weight
      self.class_weight = get_class_weight(class_weight)
  
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 1 to create a new LovaszLoss object from inherited base classes: nn with example: obj = LovaszLoss(loss_type, classes, per_image, reduction, class_weight, loss_weight)