demo.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import sys
  15. import os
  16. import argparse
  17. import deploy
  18. def arg_parser():
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument(
  21. "--model_dir",
  22. "-m",
  23. type=str,
  24. default=None,
  25. help="path to openvino model .xml file")
  26. parser.add_argument(
  27. "--device",
  28. "-d",
  29. type=str,
  30. default='CPU',
  31. help="Specify the target device to infer on:[CPU, GPU, FPGA, HDDL, MYRIAD,HETERO]"
  32. "Default value is CPU")
  33. parser.add_argument(
  34. "--img",
  35. "-i",
  36. type=str,
  37. default=None,
  38. help="path to an image files")
  39. parser.add_argument(
  40. "--img_list",
  41. "-l",
  42. type=str,
  43. default=None,
  44. help="Path to a imglist")
  45. parser.add_argument(
  46. "--cfg_dir",
  47. "-c",
  48. type=str,
  49. default=None,
  50. help="Path to PaddelX model yml file")
  51. return parser
  52. def main():
  53. parser = arg_parser()
  54. args = parser.parse_args()
  55. model_xml = args.model_dir
  56. model_yaml = args.cfg_dir
  57. #model init
  58. if("CPU" not in args.device):
  59. predictor = deploy.Predictor(model_xml,model_yaml,args.device)
  60. else:
  61. predictor = deploy.Predictor(model_xml,model_yaml)
  62. #predict
  63. if(args.img_list != None):
  64. f = open(args.img_list)
  65. lines = f.readlines()
  66. for im_path in lines:
  67. print(im_path)
  68. predictor.predict(im_path.strip('\n'))
  69. f.close()
  70. else:
  71. im_path = args.img
  72. predictor.predict(im_path)
  73. if __name__ == "__main__":
  74. main()