RKNN is Rockchip’s model format for running neural networks on Rockchip NPUs.
To convert onnx or other model format to rknn we use github rknn-toolkit, the current version that we test for this post v2.3.2
PyTorch / ONNX model
↓
RKNN-Toolkit2 on PC
↓
model.rknn
↓
RKNN Runtime on Rockchip board
↓
NPU inference
What is RKNN-Toolkit?
For modern chips such as RK3566 and RK3588, the RKNN-Toolkit2 runs on the development PC and
provides:
Model conversion to .rknn
INT8 quantization
Model validation
Accuracy and performance analysis
PC simulation or connected-board testing
What to install
Machine
Install
Purpose
Development PC
RKNN-Toolkit2
Convert ONNX/PyTorch models into .rknn
Board using Python
RKNN-Toolkit-Lite2
Load and run .rknn models
Board using C/C++
RKNN Runtime, usually librknnrt.so
Native deployment and inference
Board firmware/kernel
RKNPU driver
Communicate with the NPU hardware
Do not install the complete RKNN-Toolkit2 package on the board. It belongs on the PC. Rockchip describes Lite2 as the
board-side Python API and RKNN Runtime as the board-side C/C++ API. Official architecture
For C/C++ deployment, the board image often already contains the NPU driver and runtime. For Python deployment,
install the matching Lite2 wheel from the Toolkit2 repository. Keep Toolkit2, Lite2/runtime, driver, and model
versions compatible.
Convert a pretrained YOLOv8 ONNX model for RK3566, copy it to
the board, run RKNNLite inference, and understand the output.
Convert to INT8
INT8 quantization requires a representative calibration dataset. During RKNN compilation, representative images are passed through the network so RKNN Toolkit2 can determine quantization ranges/scales.
Info
For the pretrained YOLO26n COCO model, you don't need a special set of “YOLO26 calibration images.” You need a collection of representative images similar to what the model will see during inference.
!!! tip coco8.yaml
For a first test, the easiest choice is Ultralytics' small COCO dataset, coco8.yaml. Ultralytics' RKNN exporter accepts a dataset YAML via data=... and internally creates the image list that RKNN Toolkit2 uses for calibration.
importcv2importnumpyasnpfromrknnlite.apiimportRKNNLiteMODEL="yolo26n-rk3566.rknn"IMAGE="bus.jpg"rknn=RKNNLite()ret=rknn.load_rknn(MODEL)ifret!=0:raiseRuntimeError("Could not load RKNN")ret=rknn.init_runtime()ifret!=0:raiseRuntimeError("Could not initialize RKNN runtime")image=cv2.imread(IMAGE)image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)image=cv2.resize(image,(640,640))input_tensor=np.expand_dims(image,axis=0)outputs=rknn.inference(inputs=[input_tensor])fori,outputinenumerate(outputs):print(i,output.shape)rknn.release()