F1 Scores#
- class anomalib.metrics.F1Score(fields=None, prefix='', strict=True, **kwargs)#
Bases:
AnomalibMetric,BinaryF1ScoreWrapper to add AnomalibMetric functionality to F1Score metric.
This class wraps the torchmetrics
BinaryF1Scoreto make it compatible with Anomalib’s batch processing capabilities.Example
>>> from anomalib.metrics import F1Score >>> from anomalib.data import ImageBatch >>> import torch >>> # Create metric >>> f1 = F1Score(fields=["pred_score", "gt_label"]) >>> # Create sample batch >>> batch = ImageBatch( ... image=torch.rand(4, 3, 32, 32), ... pred_score=torch.tensor([0, 0, 1, 1]), ... gt_label=torch.tensor([0, 1, 1, 1]) ... ) >>> # Update and compute >>> f1.update(batch) >>> f1.compute() tensor(0.8000)
- class anomalib.metrics.F1Max(fields=None, prefix='', strict=True, **kwargs)#
Bases:
AnomalibMetric,_F1MaxWrapper to add AnomalibMetric functionality to F1Max metric.
This class wraps the internal
_F1Maxmetric to make it compatible with Anomalib’s batch processing capabilities.Example
>>> from anomalib.metrics import F1Max >>> from anomalib.data import ImageBatch >>> import torch >>> # Create metric with batch fields >>> f1_max = F1Max(fields=["pred_score", "gt_label"]) >>> # Create sample batch >>> batch = ImageBatch( ... image=torch.rand(4, 3, 32, 32), ... pred_score=torch.tensor([0.1, 0.4, 0.35, 0.8]), ... gt_label=torch.tensor([0, 0, 1, 1]) ... ) >>> # Update and compute >>> f1_max.update(batch) >>> f1_max.compute() tensor(0.8000)