I am trying to understand how to use hailort to run inference on pretrained models with hailo8l on my raspberry pi 5.
While I did see the raspberry 5 examples, it is very complicated with streaming etc, and I want to start with a simple example where I take a model, image, pass the image trhoguh the model and see the output.
I did see in a few places (including using hailo tutorial
command) something like working example code, but I couldn’t get a real prediction out of it.
# running on HailoRT v4.19.0, Raspberry Pi 5 AI HAT (Hailo8, python 3.10)
import numpy as np
import hailo_platform as hpf
hef_path = './retinaface_mobilenet_v1.hef'
hef = hpf.HEF(hef_path)
with hpf.VDevice() as target:
configure_params = hpf.ConfigureParams.create_from_hef(hef, interface=hpf.HailoStreamInterface.PCIe)
network_group = target.configure(hef, configure_params)[0]
network_group_params = network_group.create_params()
input_vstream_info = hef.get_input_vstream_infos()[0]
output_vstream_info = hef.get_output_vstream_infos()[0]
input_vstreams_params = hpf.InputVStreamParams.make_from_network_group(network_group, quantized=False, format_type=hpf.FormatType.FLOAT32)
output_vstreams_params = hpf.OutputVStreamParams.make_from_network_group(network_group, quantized=False, format_type=hpf.FormatType.FLOAT32)
input_shape = input_vstream_info.shape
output_shape = output_vstream_info.shape
print(f"Input shape: {input_shape}, Output shape: {output_shape}")
with network_group.activate(network_group_params):
with hpf.InferVStreams(network_group, input_vstreams_params, output_vstreams_params) as infer_pipeline:
for _ in range(10):
random_input = np.random.rand(*input_shape).astype(np.float32)
input_data = {input_vstream_info.name: np.expand_dims(random_input, axis=0)}
results = infer_pipeline.infer(input_data)
output_data = results[output_vstream_info.name]
print(f"Inference output: {output_data}")
The issues I’m having is:
- I’m not even sure what output I should take. in the example(s) they do
output_vstream_info = hef.get_output_vstream_infos()[0]
but I don’t think it is the last layer where I should actually take. Instead I sawoutput_vstream_info = hef.get_output_vstream_infos()[-1]
that made more sense since it 'feels ’ more like a last layer, but I really can’t tell. - How do I post-process to get the wanted results.? In the pi5 hailo examples they are using compiled postprocess in the inference pipeline, but I want to have more control (and also to learn how things work) and using something more like in the example code, where I take the inference result and process it myself.
If anyone has a working ‘real’ example (that if I’ll pass a training/real image the results would make sense) for any model that would be amazing.