|
从rknn-toolkit1.3.0的user guide上面看到,使用python api在build rknn模型的时候多了一个rknn_batch_size的参数,意味着可以进行batch inference了。
但是我今天测试的时候,发现了一个问题,以下是描述:
希望版主能改帮忙查找一下问题
rknn-toolkit: 1.3.0
rknn驱动:1.3.0
模型:tensorflow的pb模型,模型输入[160,160,3],模型输出应该是(128,)的结果
问题:单张图的推理时间为0.014s,rknn_batch_size=2时推理时间为0.03s,但是rknn_batch_size=2时的输出结果仍是一张图的结果,不知道从Inference到取得结果的过程中,是否存在一些问题
测试代码:
if __name__ == '__main__':
# Create RKNN object
rknn = RKNN()
# Config for Model Input PreProcess
rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
#rknn.config(channel_mean_value='127.5 127.5 127.5 127.5', reorder_channel='0 1 2', quantized_dtype='asymmetric_quantized-u8')
# Load TensorFlow Model
print('--> Loading model')
rknn.load_tensorflow(tf_pb='./model.pb',
inputs=['input_1'],
outputs=['strided_slice'],
input_size_list=[[160, 160, 3]])
print('done')
# Build Model
print('--> Building model')
rknn.build(do_quantization=True, dataset='./dataset_416x416.txt', pre_compile=True, rknn_batch_size=2)
print('done')
# Export RKNN Model
rknn.export_rknn('./model_1.3_pre_2.rknn')
# Direct Load RKNN Model
rknn.load_rknn('./model_1.3_pre_2.rknn')
# Set inputs
orig_img1 = cv2.imread('./pic1.jpg')
img1 = cv2.cvtColor(orig_img1, cv2.COLOR_BGR2RGB)
img1 = cv2.resize(img1, (160, 160), interpolation=cv2.INTER_CUBIC)
orig_img2 = cv2.imread('./pic2.jpg')
img2 = cv2.cvtColor(orig_img2, cv2.COLOR_BGR2RGB)
img2 = cv2.resize(img2, (160, 160), interpolation=cv2.INTER_CUBIC)
# init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime(target='rk1808', device_id='TS018082190800200')
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# Inference
print('--> Running model')
s = time.time()
mat = np.array([img1, img2])
outputs = rknn.inference(inputs=[mat])
e= time.time()
print('time:', e-s)
print('done')
print(len(outputs))
print(outputs)
print(outputs[0].shape)
# Release RKNN Context
rknn.release()
|
|