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)
# 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')