| 27 | |
| 28 | |
| 29 | def parse_args(): |
| 30 | parser = argparse.ArgumentParser(description='Train a detector') |
| 31 | parser.add_argument('config', help='train config file path') |
| 32 | parser.add_argument('--work-dir', help='the dir to save logs and models') |
| 33 | parser.add_argument( |
| 34 | '--resume-from', help='the checkpoint file to resume from') |
| 35 | parser.add_argument( |
| 36 | '--no-validate', |
| 37 | action='store_true', |
| 38 | help='whether not to evaluate the checkpoint during training') |
| 39 | group_gpus = parser.add_mutually_exclusive_group() |
| 40 | group_gpus.add_argument( |
| 41 | '--gpus', |
| 42 | type=int, |
| 43 | help='number of gpus to use ' |
| 44 | '(only applicable to non-distributed training)') |
| 45 | group_gpus.add_argument( |
| 46 | '--gpu-ids', |
| 47 | type=int, |
| 48 | nargs='+', |
| 49 | help='ids of gpus to use ' |
| 50 | '(only applicable to non-distributed training)') |
| 51 | parser.add_argument('--seed', type=int, default=None, help='random seed') |
| 52 | parser.add_argument( |
| 53 | '--deterministic', |
| 54 | action='store_true', |
| 55 | help='whether to set deterministic options for CUDNN backend.') |
| 56 | parser.add_argument( |
| 57 | '--options', |
| 58 | nargs='+', |
| 59 | action=DictAction, |
| 60 | help='override some settings in the used config, the key-value pair ' |
| 61 | 'in xxx=yyy format will be merged into config file (deprecate), ' |
| 62 | 'change to --cfg-options instead.') |
| 63 | parser.add_argument( |
| 64 | '--cfg-options', |
| 65 | nargs='+', |
| 66 | action=DictAction, |
| 67 | help='override some settings in the used config, the key-value pair ' |
| 68 | 'in xxx=yyy format will be merged into config file. If the value to ' |
| 69 | 'be overwritten is a list, it should be like key="[a,b]" or key=a,b ' |
| 70 | 'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" ' |
| 71 | 'Note that the quotation marks are necessary and that no white space ' |
| 72 | 'is allowed.') |
| 73 | parser.add_argument( |
| 74 | '--launcher', |
| 75 | choices=['none', 'pytorch', 'slurm', 'mpi'], |
| 76 | default='none', |
| 77 | help='job launcher') |
| 78 | parser.add_argument('--local_rank', type=int, default=0) |
| 79 | args = parser.parse_args() |
| 80 | if 'LOCAL_RANK' not in os.environ: |
| 81 | os.environ['LOCAL_RANK'] = str(args.local_rank) |
| 82 | |
| 83 | if args.options and args.cfg_options: |
| 84 | raise ValueError( |
| 85 | '--options and --cfg-options cannot be both ' |
| 86 | 'specified, --options is deprecated in favor of --cfg-options') |