parser.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import os
  2. from chainer_addons.training import OptimizerType
  3. from chainer_addons.models import PrepareType
  4. from cvargparse import Arg, ArgFactory
  5. from cvdatasets.utils import read_info_file
  6. DEFAULT_INFO_FILE=os.environ.get("DATA", "/home/korsch/Data/info.yml")
  7. info_file = read_info_file(DEFAULT_INFO_FILE)
  8. def default_factory(extra_list=[]):
  9. return ArgFactory(extra_list + [
  10. Arg("data", default=DEFAULT_INFO_FILE),
  11. Arg("dataset", choices=info_file.DATASETS.keys()),
  12. Arg("parts", choices=info_file.PARTS.keys()),
  13. Arg("--model_type", "-mt",
  14. default="resnet", choices=info_file.MODELS.keys(),
  15. help="type of the model"),
  16. Arg("--input_size", type=int, nargs="+", default=0,
  17. help="overrides default input size of the model, if greater than 0"),
  18. PrepareType.as_arg("prepare_type",
  19. help_text="type of image preprocessing"),
  20. Arg("--load", type=str, help="ignore weights and load already fine-tuned model"),
  21. Arg("--n_jobs", "-j", type=int, default=0,
  22. help="number of loading processes. If 0, then images are loaded in the same process"),
  23. Arg("--warm_up", type=int, help="warm up epochs"),
  24. OptimizerType.as_arg("optimizer", "opt",
  25. help_text="type of the optimizer"),
  26. Arg("--cosine_schedule", action="store_true",
  27. help="enable cosine annealing LR schedule"),
  28. Arg("--l1_loss", action="store_true",
  29. help="(only with \"--only_head\" option!) use L1 Hinge Loss instead of Softmax Cross-Entropy"),
  30. Arg("--from_scratch", action="store_true",
  31. help="Do not load any weights. Train the model from scratch"),
  32. Arg("--label_shift", type=int, default=1,
  33. help="label shift"),
  34. Arg("--swap_channels", action="store_true",
  35. help="preprocessing option: swap channels from RGB to BGR"),
  36. Arg("--label_smoothing", type=float, default=0,
  37. help="Factor for label smoothing"),
  38. Arg("--no_center_crop_on_val", action="store_true",
  39. help="do not center crop imaages in the validation step!"),
  40. Arg("--only_head", action="store_true", help="fine-tune only last layer"),
  41. Arg("--no_progress", action="store_true", help="dont show progress bar"),
  42. Arg("--augment", action="store_true", help="do data augmentation (random croping and random hor. flipping)"),
  43. Arg("--force_load", action="store_true", help="force loading from caffe model"),
  44. Arg("--only_eval", action="store_true", help="evaluate the model only. do not train!"),
  45. Arg("--init_eval", action="store_true", help="evaluate the model before training"),
  46. Arg("--no_snapshot", action="store_true", help="do not save trained model"),
  47. Arg("--output", "-o", type=str, default=".out", help="output folder"),
  48. ])\
  49. .seed()\
  50. .batch_size()\
  51. .epochs()\
  52. .debug()\
  53. .learning_rate(lr=1e-2, lrs=10, lrt=1e-5, lrd=1e-1)\
  54. .weight_decay(default=5e-4)