coral tpu, usb, proxmox, lxc container, unprivileged, docker, frigate, home assistant, debian, python
This guide is how I got a Coral TPU (USB) working in an unprivileged LXC container.
At the end, you should be able to use the Coral TPU for inferencing inside of an unprivileged LXC container as well as Docker containers within the LXC, such as Frigate.
This does NOT require privileged LXC or docker container.
NOTES:
- Proxmox Version: 8.1.10
- LXC Container: Debian 10/11 (Example #1)
- Debian 12 was used as the Docker host (Example #2)
- Docker Version: 26.0.0 (Example #2)
-
Identify USB device on Proxmox Host
NOTE: Your
Bus
/Device
will probably be different. As for the Name and IDs, those will change after drivers are installed or inferencing is done for the first time on the device.-
Run
lsusb
Bus 009 Device 002: ID 1a6e:089a Global Unichip Corp.
OR
Bus 009 Device 003: ID 18d1:9302 Google Inc.
-
-
Create and apply
udev
rules for Coral device-
Create
/etc/udev/rules.d/71-edgetpu.rules
with:SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", MODE="0664", TAG+="uaccess", OWNER="100000", GROUP="100000" SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", MODE="0664", TAG+="uaccess", OWNER="100000", GROUP="100000"
This will automatically set permissions on the USB devices when they are mounted by the system.
-
Apply and reload rules
RUN
udevadm control --reload-rules && udevadm trigger
-
-
Add the following lines to your LXC config
NOTE: Make sure to replace
<BUS_ID>
with yours from step 1. (Like mine is 009)-
Edit
/etc/pve/lxc/<lxcid>.conf
and add:lxc.cgroup2.devices.allow: c 29:0 rwm lxc.cgroup2.devices.allow: c 189:* rwm lxc.mount.entry: /dev/bus/usb/<BUS_ID> dev/bus/usb/<BUS_ID> none bind,optional,create=dir 0, 0
-
You should now be able to test with the example from https://coral.ai/docs/accelerator/get-started/
Example 1 (LXC):
- Running in a clean Debian 11 LXC container with the above steps completed:
- NOTE: Debian 11 is used because the default Python3 version in Debian 12 is too new for PyCoral
python3 --version
Python 3.9.2
apt update -y && apt install -y sudo curl gnupg2 usbutils git
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 -
apt update -y && apt install -y libedgetpu1-std python3-pycoral
git clone https://github.com/google-coral/pycoral.git
cd pycoral
bash examples/install_requirements.sh classify_image.py
python3 examples/classify_image.py \
--model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--labels test_data/inat_bird_labels.txt \
--input test_data/parrot.jpg
...
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
13.0ms
4.1ms
4.1ms
4.1ms
4.1ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.75781
Example 2 (Docker in LXC):
-
docker run --rm -it --device=/dev/bus/usb:/dev/bus/usb debian:11 /bin/bash
-
In the Debian 11 container:
SAME COMMANDS AS EXAMPLE 1 ... ----INFERENCE TIME---- Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory. 13.0ms 4.1ms 4.2ms 4.1ms 4.1ms -------RESULTS-------- Ara macao (Scarlet Macaw): 0.75781