instance_helpers
darts_segmentation.metrics.instance_helpers
¶
Helper functions for instance segmentation metrics.
mask_to_instances
¶
Convert a binary segmentation mask into multiple instance masks. Expects a batched version of the input.
Currently only supports uint8 tensors, hence a maximum number of 255 instances per mask.
Parameters:
-
x
(torch.Tensor
) –The binary segmentation mask. Shape: (batch_size, height, width), dtype: torch.uint8
-
validate_args
(bool
, default:False
) –Whether to validate the input arguments. Defaults to False.
Returns:
-
list[torch.Tensor]
–list[torch.Tensor]: The instance masks. Length of list: batch_size. Shape of a tensor: (height, width), dtype: torch.uint8
Source code in darts-segmentation/src/darts_segmentation/metrics/instance_helpers.py
match_instances
¶
match_instances(
instances_target: torch.Tensor,
instances_preds: torch.Tensor,
match_threshold: float = 0.5,
validate_args: bool = False,
) -> tuple[int, int, int]
Match instances between target and prediction masks. Expects non-batched input from skimage.measure.label.
Parameters:
-
instances_target
(torch.Tensor
) –The instance mask of the target. Shape: (height, width), dtype: torch.uint8
-
instances_preds
(torch.Tensor
) –The instance mask of the prediction. Shape: (height, width), dtype: torch.uint8
-
match_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
validate_args
(bool
, default:False
) –Whether to validate the input arguments. Defaults to False.
Returns: