Thresholds#

class anomalib.metrics.F1AdaptiveThreshold(fields=None, prefix='', strict=True, **kwargs)#

Bases: AnomalibMetric, _F1AdaptiveThreshold

Wrapper to add AnomalibMetric functionality to F1AdaptiveThreshold metric.

class anomalib.metrics.ManualThreshold(default_value=0.5, **kwargs)#

Bases: Threshold

Initialize Manual Threshold.

Parameters:
  • default_value (float) – Default threshold value. Defaults to 0.5.

  • kwargs – Any keyword arguments.

Examples

>>> from anomalib.metrics import ManualThreshold
>>> import torch
...
>>> manual_threshold = ManualThreshold(default_value=0.5)
...
>>> labels = torch.randint(low=0, high=2, size=(5,))
>>> preds = torch.rand(5)
...
>>> threshold = manual_threshold(preds, labels)
>>> threshold
tensor(0.5000, dtype=torch.float64)

As the threshold is manually set, the threshold value is the same as the default_value.

>>> labels = torch.randint(low=0, high=2, size=(5,))
>>> preds = torch.rand(5)
>>> threshold = manual_threshold(preds2, labels2)
>>> threshold
tensor(0.5000, dtype=torch.float64)

The threshold value remains the same even if the inputs change.

compute()#

Compute the threshold.

In case of manual thresholding, the threshold is already set and does not need to be computed.

Returns:

Value of the optimal threshold.

Return type:

Tensor

static update(*args, **kwargs)#

Do nothing.

Parameters:
  • *args – Any positional arguments.

  • **kwargs – Any keyword arguments.

Return type:

None