|
楼主 |
发表于 2019-6-4 10:05:33
|
显示全部楼层
补充
模型转换
- # To use Inference Engine backend, specify location of plugins:
- # export LD_LIBRARY_PATH=/opt/intel/deeplearning_deploymenttoolkit/deployment_tools/external/mklml_lnx/lib:$LD_LIBRARY_PATH
- import cv2 as cv
- import numpy as np
- import argparse
- import compileall
- import time
- import datetime
- from PIL import Image
- from rknn.api import RKNN
- compileall.compile_dir(r'./')
- #inWidth = args.width
- #inHeight = args.height
- # Create RKNN object
- rknn = RKNN()
- # Config for Model Input PreProcess
- rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2')
- #rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
- #Robert Lee
- print('--> Loading model')
- ret = rknn.load_tflite(model='./graph_opt.tflite')
- if ret != 0:
- print('Load failed!')
- exit(ret)
- print('done')
- # Build Model
- print('--> Building model')
- rknn.build(do_quantization=True,dataset='./dataset.txt')
- print('done')
- # Export RKNN Model
- rknn.export_rknn('./graph_opt_test.rknn')
- rknn.release()
- exit(0)
模型推理
- # To use Inference Engine backend, specify location of plugins:
- # export LD_LIBRARY_PATH=/opt/intel/deeplearning_deploymenttoolkit/deployment_tools/external/mklml_lnx/lib:$LD_LIBRARY_PATH
- import cv2 as cv
- import numpy as np
- import argparse
- import compileall
- import time
- from rknn.api import RKNN
- import pickle
- compileall.compile_dir(r'./')
- parser = argparse.ArgumentParser()
- parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
- parser.add_argument('--thr', default=0.2, type=float, help='Threshold value for pose parts heat map')
- parser.add_argument('--width', default=368, type=int, help='Resize input to specific width.')
- parser.add_argument('--height', default=368, type=int, help='Resize input to specific height.')
- args = parser.parse_args()
- BODY_PARTS = { "Nose": 0, "Neck": 1, "RShoulder": 2, "RElbow": 3, "RWrist": 4,
- "LShoulder": 5, "LElbow": 6, "LWrist": 7, "RHip": 8, "RKnee": 9,
- "RAnkle": 10, "LHip": 11, "LKnee": 12, "LAnkle": 13, "REye": 14,
- "LEye": 15, "REar": 16, "LEar": 17, "Background": 18 }
- POSE_PAIRS = [ ["Neck", "RShoulder"], ["Neck", "LShoulder"], ["RShoulder", "RElbow"],
- ["RElbow", "RWrist"], ["LShoulder", "LElbow"], ["LElbow", "LWrist"],
- ["Neck", "RHip"], ["RHip", "RKnee"], ["RKnee", "RAnkle"], ["Neck", "LHip"],
- ["LHip", "LKnee"], ["LKnee", "LAnkle"], ["Neck", "Nose"], ["Nose", "REye"],
- ["REye", "REar"], ["Nose", "LEye"], ["LEye", "LEar"] ]
- inWidth = args.width
- inHeight = args.height
- starttime = time.time()
- #=====================================================================================
- # Create RKNN object
- rknn = RKNN()
- # Config for Model Input PreProcess
- rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2')
- #rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
- #=====================================================================================
- ret = rknn.load_rknn(path='./graph_opt_test.rknn')
- #net = cv.dnn.readNetFromTensorflow("graph_opt.pb")
- print('--> Init runtime environment')
- ret = rknn.init_runtime()
- if ret != 0:
- print('Init runtime environment failed')
- exit(ret)
- print('done')
- #=====================================================================================
- frame = cv.imread('./apink1_crop.jpg')
- vid_writer = None
- print("[INFO] iamge processed, elapsed time: %f" % (time.time() - starttime))
- frameWidth = frame.shape[1]
- frameHeight = frame.shape[0]
- outlist = rknn.inference(inputs=[cv.dnn.blobFromImage(frame, 1.0, (inWidth, inHeight), (127.5, 127.5, 127.5), swapRB=True, crop=False)],data_type='float')
- print("[INFO] one frame processed, elapsed time: %f" % (time.time() - starttime))
- #out = out[:, :19, :, :] # MobileNet output [1, 57, -1, -1], we only need the first 19 elements
- out1 = outlist[0]
- out = out1.reshape(1,57,46,46)
- out = out[:, :19, :, :]
- data = out
- print(data.shape)
- print(type(data))
- #=====================================================================================
- print("[INFO] one frame processed, elapsed time: %f" % (time.time() - starttime))
- fw = open('dataFiletest1.txt','wb')
- pickle.dump(outlist[0],fw)
- fw.close
|
|