frigate icon indicating copy to clipboard operation
frigate copied to clipboard

[EdgeTPU Support]: Cannot mount USB TPU into docker container

Open patrick-zinner opened this issue 2 years ago • 7 comments

Describe the problem you are having

Hi,

I want to use the USB Edge TPU for Frigate running on Docker. The host machine runs Ubuntu 22.04.1 LTS. I did all the getting started stuff and lsusb shows:

Bus 002 Device 002: ID 1a6e:089a Global Unichip Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
Bus 001 Device 004: ID 0bda:c821 Realtek Semiconductor Corp. Bluetooth Radio
Bus 001 Device 003: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Sometimes it shows Google Inc. instead of the Global Unichip Corp. (probably after executing make reset).

Frigate runs using this docker compose configuration:

  frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: blakeblackshear/frigate:stable
    shm_size: "64mb" # update for your cameras based on calculation above
    volumes:
      - /dev/bus/usb:/dev/bus/usb # also tried to use the devices section
      - /etc/localtime:/etc/localtime:ro
      - ./frigate/config/config.yml:/config/config.yml:ro
      - ./frigate/media:/media/frigate 
      - type: tmpfs 
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "5000:5000"
      - "1935:1935" # RTMP feeds
    environment:
      FRIGATE_RTSP_PASSWORD: "hunter2"

When i connect to the container and execute lsusb then I get the following result:

Bus 002 Device 002: ID 1a6e:089a
Bus 002 Device 001: ID 1d6b:0003 Linux 5.15.0-58-generic xhci-hcd xHCI Host Controller
Bus 001 Device 005: ID 0d8c:0014 C-Media Electronics Inc. USB Audio Device
Bus 001 Device 004: ID 0bda:c821 Realtek  Bluetooth Radio
Bus 001 Device 003: ID 10c4:ea60 Silicon Labs Sonoff Zigbee 3.0 USB Dongle Plus
Bus 001 Device 001: ID 1d6b:0002 Linux 5.15.0-58-generic xhci-hcd xHCI Host Controller

When I configure the Coral as detector in Frigate, it starts up at first and even logs "TPU found" but then crashes because it cannot find the coral (anymore?).

I've read several issues and threads here but all the solutions to previous problems do not work for me. Any idea what I can change?

Version

0.11.1-2EADA21

Frigate config file

mqtt:
  host: 192.168.1.xxxxxxxxxxxx

detectors:
  coral:
    device: usb
    type: edgetpu

cameras:
  intercom:
    zones:
      doorstep:
        coordinates: 785,720,1039,720,1041,720,1098,720,1162,720,1050,619,909,542,840,504,795,470,751,479,765,591,770,604
        objects:
          - person
          - dog
          - cat

    objects:
      track:
        - person
        - car
        - truck
        - motorcycle
        - dog
        - cat
    ffmpeg:
      inputs:
        - path: 'rtsp://this-is-normally-the-real-url
          roles:
            - detect
            - rtmp
            - record
record:
  enabled: True
  expire_interval: 60
  retain:
    days: 0
    mode: motion
  events:
    pre_capture: 5
    post_capture: 5
    objects:
      - person
      - dog
      - car
      - cat
      - truck
      - motorcycle
    required_zones: []
    retain:
      default: 10
      mode: motion
      objects:
        cat: 1
        dog: 1
detect:
  stationary:
    max_frames:
      default: 3000


motion:
  mask:
    - 218,720,122,720,24,720,0,664,366,658,443,659,512,661,522,720,459,699
objects:
  filters:
    car:
      mask:
        - 586,240,830,239,851,318,865,381,647,401,462,395,589,318,587,280
        - 1040,311,1050,368,1000,372,932,363,929,315
  track:
    - person
    - cat
    - dog
    - car
    - truck
    - motorcycle

docker-compose file or Docker CLI command

frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: blakeblackshear/frigate:stable
    shm_size: "64mb" # update for your cameras based on calculation above
    volumes:
      - /dev/bus/usb:/dev/bus/usb # also tried to use the devices section
      - /etc/localtime:/etc/localtime:ro
      - ./frigate/config/config.yml:/config/config.yml:ro
      - ./frigate/media:/media/frigate 
      - type: tmpfs 
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "5000:5000"
      - "1935:1935" # RTMP feeds
    environment:
      FRIGATE_RTSP_PASSWORD: "hunter2"

Relevant log output

[2023-01-28 07:33:20] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
Starting migrations
[2023-01-28 07:33:20] peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
[2023-01-28 07:33:20] peewee_migrate                 INFO    : There is nothing to migrate
[2023-01-28 07:33:20] frigate.app                    INFO    : Output process started: 213
[2023-01-28 07:33:20] detector.coral                 INFO    : Starting detection process: 212
[2023-01-28 07:33:20] frigate.edgetpu                INFO    : Attempting to load TPU as usb
[2023-01-28 07:33:20] frigate.app                    INFO    : Camera processor started for intercom: 216
[2023-01-28 07:33:20] ws4py                          INFO    : Using epoll
[2023-01-28 07:33:20] frigate.app                    INFO    : Capture process started for intercom: 218
[2023-01-28 07:33:20] ws4py                          INFO    : Using epoll
[2023-01-28 07:33:27] frigate.edgetpu                INFO    : TPU found
F driver/usb/usb_driver.cc:1148] HandleQueuedBulkIn transfer in failed. Not found: USB transfer error 5 [LibUsbDataInCallback]
Fatal Python error: Aborted

Thread 0x00007ff330ea2700 (most recent call first):
  File "/usr/lib/python3.9/threading.py", line 312 in wait
  File "/usr/lib/python3.9/multiprocessing/queues.py", line 233 in _feed
  File "/usr/lib/python3.9/threading.py", line 892 in run
  File "/usr/lib/python3.9/threading.py", line 954 in _bootstrap_inner
  File "/usr/lib/python3.9/threading.py", line 912 in _bootstrap

Thread 0x00007ff348fe2740 (most recent call first):
  File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 833 in invoke
  File "/opt/frigate/frigate/edgetpu.py", line 83 in detect_raw
  File "/opt/frigate/frigate/edgetpu.py", line 159 in run_detector
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108 in run
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315 in _bootstrap
  File "/usr/lib/python3.9/multiprocessing/popen_fork.py", line 71 in _launch
  File "/usr/lib/python3.9/multiprocessing/popen_fork.py", line 19 in __init__
  File "/usr/lib/python3.9/multiprocessing/context.py", line 277 in _Popen
  File "/usr/lib/python3.9/multiprocessing/context.py", line 224 in _Popen
  File "/usr/lib/python3.9/multiprocessing/process.py", line 121 in start
  File "/opt/frigate/frigate/edgetpu.py", line 220 in start_or_restart
  File "/opt/frigate/frigate/edgetpu.py", line 189 in __init__
  File "/opt/frigate/frigate/app.py", line 217 in start_detectors
  File "/opt/frigate/frigate/app.py", line 360 in start
  File "/opt/frigate/frigate/__main__.py", line 16 in <module>
  File "/usr/lib/python3.9/runpy.py", line 87 in _run_code
  File "/usr/lib/python3.9/runpy.py", line 197 in _run_module_as_main
[2023-01-28 07:33:40] frigate.watchdog               INFO    : Detection appears to be stuck. Restarting detection process...
[2023-01-28 07:33:40] detector.coral                 INFO    : Starting detection process: 265
[2023-01-28 07:33:40] frigate.edgetpu                INFO    : Attempting to load TPU as usb
Process detector:coral:
[2023-01-28 07:33:46] frigate.edgetpu                ERROR   : No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors.
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

[2023-01-28 07:33:50] frigate.watchdog               INFO    : Detection appears to have stopped. Exiting frigate...
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[2023-01-28 07:33:50] frigate.video                  ERROR   : intercom: Unable to read frames from ffmpeg process.
[2023-01-28 07:33:50] frigate.video                  ERROR   : intercom: ffmpeg process is not running. exiting capture thread...
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[2023-01-28 07:33:58] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
Starting migrations
[2023-01-28 07:33:58] peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
[2023-01-28 07:33:58] peewee_migrate                 INFO    : There is nothing to migrate
[2023-01-28 07:33:58] frigate.app                    INFO    : Output process started: 213
[2023-01-28 07:33:58] ws4py                          INFO    : Using epoll
[2023-01-28 07:33:58] frigate.app                    INFO    : Camera processor started for intercom: 217
[2023-01-28 07:33:58] frigate.app                    INFO    : Capture process started for intercom: 220
[2023-01-28 07:33:58] ws4py                          INFO    : Using epoll
[2023-01-28 07:33:58] detector.coral                 INFO    : Starting detection process: 212
Process detector:coral:
[2023-01-28 07:33:58] frigate.edgetpu                INFO    : Attempting to load TPU as usb
[2023-01-28 07:34:05] frigate.edgetpu                ERROR   : No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors.
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

[2023-01-28 07:34:18] frigate.watchdog               INFO    : Detection appears to have stopped. Exiting frigate...
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[2023-01-28 07:34:19] frigate.video                  ERROR   : intercom: Unable to read frames from ffmpeg process.
[2023-01-28 07:34:19] frigate.video                  ERROR   : intercom: ffmpeg process is not running. exiting capture thread...
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[2023-01-28 07:34:26] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
Starting migrations
[2023-01-28 07:34:26] peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
[2023-01-28 07:34:26] peewee_migrate                 INFO    : There is nothing to migrate
[2023-01-28 07:34:26] frigate.app                    INFO    : Output process started: 214
[2023-01-28 07:34:26] detector.coral                 INFO    : Starting detection process: 212

Operating system

Other Linux

Install method

Docker Compose

Coral version

USB

Any other information that may be helpful

No response

patrick-zinner avatar Jan 28 '23 07:01 patrick-zinner

When it shows as Google Inc. the internal driver has been loaded. When it shows as Global Unichip Corp. the internal driver has not yet loaded.

This seems like a udev rule issue

NickM-27 avatar Jan 28 '23 13:01 NickM-27

@NickM-27

When I execute the linux_device_rules.sh install script from here: https://github.com/google-coral/webcoral and then execute make reset it shows it as Google Inc.

When I try to use it in Frigate, the same problem appears. Any idea about possible solutions?

patrick-zinner avatar Jan 28 '23 14:01 patrick-zinner

Is there a reason you're passing it as a volume and not a device?

NickM-27 avatar Jan 28 '23 14:01 NickM-27

I tried both approaches because other people in other issues had success by passing it as a volume. The result is always the same for me.

patrick-zinner avatar Jan 28 '23 14:01 patrick-zinner

Have you tried different cables, different ports, etc?

NickM-27 avatar Jan 28 '23 14:01 NickM-27

Yes, I also tried using the USB port that is normally used by the Zigbee USB dongle that I am using. The Zigbee Dongle works on all ports and I've tried 3 different USB cables.

FWIW: The Zigbee USB dongle is present in all docker containers.

EDIT: Also, as long as frigate does not try to access the TPU, its visible on the host. As soon as I configure the TPU, its gone from the host as well.

patrick-zinner avatar Jan 28 '23 14:01 patrick-zinner

Same issue in homeassistant…..

fisch55 avatar Jan 29 '23 16:01 fisch55

Just a short update: I could do the following things described in this comment: https://github.com/google-coral/pycoral/issues/94#issuecomment-1343839142 but it still does not work with the way described in the post above.

patrick-zinner avatar Jan 31 '23 09:01 patrick-zinner

What do you have in lsusb? Have you tried getting the coral device to work in a different app? Bus 004 Device 002: ID 18d1:9302 Google Inc.

Maxcodesthings avatar Feb 03 '23 23:02 Maxcodesthings

I use OMV which is Debian based, but I've also done it with Ubuntu as well

Follow 1a and then reboot. repository

In my docker-compose file

    devices:
      - /dev/bus/usb:/dev/bus/usb

This is what works for me the times I've messed up the coral and needed it to work again.

trythatagain avatar Feb 04 '23 15:02 trythatagain

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.

github-actions[bot] avatar Mar 07 '23 00:03 github-actions[bot]

I use OMV which is Debian based, but I've also done it with Ubuntu as well

Follow 1a and then reboot. repository

In my docker-compose file

    devices:
      - /dev/bus/usb:/dev/bus/usb

This is what works for me the times I've messed up the coral and needed it to work again.

This is what fixed the issue for me. Thank you! Followed the steps to install it on the host, then reboot, and it worked in docker.

adriel avatar Mar 31 '23 00:03 adriel

I use OMV which is Debian based, but I've also done it with Ubuntu as well

Follow 1a and then reboot. repository

In my docker-compose file

    devices:
      - /dev/bus/usb:/dev/bus/usb

This is what works for me the times I've messed up the coral and needed it to work again.

This worked for me. Ubuntu 22.04

whatcheers avatar Mar 16 '24 15:03 whatcheers