Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/anomalib/deploy/inferencers/openvino_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from importlib.util import find_spec
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import Any

import cv2
import numpy as np
from lightning_utilities.core.imports import package_available
from omegaconf import DictConfig
from PIL import Image

Expand All @@ -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.
Expand Down Expand Up @@ -102,6 +94,10 @@ def __init__(
task: str | None = None,
config: dict | None = None,
) -> None:
if not package_available("openvino"):
msg = "OpenVINO is not installed. Please install OpenVINO to use OpenVINOInferencer."
raise ImportError(msg)

self.device = device

self.config = config
Expand All @@ -110,7 +106,7 @@ def __init__(

self.task = TaskType(task) if task else TaskType(self.metadata["task"])

def load_model(self, path: str | Path | tuple[bytes, bytes]) -> tuple[Any, Any, "CompiledModel"]:
def load_model(self, path: str | Path | tuple[bytes, bytes]) -> tuple[Any, Any, Any]:
"""Load the OpenVINO model.

Args:
Expand All @@ -121,6 +117,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):
Expand Down