From f5ff975530a61c13462c62362331d859a1c3eeb2 Mon Sep 17 00:00:00 2001 From: Dennis George Date: Fri, 9 Dec 2022 15:21:17 -0600 Subject: [PATCH] adjust SharedMemory size to largest detector model shape --- frigate/app.py | 10 ++++------ frigate/object_detection.py | 27 ++++++--------------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/frigate/app.py b/frigate/app.py index e1cbef35a..88a23774b 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -186,10 +186,11 @@ class FrigateApp: self.detection_out_events[name] = mp.Event() try: + size = max([det.model.height * det.model.width * 3 for (name, det) in self.config.detectors.items()]) shm_in = mp.shared_memory.SharedMemory( name=name, create=True, - size=self.config.model.height * self.config.model.width * 3, + size=size, ) except FileExistsError: shm_in = mp.shared_memory.SharedMemory(name=name) @@ -204,15 +205,12 @@ class FrigateApp: self.detection_shms.append(shm_in) self.detection_shms.append(shm_out) - for name, detector in self.config.detectors.items(): + for name, detector_config in self.config.detectors.items(): self.detectors[name] = ObjectDetectProcess( name, self.detection_queue, self.detection_out_events, - self.config.model, - detector.type, - detector.device, - detector.num_threads, + detector_config, ) def start_detected_frames_processor(self) -> None: diff --git a/frigate/object_detection.py b/frigate/object_detection.py index e949ebfdc..bbbc376cf 100644 --- a/frigate/object_detection.py +++ b/frigate/object_detection.py @@ -79,10 +79,7 @@ def run_detector( out_events: dict[str, mp.Event], avg_speed, start, - model_config, - det_type, - det_device, - num_threads, + detector_config, ): threading.current_thread().name = f"detector:{name}" logger = logging.getLogger(f"detector.{name}") @@ -100,10 +97,7 @@ def run_detector( frame_manager = SharedMemoryFrameManager() object_detector = LocalObjectDetector( - det_type=det_type, - det_device=det_device, - model_config=model_config, - num_threads=num_threads, + detector_config=detector_config ) outputs = {} @@ -118,7 +112,7 @@ def run_detector( except queue.Empty: continue input_frame = frame_manager.get( - connection_id, (1, model_config.height, model_config.width, 3) + connection_id, (1, detector_config.model.height, detector_config.model.width, 3) ) if input_frame is None: @@ -141,10 +135,7 @@ class ObjectDetectProcess: name, detection_queue, out_events, - model_config, - det_type=None, - det_device=None, - num_threads=3, + detector_config, ): self.name = name self.out_events = out_events @@ -152,10 +143,7 @@ class ObjectDetectProcess: self.avg_inference_speed = mp.Value("d", 0.01) self.detection_start = mp.Value("d", 0.0) self.detect_process = None - self.model_config = model_config - self.det_type = det_type - self.det_device = det_device - self.num_threads = num_threads + self.detector_config = detector_config self.start_or_restart() def stop(self): @@ -180,10 +168,7 @@ class ObjectDetectProcess: self.out_events, self.avg_inference_speed, self.detection_start, - self.model_config, - self.det_type, - self.det_device, - self.num_threads, + self.detector_config, ), ) self.detect_process.daemon = True