lattepanda-mu-ultra-npu-inference-onnx-6.ino

LattePanda Mu Ultra: x86 Compute Module for Embedded AI · File : lattepanda-mu-ultra-npu-inference-onnx-6.ino · Language : python · Use case : Exécuter une inférence d'image avec OpenVINO sur le NPU Intel de la carte LattePanda Mu Ultra.

Uses the Intel OpenVINO library to accelerate an ONNX model on the integrated NPU, leveraging the card's 115 TOPS.

Hardware: LattePanda Mu Ultra (Lunar Lake). Software: Ubuntu 24.04+, Python 3.10+, 'intel-openvino-dev'. Prerequisite: Convert ONNX to OpenVINO IR format using 'ovc'. Execution: python script.py. NPU driver must be active.

lattepanda-mu-ultra-npu-inference-onnx-6.ino

import cv2
import numpy as np
from openvino.runtime import Core

# Initialiser le noyau OpenVINO
ov_core = Core()
print("Available devices:", ov_core.available_devices)

# Charger un modèle ONNX pré-entraîné (ex: resnet50)
# Assurez-vous d'avoir un fichier model.xml et model.bin ou .onnx converti
model_path = "resnet50.xml"

def load_model_and_infer():
    try:
        # Charger le modèle sur le NPU (device='NPU')
        compiled_model = ov_core.compile_model(model_path, "NPU")
        
        # Récupérer les entrées
        input_layer = compiled_model.input(0)
        output_layer = compiled_model.output(0)
        
        # Préparer les données d'entrée (image dummy 224x224 pour démonstration)
        input_shape = input_layer.shape
        # Adapter la forme selon le modèle, souvent NHWC ou NCHW
        if len(input_shape) == 4:
            input_data = np.random.rand(*input_shape).astype(np.float32)
        else:
            raise ValueError("Shape unexpected")

        print("Running inference on NPU...")
        import time
        start_time = time.time()
        
        # Exécuter l'inférence
        results = compiled_model(input_data, output_layer)
        
        end_time = time.time()
        print(f"Inference completed in {end_time - start_time:.4f} seconds")
        print(f"Output shape: {list(output_layer.shape)}")
        
    except Exception as e:
        print(f"Error: {e}")
        print("Please ensure you have installed intel-openvino-dev and converted a model to IR format.")

if __name__ == "__main__":
    load_model_and_infer()

← Back to the board