|
地板
楼主 |
发表于 2019-6-12 10:03:29
|
只看该作者
因为转换程序都是直接用mobilenet_v1,其中只是修改为自己的输入模块和推理输出的数据保存位置,其余没有修改。
按照你的建议要确认【转换模型,模型推理的输入,量化方式】,具体要修改对应函数的哪些输入参数呢?
====================== 转换代码如下 =======================
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
rknn = RKNN()
# pre-process config
print('--> config model')
##rknn.config(channel_mean_value='103.94 116.78 123.68 58.82', reorder_channel='0 1 2')
rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2')
print('done')
# Load tensorflow model
print('--> Loading model')
ret = rknn.load_tflite(model='./graph_opt.tflite')
if ret != 0:
print('Load graph_opt failed!')
exit(ret)
print('done')
# Build model
print('--> Building model')
ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
if ret != 0:
print('Build graph_opt failed!')
exit(ret)
print('done')
# Export rknn model
print('--> Export RKNN model')
ret = rknn.export_rknn('./graph_opt.rknn')
if ret != 0:
print('Export graph_opt.rknn failed!')
exit(ret)
print('done')
# Set inputs
img = cv2.imread('./apink1_crop.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# Inference
print('--> Running model')
outlist = rknn.inference(inputs=[img])
print(outlist[0])
fw = open('dataFiletest1.txt','wb')
pickle.dump(outlist[0], fw)
fw.close()
#show_outputs(outputs)
#print('done')
# perf
print('--> Begin evaluate model performance')
perf_results = rknn.eval_perf(inputs=[img])
print('done')
rknn.release() |
|