From 2a546fb21b8213278792b143c6cababfd14f6eb9 Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Wed, 24 May 2023 15:57:07 +0200 Subject: [PATCH] Patch release 0.5.1 (#1101) * Set init_state_dict * pass openvino metadata as config * DictConfig -> dict * Update changelog * Update date * metadata_path -> metadata --------- Co-authored-by: Ashwin Vaidya --- CHANGELOG.md | 6 +++++- .../001_getting_started.ipynb | 16 ++++++++++++---- pyproject.toml | 2 +- src/anomalib/__init__.py | 2 +- .../deploy/inferencers/openvino_inferencer.py | 11 +++++------ src/anomalib/utils/callbacks/nncf/callback.py | 5 ++++- src/anomalib/utils/sweep/helpers/inference.py | 2 +- tools/inference/gradio_inference.py | 8 ++++---- tools/inference/openvino_inference.py | 2 +- 9 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c95d12689..a687b797ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [Unreleased] +## [v0.5.1] - 2023-05-24 ### Added ### Changed +- Rename `metadata_path` to `metadata` in `OpenvinoInferencer` in https://github.com/openvinotoolkit/anomalib/pull/1101 + ### Deprecated ###  Fixed +- Fix `init_state_dict` bug in `wrap_nncf_model` in https://github.com/openvinotoolkit/anomalib/pull/1101 + ## [v0.5.0] - 2023-05-09 ### Added diff --git a/notebooks/000_getting_started/001_getting_started.ipynb b/notebooks/000_getting_started/001_getting_started.ipynb index 18e0ed2d87..66a636bace 100644 --- a/notebooks/000_getting_started/001_getting_started.ipynb +++ b/notebooks/000_getting_started/001_getting_started.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -112,6 +113,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -166,6 +168,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -187,6 +190,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -204,6 +208,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -237,6 +242,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -261,6 +267,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -322,6 +329,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -434,8 +442,8 @@ ], "source": [ "openvino_model_path = output_path / \"weights\" / \"openvino\" / \"model.bin\"\n", - "metadata_path = output_path / \"weights\" / \"openvino\" / \"metadata.json\"\n", - "print(openvino_model_path.exists(), metadata_path.exists())" + "metadata = output_path / \"weights\" / \"openvino\" / \"metadata.json\"\n", + "print(openvino_model_path.exists(), metadata.exists())" ] }, { @@ -446,7 +454,7 @@ "source": [ "inferencer = OpenVINOInferencer(\n", " path=openvino_model_path, # Path to the OpenVINO IR model.\n", - " metadata_path=metadata_path, # Path to the metadata file.\n", + " metadata=metadata, # Path to the metadata file.\n", " device=\"CPU\", # We would like to run it on an Intel CPU.\n", ")" ] @@ -699,7 +707,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.10.11" }, "orig_nbformat": 4, "vscode": { diff --git a/pyproject.toml b/pyproject.toml index cd51ccaafe..e72fb7d30a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ show_error_codes = true [[tool.mypy.overrides]] -module = "torch.*" +module = ["torch.*", "wandb.*"] follow_imports = "skip" follow_imports_for_stubs = true diff --git a/src/anomalib/__init__.py b/src/anomalib/__init__.py index 3df4c49194..442773321a 100644 --- a/src/anomalib/__init__.py +++ b/src/anomalib/__init__.py @@ -3,4 +3,4 @@ # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -__version__ = "1.0.0dev" +__version__ = "0.5.1" diff --git a/src/anomalib/deploy/inferencers/openvino_inferencer.py b/src/anomalib/deploy/inferencers/openvino_inferencer.py index 8fd1571145..bb3e8b44b2 100644 --- a/src/anomalib/deploy/inferencers/openvino_inferencer.py +++ b/src/anomalib/deploy/inferencers/openvino_inferencer.py @@ -19,9 +19,7 @@ from .base_inferencer import Inferencer if find_spec("openvino") is not None: - from openvino.inference_engine import ( # type: ignore # pylint: disable=no-name-in-module - IECore, - ) + from openvino.inference_engine import IECore # type: ignore # pylint: disable=no-name-in-module class OpenVINOInferencer(Inferencer): @@ -29,7 +27,8 @@ class OpenVINOInferencer(Inferencer): Args: path (str | Path): Path to the openvino onnx, xml or bin file. - metadata_path (str | Path, optional): Path to metadata file. Defaults to None. + metadata (str | Path | dict, optional): Path to metadata file or a dict object defining the + metadata. Defaults to None. device (str | None, optional): Device to run the inference on. Defaults to "CPU". task (TaskType | None, optional): Task type. Defaults to None. """ @@ -37,13 +36,13 @@ class OpenVINOInferencer(Inferencer): def __init__( self, path: str | Path | tuple[bytes, bytes], - metadata_path: str | Path | None = None, + metadata: str | Path | dict | None = None, device: str | None = "CPU", task: str | None = None, ) -> None: self.device = device self.input_blob, self.output_blob, self.network = self.load_model(path) - self.metadata = super()._load_metadata(metadata_path) + self.metadata = metadata if isinstance(metadata, dict) else super()._load_metadata(metadata) self.task = TaskType(task) if task else TaskType(self.metadata["task"]) def load_model(self, path: str | Path | tuple[bytes, bytes]): diff --git a/src/anomalib/utils/callbacks/nncf/callback.py b/src/anomalib/utils/callbacks/nncf/callback.py index 3dfbb3e532..8079d0835f 100644 --- a/src/anomalib/utils/callbacks/nncf/callback.py +++ b/src/anomalib/utils/callbacks/nncf/callback.py @@ -52,7 +52,10 @@ def setup(self, trainer: pl.Trainer, pl_module: pl.LightningModule, stage: str | config = register_default_init_args(self.config, init_loader) self.nncf_ctrl, pl_module.model = wrap_nncf_model( - model=pl_module.model, config=config, dataloader=trainer.datamodule.train_dataloader() # type: ignore + model=pl_module.model, + config=config, + dataloader=trainer.datamodule.train_dataloader(), # type: ignore + init_state_dict=None, # type: ignore ) def on_train_batch_start( diff --git a/src/anomalib/utils/sweep/helpers/inference.py b/src/anomalib/utils/sweep/helpers/inference.py index 20f0cde30c..be204a6914 100644 --- a/src/anomalib/utils/sweep/helpers/inference.py +++ b/src/anomalib/utils/sweep/helpers/inference.py @@ -61,7 +61,7 @@ def get_openvino_throughput(model_path: str | Path, test_dataset: Dataset) -> fl inferencer = OpenVINOInferencer( path=model_path / "weights" / "openvino" / "model.xml", - metadata_path=model_path / "weights" / "openvino" / "metadata.json", + metadata=model_path / "weights" / "openvino" / "metadata.json", ) start_time = time.time() for image_path in test_dataset.samples.image_path: diff --git a/tools/inference/gradio_inference.py b/tools/inference/gradio_inference.py index 7d4e5f5ca7..09265d5808 100644 --- a/tools/inference/gradio_inference.py +++ b/tools/inference/gradio_inference.py @@ -40,12 +40,12 @@ def get_parser() -> ArgumentParser: return parser -def get_inferencer(weight_path: Path, metadata_path: Path | None = None) -> Inferencer: +def get_inferencer(weight_path: Path, metadata: Path | None = None) -> Inferencer: """Parse args and open inferencer. Args: weight_path (Path): Path to model weights. - metadata_path (Path | None, optional): Metadata is required for OpenVINO models. Defaults to None. + metadata (Path | None, optional): Metadata is required for OpenVINO models. Defaults to None. Raises: ValueError: If unsupported model weight is passed. @@ -64,11 +64,11 @@ def get_inferencer(weight_path: Path, metadata_path: Path | None = None) -> Infe inferencer = torch_inferencer(path=weight_path) elif extension in (".onnx", ".bin", ".xml"): - if metadata_path is None: + if metadata is None: raise ValueError("When using OpenVINO Inferencer, the following arguments are required: --metadata") openvino_inferencer = getattr(module, "OpenVINOInferencer") - inferencer = openvino_inferencer(path=weight_path, metadata_path=metadata_path) + inferencer = openvino_inferencer(path=weight_path, metadata=metadata) else: raise ValueError( diff --git a/tools/inference/openvino_inference.py b/tools/inference/openvino_inference.py index df1848fc3c..911016cbb3 100644 --- a/tools/inference/openvino_inference.py +++ b/tools/inference/openvino_inference.py @@ -71,7 +71,7 @@ def infer(args: Namespace) -> None: args (Namespace): The arguments from the command line. """ # Get the inferencer. - inferencer = OpenVINOInferencer(path=args.weights, metadata_path=args.metadata, device=args.device) + inferencer = OpenVINOInferencer(path=args.weights, metadata=args.metadata, device=args.device) visualizer = Visualizer(mode=args.visualization_mode, task=args.task) filenames = get_image_filenames(path=args.input)