mednet.models.segment.losses

Specialized losses for semanatic segmentation.

Classes

MultiSoftJaccardBCELogitsLoss([alpha])

Implement Equation 3 in [IGLOVIKOV-2018] for the multi-output networks such as HED or Little W-Net.

MultiWeightedBCELogitsLoss()

Weighted Binary Cross-Entropy Loss for multi-layered inputs (e.g. for Holistically-Nested Edge Detection in [XIE-2015]).

SoftJaccardBCELogitsLoss([alpha])

Implement the generalized loss function of Equation (3) in.

WeightedBCELogitsLoss()

Calculates sum of weighted cross entropy loss.

class mednet.models.segment.losses.WeightedBCELogitsLoss[source]

Bases: Module

Calculates sum of weighted cross entropy loss.

Implements Equation 1 in [MANINIS-2016]. The weight depends on the current proportion between negatives and positives in the ground- truth sample being analyzed.

forward(input_, target)[source]

Forward pass.

Parameters:
  • input – Value produced by the model to be evaluated, with the shape [n, c, h, w].

  • target (Tensor) – Ground-truth information with the shape [n, c, h, w].

Return type:

Tensor

Returns:

The average loss for all input data.

class mednet.models.segment.losses.SoftJaccardBCELogitsLoss(alpha=0.7)[source]

Bases: Module

Implement the generalized loss function of Equation (3) in.

[IGLOVIKOV-2018], with J being the Jaccard distance, and H, the Binary Cross-Entropy Loss:

\[L = \alpha H + (1-\alpha)(1-J)\]

Our implementation is based on torch.nn.BCEWithLogitsLoss.

Parameters:

alpha (float) – Determines the weighting of J and H. Default: 0.7.

forward(input_, target)[source]

Forward pass.

Parameters:
  • input – Value produced by the model to be evaluated, with the shape [n, c, h, w].

  • target (Tensor) – Ground-truth information with the shape [n, c, h, w].

Return type:

Tensor

Returns:

Loss, in a single entry.

class mednet.models.segment.losses.MultiWeightedBCELogitsLoss[source]

Bases: WeightedBCELogitsLoss

Weighted Binary Cross-Entropy Loss for multi-layered inputs (e.g. for Holistically-Nested Edge Detection in [XIE-2015]).

forward(input_, target)[source]

Forward pass.

Parameters:
  • input – Value produced by the model to be evaluated, with the shape [L, n, c, h, w].

  • target (Tensor) – Ground-truth information with the shape [n, c, h, w].

Return type:

Tensor

Returns:

The average loss for all input data.

class mednet.models.segment.losses.MultiSoftJaccardBCELogitsLoss(alpha=0.7)[source]

Bases: SoftJaccardBCELogitsLoss

Implement Equation 3 in [IGLOVIKOV-2018] for the multi-output networks such as HED or Little W-Net.

Parameters:

alpha (float) – Determines the weighting of SoftJaccard and BCE. Default: 0.3.

forward(input_, target)[source]

Forward pass.

Parameters:
  • input – Value produced by the model to be evaluated, with the shape [L, n, c, h, w].

  • target (Tensor) – Ground-truth information with the shape [n, c, h, w].

Return type:

Tensor

Returns:

The average loss for all input data.