Home / Technology / RKNN RKNPU Introduction
Technology
RKNN RKNPU Introduction
NPU (Neural Processing Unit) is a processor specifically designed to accelerate neural network computation. To meet the demands of artificial intelligence, Rockchip has gradually integrated NPUs into its processors. This NPU built into Rockchip processors is called RKNPU. ZhCloudLink's AI boxes, AI cameras, and AI access control systems are all equipped with Rockchip RK3588, RK3576, RK3568, RV1106/RV1109 chips, featuring Rockchip's self-developed 4th-generation NPU. This NPU offers high computat
1. RKNPU Introduction
NPU (Neural Processing Unit) is a processor specifically designed to accelerate neural network computation. To meet the demands of artificial intelligence, Rockchip has gradually integrated NPUs into its processors. This NPU built into Rockchip processors is called RKNPU. ZhCloudLink's AI boxes, AI cameras, and AI access control systems are all equipped with Rockchip RK3588, RK3576, RK3568, RV1106/RV1109 chips, featuring Rockchip's self-developed 4th-generation NPU. This NPU offers high computational precision and supports int4, int8, and int16 mixed quantization. RKNPU4.0 is classified as RKNPU2, so the RKNPU2 SDK and toolchain must be used.
2. RKNN-Toolkit2 Introduction
RKNN-Toolkit2 provides C or Python interfaces on the PC platform to simplify model deployment and execution. Users can easily perform the following functions through this tool: model conversion, quantization, inference, performance and memory evaluation, quantization accuracy analysis, and model encryption. The RKNN software stack helps users quickly deploy AI models to Rockchip chips. The overall framework is as follows:

To use RKNPU, users must first run RKNN-Toolkit2 on a computer to convert the trained model into an RKNN format model, then deploy it on the development board using the RKNN C API or Python API. This section introduces how to quickly use RKNPU on the Luckfox Pico series boards.
3 RKNN-Toolkit2 Installation (PC Ubuntu 22.04)
3.1 Local Installation
1· Environment Requirements
| Operating System | Ubuntu18.04(x64) | Ubuntu20.04(x64) | Ubuntu22.04(x64) |
| Python Version | 3.6/3.7 | 3.8/3.9 | 3.10/3.11 |
2.Download rknn-toolkit2
git clone https://github.com/rockchip-linux/rknn-toolkit2
3.Install Python environment
sudo apt-get update
sudo apt-get install python3 python3-dev python3-pip
sudo apt-get install libxslt1-dev zlib1g zlib1g-dev libglib2.0-0 libsm6 libgl1-mesa-glx libprotobuf-dev gcc
4.Install RKNN-ToolKit2 dependencies
pip3 install -r rknn-toolkit2/packages/requirements_cpxx-1.6.0.txt
# such as:
pip3 install -r rknn-toolkit2/packages/requirements_cp310-1.6.0.txt
Select the corresponding dependency package based on your Python version:
| Python Version | RKNN-Toolkit2 Dependency Package |
| 3.6 | requirements_cp36-1.6.0.txt |
| 3.7 | requirements_cp37-1.6.0.txt |
| 3.8 | requirements_cp38-1.6.0.txt |
| 3.9 | requirements_cp39-1.6.0.txt |
| 3.10 | requirements_cp310-1.6.0.txt |
| 3.11 | requirements_cp311-1.6.0.txt |
5.Install RKNN-ToolKit2
pip3 install rknn-toolkit2/packages/rknn_toolkit2-x.x.x+xxxxxxxx-cpxx-cpxx-linux_x86_64.whl
# such as:
pip3 install rknn-toolkit2/packages/rknn_toolkit2-1.6.0+81f21f4d-cp310-cp310-linux_x86_64.whl
The package name format is: rknn_toolkit2-{version}+{commit}-cp{Python version}-cp{Python version}-linux_x86_64.whl. Select the corresponding installation package based on your Python version:
| Python Version | RKNN-Toolkit2 Installation Package |
| 3.6 | rknn_toolkit2-{version}+{commit}-cp36-cp36m-linux_x86_64.whl |
| 3.7 | rknn_toolkit2-{version}+{commit}-cp36-cp37m-linux_x86_64.whl |
| 3.8 | rknn_toolkit2-{version}+{commit}-cp36-cp38m-linux_x86_64.whl |
| 3.9 | rknn_toolkit2-{version}+{commit}-cp36-cp39m-linux_x86_64.whl |
| 3.10 | rknn_toolkit2-{version}+{commit}-cp36-cp310m-linux_x86_64.whl |
| 3.11 | rknn_toolkit2-{version}+{commit}-cp36-cp311m-linux_x86_64.whl |
If the following command runs without errors, the installation is successful:
python3
from rknn.api import RKNN
3.2 Conda Installation
It is recommended to use Conda to create a Python virtual environment, which allows flexible switching between multiple application scenarios and avoids issues such as version mismatches that prevent execution. In practice, different Python virtual environments are required for AI model training and model conversion.
3.2.1 Install Miniconda
1· Check if miniconda or other conda tools are installed. If a version number is output, it is already installed.
conda --version
2· Download the installer
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh
3· Install miniconda
chmod 777 Miniconda3-4.6.14-Linux-x86_64.sh
bash Miniconda3-4.6.14-Linux-x86_64.sh
Note: The miniconda installer must be granted permissions using chmod 777. After running the installer, press Enter to read the license terms, type yes to accept the license and continue, then press Enter again to create the miniconda folder in your home directory where virtual environments will be stored. Finally, type yes once more to initialize Conda.
4· In the computer terminal window, enter the Conda base environment
source ~/miniconda3/bin/activate # miniconda3 installation directory (modify according to custom installation)
# After success, the command prompt will change to:
# (base) xxx@xxx:~$
5· If you want to automatically activate the Miniconda environment every time you open a terminal, you can add the activation command to your shell configuration file:
vim nano ~/.bashrc
# Add the following lines at the end of the file:
source ~/miniconda3/bin/activate
# Exit conda environment
conda deactivate
3.2.2 Create RKNN-Toolkit2 Conda Environment
1· Create the RKNN-Toolkit2 development Conda environment. The -n parameter specifies the environment name, with Python version 3.9 (recommended)
conda create -n RKNN-Toolkit2 python=3.9
· Enter y to confirm installation of default packages.
2· Enter the RKNN-Toolkit2 Conda environment
conda activate RKNN-Toolkit2
3· Verify that the Python version is correct
python --version
Note: In some development environments, the Python version may not switch correctly after creating the Conda environment. Restarting the terminal can resolve this.
4· Get the RKNN-Toolkit2 installation package
git clone https://github.com/airockchip/rknn-toolkit2.git
5· Enter the folder
cd rknn-toolkit2
6· Install the dependencies for RKNN-Toolkit2. cp39 corresponds to the Conda environment Python version. Since the experiment uses version 3.8, use the dependency with the cp39 suffix
pip install tf-estimator-nightly==2.8.0.dev2021122109
pip install -r rknn-toolkit2/packages/x86_64/requirements_cp39-2.3.2.txt -i https://pypi.mirrors.ustc.edu.cn/simple/
Downloading without changing the source is too slow and may cause installation failure. If you change the source, the mirror you select may temporarily be unavailable or subject to access restrictions, which may cause download failures. You can try switching to other available mirrors.
# Common pip mirrors:
Aliyun http://mirrors.aliyun.com/pypi/simple/
USTC https://pypi.mirrors.ustc.edu.cn/simple/
Douban http://pypi.douban.com/simple/
Tsinghua https://pypi.tuna.tsinghua.edu.cn/simple/
USTC http://pypi.mirrors.ustc.edu.cn/simple/
7· Install RKNN-Toolkit2
pip install rknn-toolkit2/packages/x86_64/rknn_toolkit2-2.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Select the installation package file under the packages folder according to the Python version. The value 81f21f4d is the commit number; select according to the actual situation. For Python 3.8, use the package with the cp38 suffix.
8· Verify that the installation is successful. If there are no errors, the installation is successful.
python
>>> from rknn.api import RKNN
Result:

Questions
What input/output types does the RKNN model support on RV1106?
The RKNPU only supports int8 input and output, and only supports 4-dimensional input and 4-dimensional output. If the converted model contains float-type input/output tensor structures, data cannot be obtained correctly, and the model structure must be readjusted.
Why should the final normalization code be commented out when exporting the facenet model to ONNX?
The facenet source code uses the ReduceL2 operator (F.normalize) before outputting the 128-dimensional feature vector, which RKNPU cannot parse. Assigning this part to the CPU, commenting out the corresponding code, and re-exporting the ONNX model makes it compatible with RKNPU. The normalization operation can then be added on the CPU after converting the output data format.
What should I do if RKNN-Toolkit2 installation fails due to missing dependency or installation packages?
Select the dependency and installation packages with the suffix matching your Python version, e.g., for Python 3.10 use requirements_cp310-1.6.0.txt and rknn_toolkit2-1.6.0+81f21f4d-cp310-cp310-linux_x86_64.whl. If slow downloads cause failures, switch to a pip mirror such as Aliyun, Tsinghua, or USTC.
When running the yolov5 demo on the board, a file-not-found error occurs or the camera is occupied. How to fix it?
This is usually caused by the default rkipc program occupying the camera. Run killall rkipc or RkLunch-stop.sh to stop the background program and release the camera before running the demo.
How to correctly configure preprocessing parameters (mean_values / std_values) during model conversion?
Check the prediction part of the model training source code. For retinaface, the source subtracts the mean values (104, 117, 123) from the three channels of the image, so rknn.config should be called with mean_values=[[104, 117, 123]], std_values=[[1, 1, 1]], and quant_img_RGB2BGR=True as needed.
Zhcloudlink