mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
Added VIM3 components - There has to be a smarter way to select the LIB only when
needed on the platform.
This commit is contained in:
parent
1b8cd10142
commit
2f810ed28c
2
docker/rootfs/etc/ld.so.conf.d/vim3.conf
Normal file
2
docker/rootfs/etc/ld.so.conf.d/vim3.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#VIM3 objects
|
||||||
|
/lib/vim3
|
||||||
BIN
docker/rootfs/lib/vim3/libArchModelSw.so
Executable file
BIN
docker/rootfs/lib/vim3/libArchModelSw.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libCLC.so
Executable file
BIN
docker/rootfs/lib/vim3/libCLC.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libGAL.so
Executable file
BIN
docker/rootfs/lib/vim3/libGAL.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libNNArchPerf.so
Executable file
BIN
docker/rootfs/lib/vim3/libNNArchPerf.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libNNVXCBinary.so
Executable file
BIN
docker/rootfs/lib/vim3/libNNVXCBinary.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libOpenVX.so
Executable file
BIN
docker/rootfs/lib/vim3/libOpenVX.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libOpenVXU.so
Executable file
BIN
docker/rootfs/lib/vim3/libOpenVXU.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libVSC.so
Executable file
BIN
docker/rootfs/lib/vim3/libVSC.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libtim-vx.so
Executable file
BIN
docker/rootfs/lib/vim3/libtim-vx.so
Executable file
Binary file not shown.
BIN
docker/rootfs/lib/vim3/libvx_delegate.so
Executable file
BIN
docker/rootfs/lib/vim3/libvx_delegate.so
Executable file
Binary file not shown.
79
frigate/detectors/plugins/vim3.py
Normal file
79
frigate/detectors/plugins/vim3.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import logging
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from frigate.detectors.detection_api import DetectionApi
|
||||||
|
from frigate.detectors.detector_config import BaseDetectorConfig
|
||||||
|
from typing import Literal
|
||||||
|
from pydantic import Extra, Field
|
||||||
|
|
||||||
|
try:
|
||||||
|
from tflite_runtime.interpreter import Interpreter, load_delegate
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
from tensorflow.lite.python.interpreter import Interpreter, load_delegate
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DETECTOR_KEY = "vim3"
|
||||||
|
|
||||||
|
|
||||||
|
class vim3DetectorConfig(BaseDetectorConfig):
|
||||||
|
type: Literal[DETECTOR_KEY]
|
||||||
|
device: str = Field(default=None, title="Device Type")
|
||||||
|
|
||||||
|
|
||||||
|
class vim3Tfl(DetectionApi):
|
||||||
|
type_key = DETECTOR_KEY
|
||||||
|
|
||||||
|
def __init__(self, detector_config: vim3DetectorConfig):
|
||||||
|
device_config = {"device": "usb"}
|
||||||
|
if detector_config.device is not None:
|
||||||
|
device_config = {"device": detector_config.device}
|
||||||
|
|
||||||
|
edge_tpu_delegate = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info(f"Attempting to register VIM3 TPU")
|
||||||
|
edge_tpu_delegate = load_delegate("libvx_delegate.so")
|
||||||
|
logger.info("TPU found")
|
||||||
|
self.interpreter = Interpreter(
|
||||||
|
model_path=detector_config.model.path or "/cpu_model.tflite",
|
||||||
|
experimental_delegates=[edge_tpu_delegate],
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
logger.error(
|
||||||
|
"No EdgeTPU was detected. If you do not have a Accelerator (VIM3) device yet, you must configure CPU detectors."
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
|
self.interpreter.allocate_tensors()
|
||||||
|
|
||||||
|
self.tensor_input_details = self.interpreter.get_input_details()
|
||||||
|
self.tensor_output_details = self.interpreter.get_output_details()
|
||||||
|
|
||||||
|
def detect_raw(self, tensor_input):
|
||||||
|
self.interpreter.set_tensor(self.tensor_input_details[0]["index"], tensor_input)
|
||||||
|
self.interpreter.invoke()
|
||||||
|
|
||||||
|
boxes = self.interpreter.tensor(self.tensor_output_details[0]["index"])()[0]
|
||||||
|
class_ids = self.interpreter.tensor(self.tensor_output_details[1]["index"])()[0]
|
||||||
|
scores = self.interpreter.tensor(self.tensor_output_details[2]["index"])()[0]
|
||||||
|
count = int(
|
||||||
|
self.interpreter.tensor(self.tensor_output_details[3]["index"])()[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
detections = np.zeros((20, 6), np.float32)
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
if scores[i] < 0.4 or i == 20:
|
||||||
|
break
|
||||||
|
detections[i] = [
|
||||||
|
class_ids[i],
|
||||||
|
float(scores[i]),
|
||||||
|
boxes[i][0],
|
||||||
|
boxes[i][1],
|
||||||
|
boxes[i][2],
|
||||||
|
boxes[i][3],
|
||||||
|
]
|
||||||
|
|
||||||
|
return detections
|
||||||
Loading…
Reference in New Issue
Block a user