Files
anomalib/tests/unit/metrics/test_adaptive_threshold.py
zeekay dda5b2a367 restore the tree
The previous commit was meant to remove .github/workflows and removed
every tracked path instead — 892 files, the whole repo. This puts back
the 874 that were never in scope; the eighteen workflow files stay gone,
for the reasons that commit gives.

Content is byte-identical to 9d2aec9 outside .github/workflows.
2026-08-13 23:27:57 -07:00

26 lines
919 B
Python

"""Tests for the adaptive threshold metric."""
# Copyright (C) 2022-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
import torch
from anomalib.metrics.threshold.f1_adaptive_threshold import _F1AdaptiveThreshold
@pytest.mark.parametrize(
("labels", "preds", "target_threshold"),
[
(torch.Tensor([0, 0, 0, 1, 1]), torch.Tensor([2.3, 1.6, 2.6, 7.9, 3.3]), 3.3), # standard case
(torch.Tensor([1, 0, 0, 0]), torch.Tensor([4, 3, 2, 1]), 4), # 100% recall for all thresholds
],
)
def test_adaptive_threshold(labels: torch.Tensor, preds: torch.Tensor, target_threshold: int | float) -> None:
"""Test if the adaptive threshold computation returns the desired value."""
adaptive_threshold = _F1AdaptiveThreshold()
adaptive_threshold.update(preds, labels)
threshold_value = adaptive_threshold.compute()
assert threshold_value == target_threshold