parser.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import os
  2. from cvargparse import BaseParser, Arg
  3. from cvdatasets.utils import read_info_file
  4. DEFAULT_INFO_FILE=os.environ.get("DATA")
  5. def parse_args():
  6. parser = BaseParser()
  7. data_help = "YAML file containing dataset and model descriptions"
  8. dataset_help = "Dataset to display"
  9. parts_help = "Part annotations to display"
  10. if DEFAULT_INFO_FILE is None:
  11. parser.add_args([
  12. Arg("data", help=data_help),
  13. Arg("dataset", help=dataset_help),
  14. Arg("parts", help=parts_help),
  15. ], group_name="Dataset arguments")
  16. else:
  17. info_file = read_info_file(DEFAULT_INFO_FILE)
  18. parser.add_args([
  19. Arg("data", default=DEFAULT_INFO_FILE,
  20. help=data_help),
  21. Arg("dataset", choices=info_file.DATASETS.keys(),
  22. help=dataset_help),
  23. Arg("parts", choices=info_file.PART_TYPES.keys(),
  24. help=parts_help),
  25. ], group_name="Dataset arguments")
  26. parser.add_args([
  27. Arg("--subset", "-sub",
  28. help="Possible subsets: train, test",
  29. choices=["train", "test"],
  30. default="train", type=str),
  31. Arg("--start", "-s",
  32. help="Image id to start with",
  33. type=int, default=0),
  34. Arg("--n_images", "-n",
  35. help="Number of images to display",
  36. type=int, default=10),
  37. Arg("--only_class",
  38. help="display only the given class",
  39. type=int, default=-1),
  40. ], group_name="Sample selection arguments")
  41. parser.add_args([
  42. Arg("--feature_model", "-fm",
  43. choices=["inception", "inception_tf", "resnet"]),
  44. Arg("--features",
  45. help="pre-extracted train and test features",
  46. default=[None, None],
  47. nargs=2, type=str),
  48. ], group_name="Feature arguments")
  49. parser.add_args([
  50. Arg("--rnd",
  51. help="select random subset of present parts",
  52. action="store_true"),
  53. Arg("--no_bboxes",
  54. help="Do not display bounding boxes",
  55. action="store_true"),
  56. Arg("--no_parts",
  57. help="Do not display parts",
  58. action="store_true"),
  59. Arg("--crop_to_bb",
  60. help="Crop image to the bounding box",
  61. action="store_true"),
  62. Arg("--no_center_crop", action="store_true"),
  63. Arg("--crop_uniform",
  64. help="Try to extend the bounding box to same height and width",
  65. action="store_true"),
  66. Arg("--parts_in_bb",
  67. help="Only display parts, that are inside the bounding box",
  68. action="store_true"),
  69. Arg("--ratio",
  70. help="Part extraction ratio",
  71. type=float, default=.2),
  72. Arg("--rescale_size",
  73. help="rescales the part positions from this size to original image size",
  74. type=int, default=-1),
  75. Arg("--uniform_parts", "-u",
  76. help="Do not use GT parts, but sample parts uniformly from the image",
  77. action="store_true"),
  78. ], group_name="Display options")
  79. parser.add_args([
  80. Arg('--seed', type=int, default=12311123, help='random seed')
  81. ])
  82. return parser.parse_args()