Metrics

Mean Dice

meandice.compute_meandice(y, include_background=True, to_onehot_y=False, 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 False.

  • 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
  1. when mutually_exclusive is True, it uses a combination of argmax and to_onehot,

  2. when mutually_exclusive is False, it uses a threshold logit_thresh (optionally with a sigmoid function before thresholding).

Area under the ROC curve

rocauc.compute_roc_auc(y, to_onehot_y=False, add_softmax=False, average='macro')

Computes Area Under the Receiver Operating Characteristic Curve (ROC AUC). Referring to: sklearn.metrics.roc_auc_score . :param y_pred: input data to compute, typical classification model output.

it must be One-Hot format and first dim is batch, example shape: [16] or [16, 2].

Parameters
  • y (torch.Tensor) – ground truth to compute ROC AUC metric, the first dim is batch. example shape: [16, 1] will be converted into [16, 3].

  • to_onehot_y (bool) – whether to convert y into the one-hot format. Defaults to False.

  • add_softmax (bool) – whether to add softmax function to y_pred before computation. Defaults to False.

  • average (macro|weighted|micro|None) –

    type of averaging performed if not binary classification. default is ‘macro’.

    • ’macro’: calculate metrics for each label, and find their unweighted mean. this does not take label imbalance into account.

    • ’weighted’: calculate metrics for each label, and find their average, weighted by support (the number of true instances for each label).

    • ’micro’: calculate metrics globally by considering each element of the label indicator matrix as a label.

    • None: the scores for each class are returned.

Note

ROCAUC expects y to be comprised of 0’s and 1’s. y_pred must be either prob. estimates or confidence values.