Toybrick

rknn.inference执行问题

BlackBoy_Xuan

注册会员

积分
108
楼主
发表于 2019-6-3 14:53:58    查看: 8173|回复: 3 | [复制链接]    打印 | 只看该作者
TF转完rknn模型之后,执行rknn模型,但在卡在执行rknn.inference处,过了30min仍没有执行完,具体是什么问题造成的呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

BlackBoy_Xuan

注册会员

积分
108
沙发
 楼主| 发表于 2019-6-4 10:05:33 | 只看该作者
补充

模型转换
  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

版主

积分
2386
板凳
发表于 2019-6-11 19:33:00 | 只看该作者

rknn版本已经是1.0.0了吗
回复

使用道具 举报

BlackBoy_Xuan

注册会员

积分
108
地板
 楼主| 发表于 2019-6-12 09:54:59 | 只看该作者
是的,rknn版本已经更新至最新的了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表