RK3399运行瑞芯微官方yolov5 C++代码

2 篇文章 0 订阅
1 篇文章 0 订阅

运行结果

img width = 1280, img height = 720
Loading mode...
D RKNNAPI: ==============================================
D RKNNAPI: RKNN VERSION:
D RKNNAPI:   API: 1.4.0 (bbe0dfc build: 2020-09-14 14:06:05)
D RKNNAPI:   DRV: 1.6.0 (159d2d3 build: 2021-01-12 15:23:09)
D RKNNAPI: ==============================================
sdk version: 1.4.0 (bbe0dfc build: 2020-09-14 14:06:05) driver version: 1.6.0 (159d2d3 build: 2021-01-12 15:23:09)
model input num: 1, output num: 3
index=0 name=images_165 n_dims=4 dims=[1 3 640 640] n_elems=1228800 size=1228800 fmt=0 type=3 qnt_type=2 fl=0 zp=0 scale=0.003922
index=0 name=Conv_Conv_159/out0_0 n_dims=4 dims=[1 255 80 80] n_elems=1632000 size=1632000 fmt=0 type=3 qnt_type=2 fl=0 zp=187 scale=0.127843
index=1 name=Conv_Conv_160/out0_1 n_dims=4 dims=[1 255 40 40] n_elems=408000 size=408000 fmt=0 type=3 qnt_type=2 fl=0 zp=182 scale=0.113217
index=2 name=Conv_Conv_161/out0_2 n_dims=4 dims=[1 255 20 20] n_elems=102000 size=102000 fmt=0 type=3 qnt_type=2 fl=0 zp=172 scale=0.103272
model is NCHW input fmt
model input height=640, width=640, channel=3
Rga built version:1.04 2134dde+2021-05-18 11:00:36
once run use 77.443000 ms
loadLabelName /home/toybrick/workspace/rockchip_yolov5/model/coco_80_labels_list.txt
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
 @ (1128 74 1280 532) 0.326754
 @ (668 41 892 525) 0.373704
 @ (26 20 224 529) 0.398172
 @ (1126 38 1278 284) 0.398172
 @ (914 47 1112 532) 0.349865
 @ (216 67 414 578) 0.326754
 @ (186 0 438 319) 0.423160
 @ (858 29 1080 300) 0.398172
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse

result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person

result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
result  0: (1128,   74, 1280,  532), horse
result  1: ( 668,   41,  892,  525), horse
result  2: (  26,   20,  224,  529), horse
result  6: (1126,   38, 1278,  284), person
result 10: ( 914,   47, 1112,  532), horse
result 13: ( 216,   67,  414,  578), horse
result 23: ( 186,    0,  438,  319), person
result 37: ( 858,   29, 1080,  300), person
loop count = 10 , average run  84.673900 ms

yolov5 C++代码代码地址

https://github.com/rockchip-linux/rknpu.git /rknn/rknn_api/example/rknn_yolov5_demo

rknn 模型使用

  1. rknpu/rknn/rknn_api/examples)/rknn_yolov5_demo/model/rk180x/yolov5s_relu_rk180x_out_opt.rknn 地址yolov5s_relu_rk180x_out_opt.rknn)

  2. https://github.com/EASY-EAI/yolov5.git 转换模型

代码调整

  1. 替换rknn初始化rknn_init改为rknn_init2指定npu设备号

    	rknn_init_extend rknnInitExtend;
        rknnInitExtend.device_id ="53b07e4f50aa0da5";
        ret = rknn_init2(&ctx, model_data, model_data_size, 0,&rknnInitExtend);
    

rknn_api 调整

在yolov5 C++demo代码的CMakeFileLists.txt文件中使用系统自带的librknn_api.so文件

link_libraries(
	/usr/lib/aarch64-linux-gnu/librknn_api.so
	......
)

编译RGA(可选)

本人使用板子rk3399proD没有自带的librga.so文件故需要编译rga

代码地址

https://github.com/rockchip-linux/linux-rga.git

编译调整

原因:在瑞芯微yolov5demo代码中通过dlsym使用c_RkRgaInit,c_RkRgaDeInit,c_RkRgaBlit函数,瑞芯微开源的RGA默认编译不含该函数

CMakeFileList.txt文件增加如下信息

set(IM2D_SRCS
    core/RockchipRga.cpp
    core/GrallocOps.cpp
    core/NormalRga.cpp
    core/RgaApi.cpp      --------此处为新增
    core/NormalRgaApi.cpp
    core/RgaUtils.cpp
    im2d_api/im2d.cpp)

写在最后

可以愉快玩耍啦

  • 1
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值