| 34 | |
| 35 | |
| 36 | def parse_option(): |
| 37 | parser = argparse.ArgumentParser('Swin Transformer training and evaluation script', add_help=False) |
| 38 | parser.add_argument('--cfg', type=str, required=True, metavar="FILE", help='path to config file', ) |
| 39 | parser.add_argument( |
| 40 | "--opts", |
| 41 | help="Modify config options by adding 'KEY VALUE' pairs. ", |
| 42 | default=None, |
| 43 | nargs='+', |
| 44 | ) |
| 45 | |
| 46 | # easy config modification |
| 47 | parser.add_argument('--batch-size', type=int, help="batch size for single GPU") |
| 48 | parser.add_argument('--data-path', type=str, help='path to dataset') |
| 49 | parser.add_argument('--zip', action='store_true', help='use zipped dataset instead of folder dataset') |
| 50 | parser.add_argument('--cache-mode', type=str, default='part', choices=['no', 'full', 'part'], |
| 51 | help='no: no cache, ' |
| 52 | 'full: cache all data, ' |
| 53 | 'part: sharding the dataset into nonoverlapping pieces and only cache one piece') |
| 54 | parser.add_argument('--resume', help='resume from checkpoint') |
| 55 | parser.add_argument('--accumulation-steps', type=int, help="gradient accumulation steps") |
| 56 | parser.add_argument('--use-checkpoint', action='store_true', |
| 57 | help="whether to use gradient checkpointing to save memory") |
| 58 | parser.add_argument('--amp-opt-level', type=str, default='O1', choices=['O0', 'O1', 'O2'], |
| 59 | help='mixed precision opt level, if O0, no amp is used') |
| 60 | parser.add_argument('--output', default='output', type=str, metavar='PATH', |
| 61 | help='root of output folder, the full path is <output>/<model_name>/<tag> (default: output)') |
| 62 | parser.add_argument('--tag', help='tag of experiment') |
| 63 | parser.add_argument('--eval', action='store_true', help='Perform evaluation only') |
| 64 | parser.add_argument('--throughput', action='store_true', help='Test throughput only') |
| 65 | |
| 66 | # distributed training |
| 67 | parser.add_argument("--local_rank", type=int, required=True, help='local rank for DistributedDataParallel') |
| 68 | |
| 69 | args, unparsed = parser.parse_known_args() |
| 70 | |
| 71 | config = get_config(args) |
| 72 | |
| 73 | return args, config |
| 74 | |
| 75 | |
| 76 | def main(config): |