From 6be4c802396ce7aa393f89a60d141f739dc867e3 Mon Sep 17 00:00:00 2001 From: TurboJonte Date: Mon, 25 Mar 2024 14:02:27 +0100 Subject: [PATCH] Changed prediction label assignment for OpenVINO inferencer (#1872) * Update openvino_inferencer.py Fixed incorrect label assignment. Was True/False, now it's "Anomalous/Normal" as for the PyTorch inferencer in torch_inferencer.py * Fix ruff --------- Co-authored-by: Samet --- src/anomalib/deploy/inferencers/openvino_inferencer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/anomalib/deploy/inferencers/openvino_inferencer.py b/src/anomalib/deploy/inferencers/openvino_inferencer.py index 98cb2e498c..db0d966fad 100644 --- a/src/anomalib/deploy/inferencers/openvino_inferencer.py +++ b/src/anomalib/deploy/inferencers/openvino_inferencer.py @@ -15,6 +15,7 @@ from PIL import Image from anomalib import TaskType +from anomalib.data.utils.label import LabelName from anomalib.utils.visualization import ImageResult from .base_inferencer import Inferencer @@ -253,7 +254,7 @@ def post_process(self, predictions: np.ndarray, metadata: dict | DictConfig | No # Initialize the result variables. anomaly_map: np.ndarray | None = None - pred_label: float | None = None + pred_label: LabelName | None = None pred_mask: float | None = None # If predictions returns a single value, this means that the task is @@ -270,7 +271,8 @@ def post_process(self, predictions: np.ndarray, metadata: dict | DictConfig | No # label to the prediction if the prediction score is greater # than the image threshold. if "image_threshold" in metadata: - pred_label = pred_score >= metadata["image_threshold"] + pred_idx = pred_score >= metadata["image_threshold"] + pred_label = LabelName.ABNORMAL if pred_idx else LabelName.NORMAL if task == TaskType.CLASSIFICATION: _, pred_score = self._normalize(pred_scores=pred_score, metadata=metadata)