Skip to content

Commit 42b3ad5

Browse files
Export the flattened config in benchmark CSV. (#2391)
* Export the flattened config in benchmark CSV. Signed-off-by: Weilin Xu <[email protected]> * Update CHANGELOG Signed-off-by: Weilin Xu <[email protected]> * Reuse the existing flatten_dict(). Signed-off-by: Weilin Xu <[email protected]> --------- Signed-off-by: Weilin Xu <[email protected]> Co-authored-by: Samet Akcay <[email protected]>
1 parent f4f9b9a commit 42b3ad5

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616
### Changed
1717

1818
- Add duration of experiments in seconds in the benchmark CSV result by [mzweilin](https://github.com/mzweilin) in https://github.com/openvinotoolkit/anomalib/pull/2392
19+
- Export flat configurations in benchmark CSV results by [mzweilin](https://github.com/mzweilin) in https://github.com/openvinotoolkit/anomalib/pull/2391
1920

2021
### Deprecated
2122

src/anomalib/pipelines/benchmark/generator.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from anomalib.pipelines.components import JobGenerator
1111
from anomalib.pipelines.components.utils import get_iterator_from_grid_dict
1212
from anomalib.pipelines.types import PREV_STAGE_RESULT
13+
from anomalib.utils.config import flatten_dict
1314
from anomalib.utils.logging import hide_output
1415

1516
from .job import BenchmarkJob
@@ -39,9 +40,12 @@ def generate_jobs(
3940
"""Return iterator based on the arguments."""
4041
del previous_stage_result # Not needed for this job
4142
for _container in get_iterator_from_grid_dict(args):
43+
# Pass experimental configs as a flatten dictionary to the job runner.
44+
flat_cfg = flatten_dict(_container)
4245
yield BenchmarkJob(
4346
accelerator=self.accelerator,
4447
seed=_container["seed"],
4548
model=get_model(_container["model"]),
4649
datamodule=get_datamodule(_container["data"]),
50+
flat_cfg=flat_cfg,
4751
)

src/anomalib/pipelines/benchmark/job.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,25 @@ class BenchmarkJob(Job):
3232
model (AnomalyModule): The model to use.
3333
datamodule (AnomalibDataModule): The data module to use.
3434
seed (int): The seed to use.
35+
flat_cfg (dict): The flat dictionary of configs with dotted keys.
3536
"""
3637

3738
name = "benchmark"
3839

39-
def __init__(self, accelerator: str, model: AnomalyModule, datamodule: AnomalibDataModule, seed: int) -> None:
40+
def __init__(
41+
self,
42+
accelerator: str,
43+
model: AnomalyModule,
44+
datamodule: AnomalibDataModule,
45+
seed: int,
46+
flat_cfg: dict,
47+
) -> None:
4048
super().__init__()
4149
self.accelerator = accelerator
4250
self.model = model
4351
self.datamodule = datamodule
4452
self.seed = seed
53+
self.flat_cfg = flat_cfg
4554

4655
@hide_output
4756
def run(
@@ -74,12 +83,9 @@ def run(
7483
# TODO(ashwinvaidya17): Restore throughput
7584
# https://github.com/openvinotoolkit/anomalib/issues/2054
7685
output = {
77-
"seed": self.seed,
7886
"accelerator": self.accelerator,
79-
"model": self.model.__class__.__name__,
80-
"data": self.datamodule.__class__.__name__,
81-
"category": self.datamodule.category,
8287
**durations,
88+
**self.flat_cfg,
8389
**test_results[0],
8490
}
8591
logger.info(f"Completed with result {output}")

0 commit comments

Comments
 (0)