cm3588-neural-network-inference-9.ino

FriendlyElec CM3588 SOM (Rockchip RK3588) · File : cm3588-neural-network-inference-9.ino · Language : Python · Use case : Exécuter une inférence d'image sur la NPU RKNN pour la détection d'objets en temps réel.

Uses the RKNN-Toolkit2 API to load a compiled AI model and run inference on the RK3588's NPU.

Requires the Rockchip RKNN-Toolkit2 SDK on the host PC for model compilation and runtime libraries on the CM3588. Models must be converted to .rknn format (e.g., YOLOv5). Ensure the NPU driver is loaded. Run the script with Python 3.8+ with 'rknn-toolkit2' and 'opencv-python' dependencies installed on the board.

cm3588-neural-network-inference-9.ino

import numpy as np
import cv2
from rknn.api import RKNN

# 1. Initialisation du moteur RKNN
rknn = RKNN()
rknn.load_rknn('yolov5s.rknn')
rknn.init_runtime(target='rk3588')

# 2. Préparation des données (Chargement image et prétraitement)
input_img = cv2.imread('input.jpg')
# Redimensionnement aux dimensions d'entrée du modèle (ex: 640x640)
input_img = cv2.resize(input_img, (640, 640), interpolation=cv2.INTER_LINEAR)
input_img = input_img.transpose(2, 0, 1) # HWC -> CHW
input_img = np.expand_dims(input_img, axis=0) # Add batch dim

# 3. Exécution de l'inférence
outputs = rknn.forward(inputs=[input_img])

# 4. Post-traitement simplifié (Affichage des dimensions de la sortie)
print("Inference complete. Output shape:", outputs[0].shape)
rknn.release()

← Back to the board