Create a parser with some common arguments used by detectron2 users. Args: epilog (str): epilog passed to ArgumentParser describing the usage. Returns: argparse.ArgumentParser:
(epilog=None)
| 47 | |
| 48 | |
| 49 | def default_argument_parser(epilog=None): |
| 50 | """ |
| 51 | Create a parser with some common arguments used by detectron2 users. |
| 52 | |
| 53 | Args: |
| 54 | epilog (str): epilog passed to ArgumentParser describing the usage. |
| 55 | |
| 56 | Returns: |
| 57 | argparse.ArgumentParser: |
| 58 | """ |
| 59 | parser = argparse.ArgumentParser( |
| 60 | epilog=epilog |
| 61 | or f""" |
| 62 | Examples: |
| 63 | |
| 64 | Run on single machine: |
| 65 | $ {sys.argv[0]} --num-gpus 8 --config-file cfg.yaml |
| 66 | |
| 67 | Change some config options: |
| 68 | $ {sys.argv[0]} --config-file cfg.yaml MODEL.WEIGHTS /path/to/weight.pth SOLVER.BASE_LR 0.001 |
| 69 | |
| 70 | Run on multiple machines: |
| 71 | (machine0)$ {sys.argv[0]} --machine-rank 0 --num-machines 2 --dist-url <URL> [--other-flags] |
| 72 | (machine1)$ {sys.argv[0]} --machine-rank 1 --num-machines 2 --dist-url <URL> [--other-flags] |
| 73 | """, |
| 74 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 75 | ) |
| 76 | parser.add_argument("--config-file", default="", metavar="FILE", help="path to config file") |
| 77 | parser.add_argument( |
| 78 | "--resume", |
| 79 | action="store_true", |
| 80 | help="Whether to attempt to resume from the checkpoint directory. " |
| 81 | "See documentation of `DefaultTrainer.resume_or_load()` for what it means.", |
| 82 | ) |
| 83 | parser.add_argument("--eval-only", action="store_true", help="perform evaluation only") |
| 84 | parser.add_argument("--num-gpus", type=int, default=1, help="number of gpus *per machine*") |
| 85 | parser.add_argument("--num-machines", type=int, default=1, help="total number of machines") |
| 86 | parser.add_argument( |
| 87 | "--machine-rank", type=int, default=0, help="the rank of this machine (unique per machine)" |
| 88 | ) |
| 89 | |
| 90 | # PyTorch still may leave orphan processes in multi-gpu training. |
| 91 | # Therefore we use a deterministic way to obtain port, |
| 92 | # so that users are aware of orphan processes by seeing the port occupied. |
| 93 | port = 2 ** 15 + 2 ** 14 + hash(os.getuid() if sys.platform != "win32" else 1) % 2 ** 14 |
| 94 | parser.add_argument( |
| 95 | "--dist-url", |
| 96 | default="tcp://127.0.0.1:{}".format(port), |
| 97 | help="initialization URL for pytorch distributed backend. See " |
| 98 | "https://pytorch.org/docs/stable/distributed.html for details.", |
| 99 | ) |
| 100 | parser.add_argument( |
| 101 | "opts", |
| 102 | help="Modify config options by adding 'KEY VALUE' pairs at the end of the command. " |
| 103 | "See config references at " |
| 104 | "https://detectron2.readthedocs.io/modules/config.html#config-references", |
| 105 | default=None, |
| 106 | nargs=argparse.REMAINDER, |
no outgoing calls
no test coverage detected