blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
17.99k stars 1.64k forks source link

[Detector Support]: Coral M.2 on Proxmox and linux VM #6380

Closed briodan closed 1 year ago

briodan commented 1 year ago

Describe the problem you are having

the coral is not being recognized by frigate in the docker container.

Issue happens with both a Debian and Ubuntu VM

Version

0.12.0-da3e197

Frigate config file

mqtt:
  host: IP
  user: user
  password: password
birdseye:
  enabled: True
  mode: continuous
detectors:
  coral_pci:
    type: edgetpu
    device: pci
cameras:
  camera_2: # <------ Name the camera
    ffmpeg:
      inputs:
        - path: rtsp://user:Password@IP # <----- Update for your camera
          roles:
            - detect
            - rtmp
    rtmp:
      enabled: False # <-- RTMP should be disabled if your stream is not H264
    detect:
      width: 1280 # <---- update for your camera's resolution
      height: 720 # <---- update for your camera's resolutio
    objects:
      filters:
        car:
          mask:
            - 1118,120,850,84,322,61,0,73,0,0,574,0,666,0,718,0,868,0,965,0,1119,0,1280,0,1280,173
      track:
        - person
        - dog
        - cat
        - car
    zones:
      driveway_right:
        coordinates: 524,539,1176,525,1016,243,872,94,619,75
        objects:
          - car
      driveway_left:
        coordinates: 346,55,162,231,0,411,0,488,506,542,623,66
        objects:
          - car
    motion:
      mask:
        - 1226,32,1229,47,943,46,943,27
    snapshots:
      enabled: true
      clean_copy: true
      timestamp: true
      bounding_box: true
      crop: false
      retain:
        default: 1
        objects:
          person: 1
          car: 1
 #   record:
 #     enabled: True
 #     events:
 #       retain:
 #         default: 2
 #         mode: all

docker-compose file or Docker CLI command

version: "3.9"
services:
  frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "64mb" # update for your cameras based on calculation above
    devices:
      - /dev/apex_0:/dev/apex_0 # passes a PCIe Coral, follow driver instructions here https://coral.ai/docs/m2/get-started/#2a-on-linux
    volumes:
      - /home/user/frigate/config.yml:/config/config.yml
    ports:
      - "5000:5000"
      - "8554:8554" # RTSP feeds
      - "8555:8555/tcp" # WebRTC over tcp
      - "8555:8555/udp" # WebRTC over udp

Relevant log output

s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
s6-rc: info: service s6rc-fdholder: starting
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service s6rc-fdholder successfully started
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service log-prepare: starting
s6-rc: info: service log-prepare successfully started
s6-rc: info: service nginx-log: starting
s6-rc: info: service go2rtc-log: starting
s6-rc: info: service frigate-log: starting
s6-rc: info: service nginx-log successfully started
s6-rc: info: service go2rtc-log successfully started
s6-rc: info: service go2rtc: starting
s6-rc: info: service frigate-log successfully started
s6-rc: info: service go2rtc successfully started
s6-rc: info: service go2rtc-healthcheck: starting
s6-rc: info: service frigate: starting
2023-05-04 14:35:46.012689120  [INFO] Preparing go2rtc config...
s6-rc: info: service go2rtc-healthcheck successfully started
s6-rc: info: service frigate successfully started
s6-rc: info: service nginx: starting
2023-05-04 14:35:46.033502544  [INFO] Starting Frigate...
s6-rc: info: service nginx successfully started
s6-rc: info: service legacy-services: starting
2023-05-04 14:35:46.043740149  [INFO] Starting NGINX...
s6-rc: info: service legacy-services successfully started
2023-05-04 14:35:46.337483659  [INFO] Starting go2rtc...
2023-05-04 14:35:46.490910407  14:35:46.490 INF go2rtc version 1.2.0 linux/amd64
2023-05-04 14:35:46.492180029  14:35:46.492 INF [api] listen addr=:1984
2023-05-04 14:35:46.492432775  14:35:46.492 INF [rtsp] listen addr=:8554
2023-05-04 14:35:46.493472493  14:35:46.493 INF [srtp] listen addr=:8443
2023-05-04 14:35:46.493714884  14:35:46.493 INF [webrtc] listen addr=:8555
2023-05-04 14:35:47.030743348  [2023-05-04 14:35:47] frigate.app                    INFO    : Starting Frigate (0.12.0-da3e197)
2023-05-04 14:35:47.043594888  [2023-05-04 14:35:47] peewee_migrate                 INFO    : Starting migrations
2023-05-04 14:35:47.047533049  [2023-05-04 14:35:47] peewee_migrate                 INFO    : There is nothing to migrate
2023-05-04 14:35:47.067022196  [2023-05-04 14:35:47] frigate.app                    INFO    : Output process started: 179
2023-05-04 14:35:47.080074220  [2023-05-04 14:35:47] frigate.app                    INFO    : Camera processor started for camera_2: 183
2023-05-04 14:35:47.090006423  [2023-05-04 14:35:47] detector.coral_pci             INFO    : Starting detection process: 178
2023-05-04 14:35:47.090263034  [2023-05-04 14:35:47] frigate.detectors.plugins.edgetpu_tfl INFO    : Attempting to load TPU as pci
2023-05-04 14:35:47.091538267  [2023-05-04 14:35:47] frigate.app                    INFO    : Capture process started for camera_2: 184
2023-05-04 14:35:56.026246180  [INFO] Starting go2rtc healthcheck service...
2023-05-04 14:35:59.938296670  [2023-05-04 14:35:59] frigate.detectors.plugins.edgetpu_tfl ERROR   : No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors.
2023-05-04 14:35:59.942127676  Process detector:coral_pci:
2023-05-04 14:35:59.942130478  Traceback (most recent call last):
2023-05-04 14:35:59.942132100    File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 160, in load_delegate
2023-05-04 14:35:59.942135012      delegate = Delegate(library, options)
2023-05-04 14:35:59.942136873    File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 119, in __init__
2023-05-04 14:35:59.942147457      raise ValueError(capture.message)
2023-05-04 14:35:59.942148629  ValueError
2023-05-04 14:35:59.942149549  
2023-05-04 14:35:59.942151188  During handling of the above exception, another exception occurred:
2023-05-04 14:35:59.942152169  
2023-05-04 14:35:59.942153262  Traceback (most recent call last):
2023-05-04 14:35:59.942154603    File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
2023-05-04 14:35:59.942182715      self.run()
2023-05-04 14:35:59.942184345    File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
2023-05-04 14:35:59.942185622      self._target(*self._args, **self._kwargs)
2023-05-04 14:35:59.942186940    File "/opt/frigate/frigate/object_detection.py", line 98, in run_detector
2023-05-04 14:35:59.942197462      object_detector = LocalObjectDetector(detector_config=detector_config)
2023-05-04 14:35:59.942198806    File "/opt/frigate/frigate/object_detection.py", line 52, in __init__
2023-05-04 14:35:59.942200064      self.detect_api = create_detector(detector_config)
2023-05-04 14:35:59.942201359    File "/opt/frigate/frigate/detectors/__init__.py", line 24, in create_detector
2023-05-04 14:35:59.942202441      return api(detector_config)
2023-05-04 14:35:59.942203767    File "/opt/frigate/frigate/detectors/plugins/edgetpu_tfl.py", line 37, in __init__
2023-05-04 14:35:59.942205060      edge_tpu_delegate = load_delegate("libedgetpu.so.1.0", device_config)
2023-05-04 14:35:59.942214850    File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 162, in load_delegate
2023-05-04 14:35:59.942216138      raise ValueError('Failed to load delegate from {}\n{}'.format(
2023-05-04 14:35:59.942217290  ValueError: Failed to load delegate from libedgetpu.so.1.0
2023-05-04 14:35:59.942218271  
2023-05-04 14:36:07.382331743  [2023-05-04 14:36:07] frigate.watchdog               INFO    : Detection appears to have stopped. Exiting Frigate...
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service nginx: stopping
s6-rc: info: service go2rtc-healthcheck: stopping
2023-05-04 14:36:07.403310173  [INFO] The go2rtc-healthcheck service exited with code 256 (by signal 15)
s6-rc: info: service go2rtc-healthcheck successfully stopped
2023-05-04 14:36:07.413938333  [INFO] Service NGINX exited with code 0 (by signal 0)
s6-rc: info: service nginx successfully stopped
s6-rc: info: service nginx-log: stopping
s6-rc: info: service frigate: stopping
s6-rc: info: service nginx-log successfully stopped
2023-05-04 14:36:07.417617768  [2023-05-04 14:36:07] frigate.app                    INFO    : Stopping...
2023-05-04 14:36:07.419409713  [2023-05-04 14:36:07] frigate.storage                INFO    : Exiting storage maintainer...
2023-05-04 14:36:07.419411845  [2023-05-04 14:36:07] frigate.events                 INFO    : Exiting event cleanup...
2023-05-04 14:36:07.419413393  [2023-05-04 14:36:07] frigate.record                 INFO    : Exiting recording cleanup...
2023-05-04 14:36:07.419414728  [2023-05-04 14:36:07] frigate.stats                  INFO    : Exiting stats emitter...
2023-05-04 14:36:07.419416045  [2023-05-04 14:36:07] frigate.record                 INFO    : Exiting recording maintenance...
2023-05-04 14:36:07.419417307  [2023-05-04 14:36:07] frigate.watchdog               INFO    : Exiting watchdog...
2023-05-04 14:36:07.423047327  [2023-05-04 14:36:07] frigate.object_processing      INFO    : Exiting object processor...
2023-05-04 14:36:07.577481502  [2023-05-04 14:36:07] frigate.comms.ws               INFO    : Exiting websocket client...
2023-05-04 14:36:08.394155877  [2023-05-04 14:36:08] frigate.events                 INFO    : Exiting event processor...
2023-05-04 14:36:08.395098568  [2023-05-04 14:36:08] peewee.sqliteq                 INFO    : writer received shutdown request, exiting.
2023-05-04 14:36:08.396938147  [2023-05-04 14:36:08] watchdog.camera_2              INFO    : Terminating the existing ffmpeg process...
2023-05-04 14:36:08.397154469  [2023-05-04 14:36:08] watchdog.camera_2              INFO    : Waiting for ffmpeg to exit gracefully...
2023-05-04 14:36:08.642602297  [2023-05-04 14:36:08] frigate.output                 INFO    : exiting output process...
2023-05-04 14:36:12.544376910  /usr/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 6 leaked shared_memory objects to clean up at shutdown
2023-05-04 14:36:12.544379360    warnings.warn('resource_tracker: There appear to be %d '
2023-05-04 14:36:12.551226328  [INFO] Service Frigate exited with code 0 (by signal 0)
s6-rc: info: service frigate successfully stopped
s6-rc: info: service go2rtc: stopping
s6-rc: info: service frigate-log: stopping
2023-05-04 14:36:12.552784167  exit OK
s6-rc: info: service frigate-log successfully stopped
2023-05-04 14:36:12.556685055  [INFO] The go2rtc service exited with code 0 (by signal 0)
s6-rc: info: service go2rtc successfully stopped
s6-rc: info: service go2rtc-log: stopping
s6-rc: info: service go2rtc-log successfully stopped
s6-rc: info: service log-prepare: stopping
s6-rc: info: service s6rc-fdholder: stopping
s6-rc: info: service log-prepare successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service s6rc-fdholder successfully stopped
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Operating system

Debian

Install method

Docker Compose

Coral version

M.2

Any other information that may be helpful

followed this guide for the install, post by alexrusso51 https://www.reddit.com/r/homeassistant/comments/xzajo0/coral_tpu_proxmox_frigate/

Coral detected on proxmox system

root@pve:~# lspci -nnk | grep 089a
02:00.0 System peripheral [0880]: Global Unichip Corp. Coral Edge TPU [1ac1:089a]
        Subsystem: Global Unichip Corp. Coral Edge TPU [1ac1:089a]

gasket and apex did not load on proxmox

root@pve:~# lsmod | grep apex
root@pve:~#

PCI device mapped to VM

  GNU nano 5.4                                                                      103.conf
boot: order=scsi0;ide2;net0
cores: 1
hostpci0: 0000:02:00
ide2: none,media=cdrom
memory: 2048
meta: creation-qemu=7.2.0,ctime=1683144561
net0: virtio=26:C7:CA:CD:0C:F5,bridge=vmbr0,firewall=1
numa: 0
ostype: l26
scsi0: local-lvm:vm-103-disk-0,iothread=1,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=1497ae32-c9e1-4444-923d-8054568f124a
sockets: 1
vmgenid: 34674c82-fba9-4ed6-8ea6-4c3a9ee570d4

PCI device detected on VM

user@ubuntun:~/frigate$ lspci -nnk | grep 089a
00:10.0 System peripheral [0880]: Global Unichip Corp. Coral Edge TPU [1ac1:089a]
        Subsystem: Global Unichip Corp. Coral Edge TPU [1ac1:089a]

PCI drivers loaded on VM

user@ubuntun:~/frigate$ lsmod | grep apex
apex                   20480  1
gasket                106496  2 apex

linux device present

user@ubuntun:~/frigate$ ls -al /dev/apex_0
crw------- 1 root root 120, 0 May  3 22:56 /dev/apex_0

docker container detects driver

root@e9bc581d59fd:/opt/frigate#  ls -al /dev/apex_0
crw------- 1 root root 120, 0 May  4 14:48 /dev/apex_0
Bettman66 commented 1 year ago

Your rights are too low Proxmox Host: sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0755\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules" reboot

briodan commented 1 year ago

that did the trick thanks a bunch