This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
products:sbc:edge-2l:npu:rknn-sdk-quick-start [2026/05/31 22:03] nick [View Results] |
products:sbc:edge-2l:npu:rknn-sdk-quick-start [2026/05/31 23:55] (current) nick [Run RKNN Python demo] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== RKNN SDK Quick Start ====== | + | ====== RKNN SDK quick start ====== |
| ===== Introduction ===== | ===== Introduction ===== | ||
| This document provides a detailed introduction for beginners on how to quickly use RKNN-Toolkit2 on a computer to perform model conversion and deploy it to a Edge 2L board using RKNPU2. The examples used in this document are integrated into the [[https:// | This document provides a detailed introduction for beginners on how to quickly use RKNN-Toolkit2 on a computer to perform model conversion and deploy it to a Edge 2L board using RKNPU2. The examples used in this document are integrated into the [[https:// | ||
| - | ===== Prepare | + | ===== Prepare |
| The version information we are using is as follows: | The version information we are using is as follows: | ||
| - | * python: 3.8 | + | * Host PC Python: 3.8 |
| * rknn-toolkit2: | * rknn-toolkit2: | ||
| * rknn model zoo: 2.3.2 | * rknn model zoo: 2.3.2 | ||
| - | ==== Download RKNN Related Repositories | + | ==== Download RKNN related repositories - Host PC ==== |
| It is recommended to create a new directory to store the RKNN repositories. For example, create a folder named '' | It is recommended to create a new directory to store the RKNN repositories. For example, create a folder named '' | ||
| Line 26: | Line 26: | ||
| ``` | ``` | ||
| - | ==== Install the RKNN-Toolkit2 | + | ==== Install the RKNN-Toolkit2 |
| - | === Install Python === | + | === Install Python |
| If the Python 3.8 environment is not installed on your system, or if there are multiple versions of Python installed, it is recommended to use Miniforge Conda to create a new Python 3.8 environment. | If the Python 3.8 environment is not installed on your system, or if there are multiple versions of Python installed, it is recommended to use Miniforge Conda to create a new Python 3.8 environment. | ||
| - | === Install Miniforge Conda === | + | === Install Miniforge Conda - Host PC === |
| Download the Miniforge Conda installer from the following link: | Download the Miniforge Conda installer from the following link: | ||
| Line 37: | Line 37: | ||
| $ wget -c https:// | $ wget -c https:// | ||
| ``` | ``` | ||
| + | |||
| Then, install Miniforge Conda using the following command: | Then, install Miniforge Conda using the following command: | ||
| ```shell | ```shell | ||
| Line 42: | Line 43: | ||
| $ bash Miniforge3-Linux-x86_64.sh | $ bash Miniforge3-Linux-x86_64.sh | ||
| ``` | ``` | ||
| - | === Create Python | + | === Create Python |
| In the terminal window on the computer, execute the following command to switch to the Miniforge conda base | In the terminal window on the computer, execute the following command to switch to the Miniforge conda base | ||
| environment: | environment: | ||
| Line 56: | Line 57: | ||
| $ conda activate py38Toolkit2.3.2 | $ conda activate py38Toolkit2.3.2 | ||
| ``` | ``` | ||
| - | === Install RKNN-Toolkit2 === | + | === Install RKNN-Toolkit2 |
| Install via local wheel packag. | Install via local wheel packag. | ||
| Line 65: | Line 66: | ||
| ``` | ``` | ||
| - | === Check if the RKNN-Toolkit2 | + | === Check if the RKNN-Toolkit2 |
| Switch to Python interactive mode | Switch to Python interactive mode | ||
| ```shell | ```shell | ||
| Line 75: | Line 76: | ||
| ``` | ``` | ||
| - | ==== Install | + | ==== Install |
| - | === Install NDK on Android | + | === Android - Install NDK for Android |
| Note: This section is applicable to development boards with the Android system. If the board is running on the | Note: This section is applicable to development boards with the Android system. If the board is running on the | ||
| Linux system, please skip this section.\\ | Linux system, please skip this section.\\ | ||
| Line 89: | Line 90: | ||
| ``` | ``` | ||
| - | ==== Install GCC Cross-Compiler | + | ==== Linux - Install GCC Cross-Compiler |
| Note: This section is applicable to development boards with the Linux system. If the board is running on the | Note: This section is applicable to development boards with the Linux system. If the board is running on the | ||
| Android system, please skip this section.\\ | Android system, please skip this section.\\ | ||
| Line 101: | Line 102: | ||
| ``` | ``` | ||
| - | ===== Run Example Programs | + | ===== Run example programs |
| - | ==== Prepare | + | ==== Prepare |
| Switch to the '' | Switch to the '' | ||
| script will download an available YOLOv5 ONNX model and store it in the current model directory. Refer to the | script will download an available YOLOv5 ONNX model and store it in the current model directory. Refer to the | ||
| Line 113: | Line 114: | ||
| ``` | ``` | ||
| - | ==== Model Conversion | + | ==== Model conversion |
| Switch to the '' | Switch to the '' | ||
| the original ONNX model to the RKNN model. Refer to the following commands: | the original ONNX model to the RKNN model. Refer to the following commands: | ||
| Line 122: | Line 123: | ||
| ``` | ``` | ||
| - | ==== Run RKNN Python | + | ==== Run RKNN Python |
| - | Switch to the rknn_model_zoo/ | + | === Android |
| + | Switch to the '' | ||
| YOLOv5 model on the development board using on-board debugging. Refer to the following command: | YOLOv5 model on the development board using on-board debugging. Refer to the following command: | ||
| Line 131: | Line 133: | ||
| ``` | ``` | ||
| - | ==== Run RKNN C Demo ==== | + | === Linux === |
| - | To run a RKNN C Demo, you need to first compile the C/C++ source code into an executable file. After that, push | + | |
| + | Running on a Ubuntu 24.04 system which ship the python version of 3.12. | ||
| + | |||
| + | Download the model zoo to your Edge 2L: | ||
| + | |||
| + | ```shell | ||
| + | git clone -b v2.3.2 https:// | ||
| + | ``` | ||
| + | |||
| + | Install the python virtual environment: | ||
| + | |||
| + | ```shell | ||
| + | sudo apt update | ||
| + | sudo apt install python3.12-venv -y | ||
| + | ``` | ||
| + | |||
| + | Create the python virtual environment: | ||
| + | ```shell | ||
| + | python3 -m venv myenv312 | ||
| + | ``` | ||
| + | |||
| + | Activate the python virtual environment: | ||
| + | |||
| + | ```shell | ||
| + | source myenv312/ | ||
| + | (myenv312) khadas@Khadas: | ||
| + | Python 3.12.3 | ||
| + | ``` | ||
| + | |||
| + | Install the python package from '' | ||
| + | |||
| + | ```shell | ||
| + | (myenv312) khadas@Khadas: | ||
| + | ``` | ||
| + | |||
| + | Install the runtime libraries from '' | ||
| + | |||
| + | ```shell | ||
| + | sudo cp librknnrt.so /usr/lib/ | ||
| + | ``` | ||
| + | |||
| + | Install the OpenCV: | ||
| + | |||
| + | ```shell | ||
| + | (myenv312) khadas@Khadas: | ||
| + | ``` | ||
| + | |||
| + | Copy the converted model in [[# | ||
| + | |||
| + | ```shell | ||
| + | adb push examples/ | ||
| + | ``` | ||
| + | |||
| + | Modify the demo code: | ||
| + | |||
| + | ```diff | ||
| + | diff --git a/ | ||
| + | index 21b4132..46b24d4 100644 | ||
| + | --- a/ | ||
| + | +++ b/ | ||
| + | @@ -1,5 +1,5 @@ | ||
| + | -from rknn.api import RKNN | ||
| + | - | ||
| + | +from rknnlite.api import RKNNLite as RKNN | ||
| + | +import numpy as np | ||
| + | |||
| + | class RKNN_model_container(): | ||
| + | def __init__(self, | ||
| + | @@ -9,10 +9,7 @@ class RKNN_model_container(): | ||
| + | | ||
| + | |||
| + | | ||
| + | - if target==None: | ||
| + | - ret = rknn.init_runtime() | ||
| + | - else: | ||
| + | - ret = rknn.init_runtime(target=target, | ||
| + | + ret = rknn.init_runtime() | ||
| + | if ret != 0: | ||
| + | | ||
| + | | ||
| + | @@ -33,10 +30,12 @@ class RKNN_model_container(): | ||
| + | | ||
| + | | ||
| + | |||
| + | + inputs = [np.expand_dims(item, | ||
| + | + | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | def release(self): | ||
| + | | ||
| + | - self.rknn = None | ||
| + | \ No newline at end of file | ||
| + | + self.rknn = None | ||
| + | (myenv312) khadas@Khadas: | ||
| + | ``` | ||
| + | |||
| + | Run the Yolov5 demo: | ||
| + | |||
| + | ```shell | ||
| + | (myenv312) khadas@Khadas: | ||
| + | (myenv312) khadas@Khadas: | ||
| + | ``` | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Deactivate the python virtual enviranment: | ||
| + | |||
| + | ```shell | ||
| + | (myenv312) khadas@Khadas: | ||
| + | ``` | ||
| + | |||
| + | |||
| + | ==== Run RKNN C demo ==== | ||
| + | To run a RKNN C demo, you need to first compile the C/C++ source code into an executable file. After that, push | ||
| the executable file, model files, input images, and other related files to the development board. Finally, execute | the executable file, model files, input images, and other related files to the development board. Finally, execute | ||
| the executable file on the development board. | the executable file on the development board. | ||
| - | === Board is running on the Android | + | === Android === |
| In the '' | In the '' | ||
| Line 149: | Line 266: | ||
| ``` | ``` | ||
| - | Push Files to the Edge 2L Board: | + | Push Files to the Edge 2L board: |
| ```shell | ```shell | ||
| $ cd Projects/ | $ cd Projects/ | ||
| $ adb root | $ adb root | ||
| - | $ adb install/ | + | $ adb push install/ |
| ``` | ``` | ||
| - | Run the Demo on Edge 2L Board: | + | Run the Demo on Edge 2L board: |
| ```shell | ```shell | ||
| $ adb shell | $ adb shell | ||
| Line 163: | Line 280: | ||
| $ ./ | $ ./ | ||
| ``` | ``` | ||
| - | === Board is running on the Linux system | + | === Linux === |
| In the '' | In the '' | ||
| Line 176: | Line 293: | ||
| ``` | ``` | ||
| - | Push Files to the Edge 2L Board: | + | Push Files to the Edge 2L board: |
| ```shell | ```shell | ||
| $ cd Projects/ | $ cd Projects/ | ||
| Line 182: | Line 299: | ||
| ``` | ``` | ||
| - | Run the Demo on Edge 2L Board: | + | Run the Demo on Edge 2L board: |
| ```shell | ```shell | ||
| $ adb shell | $ adb shell | ||
| Line 190: | Line 307: | ||
| ``` | ``` | ||
| - | + | ==== View results | |
| - | + | ||
| - | ==== View Results | + | |
| By default, the output image is saved at the path '' | By default, the output image is saved at the path '' | ||
| from the board to the local machine. In the local computer terminal, execute the following command: | from the board to the local machine. In the local computer terminal, execute the following command: | ||
| ```shell | ```shell | ||
| - | $ adb pull /data/ | + | $ adb pull /home/khadas/ |
| ``` | ``` | ||
| {{: | {{: | ||
| - | + | ===== See also ===== | |
| - | ===== See Also ===== | + | |
| [[https:// | [[https:// | ||