Skip to content

Commit

Permalink
update yolo series model support
Browse files Browse the repository at this point in the history
  • Loading branch information
zen committed Sep 18, 2023
1 parent e13992d commit 2246218
Show file tree
Hide file tree
Showing 172 changed files with 89,220 additions and 5,119 deletions.
46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@

# RKNN模型库
​ Rockchip Neural Network(RKNN)是瑞芯微为了加速模型推理而基于自身NPU硬件架构定义的一套模型格式.使用该格式定义的模型在Rockchip NPU上可以获得远高于CPU/GPU的性能.
​ RKNN Model Zoo是由像您这样的社区成员贡献的覆盖不同任务,不同框架的SOTA模型的集合.它涵盖了模型转换,模型评估和模型部署等基于Rockchip NPU的完整AI应用开发流程. 每个模型都包含**模型转换,模型评估,模型部署**相关的脚本,如果有对模型原始工程调整的,还会提供相应的脚本或补丁.
​ RKNN Model Zoo是由像您这样的社区成员贡献的覆盖不同任务、不同应用场景的SOTA模型集合。它涵盖了模型转换模型评估和模型部署等基于Rockchip NPU的完整AI应用开发流程

<br>
<br/>

相关模型权重请从[百度网盘](https://eyun.baidu.com/s/3humTUNq)获取,密码为 rknn
除了从提供的github仓库直接导出模型,模型文件也可以从[百度网盘](https://eyun.baidu.com/s/3humTUNq)获取,密码为 rknn

(网盘提供的 RKNN 模型如无特别说明,则基于最新 release 版本的 RKNN-Toolkit1/2 生成,使用 RKNN 模型时请先将设备的 NPU 驱动更新至最新的 release 版本;如无法更新驱动,则需要使用旧版本 RKNN-Toolkit 生成与驱动匹配的 RKNN 模型)

<br/>

为了规范转模型操作,RKNN Model Zoo提供了模型转换工具,通过配置 yaml 的形式转模型,兼容 toolkit1/2,支持对导出的模型进行(包括连板/Capi)验证,包含验证推理精度、验证推理性能、记录测试结果。更多说明请参考[文档](./common/rknn_converter/README.md)



## 更新简述
<details>
<summary>&#160&#160&#160 2023-09-18</summary>
模型新增:<br/>
&#160&#160&#160&#160 1.Yolo 系列模型新增 yolov6,yolov8,ppyoloe 支持<br/>
功能优化:<br/>
&#160&#160&#160&#160 1.完善模型转换、定频功能。新增rv1106/rk3562支持。
</details>


<details>
<summary>&#160&#160&#160 2022-11-15</summary>
Expand All @@ -25,7 +37,6 @@
</details>



<br>


Expand All @@ -36,7 +47,7 @@

|模型 |说明 |
|-|-|
|<b>[YOLO](models/CV/object_detection/yolo)</b>|支持 yolo 系列的检测模型,目前包含 yolov5/ yolov7/ yolox支持 RKNN-Toolkit1/2|
|<b>[YOLO](models/CV/object_detection/yolo)</b>|支持 yolo 系列的检测模型,目前包含 yolov5/6/7/8、ppyoloe、yolox支持 RKNN-Toolkit1/2|

<br>

Expand All @@ -49,12 +60,25 @@





## 添加模型指南

Fork该仓库并更新代码,提交 merge request ,会有RKNPU的研发人员进行评审、提供意见与帮助、接收代码。代码作者也将添加在致谢/共同作者中。

在 models 目录下找到对应模型的类别(如果对类别不确定,可联系RKNPU研发人员探讨),在文档中说明模型的开源库来源,并添加对应的模型转换/Python demo/Cdemo。这里推荐基于官方的开源模型库 fork 并使用固定的 commit 进行后续的开发,避免因开源库的更新导致 RKNN Model Zoo 的代码失效。

由于开发者通常只有单一型号的开发板,添加代码时以您手上的板子进行验证即可。代码接收后,RKNPU研发人员会补充并完善其他芯片的兼容性问题。

如遇到任何疑问、问题,欢迎联系 RKNPU研发人员解决。





## Acknowledgements

<details>
<summary>&#160&#160&#160 expand</summary>
https://github.com/ultralytics/yolov5<br/>
https://github.com/WongKinYiu/yolov7<br/>
https://github.com/Megvii-BaseDetection/YOLOX<br/>
https://github.com/ultralytics/yolov5<br/>https://github.com/meituan/YOLOv6<br/>https://github.com/WongKinYiu/yolov7<br/>https://github.com/ultralytics/ultralytics<br/>
https://github.com/Megvii-BaseDetection/YOLOX<br/>https://github.com/PaddlePaddle/PaddleDetection<br/>
https://github.com/mit-han-lab/lite-transformer<br/>
</details>

36 changes: 34 additions & 2 deletions capi_tools/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Capi Tools 说明:

### 1. 定频工具
## 1. 定频工具

##### 文件: scaling_frequency.sh

Expand All @@ -10,7 +10,7 @@

​ 一代NPU: RV1109, RV1126, RK1808

二代NPU: RK3566, RK3568, RK3588
​ 二代NPU: RK3566, RK3568, RK3588, RK3562, RV1103, RV1106

##### 使用方法(以rk3566为例)

Expand All @@ -28,3 +28,35 @@ chmod 777 /data/scaling_frequency.sh
/data/scaling_frequency.sh -c rk3566
```

**默认定频到最高频率, 如需使用其他频率:**

```
请修改 scaling_frequency.sh 中对应芯片平台的定频配置,这里以 rv1126 为例子,可以找到如下代码
if [ $chip_name == 'rv1126' ]; then
seting_strategy=1
CPU_freq=1512000
NPU_freq=934000000
DDR_freq=924000000
修改对应的数值配置,即可修改定频的频率。
```



## 2.CAPI 测试工具

CAPI测试工具帮助开发者快速验证板端的CAPI接口的可执行性、各接口的调用耗时。通常该接口被 RKNN CONVERTER 功能所使用,默认使用发布版本的 librknnrt.so 进行验证。如在 RKNPU2 对应平台需替换成其他版本的,请替换demo中对应的 rt.so 文件。

```
Toolkit2 runtime path:
./rknn_model_zoo/capi_tools/toolkit2/rknn_capi_test/install/{platform}/{system_type}/rknn_capi_test/lib/librknnrt.so
platform 代表芯片平台,如 rk3588, rv1106
system_type 代表板端系统类型,如安卓、Linux
```

```
测试工具使用方法:
rknn_capi_test ./xxx.rknn
即可测试模型的推理耗时
```

84 changes: 58 additions & 26 deletions capi_tools/scaling_frequency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@
chip_name=0
freq_set_status=0

# order
# rk1808 0
# rk3399pro 1
# rv1109 2
# rv1126 3
# rk3566 4
# rk3568 5
# rk3588 6

### rv1103/rv1106 do not have bash command, not support now
# rv1103 7
# rv1106 8


usage()
{
echo "USAGE: ./fixed_frequency.sh -c {chip_name} [-h]"
Expand Down Expand Up @@ -76,23 +62,28 @@ if [ $chip_name == 'rv1126' ]; then
seting_strategy=1
CPU_freq=1512000
NPU_freq=934000000
DDR_freq=934000000
DDR_freq=924000000
elif [ $chip_name == 'rv1109' ]; then
seting_strategy=1
CPU_freq=1512000
NPU_freq=594000000
DDR_freq=934000000
DDR_freq=924000000
elif [ $chip_name == 'rk1808' ]; then
seting_strategy=1
# CPU_freq=1512000
CPU_freq=1200000
NPU_freq=792000000
DDR_freq=934000000
DDR_freq=924000000
elif [ $chip_name == 'rk3399pro' ]; then
seting_strategy=2
CPU_freq=1512000
NPU_freq=792000000
DDR_freq=934000000
elif [ $chip_name == 'rk3562' ]; then
seting_strategy=6
CPU_freq=2016000
NPU_freq=1000000000
DDR_freq=1560000000
elif [ $chip_name == 'rk3566' ]; then
seting_strategy=3
CPU_freq=1800000
Expand All @@ -105,18 +96,18 @@ elif [ $chip_name == 'rk3568' ]; then
DDR_freq=1560000000
elif [ $chip_name == 'rk3588' ]; then
seting_strategy=4
CPU_freq=2400000
CPU_freq=2256000
NPU_freq=1000000000
DDR_freq=2112000000
elif [ $chip_name == 'rv1106' ]; then
seting_strategy=5
CPU_freq=1608000
NPU_freq=420000000
NPU_freq=500000000
DDR_freq=924000000
elif [ $chip_name == 'rv1103' ]; then
seting_strategy=5
CPU_freq=1608000
NPU_freq=420000000
NPU_freq=500000000
DDR_freq=924000000
else
echo "$chip_name not recognize"
Expand All @@ -126,6 +117,7 @@ fi


echo "Try seting frequency for "${chip_name}
echo " Setting strategy as $seting_strategy"
echo " NPU seting to "$NPU_freq
echo " CPU seting to "$CPU_freq
echo " DDR seting to "$DDR_freq
Expand All @@ -151,13 +143,18 @@ case $seting_strategy in
print_and_compare_result $NPU_freq $cur_freq

echo "DDR: seting frequency"
print_not_support_adjust DDR $DDR_freq
cat /sys/kernel/debug/clk/clk_summary | grep dpll
if [ $chip_name == 'rk1808' ]; then
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep pll_dpll | awk '{split($0,a," "); print a[4]}')
else
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep pll_dpll | awk '{split($0,a," "); print a[5]}')
fi
cur_freq="`expr $cur_freq \* 2`"
print_not_support_adjust DDR $DDR_freq $cur_freq
;;

# for rk3399pro
2)
echo "seting strategy not implement now"
echo "seting strategy not implement for rk3399pro now"
;;

# for rk3566, rk3568
Expand Down Expand Up @@ -186,9 +183,11 @@ case $seting_strategy in
echo "CPU: seting frequency"
echo " Core0"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
# echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
echo 1800000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $cur_freq
# print_and_compare_result $CPU_freq $cur_freq
print_and_compare_result 1800000 $cur_freq

echo " Core4"
echo userspace > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
Expand All @@ -209,6 +208,10 @@ case $seting_strategy in
echo $NPU_freq > /sys/class/devfreq/fdab0000.npu/userspace/set_freq
cur_freq=$(cat /sys/class/devfreq/fdab0000.npu/cur_freq)
print_and_compare_result $NPU_freq $cur_freq
elif [ -e /sys/class/devfreq/devfreq0/governor ];then
echo performance > /sys/class/devfreq/devfreq0/governor
cur_freq=$(cat /sys/class/devfreq/devfreq0/cur_freq)
print_and_compare_result $NPU_freq $cur_freq
else
cur_freq=$(cat /sys/kernel/debug/clk/scmi_clk_npu/clk_rate)
print_not_support_adjust NPU $NPU_freq $cur_freq
Expand Down Expand Up @@ -236,7 +239,9 @@ case $seting_strategy in
print_and_compare_result $CPU_freq $cur_freq

echo "NPU: seting frequency"
echo " no strategy to seting DDR frequency"
# echo " no strategy to seting DDR frequency"
# echo $NPU_freq > /sys/kernel/debug/clk/aclk_npu_root/clk_rate
echo $NPU_freq > /sys/kernel/debug/clk/clk_500m_src/clk_rate
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep aclk_npu_root | awk '{split($0,a," "); print a[5]}')
print_and_compare_result $NPU_freq $cur_freq

Expand All @@ -246,6 +251,33 @@ case $seting_strategy in
cur_freq="`expr $cur_freq \* 2`"
print_and_compare_result $DDR_freq $cur_freq
;;

# rk3562
6)
echo "CPU: seting frequency"
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $CPU_freq > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed
cur_freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
print_and_compare_result $CPU_freq $cur_freq

echo "NPU: seting frequency"
echo userspace > /sys/devices/platform/ff300000.npu/devfreq/ff300000.npu/governor
echo $NPU_freq > /sys/devices/platform/ff300000.npu/devfreq/ff300000.npu/userspace/set_freq
cur_freq=$(cat /sys/class/devfreq/ff300000.npu/cur_freq)
print_and_compare_result $NPU_freq $cur_freq

echo "DDR: seting frequency"
if [ -e /sys/class/devfreq/dmc/governor ];then
echo userspace > /sys/class/devfreq/dmc/governor
echo $DDR_freq > /sys/class/devfreq/dmc/userspace/set_freq
cur_freq=$(cat /sys/class/devfreq/dmc/cur_freq)
print_and_compare_result $DDR_freq $cur_freq
else
cur_freq=$(cat /sys/kernel/debug/clk/clk_summary | grep scmi_clk_ddr | awk '{split($0,a," "); print a[5]}')
print_not_support_adjust DDR $DDR_freq $cur_freq
fi
;;

*)
echo "seting strategy not implement now"
;;
Expand Down
26 changes: 17 additions & 9 deletions capi_tools/toolkit1/rknn_capi_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# for linux
if (CMAKE_C_COMPILER MATCHES "aarch64")
set(LIB_ARCH lib64)
add_definitions(-DRK1808=1)
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
if (CMAKE_C_COMPILER MATCHES "aarch64")
set(LIB_ARCH lib64)
add_definitions(-DRK1808=1)
else()
set(LIB_ARCH lib)
add_definitions(-DRK1808=0)
endif()
set(PTHREAD pthread)
else()
set(LIB_ARCH lib)
add_definitions(-DRK1808=0)
endif()

# for android
if (${TARGET_SOC} STREQUAL "RK3399PRO")
set(LIB_ARCH lib64)
add_definitions(-DRK1808=1)
set(PTHREAD "")
endif()
# for android
# if (${TARGET_SOC} STREQUAL "RK3399PRO")
# set(LIB_ARCH lib64)
# add_definitions(-DRK1808=1)
# endif()


# stb
Expand Down Expand Up @@ -72,6 +78,7 @@ if (${ZERO_COPY})
# ${LIBPNG_LIB}
${ZLIB_LIB}
dl
${PTHREAD}
)
else()
message("Build rknn_capi_test")
Expand All @@ -88,6 +95,7 @@ else()
# ${LIBPNG_LIB}
${ZLIB_LIB}
dl
${PTHREAD}
)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cmake .. \
-DMZ_ROOT=${MZ_ROOT} \
-DTARGET_SOC=RK3399PRO \
-DCMAKE_SYSTEM_NAME=Linux \
-DZERO_COPY=0 \
-DZERO_COPY=0
make -j4
make install

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions capi_tools/toolkit1/rknn_capi_test/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <sys/time.h>
#include <unistd.h>

// #if (TARGET_SOC==RK3399PRO)
#include <pthread.h>
// #endif


#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
Expand Down
2 changes: 1 addition & 1 deletion capi_tools/toolkit2/rknn_capi_test/build-android_RK356X.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

if [ -z ${ANDROID_NDK_PATH} ]
then
ANDROID_NDK_PATH=/home/lc/ndk/android-ndk-r23b
ANDROID_NDK_PATH=~/opt/android-ndk-r17
fi

BUILD_TYPE=Release
Expand Down
2 changes: 1 addition & 1 deletion capi_tools/toolkit2/rknn_capi_test/build-android_RK3588.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

if [ -z ${ANDROID_NDK_PATH} ]
then
ANDROID_NDK_PATH=/home/lc/ndk/android-ndk-r23b
ANDROID_NDK_PATH=~/opt/android-ndk-r17
fi

BUILD_TYPE=Release
Expand Down
Loading

0 comments on commit 2246218

Please sign in to comment.