فهرست منبع

add models and convert speed to ms

Blake Blackshear 5 سال پیش
والد
کامیت
bb8e4621f5
5فایلهای تغییر یافته به همراه17 افزوده شده و 20 حذف شده
  1. 9 8
      Dockerfile
  2. 3 3
      detect_objects.py
  3. 2 2
      frigate/edgetpu.py
  4. 1 1
      frigate/object_processing.py
  5. 2 6
      frigate/video.py

+ 9 - 8
Dockerfile

@@ -7,7 +7,7 @@ RUN apt -qq update && apt -qq install --no-install-recommends -y \
     software-properties-common \
     # apt-transport-https ca-certificates \
     build-essential \
-    gnupg wget \
+    gnupg wget unzip \
     # libcap-dev \
     && add-apt-repository ppa:deadsnakes/ppa -y \
     && apt -qq install --no-install-recommends -y \
@@ -44,15 +44,16 @@ RUN apt -qq update && apt -qq install --no-install-recommends -y \
     && rm -rf /var/lib/apt/lists/* \
     && (apt-get autoremove -y; apt-get autoclean -y)
 
-# # symlink the model and labels
-# RUN wget -q https://github.com/google-coral/edgetpu/raw/master/test_data/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite -O mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --trust-server-names
-# RUN wget -q https://dl.google.com/coral/canned_models/coco_labels.txt -O coco_labels.txt --trust-server-names
-# RUN ln -s mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite /frozen_inference_graph.pb
-# RUN ln -s /coco_labels.txt /label_map.pbtext
+# get model and labels
+RUN wget -q https://github.com/google-coral/edgetpu/raw/master/test_data/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite -O /edgetpu_model.tflite --trust-server-names
+RUN wget -q https://dl.google.com/coral/canned_models/coco_labels.txt -O /labelmap.txt --trust-server-names
+RUN wget -q https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip -O /cpu_model.zip && \
+    unzip /cpu_model.zip detect.tflite -d / && \
+    mv /detect.tflite /cpu_model.tflite && \
+    rm /cpu_model.zip
 
 WORKDIR /opt/frigate/
 ADD frigate frigate/
 COPY detect_objects.py .
-COPY benchmark.py .
 
-CMD ["python3", "-u", "benchmark.py"]
+CMD ["python3.7", "-u", "detect_objects.py"]

+ 3 - 3
detect_objects.py

@@ -75,7 +75,7 @@ class CameraWatchdog(threading.Thread):
                 process = camera_process['process']
                 if not process.is_alive():
                     print(f"Process for {name} is not alive. Starting again...")
-                    camera_process['fps'].value = 10.0
+                    camera_process['fps'].value = float(self.config[name]['fps'])
                     camera_process['skipped_fps'].value = 0.0
                     process = mp.Process(target=track_camera, args=(name, self.config[name], FFMPEG_DEFAULT_CONFIG, GLOBAL_OBJECT_CONFIG, 
                         self.tflite_process.detect_lock, self.tflite_process.detect_ready, self.tflite_process.frame_ready, self.tracked_objects_queue, 
@@ -135,7 +135,7 @@ def main():
     camera_processes = {}
     for name, config in CONFIG['cameras'].items():
         camera_processes[name] = {
-            'fps': mp.Value('d', 10.0),
+            'fps': mp.Value('d', float(config[name]['fps'])),
             'skipped_fps': mp.Value('d', 0.0)
         }
         camera_process = mp.Process(target=track_camera, args=(name, config, FFMPEG_DEFAULT_CONFIG, GLOBAL_OBJECT_CONFIG, 
@@ -167,7 +167,7 @@ def main():
         stats = {
             'coral': {
                 'fps': tflite_process.fps.value,
-                'inference_speed': tflite_process.avg_inference_speed.value
+                'inference_speed': round(tflite_process.avg_inference_speed.value*1000, 2)
             }
         }
 

+ 2 - 2
frigate/edgetpu.py

@@ -36,10 +36,10 @@ class ObjectDetector():
         
         if edge_tpu_delegate is None:
             self.interpreter = tflite.Interpreter(
-                model_path=model_file)
+                model_path='/cpu_model.tflite')
         else:
             self.interpreter = tflite.Interpreter(
-                model_path=model_file,
+                model_path='/edgetpu_model.tflite',
                 experimental_delegates=[edge_tpu_delegate])
         
         self.interpreter.allocate_tensors()

+ 1 - 1
frigate/object_processing.py

@@ -13,7 +13,7 @@ import matplotlib.pyplot as plt
 from frigate.util import draw_box_with_label
 from frigate.edgetpu import load_labels
 
-PATH_TO_LABELS = '/lab/labelmap.txt'
+PATH_TO_LABELS = '/labelmap.txt'
 
 LABELS = load_labels(PATH_TO_LABELS)
 cmap = plt.cm.get_cmap('tab10', len(LABELS.keys()))

+ 2 - 6
frigate/video.py

@@ -122,12 +122,9 @@ def track_camera(name, config, ffmpeg_global_config, global_objects_config, dete
     for obj in objects_with_config:
         object_filters[obj] = {**global_object_filters.get(obj, {}), **camera_object_filters.get(obj, {})}
 
-    min_fps = config.get('min_fps', 0)
+    expected_fps = config['fps']
     take_frame = config.get('take_frame', 1)
 
-    # TODO: some kind of watchdog replacement...
-    # watchdog_timeout = config.get('watchdog_timeout', 300)
-
     frame_shape = get_frame_shape(ffmpeg_input)
     frame_size = frame_shape[0] * frame_shape[1] * frame_shape[2]
 
@@ -175,7 +172,6 @@ def track_camera(name, config, ffmpeg_global_config, global_objects_config, dete
         frame_bytes = ffmpeg_process.stdout.read(frame_size)
 
         if not frame_bytes:
-            # TODO: restart the ffmpeg process and track number of restarts
             break
 
         # limit frame rate
@@ -197,7 +193,7 @@ def track_camera(name, config, ffmpeg_global_config, global_objects_config, dete
         motion_boxes = motion_detector.detect(frame)
 
         # skip object detection if we are below the min_fps
-        if frame_num > 50 and fps.value < min_fps:
+        if frame_num > 50 and fps.value < expected_fps-1:
             skipped_fps_tracker.update()
             skipped_fps.value = skipped_fps_tracker.eps()
             continue