From e4da3822b132e1195c1f781eb1f20c2e2be045d5 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 11 Oct 2020 09:40:20 -0500 Subject: [PATCH] cleanup detection shms --- detect_objects.py | 10 +++++++++- frigate/edgetpu.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/detect_objects.py b/detect_objects.py index cb59bd71d..ee2749fb4 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -174,10 +174,15 @@ def main(): # Queue for clip processing event_queue = mp.Queue() - # create the detection pipes + # create the detection pipes and shms out_events = {} + camera_shms = [] for name in CONFIG['cameras'].keys(): out_events[name] = mp.Event() + shm_in = mp.shared_memory.SharedMemory(name=name, create=True, size=300*300*3) + shm_out = mp.shared_memory.SharedMemory(name=f"out-{name}", create=True, size=20*6*4) + camera_shms.append(shm_in) + camera_shms.append(shm_out) detection_queue = mp.Queue() @@ -302,6 +307,9 @@ def main(): camera_process['capture_thread'].join() for detector in detectors: detector.stop() + for shm in camera_shms: + shm.close() + shm.unlink() sys.exit() signal.signal(signal.SIGTERM, receiveSignal) diff --git a/frigate/edgetpu.py b/frigate/edgetpu.py index 10bf7ede9..90f9a7aea 100644 --- a/frigate/edgetpu.py +++ b/frigate/edgetpu.py @@ -165,9 +165,9 @@ class RemoteObjectDetector(): self.fps = EventsPerSecond() self.detection_queue = detection_queue self.event = event - self.shm = mp.shared_memory.SharedMemory(name=self.name, create=True, size=300*300*3) + self.shm = mp.shared_memory.SharedMemory(name=self.name, create=False) self.np_shm = np.ndarray((1,300,300,3), dtype=np.uint8, buffer=self.shm.buf) - self.out_shm = mp.shared_memory.SharedMemory(name=f"out-{self.name}", create=True, size=20*6*4) + self.out_shm = mp.shared_memory.SharedMemory(name=f"out-{self.name}", create=False) self.out_np_shm = np.ndarray((20,6), dtype=np.float32, buffer=self.out_shm.buf) def detect(self, tensor_input, threshold=.4):