Tensorflow and official docker image - CPU instruction issue

@anilet , how do you find the stability/performance of tensorflow?

I use Motion for image capture - https://motion-project.github.io . Prior to that i used MotionEye, which wraps a nice webui around motion. I removed it though as i wanted to use the latest Motion binary and came across some issues mixing the 2

@steve1, Tensorflow looks like performing great, it is detecting objects most of the time, I am scanning for people and cars. I am having issues with adjusting sensitivity of motion detection. I am using kerberos.io. Will try motion later.

i’ve since re-created a new wheel from the official tensorflow debug docker container (1.11.0) and the person identification is now averaging 0.5 seconds! HA container is now stable as well.

2 Likes

@M203 i tried your images again now that tensorflow is stable, but couldn’t get it to identify either the person or the cars in your sample photos. I wonder if its the glare on the windows that’s confusing the analysis? Feel free to attach a pic from outside or a different angle if you like

For others who are getting stuck on this CPU instruction issue, here is the way i ended up doing it that seems to work reliably and not crash home assistant.

Make a directory on your host to store the generated wheel, this folder must also be accessible to your HA container

cd /volume1/motion/storage/tensorflow/
mkdir builds
cd builds

Grab the office devel docker for tensorflow

docker run -it -w /tensorflow -v $PWD:/mnt -e HOST_PERMS="$(id -u):$(id -g)" tensorflow/tensorflow:1.11.0-devel bash

You are now in the temp build container, so update it just in case it has changed

git pull

Grab python 3.6, to match the python distributed with HA

add-apt-repository ppa:jonathonf/python-3.6
apt update
apt install python3.6 python3.6-dev

Configure (i accepted all the defaults, make sure you choose the python 3.6 version )

./configure

Here is how it looked on my system;

root@10bc21dc373f:/tensorflow# ./configure
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command “bazel shutdown”.
You have bazel 0.15.0 installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3.6

Found possible Python library paths:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.6/dist-packages
Please input the desired Python library path to use. Default is [/usr/lib/python3/dist-packages]
/usr/local/lib/python3.6/dist-packages

Hit enter until the command completes, unless you want to change things or enable GPU features etc

Build - this took 3 hours on my NAS

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

Create the package

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt
chown $HOST_PERMS /mnt/tensorflow-*

Exit the temp build container and enter into HA

docker exec -it homeassistant  /bin/bash

Install the generated wheel (change path to whatever you mounted the build directory as)

pip3 install /storagemotion/tensorflow/builds/tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl

Exit the container and restart

docker restart homeassistant

Then see how you go!

1 Like

Thanks for trying, yes probably the glare. Will see if I can get one without. Thanks!

I’m trying your instructions on my synology NAS (with an Intel atom CPU - no AVX).

I to to the bazel build step and get this error

ERROR: /tensorflow/third_party/python_runtime/BUILD:5:1: no such package '@local_config_python//': Traceback (most recent call last):
  File "/tensorflow/third_party/py/python_configure.bzl", line 308
	_create_local_python_repository(repository_ctx)
  File "/tensorflow/third_party/py/python_configure.bzl", line 272, in _create_local_python_repository
	_get_numpy_include(repository_ctx, python_bin)
  File "/tensorflow/third_party/py/python_configure.bzl", line 256, in _get_numpy_include
	_execute(repository_ctx, [python_bin, "-c",..."], <2 more arguments>)
  File "/tensorflow/third_party/py/python_configure.bzl", line 55, in _execute
	_fail("\n".join([error_msg.strip() if ... ""]))
  File "/tensorflow/third_party/py/python_configure.bzl", line 28, in _fail
	fail(("%sPython Configuration Error:%...)))

Python Configuration Error: Problem getting numpy include path.
Traceback (most recent call last):
 File "<string>", line 1, in <module>

ModuleNotFoundError: No module named 'numpy'
Is numpy installed?
  and referenced by '//third_party/python_runtime:headers'

Did you somehow install numpy in the docker image? installing it via:

apt-get install python3-numpy

Gives me errors about missing the multiarray library

If I don’t switch out the python version (just defaults to all configure options) it seems to build (i didn’t let it finish since it takes so long)

I finally got this to work. @steve1 I had run the following before building tensorflow

curl https://bootstrap.pypa.io/get-pip.py | python3.6
pip3.6 install numpy

I got messages about missing keras python packages after a couple of hours of compiling, a quick google search lead me to this https://github.com/tensorflow/tensorflow/issues/21518

So I also installed those libraries:

pip3.6 install keras_applications==1.0.4 --no-deps
pip3.6 install keras_preprocessing==1.0.2 --no-deps

Thanks for your original post, I know I wouldn’t have gotten as far as I did without it. I tried it with a test image of my cats, and it found them both :slight_smile:

nice!

No, i didn’t need to run those steps you mentioned but glad its working for you

I have the same NAS (918+). could you please provide the wheel and what you finally settled for. Thanks a lot in advance. cheers.

sure, here is the wheel i installed. Let me know if the link doesn’t work.

https://1drv.ms/u/s!AvxcjnmzvckvsMMVCvTEikwwEzyV9A">https://1drv.ms/u/s!AvxcjnmzvckvsMMVCvTEikwwEzyV9A

Note i don’t have this running any more, but it certainly worked as per the above

Thanks a lot. I will give it a try.

But Last week end I managed to compile my own based on your (combined with ksheumaker) instructions above. But when i finally tried to pip install in HA, it threw the error “not a supported wheel on this platform”. On further investigation i found HA now uses python3.7. I tried to re-compile it using 3.7 but looks like that version of tensorflow () is not compatible with 3.7. Will try with the latest image sometime this week.

do you mind telling me, what you are using currently? Thanks.

Just tried yours. throws the same error.

tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform

just retried on my 918+

Copy wheel into HA docker container, then ;

root@homeassistant:/storagemotion/tensorflow/builds#
pip install tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl
Processing ./tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl

It then downloaded the dependancies and completed successfully;

Successfully installed setuptools-39.1.0 tensorboard-1.11.0 tensorflow-1.11.0

I’m using a older version of HA though, this may be the issue as you mentioned?

root@homeassistant:/storagemotion/tensorflow/builds# python --version
Python 3.6.8

Home Assistant
0.87.0

I am on 0.91

# python --version
Python 3.7.3
#

Is there anyone that can upload their compiled version without the avx instruction set? I’m trying the compile on my HP Gen8 server, but it keeps failing for various reasons, related to configuration version mismatches, etc.

1 Like

If you still need a non-AVX version, here’s a link to one I compiled without AVX. It’s targetting Westmere CPUs (x5670 and the like), which I think is 1 generation older than your Gen8 runs, so you should be good.

Hi all… You all might want to check out Frigate, it’s a new dockerized tensorflow component that analyzes streams directly reports results over MQTT. It’s purpose built for running on a separate machine from your main HA instance in a docker, so it gives you a lot of options. It also utilizes Google Coral, so for $75 you can take a ton of load off your CPU.

1 Like

Thanks - still out of luck though - get “tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform” when trying to install.

It looks like the latest version of HA has moved to Python 3.7 - which might be the reason.

According to this, python 3.7 should be supported:
https://github.com/tensorflow/tensorflow/issues/17022

You can check this github,


There are lots of wheels for probably every need.
I am using this for my nuc7pjyh with ubuntu 18.04 for instance: