anomalib.utils.metrics.aupro

Implementation of AUPRO score based on TorchMetrics.

Module Contents

Classes

AUPRO

Area under per region overlap (AUPRO) Metric.

class anomalib.utils.metrics.aupro.AUPRO(compute_on_step: bool = True, dist_sync_on_step: bool = False, process_group: Optional[Any] = None, dist_sync_fn: Callable = None, fpr_limit: float = 0.3)[source]

Bases: torchmetrics.Metric

Area under per region overlap (AUPRO) Metric.

is_differentiable :bool = False[source]
higher_is_better :Optional[bool][source]
full_state_update :bool = False[source]
preds :List[torch.Tensor][source]
target :List[torch.Tensor][source]
update(preds: torch.Tensor, target: torch.Tensor) None[source]

Update state with new values.

Parameters
  • preds (Tensor) – predictions of the model

  • target (Tensor) – ground truth targets

_compute() Tuple[torch.Tensor, torch.Tensor][source]

Compute the pro/fpr value-pairs until the fpr specified by self.fpr_limit.

It leverages the fact that the overlap corresponds to the tpr, and thus computes the overall PRO curve by aggregating per-region tpr/fpr values produced by ROC-construction.

Raises

ValueError – ValueError is raised if self.target doesn’t conform with requirements imposed by kornia for connected component analysis.

Returns

tuple containing final fpr and tpr values.

Return type

Tuple[Tensor, Tensor]

compute() torch.Tensor[source]

Fist compute PRO curve, then compute and scale area under the curve.

Returns

Value of the AUPRO metric

Return type

Tensor

generate_figure() Tuple[matplotlib.figure.Figure, str][source]

Generate a figure containing the PRO curve and the AUPRO.

Returns

Tuple containing both the figure and the figure title to be used for logging

Return type

Tuple[Figure, str]

static interp1d(old_x: torch.Tensor, old_y: torch.Tensor, new_x: torch.Tensor) torch.Tensor[source]

Function to interpolate a 1D signal linearly to new sampling points.

Parameters
  • old_x (Tensor) – original 1-D x values (same size as y)

  • old_y (Tensor) – original 1-D y values (same size as x)

  • new_x (Tensor) – x-values where y should be interpolated at

Returns

y-values at corresponding new_x values.

Return type

Tensor