forked from blakeblackshear/frigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenVino Detector (blakeblackshear#3768)
* 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
- Loading branch information
Showing
9 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
numpy == 1.19.* | ||
openvino == 2022.* | ||
openvino-dev[tensorflow2] == 2022.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters