Skip to content

Commit

Permalink
Basic support for multiple Hailo models
Browse files Browse the repository at this point in the history
This allows multiple models to be loaded and used through separate
Hailo objects. They should be used in serial in the same thread,
however, as there is no other locking applied.

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman committed Oct 24, 2024
1 parent e543679 commit 66f9591
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions picamera2/devices/hailo/hailo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@


class Hailo:
TARGET = None
TARGET_REF_COUNT = 0

def __init__(self, hef_path, batch_size=None, output_type='FLOAT32'):
"""
Initialize the HailoAsyncInference class with the provided HEF model file path.
Expand All @@ -20,7 +23,10 @@ def __init__(self, hef_path, batch_size=None, output_type='FLOAT32'):

self.batch_size = batch_size
self.hef = HEF(hef_path)
self.target = VDevice(params)
if Hailo.TARGET is None:
Hailo.TARGET = VDevice(params)
Hailo.TARGET_REF_COUNT += 1
self.target = Hailo.TARGET
self.infer_model = self.target.create_infer_model(hef_path)
self.infer_model.set_batch_size(1 if batch_size is None else batch_size)
self._set_input_output(output_type)
Expand Down Expand Up @@ -175,4 +181,6 @@ def _create_bindings(self):
def close(self):
"""Release the Hailo device."""
del self.configured_infer_model
self.target.release()
Hailo.TARGET_REF_COUNT -= 1
if Hailo.TARGET_REF_COUNT == 0:
self.target.release()

0 comments on commit 66f9591

Please sign in to comment.