anomalib.utils.metrics.optimal_f1

Implementation of Optimal F1 score based on TorchMetrics.

Module Contents

Classes

OptimalF1

Optimal F1 Metric.

class anomalib.utils.metrics.optimal_f1.OptimalF1(num_classes: int, **kwargs)[source]

Bases: torchmetrics.Metric

Optimal F1 Metric.

Compute the optimal F1 score at the adaptive threshold, based on the F1 metric of the true labels and the predicted anomaly scores.

update(preds: torch.Tensor, target: torch.Tensor) None[source]

Update the precision-recall curve metric.

compute() torch.Tensor[source]

Compute the value of the optimal F1 score.

Compute the F1 scores while varying the threshold. Store the optimal threshold as attribute and return the maximum value of the F1 score.

Returns

Value of the F1 score at the optimal threshold.