Toybrick

关于mobilenet rknn模型的推理时间问题

chuyee

中级会员

积分
352
楼主
发表于 2019-2-9 09:12:54    查看: 24433|回复: 23 | [复制链接]    打印 | 显示全部楼层
直接调用rknn.load_rknn()加载example中转化好了的rknn模型,计算了一下rknn.inference()示例图片的时间,结果如下:

mobilenet_v1: 0.286s
mobilenet_v2: 0.255s
mobilenet_ssd: 0.671s


这样算下来只有3~4FPS。请问这个结果合理吗?速度还能再提高吗?
回复

使用道具 举报

chuyee

中级会员

积分
352
沙发
 楼主| 发表于 2019-2-9 09:36:01 | 显示全部楼层
统计inference()时间的改动如下:

--- test.py        2019-02-08 17:13:51.681182986 -0800
+++ test.py        2019-02-08 11:44:23.350497563 -0800
@@ -1,6 +1,7 @@
import numpy as np
import cv2
from rknn.api import RKNN
+from datetime import datetime

def show_outputs(outputs):
     output = outputs[0][0]
@@ -49,9 +50,11 @@

     # Inference
     print('--> Running model')
+    start = datetime.now()
     outputs = rknn.inference(inputs=[img])
+    end = datetime.now()
     show_outputs(outputs)
-    print('done')
+    print('inference time:', end - start)
     #print('inference result: ', outputs)

     rknn.release()
回复

使用道具 举报

chuyee

中级会员

积分
352
板凳
 楼主| 发表于 2019-2-14 01:42:18 | 显示全部楼层
troy 发表于 2019-2-13 17:18
请问是在PC还是板子上运行的?

TB-RK3399Pro板子上.      
回复

使用道具 举报

chuyee

中级会员

积分
352
地板
 楼主| 发表于 2019-2-15 02:29:25 | 显示全部楼层
程子 发表于 2019-2-14 16:13
刚刚在板子上测试了一下,用RKNN的计时。

mobilenet-ssd

你用的demo里面自带的统计吗?能用我上面的patch试一下吗?直接计算rknn.inference()的时间,就是时间减一下,非常简单。
回复

使用道具 举报

chuyee

中级会员

积分
352
5#
 楼主| 发表于 2019-2-15 08:07:35 | 显示全部楼层
I got 90FPS for mobilenet_v1 from the 'perf_debug' prints. However it doesn't align with the real time used (as I measured from the above patch for rknn.inference()). What's the problem here? Is there a way to infer multiple images in one rknn inference call?


--> Begin evaluate model performance
========================================================================
                               Performance                              
========================================================================
Layer ID    Name                                         Time(us)
0           ConvolutionReluPoolingLayer2_2               2624
1           ConvolutionReluPoolingLayer2_2               343
2           ConvolutionReluPoolingLayer2_2               297
3           ConvolutionReluPoolingLayer2_2               410
4           ConvolutionReluPoolingLayer2_2               204
5           ConvolutionReluPoolingLayer2_2               254
6           ConvolutionReluPoolingLayer2_2               228
7           ConvolutionReluPoolingLayer2_2               277
8           ConvolutionReluPoolingLayer2_2               203
9           ConvolutionReluPoolingLayer2_2               258
10          ConvolutionReluPoolingLayer2_2               279
11          ConvolutionReluPoolingLayer2_2               227
12          ConvolutionReluPoolingLayer2_2               228
13          ConvolutionReluPoolingLayer2_2               258
14          ConvolutionReluPoolingLayer2_2               307
15          ConvolutionReluPoolingLayer2_2               227
16          ConvolutionReluPoolingLayer2_2               304
17          ConvolutionReluPoolingLayer2_2               227
18          ConvolutionReluPoolingLayer2_2               302
19          ConvolutionReluPoolingLayer2_2               226
20          ConvolutionReluPoolingLayer2_2               303
21          ConvolutionReluPoolingLayer2_2               238
22          ConvolutionReluPoolingLayer2_2               303
23          ConvolutionReluPoolingLayer2_2               245
24          ConvolutionReluPoolingLayer2_2               233
25          ConvolutionReluPoolingLayer2_2               433
26          ConvolutionReluPoolingLayer2_2               331
27          PoolingLayer2_1                              280
28          FullyConnectedReluLayer_0                    392
29          TensorTranspose_0                            153
30          SoftmaxLayer_1                               479
Total Time(us): 11073
FPS(800MHz): 90.31
========================================================================
回复

使用道具 举报

chuyee

中级会员

积分
352
6#
 楼主| 发表于 2019-2-15 10:53:46 | 显示全部楼层
程子 发表于 2019-2-15 10:46
我用 rknn.eval_perf() 来评估时间。

你的 datetime.now() 的方法看起来没啥问题,但是结果感觉不太正常。 ...

我也不是说我不相信RKNN统计的结果哈,但mobilenet-ssd半秒一帧基本就是没法用的啊!现在的问题是怎么能够把理论上的90FPS变成实际中可以使用的检测速度,至少也得25FPS吧?
回复

使用道具 举报

chuyee

中级会员

积分
352
7#
 楼主| 发表于 2019-2-15 15:43:31 | 显示全部楼层
slim 发表于 2019-2-15 11:20
@chuyee I got the same results. About ~0.7s for mobilenet_ssd.  rknn.eval_perf() is the simulator  ...

That's a critical issue. Can someone from RK confirm?
回复

使用道具 举报

chuyee

中级会员

积分
352
8#
 楼主| 发表于 2019-2-15 16:39:20 | 显示全部楼层
One more information, seems like this is a Python specific bug. C API result is much faster. Below is my rknn_mobilenet running time:

rknn_init takes 0.068531s
rknn_query takes 0.000018s
rknn_inputs_set takes 0.001168s
rknn_run takes 0.000126s
rknn_outputs_get takes 0.000637s

perf_run.run_duration = 9993 us

Does anyone know how to map each rknn functions to the perf duration (~10ms)? I know rknn_run() is non-blocking call and rknn_outputs_get() is blocking. But it's only 0.6ms. What else does the 10ms include?
回复

使用道具 举报

chuyee

中级会员

积分
352
9#
 楼主| 发表于 2019-2-22 04:43:10 | 显示全部楼层
MraxZhao 发表于 2019-2-21 12:39
how can i  get the information inferance function using?is NPU or is CPU

I don't know either. I guess it might be done by CPU because inference result is correct while the speed is much slower.
回复

使用道具 举报

chuyee

中级会员

积分
352
10#
 楼主| 发表于 2019-2-27 16:14:50 | 显示全部楼层
升级成rknn v0.9.8.1后速度提高了10多倍,标志成问题解决。测试结果如下:

mobilenet_v1: 0.021s
mobilenet_v2: 0.026s
mobilenet_ssd: 0.045s
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表