demo.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. "--img", "-i", type=str, default=None, help="path to an image files")
  28. parser.add_argument(
  29. "--img_list", "-l", type=str, default=None, help="Path to a imglist")
  30. parser.add_argument(
  31. "--cfg_file",
  32. "-c",
  33. type=str,
  34. default=None,
  35. help="Path to PaddelX model yml file")
  36. parser.add_argument(
  37. "--thread_num",
  38. "-t",
  39. type=int,
  40. default=1,
  41. help="Path to PaddelX model yml file")
  42. return parser
  43. def main():
  44. parser = arg_parser()
  45. args = parser.parse_args()
  46. model_nb = args.model_dir
  47. model_yaml = args.cfg_file
  48. thread_num = args.thread_num
  49. #model init
  50. predictor = deploy.Predictor(model_nb, model_yaml, thread_num)
  51. #predict
  52. if (args.img_list != None):
  53. f = open(args.img_list)
  54. lines = f.readlines()
  55. for im_path in lines:
  56. print(im_path)
  57. predictor.predict(im_path.strip('\n'))
  58. f.close()
  59. else:
  60. im_path = args.img
  61. predictor.predict(im_path)
  62. if __name__ == "__main__":
  63. main()