Face and person detection with Deepstack - local and free!

@Yoinkz theres many ways you could go about it, I actually replaced the whole OSX with Ubuntu, but equally you could run in Virtualbox. Then, I just followed the Deepstack docs, simples :slight_smile:

1 Like

Makes sense.

I think for my room occupany stuff it would be best to have perhaps two cameras. One in the corner of the room looking over everything and one along the desk checking to see if anyone is sat down. The one in the corner would probably miss someone sat at the desk as its going to be almost behind a large chair.

I guess a standard PIR to capture initial movement for turning lights on quickly would complete the package.

It’s either than or a mixture of an IR beam and motion sensors.

1 Like

Yeah I went the snapshot/motion route because I wasn’t comfortable with a live stream analysis, even though all my cameras are local

1 Like

Okay Rob,

Will give it a try :slight_smile:

1 Like

@TheDanShepherd I’ve been using this component ‘realtime’ for occupancy detection - rather than trigger on motion - and it works rather well. i have the scan set for 10s and it gives me a pretty solid overview of how many people are where in the house. I use it to help keep lights on when people have been sat still passed the trigger point of my PIR automations!
the resultant problem is one of performance. my basement server (@robmarkcole it’s an old but decent i3 2130 with 16g ram) spent until recently most of its waking life idling, the occasional plex transcode taking me to around 10%. Now, with three cameras running oject/person model only (no face component being used) it’s at 45%-60% all the time. I would like to employ this component on more cameras/in more rooms, but worry that it’ll peg my server and affect other services it provides.
Also worth noting is that my homes energy usage has noticably risen as a result of this heavier server activity. only 25p a day more, but still…
Fantastic component all in all. Great work Robin!

3 Likes

that’s the reason why don’t you run the image_processing.scan service every 10 seconds. it overloads the server and may cause it to crash. Only scan when it is necessary. This is what I have for my kitchen and it works fine for me…

##########################################################
# Automation
##########################################################
automation:
  - alias: 'Start scan when Scan Kitchen is on'
    initial_state: on
    trigger:
      platform: state
      entity_id: input_boolean.scan_kitchen
      from: 'off'
      to: 'on'
    action:
      - service: image_processing.scan
        entity_id:
          - image_processing.kitchen_person_count
      - delay:
          seconds: 1
      - service: input_boolean.turn_off
        entity_id: input_boolean.scan_kitchen
      - service: timer.start
        entity_id: timer.scan_kitchen

  - alias: 'Kitchen activity detected start scan'
    initial_state: on
    trigger:
      platform: state
      entity_id:
        - binary_sensor.kitchen_motion_sensor
        - binary_sensor.kitchen_door_motion_sensor
        - binary_sensor.cam_3_field_detection
        - binary_sensor.kitchen_window
        - binary_sensor.back_door
    condition:
      - condition: state
        entity_id: binary_sensor.kitchen_occupancy
        state: 'off'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.scan_kitchen

  # When timer is done, start scan
  - alias: 'Scan Kitchen Timer Finish'
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.scan_kitchen
    condition:
      - condition: state
        entity_id: binary_sensor.kitchen_occupancy
        state: 'on'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.scan_kitchen






##########################################################
# Timer
##########################################################
timer:
  scan_kitchen:
    name: 'Scan Kitchen Timer'
    duration: '00:00:30'






##########################################################
# Input Boolean
##########################################################
input_boolean:
  scan_kitchen:
    name: Scan Kitchen
    initial: off






##########################################################
# Binary Sensor
##########################################################
binary_sensor:
  - platform: template
    sensors:
      kitchen_occupancy:
        friendly_name: "Kitchen Occupancy"
        device_class: occupancy
        value_template: >-
          {{ states('image_processing.kitchen_person_count')|float > 0 }}





##########################################################
# Customize
##########################################################
homeassistant:
  customize:
    image_processing.kitchen_person_count:
      friendly_name: 'Kitchen Person Count'
9 Likes

an interesting approach @masterkenobi - so basically it waits for any initial motion to ‘die down’ before checking against the deepstack model. nice.
is the timer set at 30s for any particular reason?

Basically when activity is detected (motion and door open or close), it will start scan if no one was detected prior to that. If someone is detected, then it will continue to scan for every 30 seconds until no one is detected.

No particular reason why 30 seconds. You can adjust it until you feel it is balanced between performance and results.

2 Likes

I’ve installed the container for both facial and object detection. While i can get the object detections working everything i’ve tried for the facial detection component doesn’t return any results. I’ve run the service "name": "Superman", "file_path": "/config/www/superman.jpg" and then run the scan service. The component neither detects a person in the picture nor the identified face. Again no issue with he object detection. Don’t really see any errors in my log. Any ideas?

1 Like

Has superman been home yet?

4 Likes

@nickrout that was just an example. Nothing i put in the entity triggers neither a scan nor a teach command. You would think that even if I can’t get it to detect a thought face that it would at least detect that there was a person in the picture.

@Maaniac double check that you are running the container with both object and face detection

1 Like

@robmarkcole i copied the code directly from your github page. How can I check?

Should be:

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

You can always try the test image

1 Like

@robmarkcole yes that is the one i installed. Its roughly 1.7 gb in size. running image processing scan i can see nothing changes in the log. Doing the same for object detection does.

I just added your test image. Under image_processing.face_counter its giving me a 0 value.

1 Like

@Maaniac Which OS are you running docker on? There is a known issue (currently, windows and mac) where requests can take so long that they timeout

1 Like

@robmarkcole running this docker on my mac. The one on my VM doesn’t have enough memory to run this container.

1 Like

has anyone tried Deepstack with Intel Neural Compute Stick 2?
is it feasible?

1 Like

That looks intriguing.

1 Like

@Maaniac the mac issue is being worked on. Recommend you install Ubuntu in Virtualbox and use docker then for the timebeing.
@katsaplias support for the stick is on the roadmap

1 Like