parser.py 2.7 KB

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