From f662ee7940fefa62af3c46394a5c05c7686e4be8 Mon Sep 17 00:00:00 2001 From: blaz-r Date: Mon, 11 Nov 2024 19:58:50 +0100 Subject: [PATCH 1/3] Fix accelerator in docs and config Signed-off-by: blaz-r --- docs/source/markdown/guides/how_to/pipelines/tiled_ensemble.md | 2 +- tools/tiled_ensemble/ens_config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/markdown/guides/how_to/pipelines/tiled_ensemble.md b/docs/source/markdown/guides/how_to/pipelines/tiled_ensemble.md index 3550efb5fd..f076ec28db 100644 --- a/docs/source/markdown/guides/how_to/pipelines/tiled_ensemble.md +++ b/docs/source/markdown/guides/how_to/pipelines/tiled_ensemble.md @@ -50,7 +50,7 @@ General settings at the top of the config file are used to set up the random `se ```{code-block} yaml seed: 42 -accelerator: "gpu" +accelerator: "cuda" default_root_dir: "results" ``` diff --git a/tools/tiled_ensemble/ens_config.yaml b/tools/tiled_ensemble/ens_config.yaml index 2490b22e9a..06fd63c608 100644 --- a/tools/tiled_ensemble/ens_config.yaml +++ b/tools/tiled_ensemble/ens_config.yaml @@ -1,5 +1,5 @@ seed: 42 -accelerator: "gpu" +accelerator: "cuda" default_root_dir: "results" tiling: From 23d14bf1b48bfe1e69dfe17894c488f4d24d507e Mon Sep 17 00:00:00 2001 From: blaz-r Date: Mon, 11 Nov 2024 20:29:47 +0100 Subject: [PATCH 2/3] Fix ensemble workdir to support folder dataset Signed-off-by: blaz-r --- .../tiled_ensemble/components/utils/ensemble_engine.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/anomalib/pipelines/tiled_ensemble/components/utils/ensemble_engine.py b/src/anomalib/pipelines/tiled_ensemble/components/utils/ensemble_engine.py index 449109ed3f..a1325236ae 100644 --- a/src/anomalib/pipelines/tiled_ensemble/components/utils/ensemble_engine.py +++ b/src/anomalib/pipelines/tiled_ensemble/components/utils/ensemble_engine.py @@ -50,8 +50,12 @@ def setup_ensemble_workspace(args: dict, versioned_dir: bool = True) -> Path: Path: path to new workspace root dir """ model_name = args["TrainModels"]["model"]["class_path"].split(".")[-1] - dataset_name = args["data"]["class_path"].split(".")[-1] - category = args["data"]["init_args"]["category"] + # get dataset name if present in init_args + dataset_name = args["data"]["init_args"].get("name", None) + if dataset_name is None: + # if not specified, take class name + dataset_name = args["data"]["class_path"].split(".")[-1] + category = args["data"]["init_args"].get("category", "") root_dir = Path(args["default_root_dir"]) / model_name / dataset_name / category return create_versioned_dir(root_dir) if versioned_dir else root_dir / "latest" From f0917154488bfec61ea199709f1ddea7fe1c4b85 Mon Sep 17 00:00:00 2001 From: blaz-r Date: Mon, 11 Nov 2024 20:31:47 +0100 Subject: [PATCH 3/3] Fix val + test split and task reading from config Signed-off-by: blaz-r --- .../pipelines/tiled_ensemble/test_pipeline.py | 13 +++++++++++-- .../pipelines/tiled_ensemble/train_pipeline.py | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/anomalib/pipelines/tiled_ensemble/test_pipeline.py b/src/anomalib/pipelines/tiled_ensemble/test_pipeline.py index 7fdd61e9ff..fb1f25bc5a 100644 --- a/src/anomalib/pipelines/tiled_ensemble/test_pipeline.py +++ b/src/anomalib/pipelines/tiled_ensemble/test_pipeline.py @@ -8,6 +8,7 @@ import torch +from anomalib import TaskType from anomalib.data.utils import TestSplitMode from anomalib.pipelines.components.base import Pipeline, Runner from anomalib.pipelines.components.runners import ParallelRunner, SerialRunner @@ -48,9 +49,12 @@ def _setup_runners(self, args: dict) -> list[Runner]: """ runners: list[Runner] = [] - if args["data"]["init_args"]["test_split_mode"] == TestSplitMode.NONE: + test_split_mode = args["data"]["init_args"].get("test_split_mode", None) + if test_split_mode == TestSplitMode.NONE: logger.info("Test split mode set to `none`, skipping test phase.") return runners + if test_split_mode is None: + logger.warning("Test split mode not set in data config, dataset specific default will be used.") seed = args["seed"] accelerator = args["accelerator"] @@ -59,7 +63,12 @@ def _setup_runners(self, args: dict) -> list[Runner]: normalization_stage = NormalizationStage(args["normalization_stage"]) threshold_stage = ThresholdStage(args["thresholding"]["stage"]) model_args = args["TrainModels"]["model"] - task = args["data"]["init_args"]["task"] + + task = args["data"]["init_args"].get("task", None) + if task is None: + logger.info("Task not provided, defaulting to segmentation. Set 'task' in config data section to change.") + task = TaskType.SEGMENTATION + metrics = args["TrainModels"]["metrics"] predict_job_generator = PredictJobGenerator( diff --git a/src/anomalib/pipelines/tiled_ensemble/train_pipeline.py b/src/anomalib/pipelines/tiled_ensemble/train_pipeline.py index 38e4e34e4b..a989146740 100644 --- a/src/anomalib/pipelines/tiled_ensemble/train_pipeline.py +++ b/src/anomalib/pipelines/tiled_ensemble/train_pipeline.py @@ -92,9 +92,12 @@ def _setup_runners(self, args: dict) -> list[Runner]: ), ) - if data_args["init_args"]["val_split_mode"] == ValSplitMode.NONE: + val_split_mode = data_args["init_args"].get("val_split_mode", None) + if val_split_mode == ValSplitMode.NONE: logger.warning("No validation set provided, skipping statistics calculation.") return runners + if val_split_mode is None: + logger.warning("Validation split mode not set in data config, dataset specific default will be used.") # 2. predict using validation data if accelerator == "cuda":