MCPcopy Create free account
hub / github.com/CHENGY12/PLOT / load_model

Method load_model

plot-coop/trainers/plot.py:374–405  ·  view source on GitHub ↗
(self, directory, epoch=None)

Source from the content-addressed store, hash-verified

372 return input, label
373
374 def load_model(self, directory, epoch=None):
375 if not directory:
376 print("Note that load_model() is skipped as no pretrained model is given")
377 return
378
379 names = self.get_model_names()
380
381 # By default, the best model is loaded
382 model_file = "model-best.pth.tar"
383
384 if epoch is not None:
385 model_file = "model.pth.tar-" + str(epoch)
386
387 for name in names:
388 model_path = osp.join(directory, name, model_file)
389
390 if not osp.exists(model_path):
391 raise FileNotFoundError('Model not found at "{}"'.format(model_path))
392
393 checkpoint = load_checkpoint(model_path)
394 state_dict = checkpoint["state_dict"]
395 epoch = checkpoint["epoch"]
396
397 # Ignore fixed token vectors
398 if "token_prefix" in state_dict:
399 del state_dict["token_prefix"]
400
401 if "token_suffix" in state_dict:
402 del state_dict["token_suffix"]
403
404 print("Loading weights to {} " 'from "{}" (epoch = {})'.format(name, model_path, epoch))
405 self._models[name].load_state_dict(state_dict, strict=False)

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected