demo.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  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", "-i", type=str, default=None, help="path to an image files")
  35. parser.add_argument(
  36. "--img_list", "-l", type=str, default=None, help="Path to a imglist")
  37. parser.add_argument(
  38. "--cfg_file",
  39. "-c",
  40. type=str,
  41. default=None,
  42. help="Path to PaddelX model yml file")
  43. return parser
  44. def main():
  45. parser = arg_parser()
  46. args = parser.parse_args()
  47. model_xml = args.model_dir
  48. model_yaml = args.cfg_file
  49. #model init
  50. if ("CPU" not in args.device):
  51. predictor = deploy.Predictor(model_xml, model_yaml, args.device)
  52. else:
  53. predictor = deploy.Predictor(model_xml, model_yaml)
  54. #predict
  55. if (args.img_list != None):
  56. f = open(args.img_list)
  57. lines = f.readlines()
  58. for im_path in lines:
  59. print(im_path)
  60. predictor.predict(im_path.strip('\n'))
  61. f.close()
  62. else:
  63. im_path = args.img
  64. predictor.predict(im_path)
  65. if __name__ == "__main__":
  66. main()