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

Benchmarking tool with Comet #545

Merged
merged 6 commits into from
Sep 14, 2022
Merged
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
3 changes: 2 additions & 1 deletion docs/source/guides/benchmarking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Benchmarking
=============

To add to the suit of experiment tracking and optimization, anomalib also includes a benchmarking script for gathering results across different combinations of models, their parameters, and dataset categories. The model performance and throughputs are logged into a csv file that can also serve as a means to track model drift. Optionally, these same results can be logged to Weights and Biases and TensorBoard. A sample configuration file is shown below.
To add to the suit of experiment tracking and optimization, anomalib also includes a benchmarking script for gathering results across different combinations of models, their parameters, and dataset categories. The model performance and throughputs are logged into a csv file that can also serve as a means to track model drift. Optionally, these same results can be logged to Comet, Weights and Biases and TensorBoard. A sample configuration file is shown below.

.. code-block:: yaml
Expand All @@ -13,6 +13,7 @@ To add to the suit of experiment tracking and optimization, anomalib also includ
- cpu
- gpu
writer:
- comet
- wandb
- tensorboard
grid_search:
Expand Down
4 changes: 3 additions & 1 deletion tools/benchmarking/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import torch
from omegaconf import DictConfig, ListConfig, OmegaConf
from pytorch_lightning import Trainer, seed_everything
from utils import convert_to_openvino, upload_to_wandb, write_metrics
from utils import convert_to_openvino, upload_to_comet, upload_to_wandb, write_metrics

from anomalib.config import get_configurable_parameters, update_input_size_config
from anomalib.data import get_datamodule
Expand Down Expand Up @@ -225,6 +225,8 @@ def distribute(config: Union[DictConfig, ListConfig]):
distribute_over_gpus(config, folder=runs_folder)
if "wandb" in config.writer:
upload_to_wandb(team="anomalib", folder=runs_folder)
if "comet" in config.writer:
upload_to_comet(folder=runs_folder)
ashwinvaidya17 marked this conversation as resolved.
Show resolved Hide resolved


def sweep(
Expand Down
4 changes: 2 additions & 2 deletions tools/benchmarking/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# SPDX-License-Identifier: Apache-2.0

from .convert import convert_to_openvino
from .metrics import upload_to_wandb, write_metrics
from .metrics import upload_to_comet, upload_to_wandb, write_metrics

__all__ = ["convert_to_openvino", "write_metrics", "upload_to_wandb"]
__all__ = ["convert_to_openvino", "write_metrics", "upload_to_comet", "upload_to_wandb"]
27 changes: 27 additions & 0 deletions tools/benchmarking/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Dict, List, Optional, Union

import pandas as pd
from comet_ml import Experiment
from torch.utils.tensorboard.writer import SummaryWriter

import wandb
Expand Down Expand Up @@ -116,3 +117,29 @@ def upload_to_wandb(
)
wandb.log(row)
wandb.finish()


def upload_to_comet(
folder: Optional[str] = None,
):
"""Upload the data in csv files to comet.

Creates a project named benchmarking_[two random characters]. This is so that the project names are unique.
One issue is that it does not check for collision

Args:
folder (optional, str): Sub-directory from which runs are picked up. Defaults to None. If none picks from runs.
"""
project = f"benchmarking_{get_unique_key(2)}"
tag_list = ["dataset.category", "model_name", "dataset.image_size", "model.backbone", "device"]
search_path = "runs/*.csv" if folder is None else f"runs/{folder}/*.csv"
for csv_file in glob(search_path):
table = pd.read_csv(csv_file)
for index, row in table.iterrows():
row = dict(row[1:]) # remove index column
tags = [str(row[column]) for column in tag_list if column in row.keys()]
experiment = Experiment(project_name=project)
ashwinvaidya17 marked this conversation as resolved.
Show resolved Hide resolved
experiment.set_name(f"{row['model_name']}_{row['dataset.category']}_{index}")
experiment.log_metrics(row, step=1, epoch=1) # populates auto-generated charts on panel view
experiment.add_tags(tags)
experiment.log_table(filename=csv_file)