| 18 | |
| 19 | |
| 20 | def parse_args(): |
| 21 | parser = argparse.ArgumentParser(description='Train a model') |
| 22 | parser.add_argument('config', help='train config file path') |
| 23 | parser.add_argument('--work-dir', help='the dir to save logs and models') |
| 24 | parser.add_argument( |
| 25 | '--resume-from', help='the checkpoint file to resume from') |
| 26 | parser.add_argument( |
| 27 | '--no-validate', |
| 28 | action='store_true', |
| 29 | help='whether not to evaluate the checkpoint during training') |
| 30 | group_gpus = parser.add_mutually_exclusive_group() |
| 31 | group_gpus.add_argument('--device', help='device used for training') |
| 32 | group_gpus.add_argument( |
| 33 | '--gpus', |
| 34 | type=int, |
| 35 | help='number of gpus to use ' |
| 36 | '(only applicable to non-distributed training)') |
| 37 | group_gpus.add_argument( |
| 38 | '--gpu-ids', |
| 39 | type=int, |
| 40 | nargs='+', |
| 41 | help='ids of gpus to use ' |
| 42 | '(only applicable to non-distributed training)') |
| 43 | parser.add_argument('--seed', type=int, default=None, help='random seed') |
| 44 | parser.add_argument( |
| 45 | '--deterministic', |
| 46 | action='store_true', |
| 47 | help='whether to set deterministic options for CUDNN backend.') |
| 48 | parser.add_argument( |
| 49 | '--options', nargs='+', action=DictAction, help='arguments in dict') |
| 50 | parser.add_argument( |
| 51 | '--launcher', |
| 52 | choices=['none', 'pytorch', 'slurm', 'mpi'], |
| 53 | default='none', |
| 54 | help='job launcher') |
| 55 | parser.add_argument('--local_rank', type=int, default=0) |
| 56 | args = parser.parse_args() |
| 57 | if 'LOCAL_RANK' not in os.environ: |
| 58 | os.environ['LOCAL_RANK'] = str(args.local_rank) |
| 59 | |
| 60 | return args |
| 61 | |
| 62 | |
| 63 | def main(): |