From d7404aa8afc680ea27fd549348ff0c0d81e2e93f Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 22 May 2025 13:59:14 +0100 Subject: [PATCH 1/2] Make OpenVINO fully optional in Anomalib Signed-off-by: Samet Akcay --- src/anomalib/deploy/inferencers/openvino_inferencer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/anomalib/deploy/inferencers/openvino_inferencer.py b/src/anomalib/deploy/inferencers/openvino_inferencer.py index 1327efeb1e..aeac60b656 100644 --- a/src/anomalib/deploy/inferencers/openvino_inferencer.py +++ b/src/anomalib/deploy/inferencers/openvino_inferencer.py @@ -51,17 +51,19 @@ import logging from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import numpy as np import torch from lightning_utilities.core.imports import module_available -from openvino.runtime.utils.data_helpers.wrappers import OVDict from PIL.Image import Image as PILImage from anomalib.data import NumpyImageBatch from anomalib.data.utils import read_image +if TYPE_CHECKING: + from openvino.runtime.utils.data_helpers.wrappers import OVDict + logger = logging.getLogger("anomalib") @@ -177,7 +179,7 @@ def pre_process(image: np.ndarray) -> np.ndarray: return image @staticmethod - def post_process(predictions: OVDict) -> dict: + def post_process(predictions: "OVDict") -> dict: """Convert OpenVINO predictions to dictionary. Args: From 7c09bda50c8b8240afc0f1f16dcfacb65eda9b9d Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 22 May 2025 17:19:41 +0100 Subject: [PATCH 2/2] Fix augmentation application when no model is attached Signed-off-by: Samet Akcay --- src/anomalib/data/datamodules/base/image.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/anomalib/data/datamodules/base/image.py b/src/anomalib/data/datamodules/base/image.py index c006e21633..bb6d883771 100644 --- a/src/anomalib/data/datamodules/base/image.py +++ b/src/anomalib/data/datamodules/base/image.py @@ -165,9 +165,15 @@ def _update_augmentations(self) -> None: for subset_name in ["train", "val", "test"]: subset = getattr(self, f"{subset_name}_data", None) augmentations = getattr(self, f"{subset_name}_augmentations", None) - model_transform = get_nested_attr(self, "trainer.model.pre_processor.transform") - if subset and model_transform: - self._update_subset_augmentations(subset, augmentations, model_transform) + model_transform = get_nested_attr(self, "trainer.model.pre_processor.transform", None) + + if subset: + if model_transform: + # If model transform exists, update augmentations with model-specific transforms + self._update_subset_augmentations(subset, augmentations, model_transform) + else: + # If no model transform, just apply the user-specified augmentations + subset.augmentations = augmentations @staticmethod def _update_subset_augmentations(