RKNN-Toolkit2 Environment Setup
The model conversion environment described in this chapter is deployed on an x86_64 Linux platform. It is recommended to complete model training and conversion in this environment. System version: WSL2 Ubuntu 22.04 / Virtual Machine Ubuntu 22.04 Tool version: RKNN-Toolkit2 2.3.2
1. Introduction to RKNPU
An NPU (Neural Processing Unit) is a specialized processor designed to accelerate neural network computations. To meet the growing demands of artificial intelligence, Rockchip has progressively integrated NPUs into its processors. These built-in NPUs are referred to as RKNPU.
The RV1126B, used in the LuckFox Aura series, integrates Rockchip’s third-generation RKNPU2 architecture, delivering up to 3.0 TOPS INT8 computing performance. It supports mixed-precision quantization including INT4, INT8, INT16, FP16, BF16, and TF32. Model conversion and deployment require the RKNPU2 SDK along with the RKNN-Toolkit2 toolchain.

2. Introduction to RKNN-Toolkit2
RKNN-Toolkit2 provides C and Python APIs on the PC platform to simplify model deployment and execution. With this toolkit, users can easily perform tasks such as model conversion, quantization, inference, performance and memory evaluation, quantization accuracy analysis, and model encryption.
The RKNN software stack enables developers to quickly deploy AI models onto Rockchip platforms. The overall framework is shown above.
To use the RKNPU, users must first run RKNN-Toolkit2 on a computer to convert a trained model into the RKNN format. The converted model can then be deployed on the development board using either the RKNN C API or Python API.
This section introduces how to quickly get started with RKNPU on the RV1126B series boards.
3 RKNN-Toolkit2 Installation (Ubuntu 22.04 X86_64 Platform)
3.1 Local Installation
-
Environment Requirements.
Operating System Version Ubuntu18.04(x64) Ubuntu20.04(x64) Ubuntu22.04(x64) Python Version 3.6/3.7 3.8/3.9 3.10/3.11 -
Download RKNN-Toolkit2.
git clone https://github.com/airockchip/rknn-toolkit2.git -
Install Python Environment.
sudo apt-get updatesudo apt-get install python3 python3-dev python3-pipsudo apt-get install libxslt1-dev zlib1g zlib1g-dev libglib2.0-0 libsm6 libgl1-mesa-glx libprotobuf-dev gcc -
Install RKNN-Toolkit2 Dependencies.
pip3 install -r rknn-toolkit2/packages/requirements_cpxx-2.2.0.txt# such as:pip3 install -r rknn-toolkit2/packages/requirements_cp310-2.2.0.txtSelect the corresponding dependencies based on your Python version:
Python Version RKNN-Toolkit2 Dependencies 3.6 requirements_cp36-2.2.0.txt 3.7 requirements_cp37-2.2.0.txt 3.8 requirements_cp38-2.2.0.txt 3.9 requirements_cp39-2.2.0.txt 3.10 requirements_cp310-2.2.0.txt 3.11 requirements_cp311-2.2.0.txt 3.12 requirements_cp312-2.2.0.txt -
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-2.2.0+81f21f4d-cp310-cp310-linux_x86_64.whlThe package name format is:
rknn_toolkit2-{version}+{commit}-cp{python_version}-cp{python_version}-linux_x86_64.whl. Choose the appropriate package based on the Python version:Python Version RKNN-Toolkit2 Package 3.6 rknn_toolkit2-2.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.7 rknn_toolkit2-2.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.8 rknn_toolkit2-2.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.9 rknn_toolkit2-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.10 rknn_toolkit2-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.11 rknn_toolkit2-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 3.12 rknn_toolkit2-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl If no errors occur after running the following command, the installation is successful:
python3from rknn.api import RKNN
3.2 Conda Installation
It is recommended to use Conda to create a Python virtual environment, allowing flexible switching between different applications and avoiding version mismatches. For example, different Python virtual environments are required for AI model training and conversion.
3.2.1 Install Miniconda
-
Check if Miniconda or another conda tool is installed by running:
conda --version -
Download the installer:
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh -
Install Miniconda:
chmod 777 Miniconda3-4.6.14-Linux-x86_64.shbash Miniconda3-4.6.14-Linux-x86_64.sh-
Note: The miniconda installation package must be given execute permission using
chmod 777. -
Follow the installation steps, read and accept the license terms, and proceed with the installation. The miniconda folder will be created in the home directory.
-
-
Enter the Conda base environment:
source ~/miniconda3/bin/activate # Miniconda3 installation directory (customize based on your setup)# After activation, the command prompt should change to:# (base) xxx@xxx:~$ -
To automatically activate the Miniconda environment each time you open a terminal, add the activation command to your shell configuration file:
vim nano ~/.bashrc# Add the following line at the end:source ~/miniconda3/bin/activate# exit conda environmentconda deactivate
3.2.2 Creating RKNN-Toolkit2 Conda Environment
-
Create the RKNN-Toolkit2 development Conda environment, specifying Python version 3.8 (recommended version):
conda create -n RKNN-Toolkit2 python=3.9- Type
yto confirm installation of the default packages.
- Type
-
Enter the RKNN-Toolkit2 Conda Environment.
conda activate RKNN-Toolkit2 -
Verify the Correct Python Version.
python --version- Note: In some development environments, the Python version may not switch properly after creating the Conda environment. Restarting the terminal may resolve this issue.
-
Clone the RKNN-Toolkit2 repository:
git clone https://github.com/airockchip/rknn-toolkit2.git -
Enter the directory:
cd rknn-toolkit2 -
Install RKNN-Toolkit2 related dependency libraries.
cp38is the corresponding Conda environment python version. The version used in the experiment is 3.8, so use the dependency with the suffixcp38pip install tf-estimator-nightly==2.8.0.dev2021122109pip install -r rknn-toolkit2/packages/requirements_cp39-2.2.0.txt -
Install RKNN-Toolkit2:
pip install rknn-toolkit2/packages/rknn_toolkit2-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl- Select the installation package from the
packagesfolder based on your Python version. For Python 3.8, use the package with thecp38suffix. The81f21f4din the filename is a commit ID; choose the appropriate version for your setup.
- Select the installation package from the
-
Verify Installation,If no errors occur, the installation is successful.
python>>> from rknn.api import RKNN