aegjoyce / ha-addons

Add-ons for Home Assistant, including unofficial support for Scrypted.
GNU General Public License v3.0
91 stars 25 forks source link

PCI Coral full_access #106

Closed gschrader closed 1 year ago

gschrader commented 1 year ago

I'm thinking about moving from Frigate to Scypted for my camera. I see you have the usb option I'm guessing for USB Corals. Is it possibly to add full_access for PCI devices? I think that's the config option that makes the Frigate add-on work.

aegjoyce commented 1 year ago

Not keen to add full_access as it will trash the security rating of the add-on. Have added GPIO and UART device inputs with v0.7.24-1, could you see if this fixes the issue?

gschrader commented 1 year ago

it didn't find it, I wonder if it needs to be devices. On another note when I installed the plugin the readme said it was not used by HomeKit so I might not be completely comprehending everything.

aegjoyce commented 1 year ago

Anything that can be exposed in devices will be exposed as part of gpio usb and uart. Do you know the hardware address of the Coral?

aegjoyce commented 1 year ago

Screenshots of how you're trying to set it up in Scrypted would be helpful if you can provide them

gschrader commented 1 year ago

I can see it in the HAOS terminal under /dev/apex_0

Frigate only shows this in the log: [2023-03-23 15:49:36] frigate.edgetpu INFO : TPU found

I haven't gotten very far with Scrypted yet, but the plugin shows this:

image

gschrader commented 1 year ago

Here's the console:

server version: 0.7.24
plugin version: @scrypted/tensorflow-lite 0.1.7
########################
3/23/2023, 3:59:37 PM
########################
python version: python3.9
requirements.txt (up to date)
--extra-index-url https://google-coral.github.io/py-repo/

# plugin
numpy>=1.16.2
# pillow for anything not intel linux
Pillow>=5.4.1; sys_platform != 'linux' or platform_machine != 'x86_64'
pillow-simd; sys_platform == 'linux' and platform_machine == 'x86_64'
pycoral~=2.0
PyGObject>=3.30.4; sys_platform != 'win32'
# libav doesnt work on arm7
av>=10.0.0; sys_platform != 'linux' or platform_machine == 'x86_64' or platform_machine == 'aarch64'
tflite-runtime==2.5.0.post1

# sort_oh
scipy
filterpy

site-packages: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64/lib/python3.9/site-packages
coral edge tpu library loaded successfully
edge tpus [{'type': 'pci', 'path': '/dev/apex_0'}]
unable to use Coral Edge TPU Failed to load delegate from libedgetpu.so.1

unable to use Coral Edge TPU all tpus failed to load

Thought for a second I made a mistake not restarting with your latest version but I presume the version numbers won't match.

gschrader commented 1 year ago

looks like it is in the scrypted container:

image

gschrader commented 1 year ago

Looks like frigate specifies some common devices

https://github.com/blakeblackshear/frigate-hass-addons/blob/80879183cb4040e4152bb56d805f2387e24ec884/frigate/config.yaml

aegjoyce commented 1 year ago

I think this is a passthrough issue - looks like it needs --privileged enabled, I will have another look at this

aegjoyce commented 1 year ago

Right, have just made some changes on Scrypted Beta to allow privileged sys_rawio access and /dev/mem access - would you mind testing this out? It's v0.7.85-1

gschrader commented 1 year ago

Looks to be the same error:

linux x64 #1 SMP PREEMPT_DYNAMIC Mon Apr 17 09:34:33 UTC 2023
server version: 0.7.85
plugin version: @scrypted/tensorflow-lite 0.1.12
########################
4/24/2023, 2:07:26 PM
########################
python version: python3.9
python prefix: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64
Removing old dependencies: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64
requirements.txt (outdated)
--extra-index-url https://google-coral.github.io/py-repo/
pycoral~=2.0
tflite-runtime==2.5.0.post1

# pillow for anything not intel linux, pillow-simd is available on x64 linux
Pillow>=5.4.1; sys_platform != 'linux' or platform_machine != 'x86_64'
pillow-simd; sys_platform == 'linux' and platform_machine == 'x86_64'

Looking in indexes: https://pypi.org/simple, https://google-coral.github.io/py-repo/
Ignoring Pillow: markers 'sys_platform != "linux" or platform_machine != "x86_64"' don't match your environment
Collecting pycoral~=2.0
  Downloading https://github.com/google-coral/pycoral/releases/download/v2.0.0/pycoral-2.0.0-cp39-cp39-linux_x86_64.whl (393 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 393.8/393.8 kB 3.0 MB/s eta 0:00:00
Collecting tflite-runtime==2.5.0.post1
  Downloading https://github.com/google-coral/pycoral/releases/download/v2.0.0/tflite_runtime-2.5.0.post1-cp39-cp39-linux_x86_64.whl (1.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 18.3 MB/s eta 0:00:00
Collecting pillow-simd
  Downloading Pillow-SIMD-9.0.0.post1.tar.gz (849 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 849.9/849.9 kB 5.3 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: numpy>=1.16.0 in /usr/lib/python3/dist-packages (from tflite-runtime==2.5.0.post1->-r /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64/requirements.txt (line 3)) (1.19.5)
Requirement already satisfied: Pillow>=4.0.0 in /usr/lib/python3/dist-packages (from pycoral~=2.0->-r /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64/requirements.txt (line 2)) (8.1.2)
Building wheels for collected packages: pillow-simd
  Building wheel for pillow-simd (setup.py): started
  Building wheel for pillow-simd (setup.py): finished with status 'done'
  Created wheel for pillow-simd: filename=Pillow_SIMD-9.0.0.post1-cp39-cp39-linux_x86_64.whl size=1288100 sha256=d19f0b1cefb7d33c5e6e3fafce9d90aafaacdf429affc342212ec862999feae9
  Stored in directory: /root/.cache/pip/wheels/2c/8b/79/3325cc689bef3b7eb3e928df7b163185f6a2677f8dde55523b
Successfully built pillow-simd
Installing collected packages: tflite-runtime, pillow-simd, pycoral
Successfully installed pillow-simd-9.0.0.post1 pycoral-2.0.0 tflite-runtime-2.5.0.post1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip available: 22.3.1 -> 23.1.1
[notice] To update, run: python3 -m pip install --upgrade pip
pip install result 0
site-packages: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64/lib/python3.9/site-packages
coral edge tpu library loaded successfully
edge tpus [{'type': 'pci', 'path': '/dev/apex_0'}]
unable to use Coral Edge TPU Failed to load delegate from libedgetpu.so.1

unable to use Coral Edge TPU all tpus failed to load
gschrader commented 1 year ago

I'm guessing you'd want to copy frigate with this:

devices:
  - /dev/dri/renderD128
  - /dev/apex_0
  - /dev/apex_1
  - /dev/apex_2
  - /dev/apex_3
  - /dev/dri/card0
  - /dev/vchiq
  - /dev/video10
  - /dev/video0

I specifically would need /dev/apex_0

aegjoyce commented 1 year ago

Ok, v0.7.85-2 adds those devices and also adds video: true in case that helps

gschrader commented 1 year ago

Looks like success, I'll do some further testing. Thanks!

linux x64 #1 SMP PREEMPT_DYNAMIC Mon Apr 17 09:34:33 UTC 2023
server version: 0.7.85
plugin version: @scrypted/tensorflow-lite 0.1.12
########################
4/24/2023, 4:04:28 PM
########################
python version: python3.9
python prefix: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64
requirements.txt (up to date)
--extra-index-url https://google-coral.github.io/py-repo/
pycoral~=2.0
tflite-runtime==2.5.0.post1

# pillow for anything not intel linux, pillow-simd is available on x64 linux
Pillow>=5.4.1; sys_platform != 'linux' or platform_machine != 'x86_64'
pillow-simd; sys_platform == 'linux' and platform_machine == 'x86_64'

site-packages: /data/scrypted_data/plugins/@scrypted/tensorflow-lite/python3.9-Linux-x86_64/lib/python3.9/site-packages
coral edge tpu library loaded successfully
edge tpus [{'type': 'pci', 'path': '/dev/apex_0'}]
added tpu {'type': 'pci', 'path': '/dev/apex_0'}
aegjoyce commented 1 year ago

This is good news! Would you mind testing v0.7.85-3 (EDIT: now v0.7.90) and see if it still works? I just removed the privileged section from config.yaml. If it still works like this then I'll push it to the main Scrypted addons, happy to have devices specified if it makes the coral work (although I still don't understand why it doesn't work when just gpio and all the other settings are enabled - it should!)

aegjoyce commented 1 year ago

Closed with latest release.

gschrader commented 1 year ago

Yup it still loads with the latest version, thanks for adding it to the main release.