det_keypoint_unite_utils.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright (c) 2021 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 ast
  15. import argparse
  16. def argsparser():
  17. parser = argparse.ArgumentParser(description=__doc__)
  18. parser.add_argument(
  19. "--det_model_dir",
  20. type=str,
  21. default=None,
  22. help=("Directory include:'model.pdiparams', 'model.pdmodel', "
  23. "'infer_cfg.yml', created by tools/export_model.py."),
  24. required=True)
  25. parser.add_argument(
  26. "--keypoint_model_dir",
  27. type=str,
  28. default=None,
  29. help=("Directory include:'model.pdiparams', 'model.pdmodel', "
  30. "'infer_cfg.yml', created by tools/export_model.py."),
  31. required=True)
  32. parser.add_argument(
  33. "--image_file", type=str, default=None, help="Path of image file.")
  34. parser.add_argument(
  35. "--image_dir",
  36. type=str,
  37. default=None,
  38. help="Dir of image file, `image_file` has a higher priority.")
  39. parser.add_argument(
  40. "--keypoint_batch_size",
  41. type=int,
  42. default=8,
  43. help=("batch_size for keypoint inference. In detection-keypoint unit"
  44. "inference, the batch size in detection is 1. Then collate det "
  45. "result in batch for keypoint inference."))
  46. parser.add_argument(
  47. "--video_file",
  48. type=str,
  49. default=None,
  50. help="Path of video file, `video_file` or `camera_id` has a highest priority."
  51. )
  52. parser.add_argument(
  53. "--camera_id",
  54. type=int,
  55. default=-1,
  56. help="device id of camera to predict.")
  57. parser.add_argument(
  58. "--det_threshold", type=float, default=0.5, help="Threshold of score.")
  59. parser.add_argument(
  60. "--keypoint_threshold",
  61. type=float,
  62. default=0.5,
  63. help="Threshold of score.")
  64. parser.add_argument(
  65. "--output_dir",
  66. type=str,
  67. default="output",
  68. help="Directory of output visualization files.")
  69. parser.add_argument(
  70. "--run_mode",
  71. type=str,
  72. default='paddle',
  73. help="mode of running(paddle/trt_fp32/trt_fp16/trt_int8)")
  74. parser.add_argument(
  75. "--device",
  76. type=str,
  77. default='cpu',
  78. help="Choose the device you want to run, it can be: CPU/GPU/XPU, default is CPU."
  79. )
  80. parser.add_argument(
  81. "--run_benchmark",
  82. type=ast.literal_eval,
  83. default=False,
  84. help="Whether to predict a image_file repeatedly for benchmark")
  85. parser.add_argument(
  86. "--enable_mkldnn",
  87. type=ast.literal_eval,
  88. default=False,
  89. help="Whether use mkldnn with CPU.")
  90. parser.add_argument(
  91. "--cpu_threads", type=int, default=1, help="Num of threads with CPU.")
  92. parser.add_argument(
  93. "--trt_min_shape", type=int, default=1, help="min_shape for TensorRT.")
  94. parser.add_argument(
  95. "--trt_max_shape",
  96. type=int,
  97. default=1280,
  98. help="max_shape for TensorRT.")
  99. parser.add_argument(
  100. "--trt_opt_shape",
  101. type=int,
  102. default=640,
  103. help="opt_shape for TensorRT.")
  104. parser.add_argument(
  105. "--trt_calib_mode",
  106. type=bool,
  107. default=False,
  108. help="If the model is produced by TRT offline quantitative "
  109. "calibration, trt_calib_mode need to set True.")
  110. parser.add_argument(
  111. '--use_dark',
  112. type=ast.literal_eval,
  113. default=True,
  114. help='whether to use darkpose to get better keypoint position predict ')
  115. parser.add_argument(
  116. '--save_res',
  117. type=bool,
  118. default=False,
  119. help=(
  120. "whether to save predict results to json file"
  121. "1) store_res: a list of image_data"
  122. "2) image_data: [imageid, rects, [keypoints, scores]]"
  123. "3) rects: list of rect [xmin, ymin, xmax, ymax]"
  124. "4) keypoints: 17(joint numbers)*[x, y, conf], total 51 data in list"
  125. "5) scores: mean of all joint conf"))
  126. return parser