(logits, labels)
return loss
Binary Lovasz hinge loss
      logits: [P] Variable, logits at each prediction (between -\infty and +\infty)
      labels: [P] Tensor, binary ground truth labels (0 or 1)
      ignore: label to ignore
Binary Lovasz hinge loss
      logits: [P] Variable, logits at each prediction (between -\infty and +\infty)
      labels: [P] Tensor, binary ground truth labels (0 or 1)
      ignore: label to ignore
Binary Lovasz hinge loss logits : [ P ] Variable logits at each prediction ( between - \ infty and + \ infty ) labels : [ P ] Tensor binary ground truth labels ( 0 or 1 ) ignore : label to ignore
def lovasz_hinge_flat(logits, labels):
    """
    Binary Lovasz hinge loss
      logits: [P] Variable, logits at each prediction (between -\infty and +\infty)
      labels: [P] Tensor, binary ground truth labels (0 or 1)
      ignore: label to ignore
    """
    if len(labels) == 0:
        # only void pixels, the gradients should be 0
        return logits.sum() * 0.
    signs = 2. * labels.float() - 1.
    errors = (1. - logits * signs)

    errors_sorted, perm = torch.sort(errors, dim=0, descending=True)
    perm = perm.data
    gt_sorted = labels[perm]
    grad = lovasz_grad(gt_sorted)
    loss = torch.dot(F.elu(errors_sorted), grad)
    return loss
def lovasz_hinge_flat ( logits , labels ) : if len ( labels ) == 0 : # only void pixels, the gradients should be 0 return logits . sum ( ) * 0. signs = 2. * labels . float ( ) - 1. errors = ( 1. - logits * signs ) errors_sorted , perm = torch . sort ( errors , dim = 0 , descending = True ) perm = perm . data gt_sorted = labels [ perm ] grad = lovasz_grad ( gt_sorted ) loss = torch . dot ( F . elu ( errors_sorted ) , grad ) return loss