Skip to content

Commit

Permalink
Fixed openvino_inferencer in gradio_inference (#972)
Browse files Browse the repository at this point in the history
* Fixed openvino_inferencer in gradio_inference

* Adjusted required arguments for gradio inference
  • Loading branch information
blaz-r authored Apr 3, 2023
1 parent e116398 commit 0f60f9c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/inference/gradio_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0f60f9c

Please sign in to comment.