snowzach / doods

DOODS - Dedicated Open Object Detection Service
MIT License
303 stars 31 forks source link

Fails to initialize edgetpu in Docker on Synology #60

Closed SebbeM closed 3 years ago

SebbeM commented 3 years ago

I have the Coral EdgeTPU connected to a Synology Diskstation with Docker and I can't get the edgetpu detector to initialize. Please see the command and error output below. I am using the config file and models directory generated with fetch_models.sh. When running in a Docker container locally, I initially get the same error but it works when I stop the container and restart it. This does not seem to work on the Diskstation. Am I missing something or is this somehow due to limitations in the host system?

sudo docker run -it --name doods --device /dev/bus/usb -v /volume1/docker/doods/models/:/opt/doods/models -v /volume1/docker/doods/config.yaml:/opt/doods/config.yaml -p 36637:8080 snowzach/doods:latest

2021-02-20T09:36:36.760Z DEBUG detector/detector.go:61 Configuring detector {"package": "detector", "config": {"name":"edgetpu","type":"tflite","model_file":"models/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite","label_file":"models/coco_labels0.txt","num_threads":0,"num_concurrent":4,"hw_accel":true,"timeout":0}} 2021-02-20T09:37:03.525Z ERROR detector/detector.go:74 Could not initialize detector edgetpu: could not initialize edgetpu /sys/bus/usb/devices/2-1 {"package": "detector"}

snowzach commented 3 years ago

It could be the host system. It could be a power related issue. Do you have it plugged into a USB 3.0? You could try plugging it into a powered USB hub and it might work. It's really hard to say.

SebbeM commented 3 years ago

I understand that it's hard to say. At least it doesn't seem to be anything obvious that I'm missing. It's plugged into a USB 3.1 port (this is its line from lsusb: < |__2-1 1a6e:089a:0100 00 3.10 5000MBit/s 896mA 1IF ( ffffffd1ffffffb2ffffffdbffffffa0)). I'll try with a powered hub to see if it makes a difference, which would make sense as 0.9 A is a lot of juice.

What would the container need from the host system? This is a heavily modified Debian distribution that's missing a lot of common stuff but I figured it wouldn't matter when running Docker.

snowzach commented 3 years ago

It's a little funky how it actually works. The first time you run it, it actually loads a driver onto the EdgeTPU and all the USB identifiers change. That's why it can't detect the EdgeTPU the first time it runs. I don't think it will actually need much from the host system that I can think of unless something funky happens between the USB drivers being loaded and the host system. The only other thing I can suggest is try running it with --privileged to see if that does anything different. The EdgeTPU is a bit of a black box for me. I just compile the drivers for it and tensorflow and it mostly just works. I can't say I can provide much insight to how it actually functions/interacts with the system sadly.

SebbeM commented 3 years ago

Thanks for your input. I went out and bought a powered hub with a 3 A power supply but I still get the same error. I have run the container with privileged flag as well without success. I'll take a look at the code and see if I can come up with something else.

snowzach commented 3 years ago

Another thought... Is docker running under virtualization? I have never been able to get the edgetpu to work in a VM with a virtual usb port. I was able to get it to work with pci passthrough and passing through the entire usb controller. Not sure how the synology does it.

SebbeM commented 3 years ago

No, Docker is running directly on the host system. Did DOODS display a similar error message to mine when running Docker within a VM? I wish there would be more information in the log but I guess the Coral does not provide it. All I can gather now it that it seems to fail at line 42 in edgetpu.go. I'm not very familiar with Go but it seems like a call to a C library, which gives me pretty bad vibes.

h4de5 commented 3 years ago

@SebbeM there was a recent update to Docker 20.10.3 in Synology DSM 6 (along with previous updates since february) Any chance you could try to get the EdgeTPU up again?

Also I assume this was not a problem with doods but with the combination synology + EdgeTPU, right? Or did you manage to get the TPU working for any other application on the NAS?

SebbeM commented 3 years ago

Is this a recent update, though? If it was released on October third of last year, it should be the version I was running when I last tried to get this working. I don't recall any updates to Docker being released since my last comment on February 27.

You are absolutely right that the problem does not seem to be with Doods at all but rather that I can't install the EdgeTPU runtime on the Synology OS. I have thought about trying to compile and package it on another machine but I haven't figured out how to do it and don't want to spend too much time on it as I assume that there would be a whole bunch of dependency issues anyway.

h4de5 commented 3 years ago

i found this post on home-assistant - he claims the edgetpu works in docker on his ds920+ https://community.home-assistant.io/t/image-processing-with-usb-acceleration-all-pi-archived/118445/185

in regards of the docker update : https://www.synology.com/en-in/releaseNote/Docker the upgrade vom docker v18 to v20 was made last month.

SebbeM commented 3 years ago

Damn, the version number looks way too much like a date! I will look at the guide and see if I can get it to work. Thanks!

h4de5 commented 3 years ago

oh. now i see :)

SebbeM commented 3 years ago

I have now gotten it to work using the instructions you linked. Thank you so much for getting back to me regarding this issue. I will happily close it now.