-
Notifications
You must be signed in to change notification settings - Fork 868
Open
Description
Describe the bug
anomalib train --config E:/anomalib_test/anomalib-main/tools/py_scripts/config_Folder.yaml
E:\anomalib_test\anomalib_env\lib\site-packages\timm\models\layers\__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
2025-12-10 09:21:02,722 - anomalib.models.components.base.anomalib_module - INFO - Initializing Patchcore model.
[12/10/25 09:21:02] INFO Initializing Patchcore model. anomalib_module.py:131
2025-12-10 09:21:04,135 - timm.models._builder - INFO - Loading pretrained weights from Hugging Face hub (timm/wide_resnet50_2.racm_in1k)
[12/10/25 09:21:04] INFO Loading pretrained weights from Hugging Face hub _builder.py:217
(timm/wide_resnet50_2.racm_in1k)
2025-12-10 09:21:05,045 - timm.models._hub - INFO - [timm/wide_resnet50_2.racm_in1k] Safe alternative available for 'pytorch_model.bin' (as 'model.safetensors'). Loading weights using safetensors.
[12/10/25 09:21:05] INFO [timm/wide_resnet50_2.racm_in1k] Safe alternative available for _hub.py:232
'pytorch_model.bin' (as 'model.safetensors'). Loading weights using
safetensors.
2025-12-10 09:21:05,105 - timm.models._builder - INFO - Missing keys (fc.weight, fc.bias) discovered while loading pretrained weights. This is expected if model is being adapted.
INFO Missing keys (fc.weight, fc.bias) discovered while loading pretrained _builder.py:282
weights. This is expected if model is being adapted.
2025-12-10 09:21:05,150 - anomalib.callbacks - INFO - Loading the callbacks
INFO Loading the callbacks __init__.py:114
2025-12-10 09:21:05,153 - anomalib.engine.engine - INFO - Overriding gradient_clip_val from None with 0 for Patchcore
INFO Overriding gradient_clip_val from None with 0 for Patchcore engine.py:102
2025-12-10 09:21:05,155 - anomalib.engine.engine - INFO - Overriding max_epochs from None with 1 for Patchcore
INFO Overriding max_epochs from None with 1 for Patchcore engine.py:102
2025-12-10 09:21:05,157 - anomalib.engine.engine - INFO - Overriding num_sanity_val_steps from None with 0 for Patchcore
INFO Overriding num_sanity_val_steps from None with 0 for Patchcore engine.py:102
2025-12-10 09:21:05,160 - anomalib.engine.engine - INFO - Overriding devices from auto with 1 for Patchcore
INFO Overriding devices from auto with 1 for Patchcore engine.py:102
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:848 in │
│ adapt_typehints │
│ │
│ 845 │ │ sorted_subtypes = sort_subtypes_for_union(subtypehints, val, prev_val, append) │
│ 846 │ │ for subtype in sorted_subtypes: │
│ 847 │ │ │ try: │
│ ❱ 848 │ │ │ │ vals.append(adapt_typehints(val, subtype, **adapt_kwargs)) │
│ 849 │ │ │ │ break │
│ 850 │ │ │ except Exception as ex: │
│ 851 │ │ │ │ if subtype is str and not isinstance(val, str) and isinstance(orig_val, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:797 in │
│ adapt_typehints │
│ │
│ 794 │ │ if typehint is float and isinstance(val, int) and not isinstance(val, bool): │
│ 795 │ │ │ val = float(val) │
│ 796 │ │ if not isinstance(val, typehint) or (typehint in (int, float) and isinstance(val │
│ ❱ 797 │ │ │ raise_unexpected_value(f"Expected a {typehint}", val) │
│ 798 │ │
│ 799 │ # Annotated │
│ 800 │ elif is_annotated(typehint): │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:719 in │
│ raise_unexpected_value │
│ │
│ 716 def raise_unexpected_value(message: str, val: Any = inspect._empty, exception: Optional[ │
│ 717 │ if val is not inspect._empty: │
│ 718 │ │ message += f". Got value: {val}" │
│ ❱ 719 │ raise ValueError(message) from exception │
│ 720 │
│ 721 │
│ 722 def raise_union_unexpected_value(subtypes, val: Any, exceptions: list[Exception]) -> NoR │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Expected a <class 'NoneType'>. Got value: Namespace(class_path='anomalib.models.Patchcore',
init_args=Namespace(backbone='wide_resnet50_2', layers=['layer2', 'layer3'], pre_trained=True,
coreset_sampling_ratio=0.1, num_neighbors=9, precision=<PrecisionType.FLOAT32: 'float32'>, pre_processor=True,
post_processor=True, evaluator=True, visualizer=True))
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\anomalib_test\py310_env\lib\runpy.py:196 in _run_module_as_main │
│ │
│ 193 │ main_globals = sys.modules["__main__"].__dict__ │
│ 194 │ if alter_argv: │
│ 195 │ │ sys.argv[0] = mod_spec.origin │
│ ❱ 196 │ return _run_code(code, main_globals, None, │
│ 197 │ │ │ │ │ "__main__", mod_spec) │
│ 198 │
│ 199 def run_module(mod_name, init_globals=None, │
│ │
│ E:\anomalib_test\py310_env\lib\runpy.py:86 in _run_code │
│ │
│ 83 │ │ │ │ │ __loader__ = loader, │
│ 84 │ │ │ │ │ __package__ = pkg_name, │
│ 85 │ │ │ │ │ __spec__ = mod_spec) │
│ ❱ 86 │ exec(code, run_globals) │
│ 87 │ return run_globals │
│ 88 │
│ 89 def _run_module_code(code, init_globals=None, │
│ │
│ in <module>:7 │
│ │
│ 4 from anomalib.cli.cli import main │
│ 5 if __name__ == '__main__': │
│ 6 │ sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) │
│ ❱ 7 │ sys.exit(main()) │
│ 8 │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:492 in main │
│ │
│ 489 def main() -> None: │
│ 490 │ """Trainer via Anomalib CLI.""" │
│ 491 │ configure_logger() │
│ ❱ 492 │ AnomalibCLI() │
│ 493 │
│ 494 │
│ 495 if __name__ == "__main__": │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:83 in __init__ │
│ │
│ 80 │ │ │ self.before_instantiate_classes() │
│ 81 │ │ │ self.instantiate_classes() │
│ 82 │ │ if run: │
│ ❱ 83 │ │ │ self._run_subcommand() │
│ 84 │ │
│ 85 │ @staticmethod │
│ 86 │ def init_parser(**kwargs) -> ArgumentParser: │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:370 in _run_subcommand │
│ │
│ 367 │ │ elif self.config["subcommand"] in {*self.subcommands(), "train", "export", "pred │
│ 368 │ │ │ fn = getattr(self.engine, self.subcommand) │
│ 369 │ │ │ fn_kwargs = self._prepare_subcommand_kwargs(self.subcommand) │
│ ❱ 370 │ │ │ fn(**fn_kwargs) │
│ 371 │ │ elif PIPELINE_REGISTRY is not None and self.subcommand in pipeline_subcommands() │
│ 372 │ │ │ run_pipeline(self.config) │
│ 373 │ │ else: │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\engine\engine.py:728 in train │
│ │
│ 725 │ │ │ # if the model is zero-shot or few-shot, we only need to run validate for no │
│ 726 │ │ │ self.trainer.validate(model, val_dataloaders, None, verbose=False, datamodul │
│ 727 │ │ else: │
│ ❱ 728 │ │ │ self.trainer.fit(model, train_dataloaders, val_dataloaders, datamodule, ckpt │
│ 729 │ │ return self.trainer.test( │
│ 730 │ │ │ model, │
│ 731 │ │ │ test_dataloaders, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:584 │
│ in fit │
│ │
│ 581 │ │ self.state.status = TrainerStatus.RUNNING │
│ 582 │ │ self.training = True │
│ 583 │ │ self.should_stop = False │
│ ❱ 584 │ │ call._call_and_handle_interrupt( │
│ 585 │ │ │ self, │
│ 586 │ │ │ self._fit_impl, │
│ 587 │ │ │ model, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:49 in │
│ _call_and_handle_interrupt │
│ │
│ 46 │ try: │
│ 47 │ │ if trainer.strategy.launcher is not None: │
│ 48 │ │ │ return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, │
│ ❱ 49 │ │ return trainer_fn(*args, **kwargs) │
│ 50 │ │
│ 51 │ except _TunerExitException: │
│ 52 │ │ _call_teardown_hook(trainer) │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:630 │
│ in _fit_impl │
│ │
│ 627 │ │ │ model_provided=True, │
│ 628 │ │ │ model_connected=self.lightning_module is not None, │
│ 629 │ │ ) │
│ ❱ 630 │ │ self._run(model, ckpt_path=ckpt_path, weights_only=weights_only) │
│ 631 │ │ │
│ 632 │ │ assert self.state.stopped │
│ 633 │ │ self.training = False │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:1039 │
│ in _run │
│ │
│ 1036 │ │ log.debug(f"{self.__class__.__name__}: preparing data") │
│ 1037 │ │ self._data_connector.prepare_data() │
│ 1038 │ │ │
│ ❱ 1039 │ │ call._call_setup_hook(self) # allow user to set up LightningModule in accelerat │
│ 1040 │ │ log.debug(f"{self.__class__.__name__}: configuring model") │
│ 1041 │ │ call._call_configure_model(self) │
│ 1042 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:109 in │
│ _call_setup_hook │
│ │
│ 106 │ │
│ 107 │ if trainer.datamodule is not None: │
│ 108 │ │ _call_lightning_datamodule_hook(trainer, "setup", stage=fn) │
│ ❱ 109 │ _call_callback_hooks(trainer, "setup", stage=fn) │
│ 110 │ _call_lightning_module_hook(trainer, "setup", stage=fn) │
│ 111 │ │
│ 112 │ trainer.strategy.barrier("post_setup") │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:228 in │
│ _call_callback_hooks │
│ │
│ 225 │ │ fn = getattr(callback, hook_name) │
│ 226 │ │ if callable(fn): │
│ 227 │ │ │ with trainer.profiler.profile(f"[Callback]{callback.state_key}.{hook_name}") │
│ ❱ 228 │ │ │ │ fn(trainer, trainer.lightning_module, *args, **kwargs) │
│ 229 │ │
│ 230 │ if pl_module: │
│ 231 │ │ # restore current_fx when nested context │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\cli.py:290 in setup │
│ │
│ 287 │ │ │ │ # the `log_dir` needs to be created as we rely on the logger to do it us │
│ 288 │ │ │ │ # but it hasn't logged anything at this point │
│ 289 │ │ │ │ fs.makedirs(log_dir, exist_ok=True) │
│ ❱ 290 │ │ │ │ self.parser.save( │
│ 291 │ │ │ │ │ self.config, config_path, skip_none=False, overwrite=self.overwrite, │
│ 292 │ │ │ │ ) │
│ 293 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_deprecated.py:187 in │
│ patched_save │
│ │
│ 184 │ def patched_save(self, cfg: Union[Namespace, Dict[str, Any]], *args, multifile: bool │
│ 185 │ │ if multifile and isinstance(cfg, dict): │
│ 186 │ │ │ cfg = self.parse_object(cfg, _skip_validation=True) │
│ ❱ 187 │ │ return self._unpatched_save(cfg, *args, multifile=multifile, **kwargs) │
│ 188 │ │
│ 189 │ ArgumentParser._unpatched_save = ArgumentParser.save │
│ 190 │ ArgumentParser.save = patched_save │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:896 in save │
│ │
│ 893 │ │ │
│ 894 │ │ if not multifile: │
│ 895 │ │ │ with open(path_fc.absolute, "w") as f: │
│ ❱ 896 │ │ │ │ f.write(self.dump(cfg, **dump_kwargs)) # type: ignore[arg-type] │
│ 897 │ │ │
│ 898 │ │ else: │
│ 899 │ │ │ cfg = cfg.clone() │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_deprecated.py:178 in │
│ patched_dump │
│ │
│ 175 │ def patched_dump(self, cfg: Union[Namespace, Dict[str, Any]], *args, **kwargs) -> st │
│ 176 │ │ if isinstance(cfg, dict): │
│ 177 │ │ │ cfg = self.parse_object(cfg, _skip_validation=True) │
│ ❱ 178 │ │ return self._unpatched_dump(cfg, *args, **kwargs) │
│ 179 │ │
│ 180 │ ArgumentParser._unpatched_dump = ArgumentParser.dump │
│ 181 │ ArgumentParser.dump = patched_dump │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:780 in dump │
│ │
│ 777 │ │ │ │ ActionLink.strip_link_target_keys(self, cfg) │
│ 778 │ │ │ │
│ 779 │ │ │ dump_kwargs = {"skip_validation": skip_validation, "skip_none": skip_none} │
│ ❱ 780 │ │ │ self._dump_cleanup_actions(cfg, self._actions, dump_kwargs) │
│ 781 │ │ │ │
│ 782 │ │ │ cfg_dict = cfg.as_dict() │
│ 783 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:817 in │
│ _dump_cleanup_actions │
│ │
│ 814 │ │ │ │ │ │ │ with suppress(ValueError): │
│ 815 │ │ │ │ │ │ │ │ value = action.serialize(value, dump_kwargs=dump_kwargs) │
│ 816 │ │ │ │ │ │ else: │
│ ❱ 817 │ │ │ │ │ │ │ value = action.serialize(value, dump_kwargs=dump_kwargs) │
│ 818 │ │ │ │ │ cfg.update(value, action_dest) │
│ 819 │ │
│ 820 │ def _dump_delete_default_entries(self, subcfg, subdefaults): │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:506 in │
│ serialize │
│ │
│ 503 │ │ │ │ │ ) │
│ 504 │ │ │ │ │ for v in value │
│ 505 │ │ │ │ ] │
│ ❱ 506 │ │ │ return adapt_typehints( │
│ 507 │ │ │ │ value, │
│ 508 │ │ │ │ self._typehint, │
│ 509 │ │ │ │ default=self.default, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:856 in │
│ adapt_typehints │
│ │
│ 853 │ │ │ │ │ continue │
│ 854 │ │ │ │ vals.append(ex) │
│ 855 │ │ if all(isinstance(v, Exception) for v in vals): │
│ ❱ 856 │ │ │ raise_union_unexpected_value(sorted_subtypes, val, vals) │
│ 857 │ │ val = next((v for v in reversed(vals) if not isinstance(v, Exception))) │
│ 858 │ │
│ 859 │ # Tuple or Set │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:726 in │
│ raise_union_unexpected_value │
│ │
│ 723 │ str_exceptions = [indent_text(str(e), first_line=False) for e in exceptions] │
│ 724 │ errors = indent_text("- " + "\n- ".join(str_exceptions)) │
│ 725 │ errors = errors.replace(f". Got value: {val}", "").replace(f" {val} ", " ") │
│ ❱ 726 │ raise ValueError( │
│ 727 │ │ f"Does not validate against any of the Union subtypes\nSubtypes: {subtypes}" │
│ 728 │ │ f"\nErrors:\n{errors}\nGiven value type: {type(val)}\nGiven value: {val}" │
│ 729 │ ) from exceptions[0] │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Does not validate against any of the Union subtypes
Subtypes: [<class 'NoneType'>, <class 'anomalib.models.components.base.anomalib_module.AnomalibModule'>]
Errors:
- Expected a <class 'NoneType'>
- ('cannot represent an object', <PrecisionType.FLOAT32: 'float32'>)
Given value type: <class 'jsonargparse._namespace.Namespace'>
Given value: Namespace(class_path='anomalib.models.Patchcore', init_args=Namespace(backbone='wide_resnet50_2',
layers=['layer2', 'layer3'], pre_trained=True, coreset_sampling_ratio=0.1, num_neighbors=9,
precision=<PrecisionType.FLOAT32: 'float32'>, pre_processor=True, post_processor=True, evaluator=True, visualizer=True))# config_Folder.yaml
data:
class_path: anomalib.data.Folder
init_args:
name: bottle
root: "datasets/MVTecAD/bottle"
normal_dir: "train/good"
abnormal_dir: "test/broken_large"
normal_test_dir: "test/good"
mask_dir: "ground_truth/broken_large"
normal_split_ratio: 0.2
extensions: [".png"]
train_batch_size: 16
eval_batch_size: 16
num_workers: 8
test_split_mode: FROM_DIR
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_ratio: 0.5
seed: null
model:
class_path: anomalib.models.Patchcore
init_args:
backbone: wide_resnet50_2
layers:
- layer2
- layer3
pre_trained: true
coreset_sampling_ratio: 0.1
num_neighbors: 9
pre_processor: true
post_processor: true
evaluator: true
visualizer: trueDataset
Folder
Model
PatchCore
Steps to reproduce the behavior
git clone https://github.com/open-edge-platform/anomalib.git
cd anomalib
pip install -e ".[full]"
anomalib train --config E:/anomalib_test/anomalib-main/tools/py_scripts/config_Folder.yamlOS information
OS information:
- OS: Window10
- Python version: 3.10.18
- Anomalib version: 2.3.0-dev
- PyTorch version: 2.5.1+cu118
- CUDA/cuDNN version: cuda11.1
- GPU models and configuration: GeForce RTX 2070
- Any other relevant information: I'm using a custom dataset]
Expected behavior
I was able to continue training using the CLI, but now I get an error!
Screenshots
No response
Pip/GitHub
GitHub
What version/branch did you use?
main(2.3.0-dev)
Configuration YAML
# config_Folder.yaml
data:
class_path: anomalib.data.Folder
init_args:
name: bottle
root: "datasets/MVTecAD/bottle"
normal_dir: "train/good"
abnormal_dir: "test/broken_large"
normal_test_dir: "test/good"
mask_dir: "ground_truth/broken_large"
normal_split_ratio: 0.2
extensions: [".png"]
train_batch_size: 16
eval_batch_size: 16
num_workers: 8
test_split_mode: FROM_DIR
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_ratio: 0.5
seed: null
model:
class_path: anomalib.models.Patchcore
init_args:
backbone: wide_resnet50_2
layers:
- layer2
- layer3
pre_trained: true
coreset_sampling_ratio: 0.1
num_neighbors: 9
pre_processor: true
post_processor: true
evaluator: true
visualizer: trueLogs
anomalib train --config E:/anomalib_test/anomalib-main/tools/py_scripts/config_Folder.yaml
E:\anomalib_test\anomalib_env\lib\site-packages\timm\models\layers\__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
2025-12-10 09:21:02,722 - anomalib.models.components.base.anomalib_module - INFO - Initializing Patchcore model.
[12/10/25 09:21:02] INFO Initializing Patchcore model. anomalib_module.py:131
2025-12-10 09:21:04,135 - timm.models._builder - INFO - Loading pretrained weights from Hugging Face hub (timm/wide_resnet50_2.racm_in1k)
[12/10/25 09:21:04] INFO Loading pretrained weights from Hugging Face hub _builder.py:217
(timm/wide_resnet50_2.racm_in1k)
2025-12-10 09:21:05,045 - timm.models._hub - INFO - [timm/wide_resnet50_2.racm_in1k] Safe alternative available for 'pytorch_model.bin' (as 'model.safetensors'). Loading weights using safetensors.
[12/10/25 09:21:05] INFO [timm/wide_resnet50_2.racm_in1k] Safe alternative available for _hub.py:232
'pytorch_model.bin' (as 'model.safetensors'). Loading weights using
safetensors.
2025-12-10 09:21:05,105 - timm.models._builder - INFO - Missing keys (fc.weight, fc.bias) discovered while loading pretrained weights. This is expected if model is being adapted.
INFO Missing keys (fc.weight, fc.bias) discovered while loading pretrained _builder.py:282
weights. This is expected if model is being adapted.
2025-12-10 09:21:05,150 - anomalib.callbacks - INFO - Loading the callbacks
INFO Loading the callbacks __init__.py:114
2025-12-10 09:21:05,153 - anomalib.engine.engine - INFO - Overriding gradient_clip_val from None with 0 for Patchcore
INFO Overriding gradient_clip_val from None with 0 for Patchcore engine.py:102
2025-12-10 09:21:05,155 - anomalib.engine.engine - INFO - Overriding max_epochs from None with 1 for Patchcore
INFO Overriding max_epochs from None with 1 for Patchcore engine.py:102
2025-12-10 09:21:05,157 - anomalib.engine.engine - INFO - Overriding num_sanity_val_steps from None with 0 for Patchcore
INFO Overriding num_sanity_val_steps from None with 0 for Patchcore engine.py:102
2025-12-10 09:21:05,160 - anomalib.engine.engine - INFO - Overriding devices from auto with 1 for Patchcore
INFO Overriding devices from auto with 1 for Patchcore engine.py:102
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:848 in │
│ adapt_typehints │
│ │
│ 845 │ │ sorted_subtypes = sort_subtypes_for_union(subtypehints, val, prev_val, append) │
│ 846 │ │ for subtype in sorted_subtypes: │
│ 847 │ │ │ try: │
│ ❱ 848 │ │ │ │ vals.append(adapt_typehints(val, subtype, **adapt_kwargs)) │
│ 849 │ │ │ │ break │
│ 850 │ │ │ except Exception as ex: │
│ 851 │ │ │ │ if subtype is str and not isinstance(val, str) and isinstance(orig_val, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:797 in │
│ adapt_typehints │
│ │
│ 794 │ │ if typehint is float and isinstance(val, int) and not isinstance(val, bool): │
│ 795 │ │ │ val = float(val) │
│ 796 │ │ if not isinstance(val, typehint) or (typehint in (int, float) and isinstance(val │
│ ❱ 797 │ │ │ raise_unexpected_value(f"Expected a {typehint}", val) │
│ 798 │ │
│ 799 │ # Annotated │
│ 800 │ elif is_annotated(typehint): │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:719 in │
│ raise_unexpected_value │
│ │
│ 716 def raise_unexpected_value(message: str, val: Any = inspect._empty, exception: Optional[ │
│ 717 │ if val is not inspect._empty: │
│ 718 │ │ message += f". Got value: {val}" │
│ ❱ 719 │ raise ValueError(message) from exception │
│ 720 │
│ 721 │
│ 722 def raise_union_unexpected_value(subtypes, val: Any, exceptions: list[Exception]) -> NoR │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Expected a <class 'NoneType'>. Got value: Namespace(class_path='anomalib.models.Patchcore',
init_args=Namespace(backbone='wide_resnet50_2', layers=['layer2', 'layer3'], pre_trained=True,
coreset_sampling_ratio=0.1, num_neighbors=9, precision=<PrecisionType.FLOAT32: 'float32'>, pre_processor=True,
post_processor=True, evaluator=True, visualizer=True))
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\anomalib_test\py310_env\lib\runpy.py:196 in _run_module_as_main │
│ │
│ 193 │ main_globals = sys.modules["__main__"].__dict__ │
│ 194 │ if alter_argv: │
│ 195 │ │ sys.argv[0] = mod_spec.origin │
│ ❱ 196 │ return _run_code(code, main_globals, None, │
│ 197 │ │ │ │ │ "__main__", mod_spec) │
│ 198 │
│ 199 def run_module(mod_name, init_globals=None, │
│ │
│ E:\anomalib_test\py310_env\lib\runpy.py:86 in _run_code │
│ │
│ 83 │ │ │ │ │ __loader__ = loader, │
│ 84 │ │ │ │ │ __package__ = pkg_name, │
│ 85 │ │ │ │ │ __spec__ = mod_spec) │
│ ❱ 86 │ exec(code, run_globals) │
│ 87 │ return run_globals │
│ 88 │
│ 89 def _run_module_code(code, init_globals=None, │
│ │
│ in <module>:7 │
│ │
│ 4 from anomalib.cli.cli import main │
│ 5 if __name__ == '__main__': │
│ 6 │ sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) │
│ ❱ 7 │ sys.exit(main()) │
│ 8 │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:492 in main │
│ │
│ 489 def main() -> None: │
│ 490 │ """Trainer via Anomalib CLI.""" │
│ 491 │ configure_logger() │
│ ❱ 492 │ AnomalibCLI() │
│ 493 │
│ 494 │
│ 495 if __name__ == "__main__": │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:83 in __init__ │
│ │
│ 80 │ │ │ self.before_instantiate_classes() │
│ 81 │ │ │ self.instantiate_classes() │
│ 82 │ │ if run: │
│ ❱ 83 │ │ │ self._run_subcommand() │
│ 84 │ │
│ 85 │ @staticmethod │
│ 86 │ def init_parser(**kwargs) -> ArgumentParser: │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\cli\cli.py:370 in _run_subcommand │
│ │
│ 367 │ │ elif self.config["subcommand"] in {*self.subcommands(), "train", "export", "pred │
│ 368 │ │ │ fn = getattr(self.engine, self.subcommand) │
│ 369 │ │ │ fn_kwargs = self._prepare_subcommand_kwargs(self.subcommand) │
│ ❱ 370 │ │ │ fn(**fn_kwargs) │
│ 371 │ │ elif PIPELINE_REGISTRY is not None and self.subcommand in pipeline_subcommands() │
│ 372 │ │ │ run_pipeline(self.config) │
│ 373 │ │ else: │
│ │
│ E:\anomalib_test\anomalib-main\src\anomalib\engine\engine.py:728 in train │
│ │
│ 725 │ │ │ # if the model is zero-shot or few-shot, we only need to run validate for no │
│ 726 │ │ │ self.trainer.validate(model, val_dataloaders, None, verbose=False, datamodul │
│ 727 │ │ else: │
│ ❱ 728 │ │ │ self.trainer.fit(model, train_dataloaders, val_dataloaders, datamodule, ckpt │
│ 729 │ │ return self.trainer.test( │
│ 730 │ │ │ model, │
│ 731 │ │ │ test_dataloaders, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:584 │
│ in fit │
│ │
│ 581 │ │ self.state.status = TrainerStatus.RUNNING │
│ 582 │ │ self.training = True │
│ 583 │ │ self.should_stop = False │
│ ❱ 584 │ │ call._call_and_handle_interrupt( │
│ 585 │ │ │ self, │
│ 586 │ │ │ self._fit_impl, │
│ 587 │ │ │ model, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:49 in │
│ _call_and_handle_interrupt │
│ │
│ 46 │ try: │
│ 47 │ │ if trainer.strategy.launcher is not None: │
│ 48 │ │ │ return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, │
│ ❱ 49 │ │ return trainer_fn(*args, **kwargs) │
│ 50 │ │
│ 51 │ except _TunerExitException: │
│ 52 │ │ _call_teardown_hook(trainer) │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:630 │
│ in _fit_impl │
│ │
│ 627 │ │ │ model_provided=True, │
│ 628 │ │ │ model_connected=self.lightning_module is not None, │
│ 629 │ │ ) │
│ ❱ 630 │ │ self._run(model, ckpt_path=ckpt_path, weights_only=weights_only) │
│ 631 │ │ │
│ 632 │ │ assert self.state.stopped │
│ 633 │ │ self.training = False │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\trainer.py:1039 │
│ in _run │
│ │
│ 1036 │ │ log.debug(f"{self.__class__.__name__}: preparing data") │
│ 1037 │ │ self._data_connector.prepare_data() │
│ 1038 │ │ │
│ ❱ 1039 │ │ call._call_setup_hook(self) # allow user to set up LightningModule in accelerat │
│ 1040 │ │ log.debug(f"{self.__class__.__name__}: configuring model") │
│ 1041 │ │ call._call_configure_model(self) │
│ 1042 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:109 in │
│ _call_setup_hook │
│ │
│ 106 │ │
│ 107 │ if trainer.datamodule is not None: │
│ 108 │ │ _call_lightning_datamodule_hook(trainer, "setup", stage=fn) │
│ ❱ 109 │ _call_callback_hooks(trainer, "setup", stage=fn) │
│ 110 │ _call_lightning_module_hook(trainer, "setup", stage=fn) │
│ 111 │ │
│ 112 │ trainer.strategy.barrier("post_setup") │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\trainer\call.py:228 in │
│ _call_callback_hooks │
│ │
│ 225 │ │ fn = getattr(callback, hook_name) │
│ 226 │ │ if callable(fn): │
│ 227 │ │ │ with trainer.profiler.profile(f"[Callback]{callback.state_key}.{hook_name}") │
│ ❱ 228 │ │ │ │ fn(trainer, trainer.lightning_module, *args, **kwargs) │
│ 229 │ │
│ 230 │ if pl_module: │
│ 231 │ │ # restore current_fx when nested context │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\lightning\pytorch\cli.py:290 in setup │
│ │
│ 287 │ │ │ │ # the `log_dir` needs to be created as we rely on the logger to do it us │
│ 288 │ │ │ │ # but it hasn't logged anything at this point │
│ 289 │ │ │ │ fs.makedirs(log_dir, exist_ok=True) │
│ ❱ 290 │ │ │ │ self.parser.save( │
│ 291 │ │ │ │ │ self.config, config_path, skip_none=False, overwrite=self.overwrite, │
│ 292 │ │ │ │ ) │
│ 293 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_deprecated.py:187 in │
│ patched_save │
│ │
│ 184 │ def patched_save(self, cfg: Union[Namespace, Dict[str, Any]], *args, multifile: bool │
│ 185 │ │ if multifile and isinstance(cfg, dict): │
│ 186 │ │ │ cfg = self.parse_object(cfg, _skip_validation=True) │
│ ❱ 187 │ │ return self._unpatched_save(cfg, *args, multifile=multifile, **kwargs) │
│ 188 │ │
│ 189 │ ArgumentParser._unpatched_save = ArgumentParser.save │
│ 190 │ ArgumentParser.save = patched_save │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:896 in save │
│ │
│ 893 │ │ │
│ 894 │ │ if not multifile: │
│ 895 │ │ │ with open(path_fc.absolute, "w") as f: │
│ ❱ 896 │ │ │ │ f.write(self.dump(cfg, **dump_kwargs)) # type: ignore[arg-type] │
│ 897 │ │ │
│ 898 │ │ else: │
│ 899 │ │ │ cfg = cfg.clone() │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_deprecated.py:178 in │
│ patched_dump │
│ │
│ 175 │ def patched_dump(self, cfg: Union[Namespace, Dict[str, Any]], *args, **kwargs) -> st │
│ 176 │ │ if isinstance(cfg, dict): │
│ 177 │ │ │ cfg = self.parse_object(cfg, _skip_validation=True) │
│ ❱ 178 │ │ return self._unpatched_dump(cfg, *args, **kwargs) │
│ 179 │ │
│ 180 │ ArgumentParser._unpatched_dump = ArgumentParser.dump │
│ 181 │ ArgumentParser.dump = patched_dump │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:780 in dump │
│ │
│ 777 │ │ │ │ ActionLink.strip_link_target_keys(self, cfg) │
│ 778 │ │ │ │
│ 779 │ │ │ dump_kwargs = {"skip_validation": skip_validation, "skip_none": skip_none} │
│ ❱ 780 │ │ │ self._dump_cleanup_actions(cfg, self._actions, dump_kwargs) │
│ 781 │ │ │ │
│ 782 │ │ │ cfg_dict = cfg.as_dict() │
│ 783 │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_core.py:817 in │
│ _dump_cleanup_actions │
│ │
│ 814 │ │ │ │ │ │ │ with suppress(ValueError): │
│ 815 │ │ │ │ │ │ │ │ value = action.serialize(value, dump_kwargs=dump_kwargs) │
│ 816 │ │ │ │ │ │ else: │
│ ❱ 817 │ │ │ │ │ │ │ value = action.serialize(value, dump_kwargs=dump_kwargs) │
│ 818 │ │ │ │ │ cfg.update(value, action_dest) │
│ 819 │ │
│ 820 │ def _dump_delete_default_entries(self, subcfg, subdefaults): │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:506 in │
│ serialize │
│ │
│ 503 │ │ │ │ │ ) │
│ 504 │ │ │ │ │ for v in value │
│ 505 │ │ │ │ ] │
│ ❱ 506 │ │ │ return adapt_typehints( │
│ 507 │ │ │ │ value, │
│ 508 │ │ │ │ self._typehint, │
│ 509 │ │ │ │ default=self.default, │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:856 in │
│ adapt_typehints │
│ │
│ 853 │ │ │ │ │ continue │
│ 854 │ │ │ │ vals.append(ex) │
│ 855 │ │ if all(isinstance(v, Exception) for v in vals): │
│ ❱ 856 │ │ │ raise_union_unexpected_value(sorted_subtypes, val, vals) │
│ 857 │ │ val = next((v for v in reversed(vals) if not isinstance(v, Exception))) │
│ 858 │ │
│ 859 │ # Tuple or Set │
│ │
│ E:\anomalib_test\anomalib_env\lib\site-packages\jsonargparse\_typehints.py:726 in │
│ raise_union_unexpected_value │
│ │
│ 723 │ str_exceptions = [indent_text(str(e), first_line=False) for e in exceptions] │
│ 724 │ errors = indent_text("- " + "\n- ".join(str_exceptions)) │
│ 725 │ errors = errors.replace(f". Got value: {val}", "").replace(f" {val} ", " ") │
│ ❱ 726 │ raise ValueError( │
│ 727 │ │ f"Does not validate against any of the Union subtypes\nSubtypes: {subtypes}" │
│ 728 │ │ f"\nErrors:\n{errors}\nGiven value type: {type(val)}\nGiven value: {val}" │
│ 729 │ ) from exceptions[0] │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Does not validate against any of the Union subtypes
Subtypes: [<class 'NoneType'>, <class 'anomalib.models.components.base.anomalib_module.AnomalibModule'>]
Errors:
- Expected a <class 'NoneType'>
- ('cannot represent an object', <PrecisionType.FLOAT32: 'float32'>)
Given value type: <class 'jsonargparse._namespace.Namespace'>
Given value: Namespace(class_path='anomalib.models.Patchcore', init_args=Namespace(backbone='wide_resnet50_2',
layers=['layer2', 'layer3'], pre_trained=True, coreset_sampling_ratio=0.1, num_neighbors=9,
precision=<PrecisionType.FLOAT32: 'float32'>, pre_processor=True, post_processor=True, evaluator=True, visualizer=True))Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels