coral tpu adventures and docker, a small writeup

Support for the docker image maintained by dlandon
Post Reply
gurkburk76
Posts: 2
Joined: Thu Feb 06, 2020 1:17 pm

coral tpu adventures and docker, a small writeup

Post by gurkburk76 » 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 :)

juan11perez
Posts: 18
Joined: Tue Apr 27, 2021 3:41 am

Re: coral tpu adventures and docker, a small writeup

Post by juan11perez » Tue Jun 08, 2021 1:03 pm

Good day, thank you for sharing this info.
I've tried following your steps and keep getting the error "ValueError: Failed to load delegate from libedgetpu.so.1" which after googling, some opinions are that is due to a faulty connection. https://zmeventnotification.readthedocs ... s_faq.html

However, Im using the same half-pci coral in unraid with frigate and it works without issues. It's just zm that doesnt work.

Did you build the docker image and added any extra paramenters to import the coral device?

Moreover, did you do the opencv cuda compiling, or are you using without cuda.

Any guidance is welcome.
thank you.

juan11perez
Posts: 18
Joined: Tue Apr 27, 2021 3:41 am

Re: coral tpu adventures and docker, a small writeup

Post by juan11perez » Fri Jun 18, 2021 10:51 am

So answering my own question; I found the problem. In the container /dev/apex_0 does not have sufficient privileges
chmod 777 /dev/apex_0 >> fixes the problem and the edgetpu loads immediately.

However, the performance is very poor. With the coral and gpu the cpu still spikes to 70% on object detection.

I have modified the objectconfig.ini per the instructions, so not sure what else can be done.

Code: Select all

				'name': 'TPU object detection',
				'enabled': 'yes',

Code: Select all

            'name': 'TPU face detection',
            'enabled': 'yes',
In comparison with Frigate https://github.com/blakeblackshear/frigate the cpu practically stays unchanged.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests