mirror of
https://github.com/hanzoai/anomalib.git
synced 2026-10-30 18:48:11 +00:00
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.
26 lines
919 B
Python
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
|