mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
e5fe323aca
* Initial work for adding OpenVino detector. Not functional * Load model and submit for inference. Sucessfully load model and initialize OpenVino engine with either CPU or GPU as device. Does not parse results for objects. * Detection working with ssdlite_mobilenetv2 FP16 model * Add OpenVIno support and model to docker image * Add documentation for OpenVino detector configuration * Adds support for ARM32/ARM64 and the Myriad X hardware - Use custom-built openvino wheel for all platforms - Add libusb build without udev for NCS2 support * Add documentation around Intel CPU requirements and NCS2 setup * Print all available output tensors * Update documentation for config parameters
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import logging
|
|
import numpy as np
|
|
import openvino.runtime as ov
|
|
|
|
from frigate.detectors.detection_api import DetectionApi
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class OvDetector(DetectionApi):
|
|
def __init__(self, det_device=None, model_config=None, num_threads=1):
|
|
self.ov_core = ov.Core()
|
|
self.ov_model = self.ov_core.read_model(model_config.path)
|
|
|
|
self.interpreter = self.ov_core.compile_model(
|
|
model=self.ov_model, device_name=det_device
|
|
)
|
|
logger.info(f"Model Input Shape: {self.interpreter.input(0).shape}")
|
|
self.output_indexes = 0
|
|
while True:
|
|
try:
|
|
tensor_shape = self.interpreter.output(self.output_indexes).shape
|
|
logger.info(f"Model Output-{self.output_indexes} Shape: {tensor_shape}")
|
|
self.output_indexes += 1
|
|
except:
|
|
logger.info(f"Model has {self.output_indexes} Output Tensors")
|
|
break
|
|
|
|
def detect_raw(self, tensor_input):
|
|
|
|
infer_request = self.interpreter.create_infer_request()
|
|
infer_request.infer([tensor_input])
|
|
|
|
results = infer_request.get_output_tensor()
|
|
|
|
detections = np.zeros((20, 6), np.float32)
|
|
i = 0
|
|
for object_detected in results.data[0, 0, :]:
|
|
if object_detected[0] != -1:
|
|
logger.debug(object_detected)
|
|
if object_detected[2] < 0.1 or i == 20:
|
|
break
|
|
detections[i] = [
|
|
object_detected[1], # Label ID
|
|
float(object_detected[2]), # Confidence
|
|
object_detected[4], # y_min
|
|
object_detected[3], # x_min
|
|
object_detected[6], # y_max
|
|
object_detected[5], # x_max
|
|
]
|
|
i += 1
|
|
|
|
return detections
|