Safemotion Lib
Loading...
Searching...
No Matches
Classes | Functions
fastreid.engine.defaults Namespace Reference

Classes

class  DefaultPredictor
 
class  DefaultTrainer
 

Functions

 default_argument_parser ()
 
 default_setup (cfg, args)
 

Detailed Description

This file contains components with some default boilerplate logic user may need
in training / testing. They will not work for everyone, but many users may find them useful.
The behavior of functions/classes in this file is subject to change,
since they are meant to represent the "common default behavior" people need in their projects.

Function Documentation

◆ default_argument_parser()

fastreid.engine.defaults.default_argument_parser ( )
Create a parser with some common arguments used by fastreid users.
Returns:
    argparse.ArgumentParser:

Definition at line 39 of file defaults.py.

39def default_argument_parser():
40 """
41 Create a parser with some common arguments used by fastreid users.
42 Returns:
43 argparse.ArgumentParser:
44 """
45 parser = argparse.ArgumentParser(description="fastreid Training")
46 parser.add_argument("--config-file", default="", metavar="FILE", help="path to config file")
47 parser.add_argument(
48 "--finetune",
49 action="store_true",
50 help="whether to attempt to finetune from the trained model",
51 )
52 parser.add_argument(
53 "--resume",
54 action="store_true",
55 help="whether to attempt to resume from the checkpoint directory",
56 )
57 parser.add_argument("--eval-only", action="store_true", help="perform evaluation only")
58 parser.add_argument("--num-gpus", type=int, default=1, help="number of gpus *per machine*")
59 parser.add_argument("--num-machines", type=int, default=1, help="total number of machines")
60 parser.add_argument(
61 "--machine-rank", type=int, default=0, help="the rank of this machine (unique per machine)"
62 )
63
64 # PyTorch still may leave orphan processes in multi-gpu training.
65 # Therefore we use a deterministic way to obtain port,
66 # so that users are aware of orphan processes by seeing the port occupied.
67 # port = 2 ** 15 + 2 ** 14 + hash(os.getuid() if sys.platform != "win32" else 1) % 2 ** 14
68 port = 30000 + random.randint(1, 10000) + random.randint(1, 5000)
69 parser.add_argument("--dist-url", default="tcp://127.0.0.1:{}".format(port))
70 parser.add_argument(
71 "opts",
72 help="Modify config options using the command-line",
73 default=None,
74 nargs=argparse.REMAINDER,
75 )
76 return parser
77
78

◆ default_setup()

fastreid.engine.defaults.default_setup ( cfg,
args )
Perform some basic common setups at the beginning of a job, including:
1. Set up the detectron2 logger
2. Log basic information about environment, cmdline arguments, and config
3. Backup the config to the output directory
Args:
    cfg (CfgNode): the full config to be used
    args (argparse.NameSpace): the command line arguments to be logged

Definition at line 79 of file defaults.py.

79def default_setup(cfg, args):
80 """
81 Perform some basic common setups at the beginning of a job, including:
82 1. Set up the detectron2 logger
83 2. Log basic information about environment, cmdline arguments, and config
84 3. Backup the config to the output directory
85 Args:
86 cfg (CfgNode): the full config to be used
87 args (argparse.NameSpace): the command line arguments to be logged
88 """
89 output_dir = cfg.OUTPUT_DIR
90 if comm.is_main_process() and output_dir:
91 PathManager.mkdirs(output_dir)
92
93 rank = comm.get_rank()
94 setup_logger(output_dir, distributed_rank=rank, name="fvcore")
95 logger = setup_logger(output_dir, distributed_rank=rank)
96
97 logger.info("Rank of current process: {}. World size: {}".format(rank, comm.get_world_size()))
98 logger.info("Environment info:\n" + collect_env_info())
99
100 logger.info("Command line arguments: " + str(args))
101 if hasattr(args, "config_file") and args.config_file != "":
102 logger.info(
103 "Contents of args.config_file={}:\n{}".format(
104 args.config_file, PathManager.open(args.config_file, "r").read()
105 )
106 )
107
108 logger.info("Running with full config:\n{}".format(cfg))
109 if comm.is_main_process() and output_dir:
110 # Note: some of our scripts may expect the existence of
111 # config.yaml in output directory
112 path = os.path.join(output_dir, "config.yaml")
113 with PathManager.open(path, "w") as f:
114 f.write(cfg.dump())
115 logger.info("Full config saved to {}".format(os.path.abspath(path)))
116
117 # make sure each worker has a different, yet deterministic seed if specified
118 seed_all_rng()
119
120 # cudnn benchmark has large overhead. It shouldn't be used considering the small size of
121 # typical validation set.
122 if not (hasattr(args, "eval_only") and args.eval_only):
123 torch.backends.cudnn.benchmark = cfg.CUDNN_BENCHMARK
124
125