callcut.training.DiceLoss🔗

class callcut.training.DiceLoss(smooth=1.0)[source]🔗

Dice loss for optimizing overlap directly.

Minimizes 1 - Dice coefficient, where Dice measures the overlap between predictions and targets. Effective for segmentation tasks with imbalanced classes.

The Dice coefficient is:

\[\begin{split}Dice = \\frac{2 |P \\cap T|}{|P| + |T|}\end{split}\]
Parameters:
smoothfloat

Smoothing factor for numerical stability. Prevents division by zero when both prediction and target are empty.

Attributes

smooth

Smoothing factor.

Methods

forward(logits, targets)

Compute Dice loss.

Examples

>>> loss_fn = DiceLoss(smooth=1.0)
>>> loss = loss_fn(logits, targets)
forward(logits, targets)[source]🔗

Compute Dice loss.

Parameters:
logitsTensor

Raw model output (before sigmoid).

targetsTensor

Ground truth binary labels.

Returns:
lossTensor

Scalar loss value.

property smooth🔗

Smoothing factor.

Type:

float