Toybrick

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

chuyee

中级会员

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

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


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

使用道具 举报

chuyee

中级会员

积分
352
来自 24#
 楼主| 发表于 2019-2-27 16:14:50 | 只看该作者
升级成rknn v0.9.8.1后速度提高了10多倍,标志成问题解决。测试结果如下:

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

使用道具 举报

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()
回复

使用道具 举报

troy

版主

积分
2346
板凳
发表于 2019-2-13 17:18:40 | 只看该作者
chuyee 发表于 2019-2-9 09:36
统计inference()时间的改动如下:

--- test.py        2019-02-08 17:13:51.681182986 -0800

请问是在PC还是板子上运行的?
回复

使用道具 举报

chuyee

中级会员

积分
352
地板
 楼主| 发表于 2019-2-14 01:42:18 | 只看该作者
troy 发表于 2019-2-13 17:18
请问是在PC还是板子上运行的?

TB-RK3399Pro板子上.      
回复

使用道具 举报

程子

中级会员

积分
386
5#
发表于 2019-2-14 16:13:18 | 只看该作者
刚刚在板子上测试了一下,用RKNN的计时。

mobilenet-ssd
Total Time(us): 14725
FPS: 67.91

mobilenet_v1
Total Time(us): 6921
FPS: 144.49

mobilenet_v2
Total Time(us): 8771
FPS: 114.01
回复

使用道具 举报

chuyee

中级会员

积分
352
6#
 楼主| 发表于 2019-2-15 02:29:25 | 只看该作者
程子 发表于 2019-2-14 16:13
刚刚在板子上测试了一下,用RKNN的计时。

mobilenet-ssd

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

使用道具 举报

chuyee

中级会员

积分
352
7#
 楼主| 发表于 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
========================================================================
回复

使用道具 举报

程子

中级会员

积分
386
8#
发表于 2019-2-15 10:46:32 | 只看该作者
我用 rknn.eval_perf() 来评估时间。

你的 datetime.now() 的方法看起来没啥问题,但是结果感觉不太正常。
你用 rknn.eval_perf() 计算的时间应该是正常的,文档里有说开启 perf_debug (打印每一层用时) 之后性能会有所下降,而我没开。
回复

使用道具 举报

chuyee

中级会员

积分
352
9#
 楼主| 发表于 2019-2-15 10:53:46 | 只看该作者
程子 发表于 2019-2-15 10:46
我用 rknn.eval_perf() 来评估时间。

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

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

使用道具 举报

slim

注册会员

积分
82
10#
发表于 2019-2-15 11:20:30 | 只看该作者
chuyee 发表于 2019-2-15 10:53
我也不是说我不相信RKNN统计的结果哈,但mobilenet-ssd半秒一帧基本就是没法用的啊!现在的问题是怎么能 ...

@chuyee I got the same results. About ~0.7s for mobilenet_ssd.  rknn.eval_perf() is the simulator results.

Looks like a bug. I think rknn.inference() function is not using the NPU, its only running on the CPU.
回复

使用道具 举报

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

本版积分规则

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


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