contraction_net.losses

Classes

BCEDiceLoss

A combination of Binary Cross Entropy (BCE) and Dice Loss for binary segmentation tasks.

SmoothnessLoss

Computes the smoothness loss for a sequence of predictions.

Functions

f1_score(logits, true_labels[, threshold, epsilon])

Computes the F1 score for binary classification.

Module Contents

class contraction_net.losses.BCEDiceLoss(loss_params=(1, 1))[source]

Bases: torch.nn.Module

A combination of Binary Cross Entropy (BCE) and Dice Loss for binary segmentation tasks.

Parameters:

loss_params (tuple, optional) – A tuple containing the weights for BCE and Dice losses respectively. Default is (1, 1).

dice_loss(inputs, targets, epsilon=1e-6)[source]

Computes the Dice loss.

forward(inputs, targets)[source]

Computes the combined BCE and Dice loss.

bce_loss
loss_params = (1, 1)
dice_loss(inputs, targets, epsilon=1e-06)[source]
forward(inputs, targets)[source]
class contraction_net.losses.SmoothnessLoss(alpha=10)[source]

Bases: torch.nn.Module

Computes the smoothness loss for a sequence of predictions.

Parameters:

alpha (float, optional) – Weight of the smoothness loss component. Default is 10.

forward(predictions)[source]

Computes the smoothness loss for a sequence of predictions.

alpha = 10
forward(predictions)[source]
contraction_net.losses.f1_score(logits, true_labels, threshold=0.5, epsilon=1e-07)[source]

Computes the F1 score for binary classification.

Parameters:
  • logits (torch.Tensor) – The raw output from the model (before applying sigmoid).

  • true_labels (torch.Tensor) – The ground truth binary labels.

  • threshold (float, optional) – The threshold to convert probabilities to binary predictions. Default is 0.5.

  • epsilon (float, optional) – A small value to avoid division by zero. Default is 1e-7.

Returns:

The computed F1 score.

Return type:

float