Browse Source

stop using pycoral libs for efficiency

Blake Blackshear 3 năm trước cách đây
mục cha
commit
2181379475
3 tập tin đã thay đổi với 21 bổ sung17 xóa
  1. 15 10
      frigate/edgetpu.py
  2. 2 2
      frigate/events.py
  3. 4 5
      frigate/video.py

+ 15 - 10
frigate/edgetpu.py

@@ -9,7 +9,6 @@ from abc import ABC, abstractmethod
 from typing import Dict
 
 import numpy as np
-from pycoral.adapters import detect
 import tflite_runtime.interpreter as tflite
 from setproctitle import setproctitle
 from tflite_runtime.interpreter import load_delegate
@@ -103,19 +102,25 @@ class LocalObjectDetector(ObjectDetector):
         self.interpreter.set_tensor(self.tensor_input_details[0]["index"], tensor_input)
         self.interpreter.invoke()
 
-        objects = detect.get_objects(self.interpreter, 0.4)
+        boxes = self.interpreter.tensor(self.tensor_output_details[0]["index"])()[0]
+        class_ids = self.interpreter.tensor(self.tensor_output_details[1]["index"])()[0]
+        scores = self.interpreter.tensor(self.tensor_output_details[2]["index"])()[0]
+        count = int(
+            self.interpreter.tensor(self.tensor_output_details[3]["index"])()[0]
+        )
 
         detections = np.zeros((20, 6), np.float32)
-        for i, obj in enumerate(objects):
-            if i == 20:
+
+        for i in range(count):
+            if scores[i] < 0.4 or i == 20:
                 break
             detections[i] = [
-                obj.id,
-                obj.score,
-                obj.bbox.ymin,
-                obj.bbox.xmin,
-                obj.bbox.ymax,
-                obj.bbox.xmax,
+                class_ids[i],
+                float(scores[i]),
+                boxes[i][0],
+                boxes[i][1],
+                boxes[i][2],
+                boxes[i][3],
             ]
 
         return detections

+ 2 - 2
frigate/events.py

@@ -112,7 +112,7 @@ class EventCleanup(threading.Thread):
     def expire(self, media_type):
         ## Expire events from unlisted cameras based on the global config
         if media_type == "clips":
-            retain_config = self.config.clips.retain
+            retain_config = self.config.record.events.retain
             file_extension = "mp4"
             update_params = {"has_clip": False}
         else:
@@ -163,7 +163,7 @@ class EventCleanup(threading.Thread):
         ## Expire events from cameras based on the camera config
         for name, camera in self.config.cameras.items():
             if media_type == "clips":
-                retain_config = camera.clips.retain
+                retain_config = camera.record.events.retain
             else:
                 retain_config = camera.snapshots.retain
             # get distinct objects in database for this camera

+ 4 - 5
frigate/video.py

@@ -413,17 +413,16 @@ def detect(
     object_detector, frame, model_shape, region, objects_to_track, object_filters
 ):
     tensor_input = create_tensor_input(frame, model_shape, region)
-    scale = float(region[2] - region[0]) / model_shape[0]
 
     detections = []
     region_detections = object_detector.detect(tensor_input)
     for d in region_detections:
         box = d[2]
         size = region[2] - region[0]
-        x_min = int(max(0, box[1]) * scale + region[0])
-        y_min = int(max(0, box[0]) * scale + region[1])
-        x_max = int(min(frame.shape[1], box[3]) * scale + region[0])
-        y_max = int(min(frame.shape[0], box[2]) * scale + region[1])
+        x_min = int((box[1] * size) + region[0])
+        y_min = int((box[0] * size) + region[1])
+        x_max = int((box[3] * size) + region[0])
+        y_max = int((box[2] * size) + region[1])
         det = (
             d[0],
             d[1],