MCPcopy Create free account
hub / github.com/OpenDriveLab/OccNet / main

Function main

tools/train.py:102–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100def main():
101 args = parse_args()
102
103 cfg = Config.fromfile(args.config)
104 if args.cfg_options is not None:
105 cfg.merge_from_dict(args.cfg_options)
106 # import modules from string list.
107 if cfg.get('custom_imports', None):
108 from mmcv.utils import import_modules_from_strings
109 import_modules_from_strings(**cfg['custom_imports'])
110
111 # import modules from plguin/xx, registry will be updated
112 if hasattr(cfg, 'plugin'):
113 if cfg.plugin:
114 import importlib
115 if hasattr(cfg, 'plugin_dir'):
116 plugin_dir = cfg.plugin_dir
117 _module_dir = os.path.dirname(plugin_dir)
118 _module_dir = _module_dir.split('/')
119 _module_path = _module_dir[0]
120
121 for m in _module_dir[1:]:
122 _module_path = _module_path + '.' + m
123 print(_module_path)
124 plg_lib = importlib.import_module(_module_path)
125 else:
126 # import dir is the dirpath for the config file
127 _module_dir = os.path.dirname(args.config)
128 _module_dir = _module_dir.split('/')
129 _module_path = _module_dir[0]
130 for m in _module_dir[1:]:
131 _module_path = _module_path + '.' + m
132 print(_module_path)
133 plg_lib = importlib.import_module(_module_path)
134
135 from projects.mmdet3d_plugin.bevformer.apis.train import custom_train_model
136 # set cudnn_benchmark
137 if cfg.get('cudnn_benchmark', False):
138 torch.backends.cudnn.benchmark = True
139
140 # work_dir is determined in this priority: CLI > segment in file > filename
141 if args.work_dir is not None:
142 # update configs according to CLI args if args.work_dir is not None
143 cfg.work_dir = args.work_dir
144 elif cfg.get('work_dir', None) is None:
145 # use config filename as default work_dir if cfg.work_dir is None
146 cfg.work_dir = osp.join('./work_dirs',
147 osp.splitext(osp.basename(args.config))[0])
148 # if args.resume_from is not None:
149 if args.resume_from is not None and osp.isfile(args.resume_from):
150 cfg.resume_from = args.resume_from
151 if args.gpu_ids is not None:
152 cfg.gpu_ids = args.gpu_ids
153 else:
154 cfg.gpu_ids = range(1) if args.gpus is None else range(args.gpus)
155 if digit_version(TORCH_VERSION) == digit_version('1.8.1') and cfg.optimizer['type'] == 'AdamW':
156 cfg.optimizer['type'] = 'AdamW2' # fix bug in Adamw
157 if args.autoscale_lr:
158 # apply the linear scaling rule (https://arxiv.org/abs/1706.02677)
159 cfg.optimizer['lr'] = cfg.optimizer['lr'] * len(cfg.gpu_ids) / 8

Callers 1

train.pyFile · 0.70

Calls 3

custom_train_modelFunction · 0.90
parse_argsFunction · 0.70
init_weightsMethod · 0.45

Tested by

no test coverage detected