toolbelt¶
‘Classical’ losses imported from https://github.com/BloodAxe/pytorch-toolbelt and adapted to our projects.
- class mfai.pytorch.losses.toolbelt.DiceLoss(mode, classes=None, log_loss=False, from_logits=True, smooth=0.0, ignore_index=None, eps=1e-07)[source]¶
Bases:
_Loss- Parameters:
- compute_score(output, target, smooth=0.0, eps=1e-07, dims=None)[source]¶
Code from /segmentation_models_pytorch/losses/_functional.py.
- forward(y_pred, y_true)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
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 mfai.pytorch.losses.toolbelt.SoftBCEWithLogitsLoss(weight=None, ignore_index=-100, reduction='mean', smooth_factor=None, pos_weight=None)[source]¶
Bases:
Module- Parameters:
- class mfai.pytorch.losses.toolbelt.SoftCrossEntropyLoss(reduction='mean', smooth_factor=0.0, ignore_index=-100, dim=1)[source]¶
Bases:
Module- forward(y_pred, y_true)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
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.
- label_smoothed_nll_loss(lprobs, target, epsilon, ignore_index=None, reduction='mean', dim=-1)[source]¶
NLL loss with label smoothing.
References
https://github.com/pytorch/fairseq/blob/master/fairseq/criterions/label_smoothed_cross_entropy.py
- Parameters:
lprobs (
Tensor) – Log-probabilities of predictions (e.g after log_softmax).target (
Tensor) – Ground truth labels.epsilon (
float) – Smoothing factor.reduction (
str) –Reduction method. “none”: No reduction will be applied, “mean”: The sum of the output will be divided by the number of
elements in the output,
”sum”: The output will be summed.
dim (
int) – Dimension along which to compute the loss.
- Returns:
Loss values.
- Return type:
Tensor