Compare commits

..
35 Commits
Author SHA1 Message Date
Blake Blackshear 30ad0e30f8 allow mqtt password to be set by env var 2020-03-01 07:23:56 -06:00
Blake Blackshear 7bad89c9bf update benchmark script to mirror actual frigate use 2020-03-01 07:16:56 -06:00
Blake Blackshear f077c397f4 improve detection processing and restart when stuck 2020-03-01 07:16:49 -06:00
Blake Blackshear cc729d83a8 handle ffmpeg process failures in the camera process itself 2020-02-26 19:02:12 -06:00
Blake Blackshear c520b81e49 add a few print statements for debugging 2020-02-25 20:37:12 -06:00
Blake Blackshear 9c304391c0 dont kill the camera process from the main process 2020-02-25 20:36:30 -06:00
Blake Blackshear 9a12b02d22 increase the buffer size a bit 2020-02-24 20:05:30 -06:00
Blake Blackshear 7686c510b3 add a few more metrics to debug 2020-02-23 18:11:39 -06:00
Blake Blackshear 2f5e322d3c cleanup the plasma store when finished with a frame 2020-02-23 18:11:08 -06:00
Blake Blackshear 1cd4c12104 dont redirect stdout for plasma store 2020-02-23 15:53:17 -06:00
Blake Blackshear 1a8b034685 reset detection fps 2020-02-23 15:53:00 -06:00
Blake Blackshear da6dc03a57 dont change dictionary while iterating 2020-02-23 11:18:00 -06:00
Blake Blackshear 7fa3b70d2d allow specifying the frame size in the config instead of detecting 2020-02-23 07:56:14 -06:00
Blake Blackshear 1fc5a2bfd4 ensure missing objects are expired even when other object types are in the frame 2020-02-23 07:55:51 -06:00
Blake Blackshear 7e84da7dad Fix watchdog last_frame calculation 2020-02-23 07:55:16 -06:00
Blake Blackshear 128be72e28 cleanup 2020-02-22 09:15:29 -06:00
Blake Blackshear aaddedc95c update docs and add back benchmark 2020-02-22 09:10:37 -06:00
Blake Blackshear ba919fb439 fix watchdog 2020-02-22 09:10:37 -06:00
Blake Blackshear b1d563f3c4 check avg wait before dropping frames 2020-02-22 09:10:37 -06:00
Blake Blackshear 204d8af5df fix watchdog restart 2020-02-22 09:10:37 -06:00
Blake Blackshear b507a73d79 improve watchdog and coral fps tracking 2020-02-22 09:10:37 -06:00
Blake Blackshear 66eeb8b5cb dont log http requests 2020-02-22 09:10:37 -06:00
Blake Blackshear efa67067c6 cleanup 2020-02-22 09:10:37 -06:00
Blake Blackshear aeb036f1a4 add models and convert speed to ms 2020-02-22 09:10:37 -06:00
Blake Blackshear 74c528f9dc add watchdog for camera processes 2020-02-22 09:10:34 -06:00
Blake Blackshear f2d54bec43 cleanup old code 2020-02-22 09:09:36 -06:00
Blake Blackshear f07d57741e add a min_fps option 2020-02-22 09:06:46 -06:00
Blake Blackshear 2c1ec19f98 check plasma store and consolidate frame drawing 2020-02-22 09:06:46 -06:00
Blake Blackshear 6a9027c002 split into separate processes 2020-02-22 09:06:43 -06:00
Blake Blackshear 60c15e4419 update tflite to 2.1.0 2020-02-22 09:05:26 -06:00
Blake Blackshear 03dbf600aa refactor some classes into new files 2020-02-22 09:05:26 -06:00
Blake Blackshear fbbb79b31b tweak process handoff 2020-02-22 09:05:26 -06:00
Blake Blackshear 496c6bc6c4 Mostly working detection in a separate process 2020-02-22 09:05:26 -06:00
Blake Blackshear 869a81c944 read from ffmpeg 2020-02-22 09:05:26 -06:00
Blake Blackshear 5b1884cfb3 WIP: revamp to incorporate motion 2020-02-22 09:05:26 -06:00
5 changed files with 29 additions and 40 deletions
+3 -3
View File
@@ -38,9 +38,9 @@ RUN apt -qq update && apt -qq install --no-install-recommends -y \
&& apt -qq install --no-install-recommends -y \
libedgetpu1-max \
## Tensorflow lite (python 3.7 only)
&& wget -q https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl \
&& python3.7 -m pip install tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl \
&& rm tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl \
&& wget -q https://dl.google.com/coral/python/tflite_runtime-2.1.0-cp37-cp37m-linux_x86_64.whl \
&& python3.7 -m pip install tflite_runtime-2.1.0-cp37-cp37m-linux_x86_64.whl \
&& rm tflite_runtime-2.1.0-cp37-cp37m-linux_x86_64.whl \
&& rm -rf /var/lib/apt/lists/* \
&& (apt-get autoremove -y; apt-get autoclean -y)
+12 -7
View File
@@ -16,6 +16,16 @@ You see multiple bounding boxes because it draws bounding boxes from all frames
[![](http://img.youtube.com/vi/nqHbCtyo4dY/0.jpg)](http://www.youtube.com/watch?v=nqHbCtyo4dY "Frigate")
## Getting Started
Build the container with
```
docker build -t frigate .
```
Models for both CPU and EdgeTPU (Coral) are bundled in the image. You can use your own models with volume mounts:
- CPU Model: `/cpu_model.tflite`
- EdgeTPU Model: `/edgetpu_model.tflite`
- Labels: `/labelmap.txt`
Run the container with
```bash
docker run --rm \
@@ -26,7 +36,7 @@ docker run --rm \
-v /etc/localtime:/etc/localtime:ro \
-p 5000:5000 \
-e FRIGATE_RTSP_PASSWORD='password' \
blakeblackshear/frigate:stable
frigate:latest
```
Example docker-compose:
@@ -36,7 +46,7 @@ Example docker-compose:
restart: unless-stopped
privileged: true
shm_size: '1g' # should work for 5-7 cameras
image: blakeblackshear/frigate:stable
image: frigate:latest
volumes:
- /dev/bus/usb:/dev/bus/usb
- /etc/localtime:/etc/localtime:ro
@@ -117,11 +127,6 @@ sensor:
value_template: '{{ states.sensor.frigate_debug.attributes["coral"]["inference_speed"] }}'
unit_of_measurement: 'ms'
```
## Using a custom model
Models for both CPU and EdgeTPU (Coral) are bundled in the image. You can use your own models with volume mounts:
- CPU Model: `/cpu_model.tflite`
- EdgeTPU Model: `/edgetpu_model.tflite`
- Labels: `/labelmap.txt`
## Tips
- Lower the framerate of the video feed on the camera to reduce the CPU usage for capturing the feed
+3 -7
View File
@@ -3,13 +3,9 @@ web_port: 5000
mqtt:
host: mqtt.server.com
topic_prefix: frigate
# client_id: frigate # Optional -- set to override default client id of 'frigate' if running multiple instances
# user: username # Optional
#################
## Environment variables that begin with 'FRIGATE_' may be referenced in {}.
## password: '{FRIGATE_MQTT_PASSWORD}'
#################
# password: password # Optional
# client_id: frigate # Optional -- set to override default client id of 'frigate' if running multiple instances
# user: username # Optional -- Uncomment for use
# password: password # Optional -- Uncomment for use
#################
# Default ffmpeg args. Optional and can be overwritten per camera.
+6 -12
View File
@@ -9,7 +9,7 @@ import multiprocessing as mp
import subprocess as sp
import numpy as np
import logging
from flask import Flask, Response, make_response, jsonify, request
from flask import Flask, Response, make_response, jsonify
import paho.mqtt.client as mqtt
from frigate.video import track_camera
@@ -76,7 +76,6 @@ class CameraWatchdog(threading.Thread):
if (self.tflite_process.detection_start.value > 0.0 and
datetime.datetime.now().timestamp() - self.tflite_process.detection_start.value > 10):
print("Detection appears to be stuck. Restarting detection process")
self.tflite_process.start_or_restart()
time.sleep(30)
for name, camera_process in self.camera_processes.items():
@@ -218,26 +217,21 @@ def main():
@app.route('/<camera_name>')
def mjpeg_feed(camera_name):
fps = int(request.args.get('fps', '3'))
height = int(request.args.get('h', '360'))
if camera_name in CONFIG['cameras']:
# return a multipart response
return Response(imagestream(camera_name, fps, height),
return Response(imagestream(camera_name),
mimetype='multipart/x-mixed-replace; boundary=frame')
else:
return "Camera named {} not found".format(camera_name), 404
def imagestream(camera_name, fps, height):
def imagestream(camera_name):
while True:
# max out at specified FPS
time.sleep(1/fps)
# max out at 1 FPS
time.sleep(1)
frame = object_processor.get_current_frame(camera_name)
if frame is None:
frame = np.zeros((height,int(height*16/9),3), np.uint8)
frame = cv2.resize(frame, dsize=(int(height*16/9), height), interpolation=cv2.INTER_LINEAR)
frame = np.zeros((720,1280,3), np.uint8)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
ret, jpg = cv2.imencode('.jpg', frame)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + jpg.tobytes() + b'\r\n\r\n')
+5 -11
View File
@@ -71,18 +71,16 @@ def run_detector(detection_queue, avg_speed, start):
object_id_str = detection_queue.get()
object_id_hash = hashlib.sha1(str.encode(object_id_str))
object_id = plasma.ObjectID(object_id_hash.digest())
object_id_out = plasma.ObjectID(hashlib.sha1(str.encode(f"out-{object_id_str}")).digest())
input_frame = plasma_client.get(object_id, timeout_ms=0)
if input_frame is plasma.ObjectNotAvailable:
continue
start.value = datetime.datetime.now().timestamp()
# detect and put the output in the plasma store
start.value = datetime.datetime.now().timestamp()
plasma_client.put(object_detector.detect_raw(input_frame), object_id_out)
object_id_out = hashlib.sha1(str.encode(f"out-{object_id_str}")).digest()
plasma_client.put(object_detector.detect_raw(input_frame), plasma.ObjectID(object_id_out))
duration = datetime.datetime.now().timestamp()-start.value
start.value = 0.0
avg_speed.value = (avg_speed.value*9 + duration)/10
class EdgeTPUProcess():
@@ -123,11 +121,7 @@ class RemoteObjectDetector():
object_id_detections = plasma.ObjectID(hashlib.sha1(str.encode(f"out-{now}")).digest())
self.plasma_client.put(tensor_input, object_id_frame)
self.detection_queue.put(now)
raw_detections = self.plasma_client.get(object_id_detections, timeout_ms=10000)
if raw_detections is plasma.ObjectNotAvailable:
self.plasma_client.delete([object_id_frame])
return detections
raw_detections = self.plasma_client.get(object_id_detections)
for d in raw_detections:
if d[1] < threshold: