MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / default_setup

Function default_setup

detectron2/engine/defaults.py:111–157  ·  view source on GitHub ↗

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

(cfg, args)

Source from the content-addressed store, hash-verified

109
110
111def default_setup(cfg, args):
112 """
113 Perform some basic common setups at the beginning of a job, including:
114
115 1. Set up the detectron2 logger
116 2. Log basic information about environment, cmdline arguments, and config
117 3. Backup the config to the output directory
118
119 Args:
120 cfg (CfgNode): the full config to be used
121 args (argparse.NameSpace): the command line arguments to be logged
122 """
123 output_dir = cfg.OUTPUT_DIR
124 if comm.is_main_process() and output_dir:
125 PathManager.mkdirs(output_dir)
126
127 rank = comm.get_rank()
128 setup_logger(output_dir, distributed_rank=rank, name="fvcore")
129 logger = setup_logger(output_dir, distributed_rank=rank)
130
131 logger.info("Rank of current process: {}. World size: {}".format(rank, comm.get_world_size()))
132 logger.info("Environment info:\n" + collect_env_info())
133
134 logger.info("Command line arguments: " + str(args))
135 if hasattr(args, "config_file") and args.config_file != "":
136 logger.info(
137 "Contents of args.config_file={}:\n{}".format(
138 args.config_file, PathManager.open(args.config_file, "r").read()
139 )
140 )
141
142 logger.info("Running with full config:\n{}".format(cfg))
143 if comm.is_main_process() and output_dir:
144 # Note: some of our scripts may expect the existence of
145 # config.yaml in output directory
146 path = os.path.join(output_dir, "config.yaml")
147 with PathManager.open(path, "w") as f:
148 f.write(cfg.dump())
149 logger.info("Full config saved to {}".format(path))
150
151 # make sure each worker has a different, yet deterministic seed if specified
152 seed_all_rng(None if cfg.SEED < 0 else cfg.SEED + rank)
153
154 # cudnn benchmark has large overhead. It shouldn't be used considering the small size of
155 # typical validation set.
156 if not (hasattr(args, "eval_only") and args.eval_only):
157 torch.backends.cudnn.benchmark = cfg.CUDNN_BENCHMARK
158
159
160class DefaultPredictor:

Callers 3

setupFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90

Calls 5

setup_loggerFunction · 0.90
collect_env_infoFunction · 0.90
seed_all_rngFunction · 0.90
dumpMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected