MCPcopy Create free account
hub / github.com/MotrixLab/insactor / main

Function main

tools/train.py:63–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61
62
63def main():
64 args = parse_args()
65
66 cfg = Config.fromfile(args.config)
67 if args.options is not None:
68 cfg.merge_from_dict(args.options)
69 # set cudnn_benchmark
70 if cfg.get('cudnn_benchmark', False):
71 torch.backends.cudnn.benchmark = True
72
73 # work_dir is determined in this priority: CLI > segment in file > filename
74 if args.work_dir is not None:
75 # update configs according to CLI args if args.work_dir is not None
76 cfg.work_dir = args.work_dir
77 elif cfg.get('work_dir', None) is None:
78 # use config filename as default work_dir if cfg.work_dir is None
79 cfg.work_dir = osp.join('./work_dirs',
80 osp.splitext(osp.basename(args.config))[0])
81 if args.resume_from is not None:
82 cfg.resume_from = args.resume_from
83 if args.gpu_ids is not None:
84 cfg.gpu_ids = args.gpu_ids
85 else:
86 cfg.gpu_ids = range(1) if args.gpus is None else range(args.gpus)
87
88 # init distributed env first, since logger depends on the dist info.
89 if args.launcher == 'none':
90 distributed = False
91 else:
92 distributed = True
93 init_dist(args.launcher, **cfg.dist_params)
94 _, world_size = get_dist_info()
95 cfg.gpu_ids = range(world_size)
96
97 # create work_dir
98 mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))
99 # dump config
100 cfg.dump(osp.join(cfg.work_dir, osp.basename(args.config)))
101 # init the logger before other steps
102 timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
103 log_file = osp.join(cfg.work_dir, f'{timestamp}.log')
104 logger = get_root_logger(log_file=log_file, log_level=cfg.log_level)
105
106 # init the meta dict to record some important information such as
107 # environment info and seed, which will be logged
108 meta = dict()
109 # log env info
110 env_info_dict = collect_env()
111 env_info = '\n'.join([(f'{k}: {v}') for k, v in env_info_dict.items()])
112 dash_line = '-' * 60 + '\n'
113 logger.info('Environment info:\n' + dash_line + env_info + '\n' +
114 dash_line)
115 meta['env_info'] = env_info
116
117 # log some basic info
118 logger.info(f'Distributed training: {distributed}')
119 logger.info(f'Config:\n{cfg.pretty_text}')
120

Callers 1

train.pyFile · 0.70

Calls 7

get_root_loggerFunction · 0.90
collect_envFunction · 0.90
set_random_seedFunction · 0.90
build_architectureFunction · 0.90
build_datasetFunction · 0.90
train_modelFunction · 0.90
parse_argsFunction · 0.70

Tested by

no test coverage detected