From acfacaaa5de8f473b5cb0a83f98a1435f9b7a3cb Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 22 Oct 2024 09:40:31 -0600 Subject: [PATCH] Handle larger images --- frigate/embeddings/functions/onnx.py | 11 +++++++++++ frigate/embeddings/maintainer.py | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/frigate/embeddings/functions/onnx.py b/frigate/embeddings/functions/onnx.py index 4e7983882..fd74d4768 100644 --- a/frigate/embeddings/functions/onnx.py +++ b/frigate/embeddings/functions/onnx.py @@ -193,6 +193,17 @@ class GenericONNXEmbedding: raise ValueError("Face embedding does not support batch inputs.") pil = self._process_image(raw_inputs) + + # handle images larger than input size + width, height = pil.size + if width > 112 or height > 112: + if width > height: + new_height = int(((width / height) * 112) // 4 * 4) + pil = pil.resize((112, new_height)) + else: + new_width = int(((height / width) * 112) // 4 * 4) + pil = pil.resize((new_width, 112)) + og = np.array(pil).astype(np.float32) # Image must be 112x112 diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 1e7606400..1bf2ade09 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -26,7 +26,7 @@ from frigate.events.types import EventTypeEnum from frigate.genai import get_genai_client from frigate.models import Event from frigate.util.builtin import serialize -from frigate.util.image import SharedMemoryFrameManager, calculate_region, area +from frigate.util.image import SharedMemoryFrameManager, area, calculate_region from .embeddings import Embeddings @@ -318,7 +318,10 @@ class EmbeddingMaintainer(threading.Thread): face_box = face.get("box") # check that face is valid - if not face_box or area(face_box) < self.config.semantic_search.face_recognition.min_area: + if ( + not face_box + or area(face_box) < self.config.semantic_search.face_recognition.min_area + ): return face_frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)