Tensorflow step-by-step guide

Keeping in sync might be problematic. I was not necessarily saying to use the whole solution, but recommending using a sensor “person detected” and only send a notification if that is true. And you can set the person detection threshold to what you want it to be. I did find tensorflow to be a bit CPU intensive, which is why I ended up only using motion to trigger it to run. But it really depends on your needs.

Is anyone using Tensorflow on a Mac? I have installed it and done the compile step. I believe it worked, but it finishes almost instantly. It creates .py files correct? I have moved the 3 folders to the correct location. When Home Assistant starts, I get this error:

    Error while setting up platform tensorflow
Traceback (most recent call last):
  File "/Users/myuser/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/myuser/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/components/tensorflow/image_processing.py", line 114, in setup_platform
    detection_graph = tf.Graph()
AttributeError: module 'tensorflow' has no attribute 'Graph'

I have the correct path to the graph setup I think

image_processing:
  - platform: tensorflow
    source:
      - entity_id: camera.driveway
    model:
      graph: /Users/myuser/.homeassistant/tensorflow/frozen_inference_graph.pb

Anyone have any ideas as to what the issue could be?

Possibly you have installed an incorrect version of Tensorflow

I’m having an issue with my graph location. Below shows the location of the .pb file, the .yaml entry, and the hass validation error.

dingus@lionsandtigers:~/hass_config/tensorflow$ pwd
/home/dingus/hass_config/tensorflow
dingus@lionsandtigers:~/hass_config/tensorflow$ ls
frozen_inference_graph.pb object_detection

image_processing:

  • platform: tensorflow
    scan_interval: 20000
    source:
    • entity_id: camera.amcrest_camera
      model:
      graph: /home/dingus/hass_config/tensorflow/frozen_inference_graph.pb
      categories:
      • category: person

Configuration invalid

Invalid config for [image_processing.tensorflow]: not a file for dictionary value @ data[‘model’][‘graph’]. Got ‘/home/dingus/hass_config/tensorflow/frozen_inference_graph.pb’. (See ?, line ?). Please check the docs at TensorFlow - Home Assistant

recommend you put in your config directory to ensure it is reachable from HA

dingus@lionsandtigers:~/hass_config$ ls
 automations.yaml    frozen_inference_graph.pb  scripts.yaml
 configuration.yaml  groups.yaml                secrets.yaml
 customize.yaml      home-assistant.log         tensorflow
 deps                home-assistant_v2.db       tts

image_processing:
  - platform: tensorflow
    scan_interval: 20000
    source:
      - entity_id: camera.amcrest_camera
    model:
      graph: /home/dingus/hass_config/frozen_inference_graph.pb      
      categories:
        - category: person

Still the same result with the config validater

For anyone looking to set up a binary sensor for a particular object, on multiple cameras, with a minimum score, this is what works for me:

 binary_sensor:
   - platform: template
     sensors:
       person:
         friendly_name: 'Person'
         value_template: >
           {% set ns = namespace(found=false) %}
           {% if states.image_processing.tensorflow_garage.attributes.matches.person or
                 states.image_processing.tensorflow_front_driveway.attributes.matches.person or
                 states.image_processing.tensorflow_back_patio.attributes.matches.person or
                 states.image_processing.tensorflow_south_east.attributes.matches.person %}
             {% for persons in states.image_processing.tensorflow_garage.attributes.matches.person %}
               {% if persons.score >= "91"|float %}
                 {% set ns.found = true %}
               {% endif %}
             {% endfor %}
             {% for persons in states.image_processing.tensorflow_front_driveway.attributes.matches.person %}
               {% if persons.score >= "91"|float %}
                 {% set ns.found = true %}
               {% endif %}
             {% endfor %}
             {% for persons in states.image_processing.tensorflow_back_patio.attributes.matches.person %}
               {% if persons.score >= "91"|float %}
                 {% set ns.found = true %}
               {% endif %}
             {% endfor %}
             {% for persons in states.image_processing.tensorflow_south_east.attributes.matches.person %}
               {% if persons.score >= "91"|float %}
                 {% set ns.found = true %}
               {% endif %}
             {% endfor %}
           {% endif %}
           {{ ns.found }}

I imagine it should be possible to shorten this by looping through states.image_processing. I’ll try re-writing it and add to the thread later.

1 Like

Checkout the python_script component, much easier than epic yaml

Did you get this working? I am having the exact issue with pretty identical configuration. Thanks.

I have spent hours working on this without luck. Pretty standard config following examples. I get no Log errors and tried three different cameras. I get no image processing. My “matches” stay at zero.

A few details that are different from most configurations as far as I have noticed:

  1. I am using a Raspberry Pi 4 with 4Gb RAM
  2. I installed TensorFlow 1.13 (instead of 1.11 as suggested in the guide)

Could any of the above be the issue?

Im pretty sure HA 0.98 will include tensorflow so you should try it out

Thanks for the feedback. But I am a bit confused. I am on 0.97.2
Is tensorflow not supported in that version?

@Zoriontsu your best bet is to watch https://github.com/home-assistant/home-assistant/issues/18374

1 Like

Hi.

Is possible to use Tensoflow on another LAN machine, separated from the Hassio?

Thanks.

Possibly via the HA rest API, but you might as well use Deepstack

Do you have an example for this, please?

Thanks.

In this repo and theres a thread in this forum https://github.com/robmarkcole/HASS-Deepstack-object

2 Likes

I see. Thanks. Failed to mention that I am using Hassbian, not HassIO.

After a number of false starts, I’ve finally been successful getting a GPU to work properly with Home Assistant and tensorflow. My 8-CPU ESXi VM running CentOS 7 and processing six cameras every five seconds used to run with a load average of between 5-7. It now runs at 0.25 and scans all six cameras every second. Keep in mind that four of these are 2560x1440 and two are 2560x1920.

At a high level, the process was:

  • Procure an NVIDIA GTX-980 off of eBay for cheap
  • Install it in my ESX server and go to great lengths to get it to cooperate with my machine and ESX
  • Configure my HA VM to see the GTX-980 via PCI Passthrough and make the appropriate setting changes to ensure it is stable and doesn’t crash the host
  • Install the CUDA toolkit (v10 is mandatory), CUDAnn and the latest NVIDIA drivers
  • Install tensorflow-gpu
  • Validate that tensorflow is actually using the GPU
  • Modify the stock HA tensorflow manifest.json with the appropriate requirements for tensorflow-gpu
  • Start Home Assistant and smile at your freed-up CPU cycles

Of course, the changes to the stock manifest.json are probably going to bite me in the future, but…

1 Like

I think we should make changes to the tensorflow integration to support gpu and tflite