coral tpu adventures and docker, a small writeup
Posted: Sat May 22, 2021 11:27 am
So i was going a bit nuts where when my mysql tables somehow got a bit wrecked, possibly because of a bad shutdown/power outage, also i'm seeing that 1.34.x docker image seems to be deprecated (https://hub.docker.com/r/dlandon/zoneminder) so i'm switching to https://github.com/dlandon/zoneminder.machine.learning that at the moment i'm writing this does not have a built docker image. Dosen't really matter i've learnt how to build one so that's ok, and educational
I built it and thought i'de give it a go at making this usb coral stick working that i've bought a few months ago since this version of zoneminder seems to be packaged together with ES server that actually has support for the TPU, great!
After a few hours of struggle a few thing dawned upon me, since i'm running it in a docker container i seem to need to passthrough the USB port to the container witch in turn means that the docker image seems to be missing a few bits like *.tflite files and python libraries/utils and making some adjustments to what group the www-data user belongs to in order for this to work.
example:
ERR detect_sequence.py:168 [Error loading same model variation for object:No module named 'pycoral']
These are the steps i hade to take in order to get this working:
sources:
https://coral.ai/models/object-detection/
download edge tpu model and labels file, for some reason in objects.ini it seems to need 2 tpu files and 1 model file. (mobilenet/mobiledet)
Inside the container i had to do this:
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt update ; sudo apt-get install libedgetpu1-std ; sudo apt-get install python3-pycoral
In the container i then did this pointing to a picture the camera took to see if the tpu picks it up.
sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --config /etc/zm/objectconfig.ini --debug --eventid X(insert pic id here)
Not sure if it will stick if i do a "docker restart zoneminder", pretty sure i'll have to redo it when i "docker rm zoneminder".
Now, i might be dumb as **** by doing this manually in the container and perhaps there is a much better way to automatize this either when building the container and/or when starting the container.
the HOOK_INSTALL=1 option that the older docker containers have seems to be missing and that can be a bit of the puzzle i'm missing.
Pretty sure i could in theory add the steps to the Dockerfile and rebuild and it would "work out of the box" but if that's the case itwould suprise me if the authoer (dlandon) would have missed so i'm more leaning towards that i'm missing something being the non-dev that i am
This are very crude steps to what *i* did to get it working and not meant to be a complete guide, if it helps you great! But i mainly would like to get some answers if i'm totally messing this up/taking the wrong steps.
After reading this (https://forums.unraid.net/topic/56632-s ... ent-932742) perhaps the best forward solution is building a VM for it.
Funny that i've just build a proxmox cluster so i guess that's the next project
It also answers my question about hooks that i wrote above, if i understand it correctly.
I was first thinking that it would be a good solution to passthrough the usb stick to the vm, but if you want to be able to move the vm within the cluster it breaks things since the usb stick is no longer attached to the vm so i guess remote ML server solution it is.
Thanks for building awsome software dlandon, you have my GoFundMe support
I built it and thought i'de give it a go at making this usb coral stick working that i've bought a few months ago since this version of zoneminder seems to be packaged together with ES server that actually has support for the TPU, great!
After a few hours of struggle a few thing dawned upon me, since i'm running it in a docker container i seem to need to passthrough the USB port to the container witch in turn means that the docker image seems to be missing a few bits like *.tflite files and python libraries/utils and making some adjustments to what group the www-data user belongs to in order for this to work.
example:
ERR detect_sequence.py:168 [Error loading same model variation for object:No module named 'pycoral']
These are the steps i hade to take in order to get this working:
sources:
https://coral.ai/models/object-detection/
download edge tpu model and labels file, for some reason in objects.ini it seems to need 2 tpu files and 1 model file. (mobilenet/mobiledet)
Inside the container i had to do this:
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt update ; sudo apt-get install libedgetpu1-std ; sudo apt-get install python3-pycoral
In the container i then did this pointing to a picture the camera took to see if the tpu picks it up.
sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --config /etc/zm/objectconfig.ini --debug --eventid X(insert pic id here)
Not sure if it will stick if i do a "docker restart zoneminder", pretty sure i'll have to redo it when i "docker rm zoneminder".
Now, i might be dumb as **** by doing this manually in the container and perhaps there is a much better way to automatize this either when building the container and/or when starting the container.
the HOOK_INSTALL=1 option that the older docker containers have seems to be missing and that can be a bit of the puzzle i'm missing.
Pretty sure i could in theory add the steps to the Dockerfile and rebuild and it would "work out of the box" but if that's the case itwould suprise me if the authoer (dlandon) would have missed so i'm more leaning towards that i'm missing something being the non-dev that i am
This are very crude steps to what *i* did to get it working and not meant to be a complete guide, if it helps you great! But i mainly would like to get some answers if i'm totally messing this up/taking the wrong steps.
After reading this (https://forums.unraid.net/topic/56632-s ... ent-932742) perhaps the best forward solution is building a VM for it.
Funny that i've just build a proxmox cluster so i guess that's the next project
It also answers my question about hooks that i wrote above, if i understand it correctly.
I was first thinking that it would be a good solution to passthrough the usb stick to the vm, but if you want to be able to move the vm within the cluster it breaks things since the usb stick is no longer attached to the vm so i guess remote ML server solution it is.
Thanks for building awsome software dlandon, you have my GoFundMe support