Tensorflow step-by-step guide

As I said before, you might want to investigate different models, some might be more lightweight. Also what hardware are you running?

Yes, but I haven’t found one that’s more lightweight. I would like one only trained on people, that’s really all I need.

Hardware is Raspberry Pi 3B+.

Checkout https://hackernoon.com/object-detection-in-google-colab-with-custom-dataset-5a7bb2b0e97e

1 Like

You can either dedicate high performance hardware for HA or offload to task specific hardware. For instance OpenCV and tensorflow can be run directly on the camera module: https://openmv.io/

1 Like

I tried installing Home Assistant with Tensorflow on a Mac Mini (mid 2011, High Sierra) but it gives me the following errors when adding Tensorflow in my config:

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

Any ideas? Is it better to install Debian on the machine?

So I tried installing Ubuntu on my Mac Mini (mid 2011) instead, but I get the same error:

Error while setting up platform tensorflow Traceback (most recent call last): File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/image_processing/tensorflow.py", line 124, in setup_platform detection_graph = tf.Graph() AttributeError: module 'tensorflow' has no attribute 'Graph'

Anyone got a clue why? Would really appreciate to get this working.

no issues running HA with TF on a Rpi3 as per these and the components instructions.

I have a old server which has no AVX, Ubuntu 16LTS - default didn’t work so I used

pip3 install tensorflow==1.5.0

and it also worked fine

1 Like

That’s interesting, thanks @cooloo for your info . It “works” on my Rpi3 as well, I get no errors – it just runs out of memory 99 times out of 100. Maybe it’s a hardware problem? Perhaps I should try on another pi.

Anyway, regarding the error I get on both Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-42-generic x86_64) and MacOS High Sierra: this is obviously not Hassbian so maybe I am doing something wrong while installing it? I installed Home Assistant in a virtual env following these steps:

And Tensorflow was also installed in a virtual env following these steps:

https://www.tensorflow.org/install/pip

When verifying the TF install I get: tf.Tensor(1692.8654, shape=(), dtype=float32) which I assume means that it was successful? Does the installation instructions have to be modified while applying it to this setup (Ubuntu on a Mac Mini)? (I tried installing TF 1.5.0 as mentioned by cooloo but it gave the same error: tf.Graph() AttributeError: module 'tensorflow' has no attribute 'Graph')

I found there was no need to follow the tensorflow install docs

I installed on raspbian and Ubuntu, no sign of memory issues in my minimal testing

object/face/emotion recognition takes HA too a new level lads!

1 Like

I found what was wrong, I was using two different virtual envs. Not it’s working on my Ubuntu installation! :slight_smile:

1 Like

If I want something to be triggered when the Tensorflow component finds an object, what is best practice? I could use a folder watcher and look for the result from the components file_out, but I assume that there is a better way?

I’m wondering is it possible to do facial recognition with tensorflow? Has anyone done it? I’m currently using Facebox but I would like to explore for better alternative.

@robmarkcole @TaperCrimp

Facebox is using Tensorflow, but there are probably many face detection models you could try

1 Like

I looked into it a one point. It seems like you can train faces as models. However, it got extremely complicated and I didn’t really need it, so I never bothered with it. I’m pretty certain it can be done though.

1 Like

@robmarkcole and @TaperCrimp

Thanks for your feedback. Sounds like too much trouble for newbie like myself. Perhaps will look into it when I’m more familiar with this.

I am using Tensorflow as a trigger, like this:

trigger:
- platform: numeric_state
entity_id: image_processing.tensorflow
above: 0

The problem is that if a person goes out of view too fast, the state gets stuck on 1, so the next time someone comes it get undetected (my Tensorflow check is triggered by a PIR).

I figured that I could use a template switch to solve this, and look on that instead. But it would be easier to just set the state of tensorflow to zero, some amount of seconds after it has triggered – is that possible?

Instead of using numeric_state, just use simple state trigger. That should take care of the issue. This what I am using:

  trigger:
    - platform: state
      entity_id:
        - image_processing.tensorflow_porch
        - image_processing.tensorflow_patio
        - image_processing.tensorflow_driveway
        - image_processing.tensorflow_backyard

Thanks! :slight_smile: But that fires also when it changes back to 0.

I want it to fire every time it gets assigned a state greater than 0, regardless of what it had before (i.e. even if it had 1 already).

Or did I misinterpret your suggestion?

Indeed, it fires every time there is a state change so you have to use a condition along with it. Here’s my full automation.

Wow, thanks a lot! Really appreciate it! :smiley: