code: def lovasz_softmax(
      probs,
      labels,
      classes="present",
      per_image=False,
      class_weight=None,
      reduction="mean",
      avg_factor=None,
      ignore_index=255,
  ):
      """Multi-class Lovasz-Softmax loss.
  
      Args:
          probs (torch.Tensor): [B, C, H, W], class probabilities at each
              prediction (between 0 and 1).
          labels (torch.Tensor): [B, H, W], ground truth labels (between 0 and
              C - 1).
          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.
          class_weight (list[float], optional): The weight for each class.
              Default: None.
          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'.
          avg_factor (int, optional): Average factor that is used to average
              the loss. This parameter only works when per_image is True.
              Default: None.
          ignore_index (int | None): The label index to be ignored. Default: 255.
  
      Returns:
          torch.Tensor: The calculated loss.
      """
  
      if per_image:
          loss = [
              lovasz_softmax_flat(
                  *flatten_probs(
                      prob.unsqueeze(0),
                      label.unsqueeze(0),
                      ignore_index,
                  ),
                  classes=classes,
                  class_weight=class_weight,
              )
              for prob, label in zip(probs, labels)
          ]
          loss = weight_reduce_loss(
              torch.stack(loss), None, reduction, avg_factor
          )
      else:
          loss = lovasz_softmax_flat(
              *flatten_probs(probs, labels, ignore_index),
              classes=classes,
              class_weight=class_weight,
          )
      return loss
  
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 7 for calling a global function with example usage: lovasz_softmax(probs, labels, classes, per_image, class_weight, reduction, avg_factor, ignore_index) and returns: loss