binary_instance_stat_scores
darts_segmentation.metrics.binary_instance_stat_scores
¶
Binary instance segmentation metrics.
BinaryInstanceAccuracy
¶
BinaryInstanceAccuracy(
threshold: float = 0.5,
matching_threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores
Binary instance accuracy metric.
Create a new instance of the BinaryInstanceStatScores metric.
Parameters:
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
matching_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Raises:
-
ValueError
–If
matching_threshold
is not a float in the [0,1] range.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
validate_args
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstanceConfusionMatrix
¶
BinaryInstanceConfusionMatrix(
normalize: bool | None = None,
threshold: float = 0.5,
matching_threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores
Binary instance confusion matrix metric.
Create a new instance of the BinaryInstanceConfusionMatrix metric.
Parameters:
-
normalize
(bool
, default:None
) –If True, return the confusion matrix normalized by the number of instances. If False, return the confusion matrix without normalization. Defaults to None.
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
matching_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Raises:
-
ValueError
–If
normalize
is not a bool.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
normalize
instance-attribute
¶
normalize = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceConfusionMatrix(
normalize
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
validate_args
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
plot(
val: torch.Tensor | None = None,
ax: torchmetrics.utilities.plot._AX_TYPE | None = None,
add_text: bool = True,
labels: list[str] | None = None,
cmap: torchmetrics.utilities.plot._CMAP_TYPE
| None = None,
) -> torchmetrics.utilities.plot._PLOT_OUT_TYPE
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstanceF1Score
¶
BinaryInstanceF1Score(
threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
zero_division: float = 0,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceFBetaScore
Binary instance F1 score metric.
Create a new instance of the BinaryInstanceF1Score metric.
Parameters:
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
zero_division
(float
, default:0
) –Value to return when there is a zero division. Defaults to 0.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
beta
instance-attribute
¶
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceFBetaScore(
validate_args
)
zero_division
instance-attribute
¶
zero_division = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceFBetaScore(
zero_division
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstanceFBetaScore
¶
BinaryInstanceFBetaScore(
beta: float,
threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
zero_division: float = 0,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores
Binary instance F-beta score metric.
Create a new instance of the BinaryInstanceFBetaScore metric.
Parameters:
-
beta
(float
) –The beta parameter for the F-beta score.
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
zero_division
(float
, default:0
) –Value to return when there is a zero division. Defaults to 0.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
beta
instance-attribute
¶
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceFBetaScore(
validate_args
)
zero_division
instance-attribute
¶
zero_division = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceFBetaScore(
zero_division
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstancePrecision
¶
BinaryInstancePrecision(
threshold: float = 0.5,
matching_threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores
Binary instance precision metric.
Create a new instance of the BinaryInstanceStatScores metric.
Parameters:
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
matching_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Raises:
-
ValueError
–If
matching_threshold
is not a float in the [0,1] range.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
validate_args
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstanceRecall
¶
BinaryInstanceRecall(
threshold: float = 0.5,
matching_threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
**kwargs: typing.Any,
)
Bases: darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores
Binary instance recall metric.
Create a new instance of the BinaryInstanceStatScores metric.
Parameters:
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
matching_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Raises:
-
ValueError
–If
matching_threshold
is not a float in the [0,1] range.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
validate_args
)
compute
¶
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
plot
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
BinaryInstanceStatScores
¶
BinaryInstanceStatScores(
threshold: float = 0.5,
matching_threshold: float = 0.5,
multidim_average: typing.Literal[
"global", "samplewise"
] = "global",
ignore_index: int | None = None,
validate_args: bool = True,
**kwargs: typing.Any,
)
Bases: torchmetrics.classification.stat_scores._AbstractStatScores
Base class for binary instance segmentation metrics.
Create a new instance of the BinaryInstanceStatScores metric.
Parameters:
-
threshold
(float
, default:0.5
) –Threshold for binarizing the prediction. Has no effect if the prediction is already binarized. Defaults to 0.5.
-
matching_threshold
(float
, default:0.5
) –The threshold for matching instances. Defaults to 0.5.
-
multidim_average
(typing.Literal['global', 'samplewise']
, default:'global'
) –How the average over multiple batches is calculated. Defaults to "global".
-
ignore_index
(int | None
, default:None
) –Ignores an invalid class. Defaults to None.
-
validate_args
(bool
, default:True
) –Weather to validate inputs. Defaults to True.
-
kwargs
(typing.Any
, default:{}
) –Additional arguments for the Metric class, regarding compute-methods. Please refer to torchmetrics for more examples.
Raises:
-
ValueError
–If
matching_threshold
is not a float in the [0,1] range.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
ignore_index
instance-attribute
¶
ignore_index = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
ignore_index
)
matching_threshold
instance-attribute
¶
matching_threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
matching_threshold
)
multidim_average
instance-attribute
¶
multidim_average = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
multidim_average
)
threshold
instance-attribute
¶
threshold = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
threshold
)
validate_args
instance-attribute
¶
validate_args = darts_segmentation.metrics.binary_instance_stat_scores.BinaryInstanceStatScores(
validate_args
)
compute
¶
update
¶
Update the metric state.
If the predictions are logits (not between 0 and 1), they are converted to probabilities using a sigmoid and then binarized using the threshold. If the predictions are probabilities, they are binarized using the threshold.
Parameters:
-
preds
(torch.Tensor
) –Predictions from model (logits or probabilities).
-
target
(torch.Tensor
) –Ground truth labels.
Raises:
-
ValueError
–If
preds
andtarget
have different shapes. -
ValueError
–If the input targets are not binary masks.
Source code in darts-segmentation/src/darts_segmentation/metrics/binary_instance_stat_scores.py
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: