Please help! I will very appreciate!
Recently, I have built myself a face identification project with arcface_mobilefacenet.hef using Hailo8L and Raspberry Pi 5 (Both scrfd.py and the model is retrieved from hailo model zoo). However, after I had configured some Hailo8L and model parameters code, I tested an API and then the server code crashed immediately. Though, the code with no Hailo8L support run smoothly.
Note: I have checked the compatibility between the kit and the model, the Hailo8L connection (Raspberry PI 5 Kit recognizes Hailo8L).
After a couple days, I can’t find out the reason of this problem.
Does anyone have the same situation or have experience about this, please give me some advice!?
Here is a piece of the Hailo8L configure code:
from scrfd import SCRFDPostProc
from hailo_platform import (Device,
VDevice,
HailoStreamInterface,
HEF, ConfigureParams,
InputVStreamParams,
OutputVStreamParams,
InferVStreams,
InputVStreams,
OutputVStreams)
with open("/usr/share/hailo-models/scrfd_2.5g_h8l.json") as f:
config = json.load(f)
anchors = config["anchors"]
if "strides" in anchors and "steps" not in anchors:
anchors["steps"] = anchors["strides"]
# send param SCRFDPostProc support
scrfd_decoder = SCRFDPostProc(
image_dims=tuple(config["input_shape"][:2]),
anchors=anchors
)
# ==============================
# Hailo inference
def _make_vstream_params_dict(make_fn, network_group, infos):
"""
Helper: call make_fn(network_group, info) or make_fn(info),
và normalize result -> dict {stream_name: VStreamParams}.
"""
params = {}
for info in infos:
made = None
try:
made = make_fn(network_group, info)
except TypeError:
try:
made = make_fn(info)
except TypeError:
made = make_fn()
# Normalize nested dicts -> flatten
if isinstance(made, dict):
for k, v in made.items():
if isinstance(v, dict):
params.update(v)
else:
params[k] = v
else:
params[info.name] = made
return params
# ==============================
def run_hailo_inference(hef_path, input_tensor):
hef = HEF(hef_path)
vdevice = VDevice()
configure_params = ConfigureParams.create_from_hef(hef, HailoStreamInterface.PCIe)
# configure return list (network groups) -> get first group
network_groups = vdevice.configure(hef, configure_params)
if isinstance(network_groups, (list, tuple)):
if len(network_groups) == 0:
raise RuntimeError("vdevice.configure returned empty list")
network_group = network_groups[0]
else:
network_group = network_groups
input_infos = hef.get_input_vstream_infos()
output_infos = hef.get_output_vstream_infos()
input_name = input_infos[0].name
# Input/Output params
make_input_fn = getattr(InputVStreamParams, "make", InputVStreamParams)
make_output_fn = getattr(OutputVStreamParams, "make", OutputVStreamParams)
input_params = _make_vstream_params_dict(make_input_fn, network_group, input_infos)
output_params = _make_vstream_params_dict(make_output_fn, network_group, output_infos)
outputs = {}
# Activate before vstreams
with network_group.activate():
with InputVStreams(network_group, input_params) as input_vstreams, \
OutputVStreams(network_group, output_params) as output_vstreams:
# Input
for in_vstream in input_vstreams:
if in_vstream.name == input_name:
in_vstream.send(input_tensor)
# Output
for out_vstream in output_vstreams:
outputs[out_vstream.name] = out_vstream.recv()
return outputs