code: def _lovasz_hinge(logits, labels, per_image=True, ignore_index=None):
      """
      Binary Lovasz hinge loss
          logits: [B, H, W] Variable, logits at each pixel (between -infinity and +infinity)
          labels: [B, H, W] Tensor, binary ground truth masks (0 or 1)
          per_image: compute the loss per image instead of per batch
          ignore: void class id
      """
      if per_image:
          loss = mean(
              _lovasz_hinge_flat(
                  *_flatten_binary_scores(
                      log.unsqueeze(0), lab.unsqueeze(0), ignore_index
                  )
              )
              for log, lab in zip(logits, labels)
          )
      else:
          loss = _lovasz_hinge_flat(
              *_flatten_binary_scores(logits, labels, ignore_index)
          )
      return loss
  
imports: from __future__ import print_function, division
  from typing import Optional, Union
  import torch
  import torch.nn.functional
  from torch.autograd import Variable
  from torch.nn.modules.loss import _Loss
label_desc: Use image node_id 2 for calling a global function with example usage: _lovasz_hinge(logits, labels, per_image, ignore_index) and returns: loss