- 1. Description
- 2. Current Support Platform
- 3. Pretrained Model
- 4. Convert to RKNN
- 5. Python Demo
- 6. Android Demo
- 7. Linux Demo
- 8. Expected Results
The model used in this example comes from the following open source projects:
https://github.com/airockchip/yolov5
RK3566, RK3568, RK3588, RK3562, RV1106, RV1103, RV1109, RK3576, RV1126, RK1808, RK3399PRO
Download link:
./yolov5s_relu.onnx
./yolov5n.onnx
./yolov5s.onnx
./yolov5m.onnx
Download with shell command:
cd model
./download_model.sh
Note: The model provided here is an optimized model, which is different from the official original model. Take yolov5n.onnx as an example to show the difference between them.
- The comparison of their output information is as follows. The left is the official original model, and the right is the optimized model.
- Taking the output change [1,19200,85]->[1,255,80,80] as an example, we delete a subgraph (the framed part in the picture) from the model and put it in post-processing (this subgraph is not quantification-friendly)
Usage:
cd python
python convert.py <onnx_model> <TARGET_PLATFORM> <dtype(optional)> <output_rknn_path(optional)>
# such as:
python convert.py ../model/yolov5s_relu.onnx rk3588
# output model will be saved as ../model/yolov5.rknn
Description:
<onnx_model>
: Specify ONNX model path.<TARGET_PLATFORM>
: Specify NPU platform name. Support Platform refer here.<dtype>(optional)
: Specify asi8
orfp
.i8
for doing quantization,fp
for no quantization. Default isi8
.<output_rknn_path>(optional)
: Specify save path for the RKNN model, default save in the same directory as ONNX model with nameyolov5.rknn
Usage:
cd python
# Inference with PyTorch model or ONNX model
python yolov5.py --model_path <pt_model/onnx_model> --img_show
# Inference with RKNN model
python yolov5.py --model_path <rknn_model> --target <TARGET_PLATFORM> --img_show
Description:
-
<TARGET_PLATFORM>
: Specify NPU platform name. Such as 'rk3588'. -
<pt_model / onnx_model / rknn_model>
: specified as the model path.
Usage:
# go back to the rknn_model_zoo root directory
cd ../../
export ANDROID_NDK_PATH=<android_ndk_path>
./build-android.sh -t <TARGET_PLATFORM> -a <ARCH> -d yolov5
# such as
./build-android.sh -t rk3588 -a arm64-v8a -d yolov5
Description:
<android_ndk_path>
: Specify Android NDK path.<TARGET_PLATFORM>
: Specify NPU platform name. Support Platform refer here.<ARCH>
: Specify device system architecture. To query device architecture, refer to the following command:# Query architecture. For Android, ['arm64-v8a' or 'armeabi-v7a'] should shown in log. adb shell cat /proc/version
With device connected via USB port, push demo files to devices:
adb root
adb remount
adb push install/<TARGET_PLATFORM>_android_<ARCH>/rknn_yolov5_demo/ /data/
adb shell
cd /data/rknn_yolov5_demo
export LD_LIBRARY_PATH=./lib
./rknn_yolov5_demo model/yolov5.rknn model/bus.jpg
-
After running, the result was saved as
out.png
. To check the result on host PC, pull back result referring to the following command:adb pull /data/rknn_yolov5_demo/out.png
usage
# go back to the rknn_model_zoo root directory
cd ../../
# if GCC_COMPILER not found while building, please set GCC_COMPILER path
(optional)export GCC_COMPILER=<GCC_COMPILER_PATH>
./build-linux.sh -t <TARGET_PLATFORM> -a <ARCH> -d yolov5
# such as
./build-linux.sh -t rk3588 -a aarch64 -d yolov5
# such as
./build-linux.sh -t rv1106 -a armhf -d yolov5
Description:
-
<GCC_COMPILER_PATH>
: Specified as GCC_COMPILER path.- For RV1106, RV1103, GCC_COMPILER version is
arm-rockchip830-linux-uclibcgnueabihf
export GCC_COMPILER=~/opt/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf
- For RV1106, RV1103, GCC_COMPILER version is
-
<TARGET_PLATFORM>
: Specify NPU platform name. Support Platform refer here. -
<ARCH>
: Specify device system architecture. To query device architecture, refer to the following command:# Query architecture. For Linux, ['aarch64' or 'armhf'] should shown in log. adb shell cat /proc/version
- If device connected via USB port, push demo files to devices:
adb push install/<TARGET_PLATFORM>_linux_<ARCH>/rknn_yolov5_demo/ /userdata/
- For other boards, use
scp
or other approaches to push all files underinstall/<TARGET_PLATFORM>_linux_<ARCH>/rknn_yolov5_demo/
touserdata
.
adb shell
cd /userdata/rknn_yolov5_demo
export LD_LIBRARY_PATH=./lib
./rknn_yolov5_demo model/yolov5.rknn model/bus.jpg
-
RV1106/1103 LD_LIBRARY_PATH must specify as the absolute path. Such as
export LD_LIBRARY_PATH=/userdata/rknn_yolov5_demo/lib
-
After running, the result was saved as
out.png
. To check the result on host PC, pull back result referring to the following command:adb pull /userdata/rknn_yolov5_demo/out.png
This example will print the labels and corresponding scores of the test image detect results, as follows:
person @ (209 244 286 506) 0.884
person @ (478 238 559 526) 0.868
person @ (110 238 230 534) 0.825
bus @ (94 129 553 468) 0.705
person @ (79 354 122 516) 0.339
- Note: Different platforms, different versions of tools and drivers may have slightly different results.