MCPcopy Index your code
hub / github.com/OpenMeshLab/MeshXL / main

Function main

main.py:141–242  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

139
140
141def main(args):
142
143 np.random.seed(args.seed)
144 torch.cuda.manual_seed_all(args.seed)
145
146 if args.checkpoint_dir is not None:
147 pass
148 elif args.test_ckpt is not None:
149 # if not define the checkpoint-dir, set to the test checkpoint folder as default
150 args.checkpoint_dir = os.path.dirname(args.test_ckpt)
151 print(f'testing directory: {args.checkpoint_dir}')
152 else:
153 raise AssertionError(
154 'Either checkpoint_dir or test_ckpt should be presented!'
155 )
156
157 os.makedirs(args.checkpoint_dir, exist_ok=True)
158 accelerator = Accelerator()
159 set_seed(args.seed)
160
161 ### build datasets and dataloaders
162 datasets, dataloaders = build_dataset_func(args)
163
164 ### build models
165 model = build_model_func(args)
166 ### set default checkpoint
167 checkpoint = None
168
169 # testing phase
170 if args.test_only:
171
172 try:
173 checkpoint = torch.load(args.test_ckpt, map_location=torch.device("cpu"))
174 model.load_state_dict(checkpoint["model"], strict=False)
175 except:
176 print('test the model from scratch...')
177
178 model, dataloaders['train'], *dataloaders['test'] = accelerator.prepare(
179 model, dataloaders['train'], *dataloaders['test']
180 )
181
182 for test_loader in dataloaders['test']:
183 test_loader.dataset.eval_func(
184 args,
185 -1,
186 model,
187 accelerator,
188 test_loader
189 )
190
191 # training phase
192 else:
193
194 assert (
195 args.checkpoint_dir is not None
196 ), "`--checkpoint_dir` is required to identify the directory to store the checkpoint"
197 os.makedirs(args.checkpoint_dir, exist_ok=True)
198

Callers 1

main.pyFile · 0.85

Calls 7

log_messagesMethod · 0.95
LoggerClass · 0.90
resume_if_possibleFunction · 0.90
do_trainFunction · 0.90
printFunction · 0.85
build_dataset_funcFunction · 0.85
build_model_funcFunction · 0.85

Tested by

no test coverage detected