orangepi-5b 使用 rknn-toolkit2 实测
主机环境:ubuntu20.04 x86_64
开发板 orangepi-5b 4G ram 32G emmc
网站介绍 http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5B.html
基于rk3588s
所以我们使用 rknn-toolkit2
step1 配置交叉编译工具链:
下载地址 https://releases.linaro.org/components/toolchain/binaries/
bash
### CROSS-COMPILE
export AARCH64_LINUX_GNU_TOOLS=/media/wmx/cross_compile_tools/aarch64-linux-gun/gcc-x86_64_aarch64-linux-gnu/bin
export ARM_LINUX_GNUEABI_TOOLS=/media/wmx/cross_compile_tools/arm-linux-guneabi/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi/bin/
export ARM_LINUX_GNUEABIHF_TOOLS=/media/wmx/cross_compile_tools/arm-linux-guneabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin
step2 下载工具RKNN-Toolkit2
github 组织 airockchip
https://github.com/airockchip
下载 https://github.com/airockchip/rknn-toolkit2
不兼容:
RKNN-Toolkit2 is not compatible with RKNN-Toolkit
版本对应:
Ubuntu 18.04 python 3.6/3.7
Ubuntu 20.04 python 3.8/3.9
Ubuntu 22.04 python 3.10/3.11
Latest version:v2.0.0-beta0
我下载的是v2.0.0-beta0 版本
/media/wmx/ws1/ai/rk/rknn-toolkit2-2.0.0-beta0
step3 在这个目录下创建虚拟环境venv:
/media/wmx/ws1/ai/rk/rknn-toolkit2-2.0.0-beta0
bash
conda create --prefix ./venv python=3.9
conda activate ./venv/
#安装依赖:
python -m pip install -r rknn-toolkit2/packages/requirements_cp39-2.0.0b0.txt -i https://mirror.baidu.com/pypi/simple
#安装软件包
python -m pip install rknn-toolkit2/packages/rknn_toolkit2-2.0.0b0+9bab5682-cp39-cp39-linux_x86_64.whl -i https://mirror.baidu.com/pypi/simple
验证是否安装成功:
python
python
from rknn.api import RKNN
没有报错,ok
step4 下载demo
https://github.com/airockchip/rknn_model_zoo
路径:
/media/wmx/ws1/ai/rk/rknn_model_zoo-2.0.0
step5 下载模型并且转换
激活的虚拟环境venv 命令行切换到目录:
bash
cd /media/wmx/ws1/ai/rk/rknn_model_zoo-2.0.0/examples/yolov5/model
# 下载模型
chmod +x download_model.sh
./download_model.sh
# 转换onnx 模型到 rknn
cd ../python
python convert.py ../model/yolov5s_relu.onnx rk3588
step6 编译示例yolo5
切换到 /media/wmx/ws1/ai/rk/rknn_model_zoo-2.0.0
修改build-linux.sh 配置交叉编译工具
AARCH64_LINUX_GNU_TOOLS是step1配置的环境变量
bash
export GCC_COMPILER=$AARCH64_LINUX_GNU_TOOLS/aarch64-linux-gnu
bash
cd /media/wmx/ws1/ai/rk/rknn_model_zoo-2.0.0
./build-linux.sh -t rk3588 -a aarch64 -d yolov5
step7 push 到板子上运行
/home/orangepi/workspace 是开发板上面已经创建的目录
bash
adb push install/rk3588_linux_aarch64/rknn_yolov5_demo/ /home/orangepi/workspace
先ssh到板子上
或者adb shell到板子上
板子上面执行的效果输出 out.png:
bash
orangepi@orangepi5b:~/workspace/rknn_yolov5_demo$ sudo ./rknn_yolov5_demo ./model/yolov5.rknn ./model/bus.jpg
load lable ./model/coco_80_labels_list.txt
model input num: 1, output num: 3
input tensors:
index=0, name=images, n_dims=4, dims=[1, 640, 640, 3], n_elems=1228800, size=1228800, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
output tensors:
index=0, name=output0, n_dims=4, dims=[1, 255, 80, 80], n_elems=1632000, size=1632000, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
index=1, name=286, n_dims=4, dims=[1, 255, 40, 40], n_elems=408000, size=408000, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
index=2, name=288, n_dims=4, dims=[1, 255, 20, 20], n_elems=102000, size=102000, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
model is NHWC input fmt
model input height=640, width=640, channel=3
origin size=640x640 crop size=640x640
input image: 640 x 640, subsampling: 4:2:0, colorspace: YCbCr, orientation: 1
scale=1.000000 dst_box=(0 0 639 639) allow_slight_change=1 _left_offset=0 _top_offset=0 padding_w=0 padding_h=0
src width=640 height=640 fmt=0x1 virAddr=0x0x20b3ff20 fd=0
dst width=640 height=640 fmt=0x1 virAddr=0x0x20c6bf30 fd=0
src_box=(0 0 639 639)
dst_box=(0 0 639 639)
color=0x72
rga_api version 1.10.1_[0]
rknn_run
person @ (209 243 286 510) 0.880
person @ (479 238 560 526) 0.871
person @ (109 238 231 534) 0.840
bus @ (91 129 555 464) 0.692
person @ (79 353 121 517) 0.301
write_image path: out.png width=640 height=640 channel=3 data=0x20b3ff20
orangepi@orangepi5b:~/workspace/rknn_yolov5_demo$ ls
lib model out.png rknn_yolov5_demo