Skip to content

Commit

Permalink
Export the flattened config in benchmark CSV. (#2391)
Browse files Browse the repository at this point in the history
* Export the flattened config in benchmark CSV.

Signed-off-by: Weilin Xu <weilin.xu@intel.com>

* Update CHANGELOG

Signed-off-by: Weilin Xu <weilin.xu@intel.com>

* Reuse the existing flatten_dict().

Signed-off-by: Weilin Xu <weilin.xu@intel.com>

---------

Signed-off-by: Weilin Xu <weilin.xu@intel.com>
Co-authored-by: Samet Akcay <samet.akcay@intel.com>
  • Loading branch information
mzweilin and samet-akcay authored Oct 25, 2024
1 parent f4f9b9a commit 42b3ad5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- 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
- Export flat configurations in benchmark CSV results by [mzweilin](https://github.com/mzweilin) in https://github.com/openvinotoolkit/anomalib/pull/2391

### Deprecated

Expand Down
4 changes: 4 additions & 0 deletions src/anomalib/pipelines/benchmark/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from anomalib.pipelines.components import JobGenerator
from anomalib.pipelines.components.utils import get_iterator_from_grid_dict
from anomalib.pipelines.types import PREV_STAGE_RESULT
from anomalib.utils.config import flatten_dict
from anomalib.utils.logging import hide_output

from .job import BenchmarkJob
Expand Down Expand Up @@ -39,9 +40,12 @@ def generate_jobs(
"""Return iterator based on the arguments."""
del previous_stage_result # Not needed for this job
for _container in get_iterator_from_grid_dict(args):
# Pass experimental configs as a flatten dictionary to the job runner.
flat_cfg = flatten_dict(_container)
yield BenchmarkJob(
accelerator=self.accelerator,
seed=_container["seed"],
model=get_model(_container["model"]),
datamodule=get_datamodule(_container["data"]),
flat_cfg=flat_cfg,
)
16 changes: 11 additions & 5 deletions src/anomalib/pipelines/benchmark/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@ class BenchmarkJob(Job):
model (AnomalyModule): The model to use.
datamodule (AnomalibDataModule): The data module to use.
seed (int): The seed to use.
flat_cfg (dict): The flat dictionary of configs with dotted keys.
"""

name = "benchmark"

def __init__(self, accelerator: str, model: AnomalyModule, datamodule: AnomalibDataModule, seed: int) -> None:
def __init__(
self,
accelerator: str,
model: AnomalyModule,
datamodule: AnomalibDataModule,
seed: int,
flat_cfg: dict,
) -> None:
super().__init__()
self.accelerator = accelerator
self.model = model
self.datamodule = datamodule
self.seed = seed
self.flat_cfg = flat_cfg

@hide_output
def run(
Expand Down Expand Up @@ -74,12 +83,9 @@ def run(
# TODO(ashwinvaidya17): Restore throughput
# https://github.com/openvinotoolkit/anomalib/issues/2054
output = {
"seed": self.seed,
"accelerator": self.accelerator,
"model": self.model.__class__.__name__,
"data": self.datamodule.__class__.__name__,
"category": self.datamodule.category,
**durations,
**self.flat_cfg,
**test_results[0],
}
logger.info(f"Completed with result {output}")
Expand Down

0 comments on commit 42b3ad5

Please sign in to comment.