Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions demos/face_recognition_demo/python/face_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
limitations under the License.
"""

import logging as log
import numpy as np

from ie_module import Module
from utils import resize_input

from openvino import PartialShape
from openvino import PartialShape, AsyncInferQueue


class FaceDetector(Module):
Expand Down Expand Up @@ -64,7 +65,6 @@ def __init__(self, core, model, input_size, confidence_threshold=0.5, roi_scale_
raise ValueError("Both input height and width should be positive for Face Detector reshape")

self.input_shape = self.model.inputs[0].shape
self.nchw_layout = self.input_shape[1] == 3
self.output_shape = self.model.outputs[0].shape
if len(self.output_shape) != 4 or self.output_shape[3] != self.Result.OUTPUT_SIZE:
raise RuntimeError("The model expects output shape with {} outputs".format(self.Result.OUTPUT_SIZE))
Expand All @@ -77,6 +77,16 @@ def __init__(self, core, model, input_size, confidence_threshold=0.5, roi_scale_
self.confidence_threshold = confidence_threshold
self.roi_scale_factor = roi_scale_factor

def deploy(self, device, max_requests=1):
self.max_requests = max_requests
compiled_model = self.core.compile_model(self.model, device)
self.output_tensor = compiled_model.outputs[0]
self.infer_queue = AsyncInferQueue(compiled_model, self.max_requests)
self.infer_queue.set_callback(self.completion_callback)
compiled_input_shape = compiled_model.inputs[0].shape
self.nchw_layout = compiled_input_shape[1] == 3
log.info('The {} model {} is loaded to {}'.format(self.model_type, self.model_path, device))

def preprocess(self, frame):
self.input_size = frame.shape
return resize_input(frame, self.input_shape, self.nchw_layout)
Expand Down