配置orangepi5pro运行rknn版本的yolov5
摘要
配置orangepi5pro运行rknn版本的yolov5,使用npu进行目标检测.
关键信息
- 板卡:orangepi5pro
- 芯片:RK3588S
- 环境:rknn2
- 转换工具:rknn-tool-kit2:1.5.0
- 系统:ubuntu20.04
原理简介
npu简介
NPU(Neural Processing Unit,神经处理单元)是一种专门设计用于加速人工智能计算的硬件加速器。它通常集成在SoC(System on Chip)中,包含多个神经网络处理器和优化内存,能够高效执行神经网络的训练和推理任务.
rknn简介
[https://blog.csdn.net/zhoujinwang/article/details/130563729]
[https://gitcode.com/rockchip-linux/rknpu2]
[https://gitcode.com/airockchip/rknn-toolkit2/tree/master/rknpu2]
[https://gitcode.com/airockchip/rknn_model_zoo/overview]
- RKNN software stack can help users to quickly deploy AI models to Rockchip chips.
RKNN-Toolkit2 is not compatible with RKNN-Toolkit
Currently only support on:
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:1.6.0(Release version)
RKNN介绍 |
---|
In order to use RKNPU, users need to first run the RKNN-Toolkit2 tool on the computer, convert the trained model into an RKNN format model, and then inference on the development board using the RKNN C API or Python API.
RKNN-Toolkit2 is a software development kit for users to perform model conversion, inference and performance evaluation on PC and Rockchip NPU platforms.
RKNN-Toolkit-Lite2 provides Python programming interfaces for Rockchip NPU platform to help users deploy RKNN models and accelerate the implementation of AI applications.
RKNN Runtime provides C/C++ programming interfaces for Rockchip NPU platform to help users deploy RKNN models and accelerate the implementation of AI applications.
RKNPU kernel driver is responsible for interacting with NPU hardware. It has been open source and can be found in the Rockchip kernel code.
实现
- 转换yolov5的pytorch版本的pt模型到rk3588的npu专用模型rknn
# 仅支持amd64
docker pull arcturusnetworks/rknn-toolkit2:1.5.0
cd ./models
docker run -it --rm -v $PWD:/models arcturusnetworks/rknn-toolkit2:1.5.0 bash
# 转换 *.pt 到 *.onnx
# 图片大小640*640
cd yolov5 && python3 export.py --rknpu --imgsz 640 640 --weight /models/yolov5_jiapingzhe_exp19.pt
# 转换 *.onnx 到 *.rknn
cd /src/examples/onnx/yolov5/ && python3 convert.py -i /models/yolov5_jiapingzhe_exp19.onnx
- 部署模型
cd ~
git clone https://gitcode.com/airockchip/rknn_model_zoo.git
# 1. 修改目标类别数,修改如下
vim ~/rknn_model_zoo/examples/yolov5/include/postprocess.h
# 2. 修改目标类别文本,内容如下
vim ~/rknn_model_zoo/examples/yolov5/model/coco_80_labels_list.txt
cd ~/rknn_model_zoo
# 3. 编译
bash ./build-linux.sh -t rk3588 -a aarch64 -d yolov5
# 4.运行(需要sudo才能访问npu硬件)
cd ~/rknn_model_zoo/install/rk3588_linux_aarch64/rknn_yolov5_demo
sudo chmod +x ./rknn_yolov5_demo
sudo ./rknn_yolov5_demo model/yolov5_jiapingzhe_exp19.rknn model/yolov5_test3.jpg
postprocess.h
#define OBJ_CLASS_NUM 37 // 目标类别数
coco_80_labels_list.txt
0: zero
1: one
2: two
3: three
4: four
5: five
6: six
7: seven
8: eight
9: nine
10: a
11: b
12: c
13: d
14: e
15: f
16: g
17: h
18: i
19: j
20: k
21: l
22: m
23: n
24: p
25: q
26: r
27: s
28: t
29: u
30: v
31: w
32: x
33: y
34: z
35: shibie
36: qifei
效果
运行效果 |
---|