Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs, config and folder support for tiled ensemble #2414

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
13 changes: 11 additions & 2 deletions src/anomalib/pipelines/tiled_ensemble/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,9 +49,12 @@
"""
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.")

Check warning on line 57 in src/anomalib/pipelines/tiled_ensemble/test_pipeline.py

View check run for this annotation

Codecov / codecov/patch

src/anomalib/pipelines/tiled_ensemble/test_pipeline.py#L57

Added line #L57 was not covered by tests

seed = args["seed"]
accelerator = args["accelerator"]
Expand All @@ -59,7 +63,12 @@
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

Check warning on line 70 in src/anomalib/pipelines/tiled_ensemble/test_pipeline.py

View check run for this annotation

Codecov / codecov/patch

src/anomalib/pipelines/tiled_ensemble/test_pipeline.py#L69-L70

Added lines #L69 - L70 were not covered by tests

metrics = args["TrainModels"]["metrics"]

predict_job_generator = PredictJobGenerator(
Expand Down
5 changes: 4 additions & 1 deletion src/anomalib/pipelines/tiled_ensemble/train_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@
),
)

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.")

Check warning on line 100 in src/anomalib/pipelines/tiled_ensemble/train_pipeline.py

View check run for this annotation

Codecov / codecov/patch

src/anomalib/pipelines/tiled_ensemble/train_pipeline.py#L100

Added line #L100 was not covered by tests

# 2. predict using validation data
if accelerator == "cuda":
Expand Down
2 changes: 1 addition & 1 deletion tools/tiled_ensemble/ens_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
seed: 42
accelerator: "gpu"
accelerator: "cuda"
default_root_dir: "results"

tiling:
Expand Down
Loading