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:
- smooth
float Smoothing factor for numerical stability. Prevents division by zero when both prediction and target are empty.
- smooth
Attributes
Smoothing factor.
Methods
forward(logits, targets)Compute Dice loss.
Examples
>>> loss_fn = DiceLoss(smooth=1.0) >>> loss = loss_fn(logits, targets)