[EdgeTPU Support]: M.2 coral with Docker Rootless
Describe the problem you are having
I have Docker Rootless running on Ubuntu Server 20.04.5 LTS with a M.2 Dual Edge TPU.
I can run inference on the host (in line with https://www.coral.ai/docs/m2/get-started/#4-run-a-model-on-the-edge-tpu).
Frigate is stable with CPU detector in my config file but constantly restarts when I try to use my Edge TPU.
I have seen similar topics regarding USB Corals which talk about updating the udev rules to allow non-root users to access USB. I think my udev rules are correct. /etc/udev/rules.d/nano 65-apex.rules:
SUBSYSTEM=="apex",` MODE="0660", GROUP="apex"
Version
0.10.1-83481af
Frigate config file
mqtt:
host: 192.168.1.104
port: 1883
topic_prefix: frigate
client_id: frigate
detectors:
coral:
type: edgetpu
device: pci
# cpu1:
# type: cpu
# num_threads: 3
cameras:
front:
ffmpeg:
inputs:
- path: rtsp://viewer:[email protected]/ch0_0.h264
roles:
- detect
- rtmp
rtmp:
enabled: True
detect:
width: 1920
height: 1080
docker-compose file or Docker CLI command
version: '3.7'
services:
home-assistant:
container_name: home-assistant
image: ghcr.io/linuxserver/homeassistant:amd64-latest
# network_mode: host
restart: unless-stopped
# privileged: true
# userns_mode: "host"
environment:
- PUID=1001
- PGID=1001
- TZ=Europe/London
#devices:
# - /dev/aeotec-zwave-stick:/zwaveusbstick
#env_file:
# - ./common.env
# - ./secret.env
ports:
- 8123:8123
volumes:
- /home/dockeruser/containers/homeassistant/homeassistant/config:/config
depends_on:
- mariadb
- mosquitto
mariadb:
image: linuxserver/mariadb
container_name: mariadb
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: "xxx"
MYSQL_DATABASE: ha_db
MYSQL_USER: homeassistant
MYSQL_PASSWORD: "xxx"
PUID: 1001
PGID: 1001
volumes:
- ./mariadb:/config
ports:
- "3306:3306"
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto
restart: unless-stopped
ports:
- "1883:1883"
- "1884:1884"
volumes:
- "./mosquitto/config:/mosquitto/config"
- "./mosquitto/data:/mosquitto/data"
- "./mosquitto/log:/mosquitto/log"
environment:
- TZ=Europe/London
- PUID=1001
- PGID=1001
frigate:
container_name: frigate
# privileged: true # this may not be necessary for all setups
restart: unless-stopped
image: blakeblackshear/frigate:stable-amd64
shm_size: "64mb" # update for your cameras based on calculation above
devices:
# - /dev/bus/usb:/dev/bus/usb # passes the USB Coral, needs to be modified for other versions
- /dev/apex_0:/dev/apex_0 # passes a PCIe Coral, follow driver instructions here https://coral.ai/docs/m2/get-started/#2a-on-linux
- /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/dockeruser/containers/homeassistant/homeassistant/frigate/config/config.yml:/config/config.yml:ro
- /home/dockeruser/data/CCTV:/media/frigate
- type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "5001:5000"
- "1935:1935" # RTMP feeds
environment:
FRIGATE_RTSP_PASSWORD: "xxx"
Relevant log output
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[2022-12-23 14:56:20] frigate.app INFO : Starting Frigate (0.10.1-83481af)
Starting migrations
[2022-12-23 14:56:20] peewee_migrate INFO : Starting migrations
There is nothing to migrate
[2022-12-23 14:56:20] peewee_migrate INFO : There is nothing to migrate
[2022-12-23 14:56:20] detector.coral INFO : Starting detection process: 217
[2022-12-23 14:56:20] frigate.app INFO : Output process started: 218
[2022-12-23 14:56:20] frigate.app INFO : Camera processor started for front: 224
[2022-12-23 14:56:20] frigate.app INFO : Capture process started for front: 227
[2022-12-23 14:56:20] frigate.edgetpu INFO : Attempting to load TPU as pci
[2022-12-23 14:56:20] frigate.edgetpu ERROR : No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors.
Process detector:coral:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 160, in load_delegate
delegate = Delegate(library, options)
File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 119, in __init__
raise ValueError(capture.message)
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/opt/frigate/frigate/edgetpu.py", line 136, in run_detector
object_detector = LocalObjectDetector(
File "/opt/frigate/frigate/edgetpu.py", line 44, in __init__
edge_tpu_delegate = load_delegate("libedgetpu.so.1.0", device_config)
File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 162, in load_delegate
raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from libedgetpu.so.1.0
[2022-12-23 14:56:20] ws4py INFO : Using epoll
[2022-12-23 14:56:21] ws4py INFO : Using epoll
Operating system
Other Linux
Install method
Docker Compose
Coral version
M.2
Any other information that may be helpful
No response
For one it looks like you're on an outdated version of frigate, recommend updating by removing -amd64 from your image.
https://github.com/blakeblackshear/frigate/issues/4636#issuecomment-1361900444 is going to be the answer. If frigate can't see your coral then one way or another it's not being passed in correctly. It could help to run with cpu detectors and see what frigate sees using ls /dev/ inside the container.
For one it looks like you're on an outdated version of frigate, recommend updating by removing
-amd64from your image.#4636 (comment) is going to be the answer. If frigate can't see your coral then one way or another it's not being passed in correctly. It could help to run with cpu detectors and see what frigate sees using
ls /dev/inside the container.
Thanks for your quick reply.
I've corrected the tag, pulled the image and updated my container. Version is now 0.11.1-2eada21.
I'm still encountering the same issue with the latest log:
[cont-init.d] executing container initialization scripts... [cont-init.d] done. [services.d] starting services [services.d] done. [2022-12-23 15:19:44] frigate.app INFO : Starting Frigate (0.11.1-2eada21) Starting migrations [2022-12-23 15:19:44] peewee_migrate INFO : Starting migrations There is nothing to migrate [2022-12-23 15:19:44] peewee_migrate INFO : There is nothing to migrate [2022-12-23 15:19:44] ws4py INFO : Using epoll [2022-12-23 15:19:44] frigate.app INFO : Output process started: 217 [2022-12-23 15:19:44] frigate.app INFO : Camera processor started for front: 223 [2022-12-23 15:19:44] detector.coral INFO : Starting detection process: 216 [2022-12-23 15:19:44] frigate.edgetpu INFO : Attempting to load TPU as pci [2022-12-23 15:19:44] frigate.edgetpu ERROR : No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors. Process detector:coral: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 160, in load_delegate delegate = Delegate(library, options) File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 119, in init raise ValueError(capture.message) ValueError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap self.run() File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "/opt/frigate/frigate/edgetpu.py", line 135, in run_detector object_detector = LocalObjectDetector( File "/opt/frigate/frigate/edgetpu.py", line 43, in init edge_tpu_delegate = load_delegate("libedgetpu.so.1.0", device_config) File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 162, in load_delegate raise ValueError('Failed to load delegate from {}\n{}'.format( ValueError: Failed to load delegate from libedgetpu.so.1.0 [2022-12-23 15:19:44] frigate.app INFO : Capture process started for front: 226 [2022-12-23 15:19:44] ws4py INFO : Using epoll
ls /dev/ in the container returned the below so not seeing apex_0.
root@2820a109676e:/opt/frigate# ls /dev/ core dri fd full mqueue null ptmx pts random shm stderr stdin stdout tty urandom zero
I already read that issue and checked udev rules for pci which is in my first post. I think those permissions are correct.
And to confirm, running ls /dev on the host outputs what?
Does it work if you run with sudo docker compose up ?
And to confirm, running ls /dev on the host outputs what?
Does it work if you run with
sudo docker compose up?
apex_0 cpu fd i2c-3 loop0 mapper psaux sda2 stderr tty11 tty2 tty28 tty36 tty44 tty52 tty60 ttyS1 ttyS18 ttyS26 ttyS6 userio vcsa1 vcsu3 zero autofs cpu_dma_latency full i2c-4 loop1 mcelog ptmx sda3 stdin tty12 tty20 tty29 tty37 tty45 tty53 tty61 ttyS10 ttyS19 ttyS27 ttyS7 vcs vcsa2 vcsu4 zfs block cuse fuse i2c-5 loop2 mem pts sdb stdout tty13 tty21 tty3 tty38 tty46 tty54 tty62 ttyS11 ttyS2 ttyS28 ttyS8 vcs1 vcsa3 vcsu5 bsg disk hpet i2c-6 loop3 mqueue random sdb1 tpm0 tty14 tty22 tty30 tty39 tty47 tty55 tty63 ttyS12 ttyS20 ttyS29 ttyS9 vcs2 vcsa4 vcsu6 btrfs-control dm-0 hugepages initctl loop4 net rfkill sg0 tpmrm0 tty15 tty23 tty31 tty4 tty48 tty56 tty7 ttyS13 ttyS21 ttyS3 ubuntu-vg vcs3 vcsa5 vfio bus dri hwrng input loop5 null rtc sg1 tty tty16 tty24 tty32 tty40 tty49 tty57 tty8 ttyS14 ttyS22 ttyS30 udmabuf vcs4 vcsa6 vga_arbiter char drm_dp_aux0 i2c-0 kfd loop6 nvram rtc0 shm tty0 tty17 tty25 tty33 tty41 tty5 tty58 tty9 ttyS15 ttyS23 ttyS31 uhid vcs5 vcsu vhci console drm_dp_aux1 i2c-1 kmsg loop7 port sda snapshot tty1 tty18 tty26 tty34 tty42 tty50 tty59 ttyprintk ttyS16 ttyS24 ttyS4 uinput vcs6 vcsu1 vhost-net core ecryptfs i2c-2 log loop-control ppp sda1 snd tty10 tty19 tty27 tty35 tty43 tty51 tty6 ttyS0 ttyS17 ttyS25 ttyS5 urandom vcsa vcsu2 vhost-vsock
I couldn't start the container with sudo whilst using rootless docker. I started the docker service with sudo systemctl start docker and then starting the container that way it does start up properly and see the coral. I thought this would work all along but ideally I want to get this working rootless.
So it's definitely a udev issue. Might be because the linked issue was referring to usb coral while yours is m.2
I'd post on the coral GitHub repo because they'll likely know better
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
sadly this is also happening on root. apex_0 is available in container, still no edgetpu support. exact same error here