# Google Coral TPU and Frigate Integration Guide This guide walks you through setting up a Coral USB Accelerator with a Proxmox host running a Frigate container. It explains the prerequisites, device initialization, udev configurations, and integration steps to enhance object detection performance using the Coral TPU. ## 1. Prerequisites 1. **Coral USB Accelerator** * Have your Coral USB Accelerator (e.g., Coral USB Accelerator v2) ready. 2. **Proxmox Host Details** * A Proxmox node (v7.x or newer) where you can create and modify LXCs. * A working Frigate LXC/container already running Frigate with your camera feeds set up. 3. **Tools to Install on the Proxmox Host** ```bash apt update apt install -y usbutils udev python3 python3-venv git unzip ``` * `usbutils`: for running `lsusb` * `udev`: to create custom rules for the Coral device * `python3`/`python3-venv`: to run PyCoral examples before LXC passthrough * `git`/`unzip`: to clone and extract repositories > **Link:** LX(C) container config paths: > [https://forum.proxmox.com/threads/where-are-lx-c-container-configurations-stored.59780/](https://forum.proxmox.com/threads/where-are-lx-c-container-configurations-stored.59780/) --- ## 2. Plug in the Coral and Verify on the Host 1. **Insert the Coral USB** into a USB 3.0 port on your Proxmox host (avoid using a passive USB hub). 2. **Check `lsusb` Immediately** ```bash lsusb | grep -i coral ``` * If it shows something like: ```bash Bus 003 Device 006: ID 1a6e:089a Global Unichip Corp. ``` that means the Coral is still in “Global Unichip” mode (`1a6e:089a`) and hasn’t been initialized yet. 3. **Install the Edge TPU Runtime on the Host** ```bash wget https://dl.google.com/coral/edgetpu_api/edgetpu_runtime_20210620.zip unzip edgetpu_runtime_20210620.zip # Choose whichever matches your hardware: dpkg -i libedgetpu1-max_*.deb # or libedgetpu1-std_.deb dpkg -i libedgetpu-dev_.deb # (optional, for headers) ``` * **Why?** This installs the kernel driver so that once you run a PyCoral example, the device will re-enumerate as `18d1:9302 Google Inc.` instead of `1a6e:089a`. * **Link:** Coral USB “Get Started” (Linux): [https://coral.ai/docs/accelerator/get-started/#pycoral-on-linux](https://coral.ai/docs/accelerator/get-started/#pycoral-on-linux) 4. **Install Pyenv on the Host** (to get Python 3.9) ```bash # Follow the Real Python tutorial: curl https://pyenv.run | bash # Then add these lines to ~/.bashrc (or ~/.zshrc): export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" source ~/.bashrc # Install Python 3.9 via pyenv: pyenv install 3.9.16 pyenv virtualenv 3.9.16 coral-tpu pyenv activate coral-tpu ``` * **Why?** PyCoral’s Python package isn’t compatible with Python 3.10+, so you need a 3.9 environment. * **Link:** Managing Python versions with Pyenv: [https://realpython.com/intro-to-pyenv/](https://realpython.com/intro-to-pyenv/) 5. **Clone the PyCoral and Test Data Repos** ```bash git clone https://github.com/google-coral/pycoral.git git clone https://github.com/google-coral/test_data.git ``` * **Why?** `pycoral` contains example scripts like `classify_image.py`; `test_data` provides models and images those examples use. 6. **Install PyCoral via pip** ```bash pip install numpy pip install pycoral ``` * **Why?** The Ubuntu package `python3-pycoral` can be outdated or missing. Installing via `pip` ensures you have the latest library. * **Link:** (User note) “I couldn’t `apt install pycoral`, so I did `pip install pycoral`.” --- ## 3. Wake Up the Coral Device (Host) 1. **Run the Classification Example** From the directory *one level above* both `pycoral/` and `test_data/`: ```bash cd ~/ # or wherever you cloned both repos python3 pycoral/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 ``` * **What Happens:** * PyCoral loads the quantized MobileNet V2 Bird model onto the Coral and runs inference on `parrot.jpg`. * In the process, the Coral’s USB interface switches from `1a6e:089a` (Global Unichip) to `18d1:9302` (Google Inc.). 2. **Verify the Mode Switch** ```bash lsusb | grep -E "18d1:9302" ``` You should see something like: ```bash Bus 003 Device 005: ID 18d1:9302 Google Inc. ``` * If it still shows `1a6e:089a`, double-check you installed the correct `libedgetpu1-*` package. 3. **Record the Bus/Device Path** * In this example, it’s `/dev/bus/usb/003/005`. You’ll use that path in the LXC config. --- ## 4. Create Udev Rules (Host) 1. **Create a New Rule File** ```bash cat < /etc/udev/rules.d/98-coral.rules SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", OWNER="root", MODE="0666", GROUP="plugdev" SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", OWNER="root", MODE="0666", GROUP="plugdev" EOF ``` * **Why?** This ensures that when the Coral switches modes, it always gets `0666` permissions so any process (including the LXC) can open it. 2. **Reload and Trigger the Rules** ```bash udevadm control --reload-rules && udevadm trigger ``` * **Confirm Permissions** ```bash ls -l /dev/bus/usb/003/005 ``` You should see: ```bash crw-rw-rw- 1 root plugdev 189, 4 Jun 1 16:15 /dev/bus/usb/003/005 ``` > **Link:** Proxmox forum: USB passthrough to LXC > [https://forum.proxmox.com/threads/passthrough-usb-device-to-lxc-keeping-the-path-dev-bus-usb-00x-00y.127774/](https://forum.proxmox.com/threads/passthrough-usb-device-to-lxc-keeping-the-path-dev-bus-usb-00x-00y.127774/) --- ## 5. Passthrough Coral into Your Frigate LXC 1. **Locate the LXC Config File** On the Proxmox host: ```bash /etc/pve/lxc/.conf ``` Replace `` with your container ID (e.g., `113`). 2. **Edit `/etc/pve/lxc/113.conf`** and append: ```ini # Allow USB character devices lxc.cgroup2.devices.allow: c 189:* rwm # Bind-mount the Coral device into the container dev0: /dev/bus/usb/003/005 ``` * **Explanation:** * `c 189:* rwm` grants the LXC permission to access all USB character devices (major 189). * `dev0: /dev/bus/usb/003/005` ensures the Coral shows up inside the container at the same path. 3. **Restart the LXC** ```bash pct stop 113 pct start 113 ``` * **Verify Inside the LXC** ```bash pct exec 113 -- lsusb | grep -i "Google Inc" ``` You should see: ```bash Bus 003 Device 005: ID 18d1:9302 Google Inc. ``` > If it still appears as `Global Unichip` inside the container, run the > classification example on the host again (so it’s already in `18d1:9302` > mode) and then restart the LXC. --- ## 6. (Optional) Install PyCoral & Edge TPU Runtime Inside the LXC If you’d like to run PyCoral scripts from within your Frigate LXC (or Frigate itself needs Python bindings), do this inside the container: 1. **Enter the LXC** ```bash pct exec 113 -- bash ``` 2. **Install the Edge TPU Runtime** ```bash wget https://dl.google.com/coral/edgetpu_api/edgetpu_runtime_20210620.zip unzip edgetpu_runtime_20210620.zip dpkg -i libedgetpu1-max_*.deb # or libedgetpu1-std_.deb ``` * **Why?** The container needs the same kernel driver to open `/dev/bus/usb/003/005`. 3. **Install PyCoral via pip** ```bash apt update apt install -y python3-pip python3-venv python3 -m venv /opt/py39 source /opt/py39/bin/activate pip install numpy pip install pycoral ``` * **Why?** You can’t rely on `apt install python3-pycoral`. Installing via `pip` ensures compatibility. 4. **Test Inside the Container** ```bash python3 - <