sinapsis-anomalib 0.1.10__py3-none-any.whl → 0.1.12__py3-none-any.whl
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.
- sinapsis_anomalib/helpers/configs.py +2 -2
- sinapsis_anomalib/helpers/env_var_keys.py +33 -0
- sinapsis_anomalib/templates/anomalib_base.py +7 -3
- sinapsis_anomalib/templates/anomalib_export.py +11 -3
- sinapsis_anomalib/templates/anomalib_train.py +9 -1
- {sinapsis_anomalib-0.1.10.dist-info → sinapsis_anomalib-0.1.12.dist-info}/METADATA +48 -15
- {sinapsis_anomalib-0.1.10.dist-info → sinapsis_anomalib-0.1.12.dist-info}/RECORD +10 -9
- {sinapsis_anomalib-0.1.10.dist-info → sinapsis_anomalib-0.1.12.dist-info}/WHEEL +0 -0
- {sinapsis_anomalib-0.1.10.dist-info → sinapsis_anomalib-0.1.12.dist-info}/licenses/LICENSE +0 -0
- {sinapsis_anomalib-0.1.10.dist-info → sinapsis_anomalib-0.1.12.dist-info}/top_level.txt +0 -0
|
@@ -55,13 +55,13 @@ class TrainerConfig(BaseModel):
|
|
|
55
55
|
accelerator (Literal["gpu", "cpu", "auto"]): The hardware accelerator to use.
|
|
56
56
|
Defaults to "auto".
|
|
57
57
|
min_epochs (int): The minimum number of epochs to train for. Defaults to 1.
|
|
58
|
-
max_epochs (int): The maximum number of epochs to train for. Defaults to
|
|
58
|
+
max_epochs (int): The maximum number of epochs to train for. Defaults to 5.
|
|
59
59
|
"""
|
|
60
60
|
|
|
61
61
|
devices: int | list[int] | str | None = "auto"
|
|
62
62
|
accelerator: Literal["cpu", "gpu", "tpu", "hpu", "auto"] = "cpu"
|
|
63
63
|
min_epochs: int = 1
|
|
64
|
-
max_epochs: int | None =
|
|
64
|
+
max_epochs: int | None = 5
|
|
65
65
|
model_config = ConfigDict(extra="allow")
|
|
66
66
|
|
|
67
67
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
from sinapsis_core.utils.env_var_keys import EnvVarEntry, doc_str, return_docs_for_vars
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class _AnomalibEnvVars(BaseModel):
|
|
9
|
+
"""Env vars for Sinapsis Anomalib."""
|
|
10
|
+
|
|
11
|
+
ANOMALIB_ROOT_DIR: EnvVarEntry = EnvVarEntry(
|
|
12
|
+
var_name="ANOMALIB_ROOT_DIR",
|
|
13
|
+
default_value="artifacts",
|
|
14
|
+
allowed_values=None,
|
|
15
|
+
description="The base directory for all Anomalib-related artifacts, such as training and exported models.",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
AnomalibEnvVars = _AnomalibEnvVars()
|
|
20
|
+
|
|
21
|
+
doc_str = return_docs_for_vars(AnomalibEnvVars, docs=doc_str, string_for_doc="""Anomalib env vars available: \n""")
|
|
22
|
+
__doc__ = doc_str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def __getattr__(name: str) -> Any:
|
|
26
|
+
"""To use as an import, when updating the value is not important."""
|
|
27
|
+
if name in AnomalibEnvVars.model_fields:
|
|
28
|
+
return AnomalibEnvVars.model_fields[name].default.value
|
|
29
|
+
|
|
30
|
+
raise AttributeError(f"Agent does not have `{name}` env var")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
_all__ = (*list(AnomalibEnvVars.model_fields.keys()), "AnomalibEnvVars")
|
|
@@ -24,6 +24,7 @@ from sinapsis_core.template_base.dynamic_template import BaseDynamicWrapperTempl
|
|
|
24
24
|
|
|
25
25
|
from sinapsis_anomalib.helpers.config_factory import CallbackFactory, LoggerFactory
|
|
26
26
|
from sinapsis_anomalib.helpers.configs import FolderConfig
|
|
27
|
+
from sinapsis_anomalib.helpers.env_var_keys import ANOMALIB_ROOT_DIR
|
|
27
28
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
28
29
|
|
|
29
30
|
EXCLUDED_MODELS = [
|
|
@@ -77,7 +78,7 @@ class EngineConfig(BaseModel):
|
|
|
77
78
|
image_metrics: METRICS_TYPE | None = None
|
|
78
79
|
pixel_metrics: METRICS_TYPE | None = None
|
|
79
80
|
logger: LOGGER_TYPE = None
|
|
80
|
-
default_root_dir: PATH_TYPE =
|
|
81
|
+
default_root_dir: PATH_TYPE = ANOMALIB_ROOT_DIR
|
|
81
82
|
callback_configs: dict[str, dict[str, Any]] | None = None
|
|
82
83
|
logger_configs: dict[str, dict[str, Any]] | None = None
|
|
83
84
|
|
|
@@ -126,7 +127,6 @@ class AnomalibBaseAttributes(TemplateAttributes):
|
|
|
126
127
|
image_metrics (METRICS_TYPE | None): Image metrics
|
|
127
128
|
pixel_metrics (METRICS_TYPE | None): Pixel metrics
|
|
128
129
|
logger (LOGGER_TYPE): Lightning logger
|
|
129
|
-
default_root_dir (PATH_TYPE): Output directory
|
|
130
130
|
callback_configs (dict[str, dict[str, Any]] | None): Callback configs
|
|
131
131
|
logger_configs (dict[str, dict[str, Any]] | None): Logger configs
|
|
132
132
|
"""
|
|
@@ -138,7 +138,6 @@ class AnomalibBaseAttributes(TemplateAttributes):
|
|
|
138
138
|
image_metrics: METRICS_TYPE | None = None
|
|
139
139
|
pixel_metrics: METRICS_TYPE | None = None
|
|
140
140
|
logger: LOGGER_TYPE = None
|
|
141
|
-
default_root_dir: PATH_TYPE = None
|
|
142
141
|
callback_configs: dict[str, dict[str, Any]] | None = None
|
|
143
142
|
logger_configs: dict[str, dict[str, Any]] | None = None
|
|
144
143
|
|
|
@@ -226,6 +225,11 @@ class AnomalibBase(BaseDynamicWrapperTemplate):
|
|
|
226
225
|
"""
|
|
227
226
|
|
|
228
227
|
def reset_state(self, template_name: str | None = None) -> None:
|
|
228
|
+
"""Re-instantiates the template.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
template_name (str | None, optional): The name of the template instance being reset. Defaults to None.
|
|
232
|
+
"""
|
|
229
233
|
if torch.cuda.is_available():
|
|
230
234
|
torch.cuda.empty_cache()
|
|
231
235
|
super().reset_state(template_name)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
|
|
4
5
|
from anomalib.deploy import CompressionType, ExportType
|
|
@@ -11,6 +12,7 @@ from sinapsis_core.utils.env_var_keys import SINAPSIS_BUILD_DOCS
|
|
|
11
12
|
from torchmetrics import Metric
|
|
12
13
|
|
|
13
14
|
from sinapsis_anomalib.helpers.configs import OpenVINOArgs
|
|
15
|
+
from sinapsis_anomalib.helpers.env_var_keys import ANOMALIB_ROOT_DIR
|
|
14
16
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
15
17
|
from sinapsis_anomalib.templates.anomalib_base import (
|
|
16
18
|
AnomalibBase,
|
|
@@ -47,6 +49,7 @@ class AnomalibExportAttributes(AnomalibBaseAttributes):
|
|
|
47
49
|
ckpt_path (str | None): Explicit path to model checkpoint.
|
|
48
50
|
generic_key_chkpt (str | None): Key to retrieve training results.
|
|
49
51
|
"""
|
|
52
|
+
|
|
50
53
|
folder_attributes: dict | None = None
|
|
51
54
|
export_type: ExportType = ExportType.TORCH
|
|
52
55
|
export_root: str | Path | None = None
|
|
@@ -82,7 +85,6 @@ class AnomalibExport(AnomalibBase):
|
|
|
82
85
|
image_metrics: null
|
|
83
86
|
pixel_metrics: null
|
|
84
87
|
logger: null
|
|
85
|
-
default_root_dir: null
|
|
86
88
|
callback_configs: null
|
|
87
89
|
logger_configs: null
|
|
88
90
|
export_type: 'openvino'
|
|
@@ -153,7 +155,8 @@ class AnomalibExport(AnomalibBase):
|
|
|
153
155
|
generic_data = self._get_generic_data(container, self.attributes.generic_key_chkpt)
|
|
154
156
|
if generic_data and isinstance(generic_data, AnomalibTrainDataClass):
|
|
155
157
|
return generic_data.checkpoint_path
|
|
156
|
-
|
|
158
|
+
if generic_data and isinstance(generic_data, dict):
|
|
159
|
+
return generic_data.get("checkpoint_path")
|
|
157
160
|
raise ValueError("No checkpoint path found")
|
|
158
161
|
|
|
159
162
|
def export_model(self, container: DataContainer) -> AnomalibExportDataClass:
|
|
@@ -166,11 +169,16 @@ class AnomalibExport(AnomalibBase):
|
|
|
166
169
|
AnomalibExportDataClass: Contains exported model path
|
|
167
170
|
"""
|
|
168
171
|
ckpt_path = self._get_checkpoint_path(container)
|
|
172
|
+
export_dir = (
|
|
173
|
+
os.path.join(ANOMALIB_ROOT_DIR, self.attributes.export_root)
|
|
174
|
+
if self.attributes.export_root
|
|
175
|
+
else ANOMALIB_ROOT_DIR
|
|
176
|
+
)
|
|
169
177
|
|
|
170
178
|
exported_path = self.engine.export(
|
|
171
179
|
model=self.model,
|
|
172
180
|
export_type=self.attributes.export_type,
|
|
173
|
-
export_root=
|
|
181
|
+
export_root=export_dir,
|
|
174
182
|
input_size=self.attributes.input_size,
|
|
175
183
|
compression_type=self.attributes.compression_type,
|
|
176
184
|
datamodule=self.data_module,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
from typing import Any
|
|
4
5
|
|
|
@@ -12,6 +13,7 @@ from sinapsis_core.template_base.dynamic_template_factory import make_dynamic_te
|
|
|
12
13
|
from sinapsis_core.utils.env_var_keys import SINAPSIS_BUILD_DOCS
|
|
13
14
|
|
|
14
15
|
from sinapsis_anomalib.helpers.configs import TrainerConfig
|
|
16
|
+
from sinapsis_anomalib.helpers.env_var_keys import ANOMALIB_ROOT_DIR
|
|
15
17
|
from sinapsis_anomalib.helpers.tags import Tags
|
|
16
18
|
from sinapsis_anomalib.templates.anomalib_base import (
|
|
17
19
|
AnomalibBase,
|
|
@@ -67,6 +69,7 @@ class AnomalibTrainAttributes(AnomalibBaseAttributes):
|
|
|
67
69
|
"""
|
|
68
70
|
|
|
69
71
|
ckpt_path: str | Path | None = None
|
|
72
|
+
train_root: str | Path | None = None
|
|
70
73
|
trainer_args: TrainerConfig = Field(default_factory=TrainerConfig)
|
|
71
74
|
|
|
72
75
|
|
|
@@ -93,7 +96,6 @@ class AnomalibTrain(AnomalibBase):
|
|
|
93
96
|
image_metrics: null
|
|
94
97
|
pixel_metrics: null
|
|
95
98
|
logger: null
|
|
96
|
-
default_root_dir: null
|
|
97
99
|
callback_configs: null
|
|
98
100
|
logger_configs: null
|
|
99
101
|
ckpt_path: null
|
|
@@ -129,7 +131,13 @@ class AnomalibTrain(AnomalibBase):
|
|
|
129
131
|
Specifically sets the maximum number of training epochs
|
|
130
132
|
based on the attributes configuration.
|
|
131
133
|
"""
|
|
134
|
+
train_dir = (
|
|
135
|
+
os.path.join(ANOMALIB_ROOT_DIR, self.attributes.train_root)
|
|
136
|
+
if self.attributes.train_root
|
|
137
|
+
else ANOMALIB_ROOT_DIR
|
|
138
|
+
)
|
|
132
139
|
existing_args = self.engine._cache.args
|
|
140
|
+
existing_args["default_root_dir"] = train_dir
|
|
133
141
|
existing_args.update(self.attributes.trainer_args.model_dump(exclude_none=True))
|
|
134
142
|
self.engine._cache = _TrainerArgumentsCache(**existing_args)
|
|
135
143
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-anomalib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.12
|
|
4
4
|
Summary: Templates for anomaly detection with computer vision using anomalib library.
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -118,7 +118,7 @@ _Export trained models for deployment in different formats._
|
|
|
118
118
|
> [!TIP]
|
|
119
119
|
> Use CLI command ```sinapsis info --example-template-config TEMPLATE_NAME``` to produce an example Agent config for the Template specified in ***TEMPLATE_NAME***.
|
|
120
120
|
|
|
121
|
-
For example, for ***
|
|
121
|
+
For example, for ***CflowTrain*** use ```sinapsis info --example-template-config CflowTrain``` to produce the following example config:
|
|
122
122
|
|
|
123
123
|
```yaml
|
|
124
124
|
agent:
|
|
@@ -127,30 +127,63 @@ templates:
|
|
|
127
127
|
- template_name: InputTemplate
|
|
128
128
|
class_name: InputTemplate
|
|
129
129
|
attributes: {}
|
|
130
|
-
- template_name:
|
|
131
|
-
class_name:
|
|
130
|
+
- template_name: CflowTrain
|
|
131
|
+
class_name: CflowTrain
|
|
132
132
|
template_input: InputTemplate
|
|
133
133
|
attributes:
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
folder_attributes:
|
|
135
|
+
name: 'dataset'
|
|
136
|
+
root: null
|
|
137
|
+
normal_dir: 'images/normal'
|
|
138
|
+
abnormal_dir: null
|
|
139
|
+
normal_test_dir: null
|
|
140
|
+
mask_dir: null
|
|
141
|
+
normal_split_ratio: 0.2
|
|
142
|
+
extensions: null
|
|
143
|
+
train_batch_size: 32
|
|
144
|
+
eval_batch_size: 32
|
|
145
|
+
num_workers: 8
|
|
146
|
+
test_split_mode:
|
|
147
|
+
- from_dir
|
|
148
|
+
test_split_ratio: 0.2
|
|
149
|
+
val_split_mode:
|
|
150
|
+
- from_test
|
|
151
|
+
val_split_ratio: 0.5
|
|
152
|
+
seed: null
|
|
136
153
|
callbacks: null
|
|
137
154
|
normalization: null
|
|
138
155
|
threshold: null
|
|
139
156
|
image_metrics: null
|
|
140
157
|
pixel_metrics: null
|
|
141
158
|
logger: null
|
|
142
|
-
default_root_dir: null
|
|
143
159
|
callback_configs: null
|
|
144
160
|
logger_configs: null
|
|
145
|
-
max_epochs: null
|
|
146
161
|
ckpt_path: null
|
|
147
|
-
|
|
162
|
+
train_root: null
|
|
163
|
+
trainer_args:
|
|
164
|
+
devices: auto
|
|
165
|
+
accelerator: cpu
|
|
166
|
+
min_epochs: 1
|
|
167
|
+
max_epochs: 5
|
|
168
|
+
cflow_init:
|
|
148
169
|
backbone: wide_resnet50_2
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
170
|
+
layers:
|
|
171
|
+
- layer2
|
|
172
|
+
- layer3
|
|
173
|
+
- layer4
|
|
174
|
+
pre_trained: true
|
|
175
|
+
fiber_batch_size: 64
|
|
176
|
+
decoder: freia-cflow
|
|
177
|
+
condition_vector: 128
|
|
178
|
+
coupling_blocks: 8
|
|
179
|
+
clamp_alpha: 1.9
|
|
180
|
+
permute_soft: false
|
|
181
|
+
lr: 0.0001
|
|
182
|
+
pre_processor: true
|
|
183
|
+
post_processor: true
|
|
184
|
+
evaluator: true
|
|
185
|
+
visualizer: true
|
|
186
|
+
|
|
154
187
|
```
|
|
155
188
|
|
|
156
189
|
<details>
|
|
@@ -188,7 +221,7 @@ templates:
|
|
|
188
221
|
class_name: CflowTrain
|
|
189
222
|
attributes:
|
|
190
223
|
folder_attributes_config_path: "configs/datamodule_config.yml"
|
|
191
|
-
|
|
224
|
+
train_root: "model"
|
|
192
225
|
max_epochs: 1
|
|
193
226
|
cflow_init:
|
|
194
227
|
lr: 0.0001
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
sinapsis_anomalib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
sinapsis_anomalib/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
sinapsis_anomalib/helpers/config_factory.py,sha256=M7CPS2qHgUWBUTYkuVGhaa2S6IJZ8C3zGPulVjgXr_U,4493
|
|
4
|
-
sinapsis_anomalib/helpers/configs.py,sha256=
|
|
4
|
+
sinapsis_anomalib/helpers/configs.py,sha256=Hp2N3sPpt498vf21x_uxrsu25oHNEiTQuu58v-biM2Q,3466
|
|
5
|
+
sinapsis_anomalib/helpers/env_var_keys.py,sha256=R2Ms5n2OgbmOKHcMThqT-fcHYaHxZ_DYu7MuEcQjGps,1056
|
|
5
6
|
sinapsis_anomalib/helpers/tags.py,sha256=Oj8vSh8AbnOfDY4UadOOteQOhjKwXSB3Rv82hpeP2YE,325
|
|
6
7
|
sinapsis_anomalib/templates/__init__.py,sha256=ltv45AB2oIhPw0jRrL0S6HMYYQp63Cr-DBjD0HjK1i0,904
|
|
7
|
-
sinapsis_anomalib/templates/anomalib_base.py,sha256=
|
|
8
|
+
sinapsis_anomalib/templates/anomalib_base.py,sha256=M6gE6E06DUizIdyZWkt-DXTWNC93qFtILj5XRQFd2TA,8703
|
|
8
9
|
sinapsis_anomalib/templates/anomalib_base_inference.py,sha256=YxYpiRK8CwzLjYJpSnNZkUq6OE9zSAbYnqNStPV9RBI,8996
|
|
9
|
-
sinapsis_anomalib/templates/anomalib_export.py,sha256=
|
|
10
|
+
sinapsis_anomalib/templates/anomalib_export.py,sha256=XGbLkiaedvmGhZJaHGblAJu79cyCgg2NQKIG8M9Iiss,8207
|
|
10
11
|
sinapsis_anomalib/templates/anomalib_openvino_inference.py,sha256=FPr2iwC3JbasJnlOgdWzO5ugbQj3Kan3xp-oxJGkC1Q,3207
|
|
11
12
|
sinapsis_anomalib/templates/anomalib_torch_inference.py,sha256=Q6aqspIjFpI7WY90jcnqNmqalhYIm_Um2As9Sx1AOeU,2862
|
|
12
|
-
sinapsis_anomalib/templates/anomalib_train.py,sha256=
|
|
13
|
-
sinapsis_anomalib-0.1.
|
|
14
|
-
sinapsis_anomalib-0.1.
|
|
15
|
-
sinapsis_anomalib-0.1.
|
|
16
|
-
sinapsis_anomalib-0.1.
|
|
17
|
-
sinapsis_anomalib-0.1.
|
|
13
|
+
sinapsis_anomalib/templates/anomalib_train.py,sha256=xwKGciZOsMKzbmjlIxn-W7GjsMgO_nr3xEsB0uVOk4g,7744
|
|
14
|
+
sinapsis_anomalib-0.1.12.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
15
|
+
sinapsis_anomalib-0.1.12.dist-info/METADATA,sha256=KQBEEwF-HP2xg3zs7lImXXEHnRWUTCYzDIZRGKyAwYE,8230
|
|
16
|
+
sinapsis_anomalib-0.1.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
sinapsis_anomalib-0.1.12.dist-info/top_level.txt,sha256=p9ltOdENM_b-Ekvb0AvXmvZRV4Bwtly7c7qeOokACvE,18
|
|
18
|
+
sinapsis_anomalib-0.1.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|