Toybrick

标题: 在pc上使用rknn-toolkit 1.3.2 调用rknn.inference(inputs=[img])需要5分钟 [打印本页]

作者: 一袋米要扛几楼    时间: 2020-6-19 14:33
标题: 在pc上使用rknn-toolkit 1.3.2 调用rknn.inference(inputs=[img])需要5分钟
root@843ead96d6af:/shares/PyTorch-YOLOv3-train# python rknn_yolo.py
--> config model
done
--> Loading model
/usr/local/lib/python3.5/dist-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
./yoloV3.pt ********************
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
done
--> Building model
W The target_platform is not set in config, using default target platform rk1808.
done
--> Export RKNN model
done
--> Init runtime environment
W [set_chip_platform_env:187]evaluate model on RK1808
done
--> Running model
W [rknn_inputs_set:1288] warning: inputs[0] expected input len is 602112, but actual len is 502500!
done
--> Begin evaluate model performance
W When performing performance evaluation, inputs can be set to None to use fake inputs.
W [set_chip_platform_env:187]evaluate model on RK1808
W [set_chip_platform_env:187]evaluate model on RK1808

在开始评估之后,需要大约5分钟才有结果。

作者: 一袋米要扛几楼    时间: 2020-6-19 14:35
  1.     model = Darknet(opt.model_def, img_size=opt.img_size)
  2.     model.load_state_dict(torch.load("./checkpoints/custom_yolov3_ckpt_900.pth", map_location=torch.device('cpu')))
  3.     model.eval()
  4.     trace_model = torch.jit.trace(model, torch.Tensor(1,3,448,448))
  5.     trace_model.save('./yoloV3.pt')
  6.     np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
  7.     model_path = './yoloV3.pt'
  8.     input_size_list = [[3, 448, 448]]

  9.     # Create RKNN object
  10.     rknn = RKNN()
  11.     print('--> config model')
  12.     rknn.config(channel_mean_value='0. 0. 0. 255.', reorder_channel='0 1 2')
  13.     print('done')

  14.     # Load pytorch model
  15.     print('--> Loading model')
  16.     ret = rknn.load_pytorch(model=model_path, input_size_list=input_size_list)
  17.     if ret != 0:
  18.         print('Load pytorch model failed!')
  19.         exit(ret)
  20.     print('done')

  21.     # Build model
  22.     print('--> Building model')
  23.     # 不量化,结果基本一致
  24.     ret = rknn.build(do_quantization=False, dataset='./valid.txt')
  25.     if ret != 0:
  26.         print('Build pytorch failed!')
  27.         exit(ret)
  28.     print('done')

  29.     # Export rknn model
  30.     print('--> Export RKNN model')
  31.     ret = rknn.export_rknn('./yoloV3.rknn')
  32.     if ret != 0:
  33.         print('Export yoloV3.rknn failed!')
  34.         exit(ret)
  35.     print('done')

  36.     ret = rknn.load_rknn('./yoloV3.rknn')

  37.     # Set inputs
  38.     img = cv2.imread('./data/custom/images/train.jpg')
  39.     img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  40.     # 归一化
  41.     img = np.array(img, dtype=np.float32)
  42.     img = np.array((img-img.min()) / img.ptp())
  43.     # print("img: ", img)

  44.     # init runtime environment
  45.     print('--> Init runtime environment')
  46.     ret = rknn.init_runtime()
  47.     if ret != 0:
  48.         print('Init runtime environment failed')
  49.         exit(ret)
  50.     print('done')

  51.     # Inference
  52.     print('--> Running model')
  53.     outputs = rknn.inference(inputs=[img])
  54.     print('done')

  55.     # # perf
  56.     print('--> Begin evaluate model performance')
  57.     perf_results = rknn.eval_perf(inputs=[img])
  58.     print('done')
  59.     rknn.release()
复制代码

作者: jefferyzhang    时间: 2020-6-19 23:28
1. 先保证drv和api是匹配的,否则运行不出结果,5分钟可能是错误超时时间。
2. 需要量化后再来看,不量化的时间是没意义的。
3. yolov3看我们教学贴都有,自己对比下和我们有什么区别。




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