|
发表于 2019-2-21 10:42:52
|
显示全部楼层
init_runtime应该在build或load_rknn完成之后调用,参考
- if __name__ == '__main__':
- # Create RKNN object
- rknn = RKNN()
- # Config for Model Input PreProcess
- rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2', batch_size=5)
- # Load TensorFlow Model
- print('--> Loading model')
- rknn.load_tensorflow(tf_pb='./ssd_mobilenet_v1_coco_2017_11_17.pb',
- inputs=['FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/mul_1'],
- outputs=['concat', 'concat_1'],
- input_size_list=[[INPUT_SIZE, INPUT_SIZE, 3]])
- print('done')
- # Build Model
- print('--> Building model')
- rknn.build(do_quantization=True, dataset='./dataset.txt')
- print('done')
- # Export RKNN Model
- rknn.export_rknn('./ssd_mobilenet_v1_coco.rknn')
- # Direct Load RKNN Model
- # rknn.load_rknn('./ssd_mobilenet_v1_coco.rknn')
- # Set inputs
- orig_img = cv2.imread('./road.bmp')
- img = cv2.cvtColor(orig_img, cv2.COLOR_BGR2RGB)
- img = cv2.resize(img, (INPUT_SIZE, INPUT_SIZE), interpolation=cv2.INTER_CUBIC)
- # 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')
- outputs = rknn.inference(inputs=[img])
- print('done')
- print('inference result: ', outputs)
|
|