robmarkcole / HASS-Deepstack-face

Home Assistant custom component for using Deepstack face recognition
https://community.home-assistant.io/t/face-and-person-detection-with-deepstack-local-and-free/92041
MIT License
219 stars 69 forks source link
computer-vision deep-learning home-assistant

HASS-Deepstack-face

Home Assistant custom components for using Deepstack face detection and recognition. Deepstack is a service which runs in a docker container and exposes various computer vision models via a REST API.

On you machine with docker, run Deepstack with the face recognition service active on port 80 with:

docker run -e VISION-FACE=True -v localstorage:/datastore -p 80:5000 --name deepstack deepquestai/deepstack

Home Assistant setup

Place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder). Then configure face recognition.

Note that by default the component will not automatically scan images, but requires you to call the image_processing.scan service e.g. using an automation.

Deepstack face recognition counts faces (detection) and (optionally) will recognize them if you have trained your Deepstack using the deepstack_teach_face service (takes extra time). Configuring detect_only = True results in faster processing than recognition mode, but any trained faces will not be listed in the matched_faces attribute. An event image_processing.detect_face is fired for each detected face.

The deepstack_face component adds an image_processing entity where the state of the entity is the total number of faces that are found in the camera image. Recognized faces are listed in the entity matched faces attribute. The component can optionally save snapshots of the processed images. If you would like to use this option, you need to create a folder where the snapshots will be stored. The folder should be in the same folder where your configuration.yaml file is located. In the example below, we have named the folder snapshots.

Add to your Home-Assistant config:

image_processing:
  - platform: deepstack_face
    ip_address: localhost
    port: 5000
    api_key: mysecretkey
    timeout: 5
    detect_only: False
    save_file_folder: /config/snapshots/
    save_timestamped_file: True
    save_faces: True
    save_faces_folder: /config/faces/
    show_boxes: True
    source:
      - entity_id: camera.local_file
        name: face_counter

Configuration variables:

Service deepstack_teach_face

This service is for teaching (or registering) faces with deepstack, so that they can be recognized.

Example valid service data:

{
  "name": "Adele",
  "file_path": "/config/www/adele.jpeg"
}

Event image_processing.detect_face

For each face that is detected, an image_processing.detect_face event is fired. The event payload includes the following data:

Remember face recognition is not performed if you have configured detect_only: True.

EVENT deepstack_face.teach_face

When a face is taugh to deepstack face, an deepstack_face.teach_face event is fired. The event payload includes the following data:

To monitor these events from the HA UI you can use Developer tools -> EVENTS -> :Listen to events.

Object recognition

For object (e.g. person) recognition with Deepstack use https://github.com/robmarkcole/HASS-Deepstack-object

Support

For code related issues such as suspected bugs, please open an issue on this repo. For general chat or to discuss Home Assistant specific issues related to configuration or use cases, please use this thread on the Home Assistant forums.

Docker tips

Add the -d flag to run the container in background, thanks @arsaboo.

FAQ

Q1: I get the following warning, is this normal?

2019-01-15 06:37:52 WARNING (MainThread) [homeassistant.loader] You are using a custom component for image_processing.deepstack_face which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

A1: Yes this is normal


Q2: I hear Deepstack is open source?

A2: Yes, see https://github.com/johnolafenwa/DeepStack


Q3: What are the minimum hardware requirements for running Deepstack?

A3. Based on my experience, I would allow 0.5 GB RAM per model.


Q4: If I teach (register) a face do I need to re-teach if I restart the container?

A4: So long as you have run the container including -v localstorage:/datastore then you do not need to re-teach, as data is persisted between restarts.


Q5: I am getting an error from Home Assistant: Platform error: image_processing - Integration deepstack_object not found

A5: This can happen when you are running in Docker, and indicates that one of the dependencies isn't installed. It is necessary to reboot your device, or rebuild your Docker container. Note that just restarting Home Assistant will not resolve this.


Video of usage

Checkout this excellent video of usage from Everything Smart Home