From 0f60f9cf62cdbdd8958902a5ef7dad4a015f8986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Rolih?= <61357777+blaz-r@users.noreply.github.com> Date: Mon, 3 Apr 2023 23:07:37 +0200 Subject: [PATCH] Fixed openvino_inferencer in gradio_inference (#972) * Fixed openvino_inferencer in gradio_inference * Adjusted required arguments for gradio inference --- tools/inference/gradio_inference.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/inference/gradio_inference.py b/tools/inference/gradio_inference.py index 2bc4df224e..1600621439 100644 --- a/tools/inference/gradio_inference.py +++ b/tools/inference/gradio_inference.py @@ -34,7 +34,7 @@ def get_args() -> Namespace: Namespace: List of arguments. """ parser = ArgumentParser() - parser.add_argument("--config", type=Path, required=True, help="Path to a config file") + parser.add_argument("--config", type=Path, required=False, help="Path to a config file") parser.add_argument("--weights", type=Path, required=True, help="Path to model weights") parser.add_argument("--metadata", type=Path, required=False, help="Path to a JSON file containing the metadata.") parser.add_argument("--share", type=bool, required=False, default=False, help="Share Gradio `share_url`") @@ -63,12 +63,18 @@ def get_inferencer(config_path: Path, weight_path: Path, metadata_path: Path | N inferencer: Inferencer module = import_module("anomalib.deploy") if extension in (".ckpt"): + if config_path is None: + raise ValueError("When using Torch Inferencer, the following arguments are required: --config") + torch_inferencer = getattr(module, "TorchInferencer") inferencer = torch_inferencer(config=config_path, model_source=weight_path, metadata_path=metadata_path) elif extension in (".onnx", ".bin", ".xml"): + if metadata_path is None: + raise ValueError("When using OpenVINO Inferencer, the following arguments are required: --metadata") + openvino_inferencer = getattr(module, "OpenVINOInferencer") - inferencer = openvino_inferencer(config=config_path, path=weight_path, metadata_path=metadata_path) + inferencer = openvino_inferencer(path=weight_path, metadata_path=metadata_path) else: raise ValueError(