From 7b24e01509d028767e195ff3d9d31ccca99ed9dd Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 16 Sep 2025 15:00:50 -0600 Subject: [PATCH] Improve openvino width detection --- .../real_time/custom_classification.py | 16 ++++++++++---- frigate/detectors/detection_runners.py | 21 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/frigate/data_processing/real_time/custom_classification.py b/frigate/data_processing/real_time/custom_classification.py index b62b29882..daa9fee96 100644 --- a/frigate/data_processing/real_time/custom_classification.py +++ b/frigate/data_processing/real_time/custom_classification.py @@ -133,8 +133,12 @@ class CustomStateClassificationProcessor(RealTimeProcessorApi): x:x2, ] - if frame.shape != (224, 224): - frame = cv2.resize(frame, (224, 224)) + if input.shape != (224, 224): + try: + input = cv2.resize(input, (224, 224)) + except Exception: + logger.warning("Failed to resize image for state classification") + return input = np.expand_dims(frame, axis=0) self.interpreter.set_tensor(self.tensor_input_details[0]["index"], input) @@ -254,8 +258,12 @@ class CustomObjectClassificationProcessor(RealTimeProcessorApi): x:x2, ] - if crop.shape != (224, 224): - crop = cv2.resize(crop, (224, 224)) + if input.shape != (224, 224): + try: + input = cv2.resize(input, (224, 224)) + except Exception: + logger.warning("Failed to resize image for object classification") + return input = np.expand_dims(crop, axis=0) self.interpreter.set_tensor(self.tensor_input_details[0]["index"], input) diff --git a/frigate/detectors/detection_runners.py b/frigate/detectors/detection_runners.py index 145fe79b7..c18a4a937 100644 --- a/frigate/detectors/detection_runners.py +++ b/frigate/detectors/detection_runners.py @@ -195,9 +195,24 @@ class OpenVINOModelRunner(BaseModelRunner): def get_input_width(self) -> int: """Get the input width of the model.""" - input_shape = self.compiled_model.inputs[0].get_shape() - # Assuming NCHW format, width is the last dimension - return int(input_shape[-1]) + input_info = self.compiled_model.inputs + first_input = input_info[0] + + try: + partial_shape = first_input.get_partial_shape() + # width dimension + if len(partial_shape) >= 4 and partial_shape[3].is_static: + return partial_shape[3].get_length() + + # If width is dynamic or we can't determine it + return -1 + except Exception: + try: + # gemini says some ov versions might still allow this + input_shape = first_input.shape + return input_shape[3] if len(input_shape) >= 4 else -1 + except Exception: + return -1 def run(self, inputs: dict[str, Any]) -> list[np.ndarray]: """Run inference with the model.