minerva.losses.dice

Attributes

BINARY_MODE

MULTICLASS_MODE

MULTILABEL_MODE

Classes

DiceLoss

Initialize the DiceLoss class.

Module Contents

minerva.losses.dice.BINARY_MODE = 'binary'
class minerva.losses.dice.DiceLoss(mode, classes=None, log_loss=False, from_logits=True, smooth=0.0, ignore_index=None, eps=1e-07)

Bases: torch.nn.modules.loss._Loss

Initialize the DiceLoss class.

Parameters

modestr

Loss mode. Valid options are ‘binary’, ‘multiclass’, or ‘multilabel’.

classesOptional[List[int]], optional

List of classes that contribute in loss computation. By default, all channels are included. By default None

log_lossbool, optional

If True, loss is computed as - log(dice_coeff). If False, loss is computed as 1 - dice_coeff, by default False

from_logitsbool, optional

If True, assumes input is raw logits. If False, assumes input is probabilities., by default True

smoothfloat, optional

Smoothness constant for dice coefficient (a), by default 0.0

ignore_indexOptional[int], optional

Label that indicates ignored pixels (does not contribute to loss), by default None

epsfloat, optional

A small epsilon for numerical stability to avoid zero division error (denominator will be always greater or equal to eps), by default 1e-7

Raises

AssertionError

If the mode is not one of ‘binary’, ‘multiclass’, or ‘multilabel’ and classes are being masked with mode=’binary’.

aggregate_loss(loss)
compute_score(output, target, smooth=0.0, eps=1e-07, dims=None)
Return type:

torch.Tensor

forward(y_pred, y_true)
Parameters:
  • y_pred (torch.Tensor)

  • y_true (torch.Tensor)

Return type:

torch.Tensor

Parameters:
  • mode (str)

  • classes (Optional[List[int]])

  • log_loss (bool)

  • from_logits (bool)

  • smooth (float)

  • ignore_index (Optional[int])

  • eps (float)

minerva.losses.dice.MULTICLASS_MODE = 'multiclass'
minerva.losses.dice.MULTILABEL_MODE = 'multilabel'