mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-23 17:52:05 +02:00
Fix ov for LPR (#20117)
* Check complex model * Reset state for complex models * Send arg * Fix * Cleanup
This commit is contained in:
parent
26178444f3
commit
1efff67e32
@ -156,9 +156,10 @@ class CudaGraphRunner(BaseModelRunner):
|
|||||||
class OpenVINOModelRunner(BaseModelRunner):
|
class OpenVINOModelRunner(BaseModelRunner):
|
||||||
"""OpenVINO model runner that handles inference efficiently."""
|
"""OpenVINO model runner that handles inference efficiently."""
|
||||||
|
|
||||||
def __init__(self, model_path: str, device: str, **kwargs):
|
def __init__(self, model_path: str, device: str, complex_model: bool, **kwargs):
|
||||||
self.model_path = model_path
|
self.model_path = model_path
|
||||||
self.device = device
|
self.device = device
|
||||||
|
self.complex_model = complex_model
|
||||||
|
|
||||||
if not os.path.isfile(model_path):
|
if not os.path.isfile(model_path):
|
||||||
raise FileNotFoundError(f"OpenVINO model file {model_path} not found.")
|
raise FileNotFoundError(f"OpenVINO model file {model_path} not found.")
|
||||||
@ -180,14 +181,16 @@ class OpenVINOModelRunner(BaseModelRunner):
|
|||||||
|
|
||||||
# Create reusable inference request
|
# Create reusable inference request
|
||||||
self.infer_request = self.compiled_model.create_infer_request()
|
self.infer_request = self.compiled_model.create_infer_request()
|
||||||
|
self.input_tensor: ov.Tensor | None = None
|
||||||
|
|
||||||
try:
|
if not complex_model:
|
||||||
input_shape = self.compiled_model.inputs[0].get_shape()
|
try:
|
||||||
input_element_type = self.compiled_model.inputs[0].get_element_type()
|
input_shape = self.compiled_model.inputs[0].get_shape()
|
||||||
self.input_tensor = ov.Tensor(input_element_type, input_shape)
|
input_element_type = self.compiled_model.inputs[0].get_element_type()
|
||||||
except RuntimeError:
|
self.input_tensor = ov.Tensor(input_element_type, input_shape)
|
||||||
# model is complex and has dynamic shape
|
except RuntimeError:
|
||||||
self.input_tensor = None
|
# model is complex and has dynamic shape
|
||||||
|
pass
|
||||||
|
|
||||||
def get_input_names(self) -> list[str]:
|
def get_input_names(self) -> list[str]:
|
||||||
"""Get input names for the model."""
|
"""Get input names for the model."""
|
||||||
@ -234,6 +237,15 @@ class OpenVINOModelRunner(BaseModelRunner):
|
|||||||
np.copyto(self.input_tensor.data, input_data)
|
np.copyto(self.input_tensor.data, input_data)
|
||||||
self.infer_request.infer(self.input_tensor)
|
self.infer_request.infer(self.input_tensor)
|
||||||
else:
|
else:
|
||||||
|
if self.complex_model:
|
||||||
|
try:
|
||||||
|
# This ensures the model starts with a clean state for each sequence
|
||||||
|
# Important for RNN models like PaddleOCR recognition
|
||||||
|
self.infer_request.reset_state()
|
||||||
|
except Exception:
|
||||||
|
# this will raise an exception for models with AUTO set as the device
|
||||||
|
pass
|
||||||
|
|
||||||
# Multiple inputs case - set each input by name
|
# Multiple inputs case - set each input by name
|
||||||
for input_name, input_data in inputs.items():
|
for input_name, input_data in inputs.items():
|
||||||
# Find the input by name
|
# Find the input by name
|
||||||
@ -379,7 +391,9 @@ def get_optimized_runner(
|
|||||||
return RKNNModelRunner(rknn_path)
|
return RKNNModelRunner(rknn_path)
|
||||||
|
|
||||||
if device != "CPU" and is_openvino_gpu_npu_available():
|
if device != "CPU" and is_openvino_gpu_npu_available():
|
||||||
return OpenVINOModelRunner(model_path, device or "AUTO", **kwargs)
|
return OpenVINOModelRunner(
|
||||||
|
model_path, device or "AUTO", complex_model, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
providers, options = get_ort_providers(device == "CPU", device, **kwargs)
|
providers, options = get_ort_providers(device == "CPU", device, **kwargs)
|
||||||
ortSession = ort.InferenceSession(
|
ortSession = ort.InferenceSession(
|
||||||
|
@ -43,7 +43,9 @@ class OvDetector(DetectionApi):
|
|||||||
self.w = detector_config.model.width
|
self.w = detector_config.model.width
|
||||||
|
|
||||||
self.runner = OpenVINOModelRunner(
|
self.runner = OpenVINOModelRunner(
|
||||||
model_path=detector_config.model.path, device=detector_config.device
|
model_path=detector_config.model.path,
|
||||||
|
device=detector_config.device,
|
||||||
|
complex_model=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# For dfine models, also pre-allocate target sizes tensor
|
# For dfine models, also pre-allocate target sizes tensor
|
||||||
|
Loading…
Reference in New Issue
Block a user