Toybrick

标题: rknn.inference执行问题 [打印本页]

作者: BlackBoy_Xuan    时间: 2019-6-3 14:53
标题: rknn.inference执行问题
TF转完rknn模型之后,执行rknn模型,但在卡在执行rknn.inference处,过了30min仍没有执行完,具体是什么问题造成的呢?
[attach]324[/attach]

作者: BlackBoy_Xuan    时间: 2019-6-4 10:05
补充

模型转换
  1. # To use Inference Engine backend, specify location of plugins:
  2. # export LD_LIBRARY_PATH=/opt/intel/deeplearning_deploymenttoolkit/deployment_tools/external/mklml_lnx/lib:$LD_LIBRARY_PATH

  3. import cv2 as cv
  4. import numpy as np
  5. import argparse
  6. import compileall
  7. import time
  8. import datetime
  9. from PIL import        Image
  10. from rknn.api import RKNN
  11. compileall.compile_dir(r'./')


  12. #inWidth = args.width
  13. #inHeight = args.height

  14. # Create RKNN object
  15. rknn = RKNN()

  16. # Config for Model Input PreProcess
  17. rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2')
  18. #rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')


  19. #Robert Lee
  20. print('--> Loading model')

  21. ret = rknn.load_tflite(model='./graph_opt.tflite')
  22. if ret != 0:
  23.     print('Load failed!')
  24.     exit(ret)


  25. print('done')


  26. # Build Model
  27. print('--> Building model')
  28. rknn.build(do_quantization=True,dataset='./dataset.txt')
  29. print('done')

  30. # Export RKNN Model
  31. rknn.export_rknn('./graph_opt_test.rknn')

  32. rknn.release()

  33. exit(0)


复制代码



模型推理
  1. # To use Inference Engine backend, specify location of plugins:
  2. # export LD_LIBRARY_PATH=/opt/intel/deeplearning_deploymenttoolkit/deployment_tools/external/mklml_lnx/lib:$LD_LIBRARY_PATH

  3. import cv2 as cv
  4. import numpy as np
  5. import argparse
  6. import compileall
  7. import time
  8. from rknn.api import RKNN
  9. import pickle
  10. compileall.compile_dir(r'./')

  11. parser = argparse.ArgumentParser()
  12. parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
  13. parser.add_argument('--thr', default=0.2, type=float, help='Threshold value for pose parts heat map')
  14. parser.add_argument('--width', default=368, type=int, help='Resize input to specific width.')
  15. parser.add_argument('--height', default=368, type=int, help='Resize input to specific height.')

  16. args = parser.parse_args()

  17. BODY_PARTS = { "Nose": 0, "Neck": 1, "RShoulder": 2, "RElbow": 3, "RWrist": 4,
  18.                "LShoulder": 5, "LElbow": 6, "LWrist": 7, "RHip": 8, "RKnee": 9,
  19.                "RAnkle": 10, "LHip": 11, "LKnee": 12, "LAnkle": 13, "REye": 14,
  20.                "LEye": 15, "REar": 16, "LEar": 17, "Background": 18 }

  21. POSE_PAIRS = [ ["Neck", "RShoulder"], ["Neck", "LShoulder"], ["RShoulder", "RElbow"],
  22.                ["RElbow", "RWrist"], ["LShoulder", "LElbow"], ["LElbow", "LWrist"],
  23.                ["Neck", "RHip"], ["RHip", "RKnee"], ["RKnee", "RAnkle"], ["Neck", "LHip"],
  24.                ["LHip", "LKnee"], ["LKnee", "LAnkle"], ["Neck", "Nose"], ["Nose", "REye"],
  25.                ["REye", "REar"], ["Nose", "LEye"], ["LEye", "LEar"] ]

  26. inWidth = args.width
  27. inHeight = args.height
  28. starttime = time.time()
  29. #=====================================================================================
  30. # Create RKNN object
  31. rknn = RKNN()
  32. # Config for Model Input PreProcess
  33. rknn.config(channel_mean_value='128 128 128 128', reorder_channel='0 1 2')
  34. #rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
  35. #=====================================================================================
  36. ret = rknn.load_rknn(path='./graph_opt_test.rknn')
  37. #net = cv.dnn.readNetFromTensorflow("graph_opt.pb")

  38. print('--> Init runtime environment')
  39. ret = rknn.init_runtime()
  40. if ret != 0:
  41.      print('Init runtime environment failed')
  42.      exit(ret)
  43. print('done')
  44. #=====================================================================================
  45. frame = cv.imread('./apink1_crop.jpg')

  46. vid_writer = None
  47. print("[INFO] iamge processed, elapsed time: %f" % (time.time() - starttime))       

  48. frameWidth = frame.shape[1]
  49. frameHeight = frame.shape[0]   


  50. 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')

  51. print("[INFO] one frame processed, elapsed time: %f" % (time.time() - starttime))
  52. #out = out[:, :19, :, :]  # MobileNet output [1, 57, -1, -1], we only need the first 19 elements
  53. out1 = outlist[0]
  54. out = out1.reshape(1,57,46,46)
  55. out = out[:, :19, :, :]
  56. data = out
  57. print(data.shape)
  58. print(type(data))
  59. #=====================================================================================
  60. print("[INFO] one frame processed, elapsed time: %f" % (time.time() - starttime))       

  61. fw = open('dataFiletest1.txt','wb')
  62. pickle.dump(outlist[0],fw)
  63. fw.close

复制代码

作者: troy    时间: 2019-6-11 19:33
BlackBoy_Xuan 发表于 2019-6-4 10:05
补充

模型转换

rknn版本已经是1.0.0了吗
作者: BlackBoy_Xuan    时间: 2019-6-12 09:54
是的,rknn版本已经更新至最新的了。




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3