Face detection with Docker/Machinebox

You were correct! Home assistant named my camera camera.saved_image which caused the issue. I changed the facebox detection sensor to
- platform: template
sensors:
facebox_detection:
friendly_name: ‘Facebox Detection’
value_template: ‘{{ states.image_processing.facebox_saved_image.attributes.faces[0][“name”].title}}’

saved_image instead of saved_images and now the facebox detection sensor will not display the name. Is this normal? I get error Could not render template Facebox Detection: UndefinedError: list object has no element 0

face face1

@masterkenobi suggest machinebox for query on wiping faces, suspect theres a docker command to clear the image. In my experience only a couple of images were required to teach a face

@ffyter checkout this article

hello. you have a great project
please help me. When I configure in automation the error message is as follows
Invalid config for [automation]: template không hợp lệ (TemplateSyntaxError: bất thường cuối trong print statement) cho giá trị giá dữ liệu [‘action’] [5] [‘data_template’] [‘message’]. Got None. (See /config/configuration.yaml, line 310). Please check the docs at https://home-assistant.io/components/automation/

########## ############################################################

Announce when people come or go.

Announce over All Chromecast Audios

######################################################################

  • id: facebox_announcement
    alias: ‘Facebox Announcement’
    initial_state: on
    trigger:
    • platform: state
      entity_id: binary_sensor.entrance_motion
      to: ‘on’
      action:
    • delay: 00:00:02
    • service: camera.snapshot
      data:
      entity_id: camera.hass_tablet # android_ip_webcam
      filename: ‘/config/www/facebox/tmp/image.jpg’
    • delay: 00:00:01
    • service: image_processing.scan
      entity_id: image_processing.facebox_saved_images
    • delay: 00:00:02
    • service_template: ‘{% if states.sensor.facebox_detection.state != “unknown” %} tts.alexa_say {% endif %}’
      data_template:
      entity_id: media_player.livingroomcc
      message: ‘{% if states.sensor.facebox_detection.state != “unknown” %} {{ states<“sensor.facebox_detection”> }} is at the door {% else %} {% endif %}’
    • service: media_player.volume_set
      data:
      entity_id: media_player.livingroomcc
      volume_level: 0.9

I use the camera of nexus 9 as a sample

Hi @robmarkcole,

Yes, there is a tool to remove faces in the web console…

I need to enter the ID of the image in the box but I am not sure where to find the ID.

I have tried looking for it in HA from the Developer tools > States and then look for image_id attributes for the image_processing entity after it detected my face. The value is like this… “D:\\Users\\ben\\Documents\\python\\teach_facebox\\ben\\IMG_20180902_192844.jpg

I used it in the above web tool but it says Not Found.

I am wondering how to find the list of image IDs captured in the system.

Also, how many images do you think is sufficient to use to teach a face? Is 5 images enough?

The face ID isn’t exposed via the HA integration, so you would need to access the facebox API directly e.g. via curl. However I think you are better just wiping the container and starting over. 5 photos per face should be sufficient

1 Like

yes you are right. thanks!

OK. I have another question. Do the faces got deleted whenever I restart the docker container or my NAS? The reason I ask is because it couldn’t match any face after I restarted the container.

That used to be the case for the free tier, might have changed recently. You would need to use a command line script to fetch/upload the model

1 Like

This worked for me to add () at the end of the template.
value_template: ‘{{ states.image_processing.faceid.attributes.faces[0][“name”].title()}}’

1 Like

@robmarkcole, I am trying to create a template binary sensor that will turn on when my face is detected and off if otherwise. This is what I have so far…

binary_sensor:
  - platform: template
    sensors:
      ben_at_couch:
        friendly_name: 'Ben At Couch'
        device_class: occupancy
        value_template: >-
            {% if states.image_processing.couch.attributes.matched_faces["Ben"] > 50 %}
              on
            {% else %}
              off
            {% endif %}
        entity_id:
          - image_processing.couch

Unfortunately it is not working. This is the error in the log…

ERROR (MainThread) [homeassistant.components.binary_sensor.template] Could not render template Ben At Couch: UndefinedError: ‘dict object’ has no attribute ‘Ben’

Please point me to the right direction on how to do this. Thanks.

Error is gone after I change to this but the sensor value doesn’t change. It stuck at off.

binary_sensor:
  - platform: template
    sensors:
      ben_at_couch:
        friendly_name: 'Ben At Couch'
        device_class: occupancy
        value_template: >-
          {%- set confidence = states.image_processing.couch.attributes.matched_faces["Ben"] -%}
          {%- if confidence is defined -%}
            {%- if confidence > 50 -%}
              on
            {%- else -%}
              off
            {%- endif -%}
          {%- else -%}
            off
          {%- endif -%}
        entity_id:
          - image_processing.couch

i have found a workaround to this. instead of binary_sensor, I am using input_boolean now.

First, create the input_boolean:

input_boolean:
  ben_at_couch:
    name: Ben at Couch

Then create the automation to turn on the input_boolean.

automation:
  - alias: 'Turn on Ben at Couch Input Boolean '
    initial_state: on
    trigger:
      platform: event
      event_type: image_processing.detect_face
      event_data:
        name: 'Ben'
        entity_id: 'image_processing.couch'
    condition:
      condition: template
      value_template: "{{ trigger.event.data.confidence|float > 50 }}"
    action:
      service: input_boolean.turn_on
      entity_id: input_boolean.ben_at_couch

…and then another automation to turn it off when my face is not detected.

automation:
  - alias: 'Turn off Ben at Couch Input Boolean '
    initial_state: on
    trigger:
      platform: state
      entity_id: image_processing.couch
    condition:
      condition: template
      value_template: "{{ states.image_processing.couch.attributes.matched_faces['Ben'] is not defined }}"
    action:
      service: input_boolean.turn_off
      entity_id: input_boolean.ben_at_couch

With this input_boolean, I can create all sorts of automation such as track my kids TV time by using facial recognition.

1 Like

Guide to deploying Facebox to AWS:

Interesting read comparing several techniques for face detection:

Just to let you know I have successfully setup Classificationbox using your custom component.

Then I gathered snapshots from my IP cameras and use them for teaching.

Now my HA can determine whether a room is occupied or not using this custom component.

It’s awesome and thank you so much!

1 Like

Read somewhere you can deploy Machinebox/Facebox on Google Cloud platform.
Can I integrate a web-hosted Machinebox instance with Hassio?

I’m not familiar with machinebox but yes with facebox. I have mine in the cloud because I don’t have enough resources to run it locally.

@forums2012 yes the google deployment is on the blog here
Let us know how you get on with GCP