- 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 = 'face_det_new\n-----TOP 5-----\n'
- for i in range(5):
- value = output_sorted[i]
- 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)
- 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='2 1 0')
- print('done')
- # Load tensorflow model
- print('--> Loading model')
- ret = rknn.load_caffe(model='./face_det_new.prototxt',
- proto='caffe',
- blobs='./face_det_new.caffemodel')
- if ret != 0:
- print('Load face_det_new failed! Ret = {}'.format(ret))
- exit(ret)
- print('done')
- # Build model
- print('--> Building model')
- ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
- if ret != 0:
- print('Build face_det_new failed!')
- exit(ret)
- print('done')
- # Export rknn model
- print('--> Export RKNN model')
- ret = rknn.export_rknn('./face_det_new.rknn')
- if ret != 0:
- print('Export face_det_new.rknn failed!')
- exit(ret)
- print('done')
- # Set inputs
- img = cv2.imread('./cat_224x224.jpg')
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- print('--> Init runtime environment')
- ret = rknn.init_runtime()
- if ret != 0:
- print('Init runtime environment failed')
- exit(ret)
- print('done')
- # Inference
- print('--> Running model')
- outputs = rknn.inference(inputs=[img])
- show_outputs(outputs)
- print('done')
- # perf
- print('--> Begin evaluate model performance')
- perf_results = rknn.eval_perf(inputs=[img])
- print('done')
- rknn.release()
复制代码
elooon 发表于 2019-3-12 15:43
interesting.
The exception below seems that somthing is wrong in inputs data
T Exception: Set inputs ...
欢迎光临 Toybrick (https://t.rock-chips.com/) | Powered by Discuz! X3.3 |