From bb8e4621f5d7d2801d751bb7a6ee29058be742cb Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Tue, 18 Feb 2020 05:55:06 -0600 Subject: [PATCH] add models and convert speed to ms --- Dockerfile | 17 +++++++++-------- detect_objects.py | 6 +++--- frigate/edgetpu.py | 4 ++-- frigate/object_processing.py | 2 +- frigate/video.py | 8 ++------ 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5289b5a89..9478692d4 100755 --- a/Dockerfile +++ b/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"] diff --git a/detect_objects.py b/detect_objects.py index 2c700f2a3..5d549801e 100644 --- a/detect_objects.py +++ b/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) } } diff --git a/frigate/edgetpu.py b/frigate/edgetpu.py index 1aecaeb48..6532d2096 100644 --- a/frigate/edgetpu.py +++ b/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() diff --git a/frigate/object_processing.py b/frigate/object_processing.py index b5c6c9abb..f2b0986ac 100644 --- a/frigate/object_processing.py +++ b/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())) diff --git a/frigate/video.py b/frigate/video.py index b67b0172d..937a448ca 100755 --- a/frigate/video.py +++ b/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