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
111
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
118 seed_all_rng()
119
120
121
122 if not (hasattr(args, "eval_only") and args.eval_only):
123 torch.backends.cudnn.benchmark = cfg.CUDNN_BENCHMARK
124
125