🛠 Exploiter le NPU 6 TOPS avec le SDK RKNN

Orange Pi 5 Plus (Rockchip RK3588) · avance · Schéma : IMG-orangepi-5-plus-avance-3-opi5p-npu-rknn.svg — chaîne RKNN : conversion d'un modèle sur PC x86, transfert du fichier .rknn vers l'Orange Pi 5 Plus, inférence sur le NPU 6 TOPS avec affichage des classes détectées

Objectives

Deploy a vision model on the RK3588's 6 TOPS NPU (mixed INT4/INT8/INT16/FP16) using Rockchip's RKNN SDK: convert a model (ONNX/TF/PyTorch) to .rknn on an x86_64 PC, then run it on the board using the rknn-lite runtime. Be aware of the vendor/mainline split: the NPU (like MPP/RGA and the closed Mali blob) is available on vendor BSP 5.10 images (Debian 11 / Ubuntu 22.04 / Orange Pi OS); under Armbian mainline, the NPU is not usable — switch to the vendor image for this tutorial.

Hardware

Complete Code

# --- Sur le PC x86_64 : conversion du modèle (Python 3.8-3.10 requis) ---
# git clone https://github.com/airockchip/rknn-toolkit2
# pip install rknn-toolkit2/rknn-toolkit2/packages/rknn_toolkit2-*.whl   # wheel selon version
python3 convert.py   # exemple : ONNX -> RKNN, quantification INT8 sur jeu d'images

# --- Sur l'Orange Pi 5 Plus (image vendor ARM64) ---
sudo apt install -y python3-pip
pip3 install rknn_toolkit_lite2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-*.whl
scp model.rknn orangepi@<ip-de-la-carte>:~/
#!/usr/bin/env python3
"""Inférence NPU avec rknn-lite2 (API du SDK airockchip/rknn-toolkit2)."""
import numpy as np
from rknnlite.api import RKNNLite

rknn = RKNNLite
assert rknn.load_rknn("model.rknn") == 0
# Utiliser les 3 cœurs NPU ; CORE_0 seul pour laisser du marge
assert rknn.init_runtime(core_mask=RKNNLite.NPU_CORE_0_1_2) == 0

input_name = rknn.get_input_name(0)[0]
img = np.zeros((224, 224, 3), dtype=np.uint8)   # remplacer par la vraie image
outputs = rknn.inference(inputs=[img])
print("Sortie :", np.asarray(outputs[0]).shape)
rknn.release

Expected Verification

The conversion on the PC produces model.rknn without errors; on the board, init_runtime returns 0 (the runtime has opened /dev/rga and the NPU device) and inference prints the shape of the output tensor. Examples from the rknn-toolkit2 repository (e.g., mobilenet, yolov5) display classes and scores; the NPU appears in ls /dev/ | grep rknpu on vendor images.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials