sinapsis-anomalib 0.1.6__tar.gz → 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sinapsis-anomalib might be problematic. Click here for more details.
- {sinapsis_anomalib-0.1.6/src/sinapsis_anomalib.egg-info → sinapsis_anomalib-0.1.8}/PKG-INFO +1 -1
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/pyproject.toml +1 -1
- sinapsis_anomalib-0.1.8/src/sinapsis_anomalib/helpers/configs.py +81 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_base.py +7 -4
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_export.py +8 -3
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_train.py +9 -15
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8/src/sinapsis_anomalib.egg-info}/PKG-INFO +1 -1
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/SOURCES.txt +1 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/LICENSE +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/README.md +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/setup.cfg +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/__init__.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/helpers/__init__.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/helpers/config_factory.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/helpers/tags.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/__init__.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_base_inference.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_openvino_inference.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_torch_inference.py +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/dependency_links.txt +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/requires.txt +0 -0
- {sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from anomalib.data.utils import TestSplitMode, ValSplitMode
|
|
6
|
+
from pydantic import BaseModel, ConfigDict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FolderConfig(BaseModel):
|
|
10
|
+
"""Configuration for the Anomalib Folder datamodule.
|
|
11
|
+
|
|
12
|
+
This model defines parameters for loading image data from a directory structure.
|
|
13
|
+
It is flexible and allows any other valid `Folder` arguments
|
|
14
|
+
(like `train_augmentations`) to be passed through.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
name (str): A descriptive name for the dataset.
|
|
18
|
+
root (str | Path | None): The root directory where the dataset is located.
|
|
19
|
+
normal_dir (str | Path | Sequence[str | Path]): Path to the directory containing normal images.
|
|
20
|
+
abnormal_dir (str | Path | Sequence[str | Path] | None): Path to the directory for abnormal images.
|
|
21
|
+
train_batch_size (int): The number of samples per batch for training. Defaults to 32.
|
|
22
|
+
eval_batch_size (int): The number of samples per batch for evaluation. Defaults to 32.
|
|
23
|
+
num_workers (int): The number of subprocesses to use for data loading. Defaults to 8.
|
|
24
|
+
seed (int | None): A random seed for reproducibility in data splitting.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
name: str
|
|
28
|
+
root: str | Path | None = None
|
|
29
|
+
normal_dir: str | Path | Sequence[str | Path]
|
|
30
|
+
abnormal_dir: str | Path | Sequence[str | Path] | None = None
|
|
31
|
+
normal_test_dir: str | Path | Sequence[str | Path] | None = None
|
|
32
|
+
mask_dir: str | Path | Sequence[str | Path] | None = None
|
|
33
|
+
normal_split_ratio: float = 0.2
|
|
34
|
+
extensions: tuple[str] | None = None
|
|
35
|
+
train_batch_size: int = 32
|
|
36
|
+
eval_batch_size: int = 32
|
|
37
|
+
num_workers: int = 8
|
|
38
|
+
test_split_mode: TestSplitMode | str = TestSplitMode.FROM_DIR
|
|
39
|
+
test_split_ratio: float = 0.2
|
|
40
|
+
val_split_mode: ValSplitMode | str = ValSplitMode.FROM_TEST
|
|
41
|
+
val_split_ratio: float = 0.5
|
|
42
|
+
seed: int | None = None
|
|
43
|
+
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TrainerConfig(BaseModel):
|
|
47
|
+
"""Defines and validates parameters for the Trainer.
|
|
48
|
+
|
|
49
|
+
This model is flexible and allows any other valid Trainer arguments to be passed.
|
|
50
|
+
|
|
51
|
+
Attributes:
|
|
52
|
+
devices (int | list[int] | str | None): The devices to use for training (e.g., 1, [0, 1], "auto").
|
|
53
|
+
Defaults to "auto".
|
|
54
|
+
accelerator (Literal["gpu", "cpu", "auto"]): The hardware accelerator to use.
|
|
55
|
+
Defaults to "auto".
|
|
56
|
+
min_epochs (int): The minimum number of epochs to train for. Defaults to 1.
|
|
57
|
+
max_epochs (int): The maximum number of epochs to train for. Defaults to 1000.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
devices: int | list[int] | str | None = "auto"
|
|
61
|
+
accelerator: Literal["cpu", "gpu", "tpu", "hpu", "auto"] = "cpu"
|
|
62
|
+
min_epochs: int = 1
|
|
63
|
+
max_epochs: int | None = None
|
|
64
|
+
model_config = ConfigDict(extra="allow")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class OpenVINOArgs(BaseModel):
|
|
68
|
+
"""Defines and validates parameters for OpenVINO model export.
|
|
69
|
+
|
|
70
|
+
This model is flexible and allows any other valid arguments for `openvino.save_model`.
|
|
71
|
+
For a full list of options, see the OpenVINO documentation.
|
|
72
|
+
|
|
73
|
+
Attributes:
|
|
74
|
+
compress_to_fp16 (bool | None): If True, compresses the model weights to FP16 precision.
|
|
75
|
+
Defaults to None.
|
|
76
|
+
compress_to_fp16 (bool | None): Print detailed information about conversion.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
compress_to_fp16: bool | None = None
|
|
80
|
+
verbose: bool = False
|
|
81
|
+
model_config = ConfigDict(extra="allow")
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/anomalib_base.py
RENAMED
|
@@ -23,6 +23,7 @@ from sinapsis_core.template_base.base_models import (
|
|
|
23
23
|
from sinapsis_core.template_base.dynamic_template import BaseDynamicWrapperTemplate, WrapperEntryConfig
|
|
24
24
|
|
|
25
25
|
from sinapsis_anomalib.helpers.config_factory import CallbackFactory, LoggerFactory
|
|
26
|
+
from sinapsis_anomalib.helpers.configs import FolderConfig
|
|
26
27
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
27
28
|
|
|
28
29
|
EXCLUDED_MODELS = [
|
|
@@ -117,7 +118,7 @@ class AnomalibBaseAttributes(TemplateAttributes):
|
|
|
117
118
|
"""Base attributes for Anomalib model templates.
|
|
118
119
|
|
|
119
120
|
Attributes:
|
|
120
|
-
folder_attributes (
|
|
121
|
+
folder_attributes (FolderConfig): Configuration for Folder datamodule. Required for training, optional
|
|
121
122
|
for export.
|
|
122
123
|
callbacks (list[Callback] | None): Lightning callbacks
|
|
123
124
|
normalization (NORMALIZATION | None): Input normalization
|
|
@@ -130,7 +131,7 @@ class AnomalibBaseAttributes(TemplateAttributes):
|
|
|
130
131
|
logger_configs (dict[str, dict[str, Any]] | None): Logger configs
|
|
131
132
|
"""
|
|
132
133
|
|
|
133
|
-
folder_attributes:
|
|
134
|
+
folder_attributes: FolderConfig | None = None
|
|
134
135
|
callbacks: list[Callback] | None = None
|
|
135
136
|
normalization: NORMALIZATION | None = None
|
|
136
137
|
threshold: THRESHOLD | None = None
|
|
@@ -209,7 +210,9 @@ class AnomalibBase(BaseDynamicWrapperTemplate):
|
|
|
209
210
|
Returns:
|
|
210
211
|
Folder: Configured data module instance
|
|
211
212
|
"""
|
|
212
|
-
|
|
213
|
+
if self.attributes.folder_attributes is None:
|
|
214
|
+
raise ValueError("'folder_attributes' must be provided to set up the data loader.")
|
|
215
|
+
return Folder(**self.attributes.folder_attributes.model_dump(exclude_none=True))
|
|
213
216
|
|
|
214
217
|
@abstractmethod
|
|
215
218
|
def execute(self, container: DataContainer) -> DataContainer:
|
|
@@ -225,4 +228,4 @@ class AnomalibBase(BaseDynamicWrapperTemplate):
|
|
|
225
228
|
def reset_state(self, template_name: str | None = None) -> None:
|
|
226
229
|
if torch.cuda.is_available():
|
|
227
230
|
torch.cuda.empty_cache()
|
|
228
|
-
super().reset_state(template_name)
|
|
231
|
+
super().reset_state(template_name)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
from pathlib import Path
|
|
3
|
-
from typing import Any
|
|
4
3
|
|
|
5
4
|
from anomalib.deploy import CompressionType, ExportType
|
|
6
5
|
from pydantic.dataclasses import dataclass
|
|
@@ -11,6 +10,7 @@ from sinapsis_core.template_base.dynamic_template_factory import make_dynamic_te
|
|
|
11
10
|
from sinapsis_core.utils.env_var_keys import SINAPSIS_BUILD_DOCS
|
|
12
11
|
from torchmetrics import Metric
|
|
13
12
|
|
|
13
|
+
from sinapsis_anomalib.helpers.configs import OpenVINOArgs
|
|
14
14
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
15
15
|
from sinapsis_anomalib.templates.anomalib_base import (
|
|
16
16
|
AnomalibBase,
|
|
@@ -53,7 +53,7 @@ class AnomalibExportAttributes(AnomalibBaseAttributes):
|
|
|
53
53
|
input_size: tuple[int, int] | None = None
|
|
54
54
|
compression_type: CompressionType | None = None
|
|
55
55
|
metric: Metric | str | None = None
|
|
56
|
-
ov_args:
|
|
56
|
+
ov_args: OpenVINOArgs | None = None
|
|
57
57
|
ckpt_path: str | None = None
|
|
58
58
|
generic_key_chkpt: str | None = None
|
|
59
59
|
|
|
@@ -123,6 +123,11 @@ class AnomalibExport(AnomalibBase):
|
|
|
123
123
|
CompressionType.INT8_ACQ,
|
|
124
124
|
CompressionType.INT8_PTQ,
|
|
125
125
|
):
|
|
126
|
+
if self.attributes.folder_attributes is None:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
f"Compression type '{self.attributes.compression_type.value}' requires "
|
|
129
|
+
"'folder_attributes' to be provided."
|
|
130
|
+
)
|
|
126
131
|
self.data_module = self.setup_data_loader()
|
|
127
132
|
|
|
128
133
|
def _get_checkpoint_path(self, container: DataContainer) -> str | Path:
|
|
@@ -170,7 +175,7 @@ class AnomalibExport(AnomalibBase):
|
|
|
170
175
|
compression_type=self.attributes.compression_type,
|
|
171
176
|
datamodule=self.data_module,
|
|
172
177
|
metric=self.attributes.metric,
|
|
173
|
-
ov_args=self.attributes.ov_args,
|
|
178
|
+
ov_args=self.attributes.ov_args.model_dump(exclude_none=True) if self.attributes.ov_args else None,
|
|
174
179
|
ckpt_path=ckpt_path,
|
|
175
180
|
)
|
|
176
181
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
from pathlib import Path
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any
|
|
4
4
|
|
|
5
5
|
from anomalib.engine.engine import _TrainerArgumentsCache
|
|
6
6
|
from pydantic import Field
|
|
@@ -11,6 +11,7 @@ from sinapsis_core.template_base.base_models import TemplateAttributeType
|
|
|
11
11
|
from sinapsis_core.template_base.dynamic_template_factory import make_dynamic_template
|
|
12
12
|
from sinapsis_core.utils.env_var_keys import SINAPSIS_BUILD_DOCS
|
|
13
13
|
|
|
14
|
+
from sinapsis_anomalib.helpers.configs import TrainerConfig
|
|
14
15
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
15
16
|
from sinapsis_anomalib.templates.anomalib_base import (
|
|
16
17
|
AnomalibBase,
|
|
@@ -59,20 +60,14 @@ class AnomalibTrainAttributes(AnomalibBaseAttributes):
|
|
|
59
60
|
"""Training-specific configuration attributes.
|
|
60
61
|
|
|
61
62
|
Attributes:
|
|
62
|
-
max_epochs (int | None): Maximum number of training epochs.
|
|
63
|
-
If None, uses default from model configuration.
|
|
64
|
-
accelerator: (Literal["cpu", "gpu", "tpu", "hpu", "auto"]): Define the device to be used during training.
|
|
65
|
-
Defaults to "cpu".
|
|
66
63
|
ckpt_path (str | Path | None): Path to checkpoint for resuming training.
|
|
67
64
|
If None, starts training from scratch.
|
|
68
|
-
trainer_args: (
|
|
65
|
+
trainer_args: (TrainerConfig): General trainer arguments. For more details see:
|
|
69
66
|
https://lightning.ai/docs/pytorch/stable/common/trainer.html#trainer-flags
|
|
70
67
|
"""
|
|
71
68
|
|
|
72
|
-
max_epochs: int | None = None
|
|
73
|
-
accelerator: Literal["cpu", "gpu", "tpu", "hpu", "auto"] = "cpu"
|
|
74
69
|
ckpt_path: str | Path | None = None
|
|
75
|
-
trainer_args:
|
|
70
|
+
trainer_args: TrainerConfig = Field(default_factory=TrainerConfig)
|
|
76
71
|
|
|
77
72
|
|
|
78
73
|
class AnomalibTrain(AnomalibBase):
|
|
@@ -101,11 +96,11 @@ class AnomalibTrain(AnomalibBase):
|
|
|
101
96
|
default_root_dir: null
|
|
102
97
|
callback_configs: null
|
|
103
98
|
logger_configs: null
|
|
104
|
-
max_epochs: null
|
|
105
99
|
ckpt_path: null
|
|
106
|
-
accelerator: gpu
|
|
107
100
|
trainer_args:
|
|
108
101
|
devices: "0"
|
|
102
|
+
accelerator: gpu
|
|
103
|
+
max_epochs: null
|
|
109
104
|
cfa_init:
|
|
110
105
|
backbone: wide_resnet50_2
|
|
111
106
|
gamma_c: 1
|
|
@@ -124,6 +119,8 @@ class AnomalibTrain(AnomalibBase):
|
|
|
124
119
|
|
|
125
120
|
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
126
121
|
super().__init__(attributes)
|
|
122
|
+
if self.attributes.folder_attributes is None:
|
|
123
|
+
raise ValueError("'folder_attributes' is required for training.")
|
|
127
124
|
self.data_module = self.setup_data_loader()
|
|
128
125
|
|
|
129
126
|
def _update_trainer_args(self) -> None:
|
|
@@ -133,10 +130,7 @@ class AnomalibTrain(AnomalibBase):
|
|
|
133
130
|
based on the attributes configuration.
|
|
134
131
|
"""
|
|
135
132
|
existing_args = self.engine._cache.args
|
|
136
|
-
existing_args
|
|
137
|
-
|
|
138
|
-
self.attributes.trainer_args[AnomalibTrainKeys.ACCELERATOR] = self.attributes.accelerator
|
|
139
|
-
existing_args.update(self.attributes.trainer_args)
|
|
133
|
+
existing_args.update(self.attributes.trainer_args.model_dump(exclude_none=True))
|
|
140
134
|
self.engine._cache = _TrainerArgumentsCache(**existing_args)
|
|
141
135
|
|
|
142
136
|
def _get_training_metrics(self) -> dict[str, Any]:
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/SOURCES.txt
RENAMED
|
@@ -9,6 +9,7 @@ src/sinapsis_anomalib.egg-info/requires.txt
|
|
|
9
9
|
src/sinapsis_anomalib.egg-info/top_level.txt
|
|
10
10
|
src/sinapsis_anomalib/helpers/__init__.py
|
|
11
11
|
src/sinapsis_anomalib/helpers/config_factory.py
|
|
12
|
+
src/sinapsis_anomalib/helpers/configs.py
|
|
12
13
|
src/sinapsis_anomalib/helpers/tags.py
|
|
13
14
|
src/sinapsis_anomalib/templates/__init__.py
|
|
14
15
|
src/sinapsis_anomalib/templates/anomalib_base.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/helpers/__init__.py
RENAMED
|
File without changes
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/helpers/config_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib/templates/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/requires.txt
RENAMED
|
File without changes
|
{sinapsis_anomalib-0.1.6 → sinapsis_anomalib-0.1.8}/src/sinapsis_anomalib.egg-info/top_level.txt
RENAMED
|
File without changes
|