推理:
# -*- coding: utf-8 -*- ''' inference the rknn model and get output ''' import numpy as np
import cv2
import os
from rknn.api import RKNN
import time
# 解析模型的输出,获得概率最大的手势和对应的概率
def get_predict(probability):
data = probability[0][0]
data = data.tolist()
max_prob = max(data)
return data.index(max_prob), max_prob, data
def load_model():
# 创建RKNN对象
rknn = RKNN(verbose=False)
# 载入RKNN模型
print('-->loading model')
rknn.load_rknn('./model/resnet_classify_batchsize256.rknn')
print('loading model done')
# 初始化RKNN运行环境
print('--> Init runtime environment')
# todo:suport 'rk3399pro','rk1808'; default is NoneC ret = rknn.init_runtime(target=None, perf_debug=False)
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
return rknn
def predict(rknn, img_dir):
for file in os.listdir(img_dir):
if not file.endswith('.jpg'):
continue
img_file = os.path.join(img_dir, file)
print(img_file)
img = cv2.imread(img_file)
imput_image = img_preprocess(img, 112, 112)
begin = time.time()
outputs = rknn.inference(inputs=[imput_image]) # 运行推理,得到推理结果
end = time.time()
print('it costs %0.3fms' % ((end - begin) * 1000))
pred, prob, output_list = get_predict(outputs) # 将推理结果转化为可视信息
print('result:%s' % pred)
# print('max_val:', prob)
print('output_list', output_list)
print('---------------------------')
if __name__ == "__main__":
rknn = load_model()
predict(rknn, img_dir='/home/DATA/')
rknn.release()
想知道问题出在了哪
作者: zxs 时间: 2019-10-12 16:12
模型转换时提示warning:
--> Loading model
W Unhandle status: the input shape of reshape layer Flatten_46_3 is not 4-D
done
--> Building model
W Unhandle status: the input shape of reshape layer Flatten_46_3 is not 4-D
done