hailo-inference-test.py

Raspberry Pi Smart Display Module · File : hailo-inference-test.py · Language : Python · Use case : Tester l'accélérateur IA Hailo connecté au slot M.2 avec une inférence simple.

Uses the Hailo API to load a compiled model and perform inference on the AI accelerator.

Requires a Hailo module (e.g., Hailo-8L) inserted into the Smart Display Module's M.2 slot. Install the Hailo SDK and Python dependencies. You must compile a model (e.g., ResNet50) to .hef format using the Hailo Dataflow Compiler. This script verifies communication with the accelerator and runs a test inference.

hailo-inference-test.py

import hailo
import numpy as np

# Charger le réseau neuronal compilé pour Hailo
# Note: Le fichier .hef doit être compilé avec Hailo Dataflow Compiler
try:
    runner = hailo.run("model_resnet50.hef")
    print("Modèle Hailo chargé avec succès.")
    
    # Exemple d'inférence avec des données aléatoires (à remplacer par une image réelle)
    input_data = np.random.rand(1, 224, 224, 3).astype(np.float32)
    output = runner.run(input_data)
    print("Inférence terminée. Shape de sortie:", output[0].shape)
except Exception as e:
    print(f"Erreur lors du chargement ou de l'inférence: {e}")
finally:
    if 'runner' in locals():
        runner.release()

← Back to the board