mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-07 02:18:07 +01:00
* Refactor common functions for tflite detector implementations * Add detector using mesa teflon delegate Non-EdgeTPU TFLite can use the standard .tflite format * Add mesa-teflon-delegate from bookworm-backports to arm64 images
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
import logging
|
|
|
|
from pydantic import Field
|
|
from typing_extensions import Literal
|
|
|
|
from frigate.detectors.detection_api import DetectionApi
|
|
from frigate.detectors.detector_config import BaseDetectorConfig
|
|
|
|
from ..detector_utils import tflite_detect_raw, tflite_init
|
|
|
|
try:
|
|
from tflite_runtime.interpreter import Interpreter
|
|
except ModuleNotFoundError:
|
|
from tensorflow.lite.python.interpreter import Interpreter
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
DETECTOR_KEY = "cpu"
|
|
|
|
|
|
class CpuDetectorConfig(BaseDetectorConfig):
|
|
type: Literal[DETECTOR_KEY]
|
|
num_threads: int = Field(default=3, title="Number of detection threads")
|
|
|
|
|
|
class CpuTfl(DetectionApi):
|
|
type_key = DETECTOR_KEY
|
|
|
|
def __init__(self, detector_config: CpuDetectorConfig):
|
|
interpreter = Interpreter(
|
|
model_path=detector_config.model.path,
|
|
num_threads=detector_config.num_threads or 3,
|
|
)
|
|
|
|
tflite_init(self, interpreter)
|
|
|
|
def detect_raw(self, tensor_input):
|
|
return tflite_detect_raw(self, tensor_input)
|