Toybrick
标题: rknn.eval_perf(inputs=[img])模型性能不一致问题 [打印本页]
作者: yuys 时间: 2019-9-25 15:17
标题: rknn.eval_perf(inputs=[img])模型性能不一致问题
TB-RK-3399Pro开发板fedora28安装SDK1.2.0(rknn-toolkit-V1.2.0),目前运行了官网demo中mobilenet_v1发现如下问题:
运行模型的实际推理时间~37.18ms,为何rknn.eval_perf(inputs=[img])接口打印出来是5.827ms(Total Time 5827us)?
运行模型的实际推理时间~45.79ms,为何rknn.eval_perf(inputs=[img])接口打印出来是13.852ms(Total Time 13852us)?
官方SDKrknn-toolkit-v1.2.0\example\mobilenet_v1\test.py如下:
import numpy as np
import cv2
from rknn.api import RKNN
def show_outputs(outputs):
output = outputs[0][0]
output_sorted = sorted(output, reverse=True)
top5_str = 'mobilenet_v1\n-----TOP 5-----\n'
for i in range(5):
value = output_sorted
index = np.where(output == value)
for j in range(len(index)):
if (i + j) >= 5:
break
if value > 0:
topi = '{}: {}\n'.format(index[j], value)
else:
topi = '-1: 0.0\n'
top5_str+= topi
print(top5_str)
def show_perfs(perfs):
perfs = 'perfs:{}\n'.format(outputs)
print(perfs)
if __name__ == '__main__':
#Create RKNN object
importtime
rknn = RKNN()
#pre-process config
T1=time.time()
print('--> config model')
rknn.config(channel_mean_value='103.94 116.78 123.68 58.82', reorder_channel='0 1 2')
T2=time.time()
print("config model time:%.2fms"%((T2-T1)*1000))
print('done')
#Load tensorflow model
print('--> Loading model')
ret = rknn.load_tflite(model='./mobilenet_v1.tflite')
if ret != 0:
print('Load mobilenet_v1 failed!')
exit(ret)
T3 = time.time()
print("Loading model time:%.2fms"%((T3-T2)*1000))
print('done')
#Build model
print('--> Building model')
ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
if ret != 0:
print('Build mobilenet_v1 failed!')
exit(ret)
T4 = time.time()
print("Building model time:%.2fms"%((T4-T3)*1000))
print('done')
#Export rknn model
print('--> Export RKNN model')
ret = rknn.export_rknn('./mobilenet_v1.rknn')
if ret != 0:
print('Export mobilenet_v1.rknn failed!')
exit(ret)
T5=time.time()
print("Export RKNN model time:%.2fms"%((T5-T4)*1000))
print('done')
#Set inputs
img= cv2.imread('./dog_224x224.jpg')
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
T6 = time.time()
print("Set inputs time:%.2fms"%((T6-T5)*1000))
#init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
T7 = time.time()
print("Init runtime environment time:%.2fms"%((T7-T6)*1000))
print('done')
#Inference
print('--> Running model')
outputs = rknn.inference(inputs=[img])
show_outputs(outputs)
T8 = time.time()
print("Inference time:%.2fms"%((T8-T7)*1000))
print('done')
#perf
print('--> Begin evaluate modelperformance')
perf_results = rknn.eval_perf(inputs=[img])
print('done')
T9=time.time()
print("perf time:%.2fms"%((T9-T8)*1000))
rknn.release()
作者: troy 时间: 2019-9-25 16:49
再次重申eval_perf打印的是在NPU端的执行时间,不包括数据的交互和传输时间。
作者: zehao 时间: 2021-3-10 14:54
请问eval_perf执行的时候是调用的/tmp/下面的哪个文件实现的内容打印。因为没有找到哪个c文件会打印出来相应的执行时间的语句
欢迎光临 Toybrick (https://t.rock-chips.com/) |
Powered by Discuz! X3.3 |