mlreco.models.layers.cluster_cnn.losses.lovasz module¶
Lovasz-Softmax and Jaccard hinge loss in PyTorch Maxim Berman 2018 ESAT-PSI KU Leuven (MIT License)
Original Paper: https://arxiv.org/pdf/1705.08790.pdf Github: https://github.com/bermanmaxim/LovaszSoftmax
-
mlreco.models.layers.cluster_cnn.losses.lovasz.lovasz_grad(gt_sorted)[source]¶ Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper
-
mlreco.models.layers.cluster_cnn.losses.lovasz.iou_binary(preds, labels, EMPTY=1.0, per_image=True)[source]¶ IoU for foreground class binary: 1 foreground, 0 background
-
mlreco.models.layers.cluster_cnn.losses.lovasz.iou(preds, labels, C, EMPTY=1.0, ignore=None, per_image=False)[source]¶ Array of IoU for each (non ignored) class
-
mlreco.models.layers.cluster_cnn.losses.lovasz.lovasz_hinge(logits, labels, per_image=True, ignore=None)[source]¶ - Binary Lovasz hinge loss
logits: [B, H, W] Variable, logits at each pixel (between -infty and +infty) 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
-
mlreco.models.layers.cluster_cnn.losses.lovasz.lovasz_hinge_flat(logits, labels)[source]¶ - 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
-
mlreco.models.layers.cluster_cnn.losses.lovasz.flatten_binary_scores(scores, labels, ignore=None)[source]¶ Flattens predictions in the batch (binary case) Remove labels equal to ‘ignore’
-
class
mlreco.models.layers.cluster_cnn.losses.lovasz.StableBCELoss[source]¶ Bases:
torch.nn.modules.module.Module-
forward(input, target, reduction='mean')[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.lovasz'¶
-
training: bool¶
-
-
mlreco.models.layers.cluster_cnn.losses.lovasz.binary_xloss(logits, labels, ignore=None)[source]¶ - Binary Cross entropy loss
logits: [B, H, W] Variable, logits at each pixel (between -infty and +infty) labels: [B, H, W] Tensor, binary ground truth masks (0 or 1) ignore: void class id
-
mlreco.models.layers.cluster_cnn.losses.lovasz.lovasz_softmax(probas, labels, classes='present', per_image=False, ignore=None)[source]¶ - Multi-class Lovasz-Softmax loss
- probas: [B, C, H, W] Variable, class probabilities at each prediction (between 0 and 1).
Interpreted as binary (sigmoid) output with outputs of size [B, H, W].
labels: [B, H, W] 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. per_image: compute the loss per image instead of per batch ignore: void class labels
-
mlreco.models.layers.cluster_cnn.losses.lovasz.lovasz_softmax_flat(probas, labels, classes='present')[source]¶ - 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.
-
mlreco.models.layers.cluster_cnn.losses.lovasz.flatten_probas(probas, labels, ignore=None)[source]¶ Flattens predictions in the batch