Skip to content

Commit 771d71d

Browse files
Merge PR #156: Refactor anomaly algorithms and add Hailo/KV260 backends
Merge the validated modular algorithm structure, canonical imports, common inference backends, Hailo-8/KV260 deployment support, and test coverage.
2 parents 91dbd47 + c36877b commit 771d71d

41 files changed

Lines changed: 1501 additions & 27 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

anomavision/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
Provides functions for performing anomaly detection in images.
99
"""
1010

11+
from .algorithm.common.feature_extraction import ResnetEmbeddingsExtractor
12+
from .algorithm.padim import Padim
13+
from .algorithm.patchcore import PatchCore
1114
from .datasets.dataset import AnodetDataset
1215
from .datasets.mvtec_dataset import MVTecDataset
13-
from .feature_extraction import ResnetEmbeddingsExtractor
14-
from .padim import Padim
15-
from .patchcore import PatchCore
1616
from .sampling_methods.kcenter_greedy import kCenterGreedy
1717
from .test import optimal_threshold, visualize_eval_data, visualize_eval_pair
1818
from .utils import get_logger # Export for users

anomavision/algorithm/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Anomaly detection algorithm implementations."""
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Shared algorithm components used by anomaly detection implementations."""
2+
3+
from .feature_extraction import ResnetEmbeddingsExtractor, concatenate_layers
4+
from .mahalanobis import MahalanobisDistance
5+
6+
__all__ = [
7+
"MahalanobisDistance",
8+
"ResnetEmbeddingsExtractor",
9+
"concatenate_layers",
10+
]
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""PaDiM anomaly detection algorithms."""
2+
3+
from .padim import Padim
4+
from .padim_lite import PadimLite, load_padim_lite
5+
6+
__all__ = ["Padim", "PadimLite", "load_padim_lite"]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import torch
1111
import torch.nn.functional as F
1212

13-
from .feature_extraction import ResnetEmbeddingsExtractor
14-
from .mahalanobis import MahalanobisDistance
15-
from .utils import pytorch_cov, split_tensor_and_run_function
13+
from ...utils import pytorch_cov, split_tensor_and_run_function
14+
from ..common.feature_extraction import ResnetEmbeddingsExtractor
15+
from ..common.mahalanobis import MahalanobisDistance
1616

1717
BACKBONE_FEATURE_SIZES = {
1818
"resnet18": OrderedDict([(0, [64]), (1, [128]), (2, [256]), (3, [512])]),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import torch
55
import torch.nn.functional as F
66

7-
from .feature_extraction import ResnetEmbeddingsExtractor
8-
from .mahalanobis import MahalanobisDistance
7+
from ..common.feature_extraction import ResnetEmbeddingsExtractor
8+
from ..common.mahalanobis import MahalanobisDistance
99

1010

1111
class PadimLite(torch.nn.Module):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Lightweight PatchCore anomaly detection algorithms."""
2+
3+
from ..common.feature_extraction import ResnetEmbeddingsExtractor
4+
from .patchcore import PatchCore, build_patchcore_from_stats
5+
6+
__all__ = [
7+
"PatchCore",
8+
"ResnetEmbeddingsExtractor",
9+
"build_patchcore_from_stats",
10+
]

anomavision/patchcore.py renamed to anomavision/algorithm/patchcore/patchcore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Lightweight PatchCore anomaly detection.
22
33
This module provides a bounded-memory PatchCore implementation that follows the
4-
public design of :mod:`anomavision.padim`: fit on a normal-image DataLoader, predict
4+
public design of :mod:`anomavision.algorithm.padim`: fit on a normal-image DataLoader, predict
55
image scores and spatial maps, and save a compact deployment artifact.
66
"""
77

@@ -12,7 +12,7 @@
1212
import torch
1313
import torch.nn.functional as F
1414

15-
from .feature_extraction import ResnetEmbeddingsExtractor
15+
from ..common.feature_extraction import ResnetEmbeddingsExtractor
1616

1717

1818
class PatchCore(torch.nn.Module):
@@ -24,7 +24,7 @@ class PatchCore(torch.nn.Module):
2424
patch distance; the pixel map is the patch-distance grid upsampled to the input
2525
resolution.
2626
27-
The public methods intentionally mirror :class:`anomavision.padim.Padim`, so the
27+
The public methods intentionally mirror :class:`anomavision.algorithm.padim.Padim`, so the
2828
model can be selected by the existing CLI training, inference, evaluation, and
2929
export workflows.
3030

0 commit comments

Comments
 (0)