Loss Function#
This module contains the implementation of loss functions for semantic segmentation.
Dice Loss#
- class fusionlab.losses.DiceLoss(mode='multiclass', log_loss=False, from_logits=True)[source]#
- __init__(mode='multiclass', log_loss=False, from_logits=True)[source]#
Implementation of Dice loss for image segmentation task. It supports “binary”, “multiclass” ref: BloodAxe/pytorch-toolbelt :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(dice); otherwise 1 - dice :param from_logits: If True assumes input is raw logits
- class fusionlab.losses.TFDiceLoss(mode='multiclass', log_loss=False, from_logits=False)[source]#
- __init__(mode='multiclass', log_loss=False, from_logits=False)[source]#
Implementation of Dice loss for image segmentation task. It supports “binary”, “multiclass” BloodAxe/pytorch-toolbelt :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(dice); otherwise 1 - dice :param from_logits: If True assumes input is raw logits
Dice Cross Entropy Loss#
- class fusionlab.losses.DiceCELoss(w_dice=0.5, w_ce=0.5, cls_weight=None)[source]#
- __init__(w_dice=0.5, w_ce=0.5, cls_weight=None)[source]#
Dice Loss + Cross Entropy Loss :param w_dice: weight of Dice Loss :param w_ce: weight of CrossEntropy loss :param cls_weight:
- forward(y_pred, y_true)[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.
- class fusionlab.losses.TFDiceCE(mode='binary', from_logits=False, w_dice=0.5, w_ce=0.5)[source]#
- __init__(mode='binary', from_logits=False, w_dice=0.5, w_ce=0.5)[source]#
Dice Loss + Cross Entropy Loss :param w_dice: weight of Dice Loss :param w_ce: weight of CrossEntropy loss :param mode: Metric mode {‘binary’, ‘multiclass’}
- call(y_true, y_pred)[source]#
Invokes the Loss instance.
- Parameters:
y_true – Ground truth values. shape = [batch_size, d0, .. dN], except sparse loss functions such as sparse categorical crossentropy where shape = [batch_size, d0, .. dN-1]
y_pred – The predicted values. shape = [batch_size, d0, .. dN]
- Returns:
Loss values with the shape [batch_size, d0, .. dN-1].
IoU Loss#
- class fusionlab.losses.IoULoss(mode='multiclass', log_loss=False, from_logits=True)[source]#
- __init__(mode='multiclass', log_loss=False, from_logits=True)[source]#
Implementation of Iou loss for image segmentation task. It supports “binary”, “multiclass” :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(jaccard); otherwise 1 - jaccard :param from_logits: If True assumes input is raw logits
- class fusionlab.losses.TFIoULoss(mode='binary', log_loss=False, from_logits=False)[source]#
- __init__(mode='binary', log_loss=False, from_logits=False)[source]#
Implementation of IoU loss for image segmentation task. It supports “binary”, “multiclass” :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(dice); otherwise 1 - dice :param from_logits: If True assumes input is raw logits
Tversky Loss#
- class fusionlab.losses.TverskyLoss(alpha, beta, mode='multiclass', log_loss=False, from_logits=True)[source]#
- __init__(alpha, beta, mode='multiclass', log_loss=False, from_logits=True)[source]#
Implementation of Tversky loss for image segmentation task. It supports “binary”, “multiclass” ref: kornia/kornia ref: kevinzakka/pytorch-goodies :param alpha: controls the penalty for false positives(FP). :param beta: controls the penalty for false negatives(FN). :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(dice); otherwise 1 - dice :param from_logits: If True assumes input is raw logits
- class fusionlab.losses.TFTverskyLoss(alpha, beta, mode='binary', log_loss=False, from_logits=False)[source]#
- __init__(alpha, beta, mode='binary', log_loss=False, from_logits=False)[source]#
Implementation of Dice loss for image segmentation task. It supports “binary”, “multiclass” ref: kornia/kornia ref: kevinzakka/pytorch-goodies :param alpha: controls the penalty for false positives(FP). :param beta: controls the penalty for false negatives(FN). :param mode: Metric mode {‘binary’, ‘multiclass’} :param log_loss: If True, loss computed as -log(dice); otherwise 1 - dice :param from_logits: If True assumes input is raw logits