diff --git a/src/anomalib/deploy/inferencers/openvino_inferencer.py b/src/anomalib/deploy/inferencers/openvino_inferencer.py index bb57a8d65a..be148dabf6 100644 --- a/src/anomalib/deploy/inferencers/openvino_inferencer.py +++ b/src/anomalib/deploy/inferencers/openvino_inferencer.py @@ -21,14 +21,6 @@ logger = logging.getLogger("anomalib") -if find_spec("openvino") is not None: - import openvino as ov - - if TYPE_CHECKING: - from openvino import CompiledModel -else: - logger.warning("OpenVINO is not installed. Please install OpenVINO to use OpenVINOInferencer.") - class OpenVINOInferencer(Inferencer): """OpenVINO implementation for the inference. @@ -102,6 +94,11 @@ def __init__( task: str | None = None, config: dict | None = None, ) -> None: + try: + import openvino as ov + except ImportError: + logger.warning("OpenVINO is not installed. Please install OpenVINO to use OpenVINOInferencer.") + raise self.device = device self.config = config @@ -121,6 +118,8 @@ def load_model(self, path: str | Path | tuple[bytes, bytes]) -> tuple[Any, Any, [tuple[str, str, ExecutableNetwork]]: Input and Output blob names together with the Executable network. """ + import openvino as ov + core = ov.Core() # If tuple of bytes is passed if isinstance(path, tuple):