code: def lovasz_softmax_flat(
      probas, labels, classes="present", weighted=None
  ):
      """
      Multi-class Lovasz-Softmax loss
        probas: [P, C] Variable, class probabilities at each prediction (between 0 and 1)
        labels: [P] Tensor, ground truth labels (between 0 and C - 1)
        classes: 'all' for all, 'present' for classes present in labels, or a list of classes to average.
      """
      if probas.numel() == 0:
          # only void pixels, the gradients should be 0
          return probas * 0.0
      C = probas.size(1)
      losses = []
      class_to_sum = (
          list(range(C)) if classes in ["all", "present"] else classes
      )
      for c in class_to_sum:
          fg = (labels == c).float()  # foreground for class c
          if classes is "present" and fg.sum() == 0:
              continue
          if C == 1:
              if len(classes) > 1:
                  raise ValueError(
                      "Sigmoid output possible only with 1 class"
                  )
              class_pred = probas[:, 0]
          else:
              class_pred = probas[:, c]
          errors = (Variable(fg) - class_pred).abs()
          errors_sorted, perm = torch.sort(errors, 0, descending=True)
          perm = perm.data
          fg_sorted = fg[perm]
          if weighted is not None:
              losses.append(
                  weighted[c]
                  * torch.dot(
                      errors_sorted, Variable(lovasz_grad(fg_sorted))
                  )
              )
          else:
              losses.append(
                  torch.dot(
                      errors_sorted, Variable(lovasz_grad(fg_sorted))
                  )
              )
      return mean(losses)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.autograd import Variable
label_desc: Use image node_id 9 for calling a global function with example usage: lovasz_softmax_flat(probas, labels, classes, weighted) and returns: mean, unknown