anomalib.utils.metrics.pro

Implementation of PRO metric based on TorchMetrics.

Module Contents

Classes

PRO

Per-Region Overlap (PRO) Score.

Functions

pro_score(→ torch.Tensor)

Calculate the PRO score for a batch of predictions.

connected_components_gpu(→ torch.Tensor)

Perform connected component labeling on GPU and remap the labels from 0 to N.

connected_components_cpu(→ torch.Tensor)

Connected component labeling on CPU.

class anomalib.utils.metrics.pro.PRO(threshold: float = 0.5, **kwargs)[source]

Bases: torchmetrics.Metric

Per-Region Overlap (PRO) Score.

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

Compute the PRO score for the current batch.

compute() torch.Tensor[source]

Compute the macro average of the PRO score across all regions in all batches.

anomalib.utils.metrics.pro.pro_score(predictions: torch.Tensor, comps: torch.Tensor, threshold: float = 0.5) torch.Tensor[source]

Calculate the PRO score for a batch of predictions.

Parameters
  • predictions (Tensor) – Predicted anomaly masks (Bx1xHxW)

  • comps – (Tensor): Labeled connected components (BxHxW). The components should be labeled from 0 to N

  • threshold (float) – When predictions are passed as float, the threshold is used to binarize the predictions.

Returns

Scalar value representing the average PRO score for the input batch.

Return type

Tensor

anomalib.utils.metrics.pro.connected_components_gpu(binary_input: torch.Tensor, num_iterations: int = 1000) torch.Tensor[source]

Perform connected component labeling on GPU and remap the labels from 0 to N.

Parameters
  • binary_input (Tensor) – Binary input data from which we want to extract connected components (Bx1xHxW)

  • num_iterations (int) – Number of iterations used in the connected component computation.

Returns

Components labeled from 0 to N.

Return type

Tensor

anomalib.utils.metrics.pro.connected_components_cpu(image: torch.Tensor) torch.Tensor[source]

Connected component labeling on CPU.

Parameters

image (Tensor) – Binary input data from which we want to extract connected components (Bx1xHxW)

Returns

Components labeled from 0 to N.

Return type

Tensor