Skip to content

Commit f720362

Browse files
cleanup docstrings
1 parent 206a9b0 commit f720362

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/anomalib/models/image/anomaly_dino/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2022-2025 Intel Corporation
1+
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

44
"""AnomalyDINO: Boosting Patch-based Few-shot Anomaly Detection with DINOv2.
@@ -15,33 +15,32 @@
1515
>>> from anomalib.data import MVTecAD
1616
>>> from anomalib.models.image.anomaly_dino.lightning_model import AnomalyDINO
1717
>>> from anomalib.engine import Engine
18-
>>>
18+
1919
>>> MVTEC_CATEGORIES = [
2020
... "hazelnut", "grid", "carpet", "bottle", "cable", "capsule", "leather",
2121
... "metal_nut", "pill", "screw", "tile", "toothbrush", "transistor", "wood", "zipper"
2222
... ]
2323
>>> MASKED_CATEGORIES = ["capsule", "hazelnut", "pill", "screw", "toothbrush"]
24-
>>>
24+
2525
>>> for category in MVTEC_CATEGORIES:
2626
... mask = category in MASKED_CATEGORIES
2727
... print(f"--- Running category: {category} | masking={mask} ---")
28-
...
28+
2929
... # Initialize data module
3030
... datamodule = MVTecAD(category=category)
31-
...
31+
3232
... # Initialize model
3333
... model = AnomalyDINO(
3434
... num_neighbours=1,
3535
... encoder_name="dinov2_vit_small_14",
3636
... masking=mask,
3737
... coreset_subsampling=False,
3838
... )
39-
...
39+
4040
... # Train and test
4141
... engine = Engine()
4242
... engine.fit(model=model, datamodule=datamodule)
4343
... engine.test(datamodule=datamodule)
44-
>>>
4544
>>> print("All categories processed.")
4645
"""
4746

src/anomalib/models/image/anomaly_dino/lightning_model.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2022-2025 Intel Corporation
1+
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

44
"""AnomalyDINO: Boosting Patch-based Few-shot Anomaly Detection with DINOv2.
@@ -15,33 +15,32 @@
1515
>>> from anomalib.data import MVTecAD
1616
>>> from anomalib.models.image.anomaly_dino.lightning_model import AnomalyDINO
1717
>>> from anomalib.engine import Engine
18-
>>>
18+
1919
>>> MVTEC_CATEGORIES = [
2020
... "hazelnut", "grid", "carpet", "bottle", "cable", "capsule", "leather",
2121
... "metal_nut", "pill", "screw", "tile", "toothbrush", "transistor", "wood", "zipper"
2222
... ]
2323
>>> MASKED_CATEGORIES = ["capsule", "hazelnut", "pill", "screw", "toothbrush"]
24-
>>>
24+
2525
>>> for category in MVTEC_CATEGORIES:
2626
... mask = category in MASKED_CATEGORIES
2727
... print(f"--- Running category: {category} | masking={mask} ---")
28-
...
28+
2929
... # Initialize data module
3030
... datamodule = MVTecAD(category=category)
31-
...
31+
3232
... # Initialize model
3333
... model = AnomalyDINO(
3434
... num_neighbours=1,
3535
... encoder_name="dinov2_vit_small_14",
3636
... masking=mask,
3737
... coreset_subsampling=False,
3838
... )
39-
...
39+
4040
... # Train and test
4141
... engine = Engine()
4242
... engine.fit(model=model, datamodule=datamodule)
4343
... engine.test(datamodule=datamodule)
44-
>>>
4544
>>> print("All categories processed.")
4645
"""
4746

@@ -107,33 +106,33 @@ class AnomalyDINO(MemoryBankMixin, AnomalibModule):
107106
>>> from anomalib.data import MVTecAD
108107
>>> from anomalib.models.image.anomaly_dino.lightning_model import AnomalyDINO
109108
>>> from anomalib.engine import Engine
110-
>>>
109+
111110
>>> MVTEC_CATEGORIES = [
112111
... "hazelnut", "grid", "carpet", "bottle", "cable", "capsule", "leather",
113112
... "metal_nut", "pill", "screw", "tile", "toothbrush", "transistor", "wood", "zipper"
114113
... ]
115114
>>> MASKED_CATEGORIES = ["capsule", "hazelnut", "pill", "screw", "toothbrush"]
116-
>>>
115+
117116
>>> for category in MVTEC_CATEGORIES:
118117
... mask = category in MASKED_CATEGORIES
119118
... print(f"--- Running category: {category} | masking={mask} ---")
120-
...
119+
121120
... # Initialize data module
122121
... datamodule = MVTecAD(category=category)
123-
...
122+
124123
... # Initialize model
125124
... model = AnomalyDINO(
126125
... num_neighbours=1,
127126
... encoder_name="dinov2_vit_small_14",
128127
... masking=mask,
129128
... coreset_subsampling=False,
130129
... )
131-
...
130+
132131
... # Train and test
133132
... engine = Engine()
134133
... engine.fit(model=model, datamodule=datamodule)
135134
... engine.test(datamodule=datamodule)
136-
>>>
135+
137136
>>> print("All categories processed.")
138137
139138
Notes:

src/anomalib/models/image/anomaly_dino/torch_model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2022-2025 Intel Corporation
1+
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

44
"""PyTorch model implementation for AnomalyDINO.
@@ -75,7 +75,9 @@ def __init__(
7575
self.sampling_ratio = sampling_ratio
7676

7777
# Load DINOv2 backbone
78-
assert encoder_name.startswith("dinov2"), f"Encoder must be dinov2, got {encoder_name}"
78+
if not encoder_name.startswith("dinov2"):
79+
err_str = f"Encoder must be dinov2, got {encoder_name}"
80+
raise ValueError(err_str)
7981
self.feature_encoder = load_dinov2_model(self.encoder_name)
8082
self.feature_encoder.eval()
8183

0 commit comments

Comments
 (0)