-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial draft * Add wandb sweep image * Refactor logging graph * Modify callbacks init for new design * Update images to hazelnut dataset * Add unwatch to graphlogger callback * Update text to match new design * Ignore mypy error * Replace paroject params * Fix project path * Fix visualizer test * Address PR comments + markdown->rst * Fix torchmetrics version * Fix tests * Add metrics configuration callback to benchmarking * Change wandb_sweep to sweep Co-authored-by: Ashwin Vaidya <ashwinitinvaidya@gmail.com>
- Loading branch information
1 parent
1dcbe1a
commit 3eda262
Showing
26 changed files
with
420 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Log model graph to respective logger.""" | ||
|
||
# Copyright (C) 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
|
||
import torch | ||
from pytorch_lightning import Callback, LightningModule, Trainer | ||
|
||
from anomalib.utils.loggers import AnomalibTensorBoardLogger, AnomalibWandbLogger | ||
|
||
|
||
class GraphLogger(Callback): | ||
"""Log model graph to respective logger.""" | ||
|
||
def on_train_start(self, trainer: Trainer, pl_module: LightningModule) -> None: | ||
"""Log model graph to respective logger. | ||
Args: | ||
trainer: Trainer object which contans reference to loggers. | ||
pl_module: LightningModule object which is logged. | ||
""" | ||
|
||
for logger in trainer.loggers: | ||
if isinstance(logger, AnomalibWandbLogger): | ||
# NOTE: log graph gets populated only after one backward pass. This won't work for models which do not | ||
# require training such as Padim | ||
logger.watch(pl_module, log_graph=True, log="all") | ||
break | ||
|
||
def on_train_end(self, trainer: Trainer, pl_module: LightningModule) -> None: | ||
"""Unwatch model if configured for wandb and log it model graph in Tensorboard if specified. | ||
Args: | ||
trainer: Trainer object which contans reference to loggers. | ||
pl_module: LightningModule object which is logged. | ||
""" | ||
|
||
for logger in trainer.loggers: | ||
if isinstance(logger, AnomalibTensorBoardLogger): | ||
logger.log_graph(pl_module, input_array=torch.ones((1, 3, 256, 256))) | ||
elif isinstance(logger, AnomalibWandbLogger): | ||
logger.unwatch(pl_module) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.. _benchmarking: | ||
|
||
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. | ||
|
||
.. code-block:: yaml | ||
seed: 42 | ||
compute_openvino: false | ||
hardware: | ||
- cpu | ||
- gpu | ||
writer: | ||
- wandb | ||
- tensorboard | ||
grid_search: | ||
dataset: | ||
category: | ||
- colour | ||
- crack | ||
image_size: [128, 256] | ||
model_name: | ||
- padim | ||
- stfpm | ||
This configuration computes the throughput and performance metrics on CPU and GPU for two categories of a custom folder dataset for Padim and STFPM models. To configure a custom dataset, use the respective model configuration file. An example for dataset configuration used in this guide is shown below. Refer `README <https://github.com/openvinotoolkit/anomalib#readme>`_ for more details. | ||
|
||
.. code-block:: yaml | ||
dataset: | ||
name: hazelnut | ||
format: folder | ||
path: path/hazelnut_toy | ||
normal_dir: good # name of the folder containing normal images. | ||
abnormal_dir: colour # name of the folder containing abnormal images. | ||
normal_test_dir: null | ||
task: segmentation # classification or segmentation | ||
mask: path/hazelnut_toy/mask/colour | ||
extensions: .jpg | ||
split_ratio: 0.2 | ||
seed: 0 | ||
image_size: 256 | ||
By default, ``compute_openvino`` is set to ``False`` to support instances where OpenVINO requirements are not installed in the environment. Once installed, this flag can be set to ``True`` to get the throughput on OpenVINO optimized models. The ``writer`` parameter is optional and can be set to ``writer: []`` in case the user only requires a csv file without logging to each respective logger. It is a good practice to set a value of seed to ensure reproducibility across runs and thus, is set to a non-zero value by default. | ||
|
||
Once a configuration is decided, benchmarking can easily be performed by calling | ||
|
||
.. code-block:: bash | ||
python tools/benchmarking/benchmark.py --config <relative/absolute path>/<paramfile>.yaml | ||
A nice feature about the provided benchmarking script is that if the host system has multiple GPUs, the runs are parallelized over all the available GPUs for faster collection of result. |
Oops, something went wrong.