RKNN Toolkit Lite2 是瑞芯微专为RK系列芯片开发的NPU加速推理API。若不使用该工具,计算任务将仅依赖CPU处理,无法充分发挥芯片高达6TOPS的NPU算力优势。
按照官方文档先拉一下官方代码库,然后通过whl文件安装,因为我是python3.10环境,选择cp310的安装包
bash
git clone https://gitee.com/LubanCat/lubancat_ai_manual_code.git
cd lubancat_ai_manual_code/dev_env/rknn_toolkit_lite2
pip install packages/rknn_toolkit_lite2-1.5.0-cp310-cp310-linux_aarch64.whl
使用官方demo测试是否安装成功,进到yolov5的demo里运行一下test.py
bash
cd examples/yolov5_inference
python test.py
这时遇到错误:
bash
Traceback (most recent call last):
File "/home/cat/lubancat_ai_manual_code/dev_env/rknn_toolkit_lite2/examples/yolov5_inference/test.py", line 5, in <module>
import cv2
ImportError: libOpenGL.so.0: cannot open shared object file: No such file or directory
安装libopengl0库解决:
bash
sudo apt install libopengl0 -y
再次运行test.py成功识别图片里的各分类对象和位置:
bash
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [09:27:18.247] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
I RKNN: [09:27:18.248] RKNN Driver Information: version: 0.9.8
I RKNN: [09:27:18.253] RKNN Model Information: version: 4, toolkit version: 1.5.0+1fa95b5c(compiler version: 1.5.0 (e6fe0c678@2023-05-25T16:15:03)), target: RKNPU v2, target platform: rk3588, framework name: ONNX, framework layout: NCHW, model inference type: static_shape
done
--> Running model
W RKNN: [09:27:18.416] Output(269): size_with_stride larger than model origin size, if need run OutputOperator in NPU, please call rknn_create_memory using size_with_stride.
W RKNN: [09:27:18.417] Output(271): size_with_stride larger than model origin size, if need run OutputOperator in NPU, please call rknn_create_memory using size_with_stride.
W RKNN: [09:27:18.417] Output(273): size_with_stride larger than model origin size, if need run OutputOperator in NPU, please call rknn_create_memory using size_with_stride.
done
class: person, score: 0.8845707178115845
box coordinate left,top,right,down: [209.6862335205078, 243.11955797672272, 285.13685607910156, 507.7035621404648]
class: person, score: 0.8669421076774597
box coordinate left,top,right,down: [477.6677174568176, 241.89217948913574, 561.1506419181824, 524.2070636749268]
class: person, score: 0.8155205845832825
box coordinate left,top,right,down: [113.02320504188538, 234.78070652484894, 224.15367484092712, 535.1200503110886]
class: person, score: 0.3176437020301819
box coordinate left,top,right,down: [80.75779604911804, 354.98213291168213, 121.49669003486633, 516.5315389633179]
class: bus , score: 0.7036669850349426
box coordinate left,top,right,down: [93.71414947509766, 128.10655891895294, 554.3451156616211, 465.07032096385956]