Metrics¶
Segmentation metrics¶
compute_meandice¶
-
compute_meandice.compute_meandice(y, include_background=True, to_onehot_y=True, mutually_exclusive=False, add_sigmoid=False, logit_thresh=0.5)¶ Computes dice score metric from full size Tensor and collects average.
- Parameters
y_pred (torch.Tensor) – input data to compute, typical segmentation model output. it must be One-Hot format and first dim is batch, example shape: [16, 3, 32, 32].
y (torch.Tensor) – ground truth to compute mean dice metric, the first dim is batch. example shape: [16, 1, 32, 32] will be converted into [16, 3, 32, 32]. alternative shape: [16, 3, 32, 32] and set to_onehot_y=False to use 3-class labels directly.
include_background (Bool) – whether to skip Dice computation on the first channel of the predicted output. Defaults to True.
to_onehot_y (Bool) – whether to convert y into the one-hot format. Defaults to True.
mutually_exclusive (Bool) – if True, y_pred will be converted into a binary matrix using a combination of argmax and to_onehot. Defaults to False.
add_sigmoid (Bool) – whether to add sigmoid function to y_pred before computation. Defaults to False.
logit_thresh (Float) – the threshold value used to convert (after sigmoid if add_sigmoid=True) y_pred into a binary matrix. Defaults to 0.5.
- Returns
[batch_size, n_classes]).
- Return type
Dice scores per batch and per class (shape
Note
- This method provides two options to convert y_pred into a binary matrix
when mutually_exclusive is True, it uses a combination of
argmaxandto_onehot,when mutually_exclusive is False, it uses a threshold
logit_thresh(optionally with asigmoidfunction before thresholding).