mipcandy.metrics#

Module Contents#

Functions#

_args_check

do_reduction

binary_dice

param outputs:

boolean class ids (B, 1, …)

param labels:

boolean class ids (B, 1, …)

param if_empty:

the value to return if both outputs and labels are empty

param reduction:

the reduction method to apply to the dice score

dice_similarity_coefficient

param outputs:

one-hot (B, N, …)

param labels:

one-hot (B, N, …)

param if_empty:

the value to return if both outputs and labels are empty

param reduction:

the reduction method to apply to the dice score

soft_dice

param outputs:

logits (B, C, …)

param labels:

logits (B, C, …)

param smooth:

the smoothness term to avoid division by zero

param batch_dice:

whether to compute dice score for each batch separately

param reduction:

the reduction method to apply to the dice score

API#

mipcandy.metrics._args_check(outputs: torch.Tensor, labels: torch.Tensor, *, dtype: torch.dtype | None = None, device: mipcandy.types.Device | None = None) tuple[torch.dtype, mipcandy.types.Device][source]#
mipcandy.metrics.do_reduction(x: torch.Tensor, method: mipcandy.types.Reduction) torch.Tensor[source]#
mipcandy.metrics.binary_dice(outputs: torch.Tensor, labels: torch.Tensor, *, if_empty: float = 1, reduction: mipcandy.types.Reduction = 'mean') torch.Tensor[source]#
Parameters:
  • outputs – boolean class ids (B, 1, …)

  • labels – boolean class ids (B, 1, …)

  • if_empty – the value to return if both outputs and labels are empty

  • reduction – the reduction method to apply to the dice score

mipcandy.metrics.dice_similarity_coefficient(outputs: torch.Tensor, labels: torch.Tensor, *, if_empty: float = 1, reduction: mipcandy.types.Reduction = 'mean') torch.Tensor[source]#
Parameters:
  • outputs – one-hot (B, N, …)

  • labels – one-hot (B, N, …)

  • if_empty – the value to return if both outputs and labels are empty

  • reduction – the reduction method to apply to the dice score

mipcandy.metrics.soft_dice(outputs: torch.Tensor, labels: torch.Tensor, *, smooth: float = 1, batch_dice: bool = True, reduction: mipcandy.types.Reduction = 'mean') torch.Tensor[source]#
Parameters:
  • outputs – logits (B, C, …)

  • labels – logits (B, C, …)

  • smooth – the smoothness term to avoid division by zero

  • batch_dice – whether to compute dice score for each batch separately

  • reduction – the reduction method to apply to the dice score