mirror of https://github.com/coqui-ai/TTS.git
Merge pull request #92 from yweweler/yweweler-fix-model-dict-restore
Fix NameError: name 'model_dict' is not defined
This commit is contained in:
commit
2634abbbd5
25
train.py
25
train.py
|
@ -400,17 +400,20 @@ def main(args):
|
|||
|
||||
if args.restore_path:
|
||||
checkpoint = torch.load(args.restore_path)
|
||||
model.load_state_dict(checkpoint['model'])
|
||||
# Partial initialization: if there is a mismatch with new and old layer, it is skipped.
|
||||
# 1. filter out unnecessary keys
|
||||
pretrained_dict = {
|
||||
k: v
|
||||
for k, v in checkpoint['model'].items() if k in model_dict
|
||||
}
|
||||
# 2. overwrite entries in the existing state dict
|
||||
model_dict.update(pretrained_dict)
|
||||
# 3. load the new state dict
|
||||
model.load_state_dict(model_dict)
|
||||
try:
|
||||
model.load_state_dict(checkpoint['model'])
|
||||
except:
|
||||
model_dict = model.state_dict()
|
||||
# Partial initialization: if there is a mismatch with new and old layer, it is skipped.
|
||||
# 1. filter out unnecessary keys
|
||||
pretrained_dict = {
|
||||
k: v
|
||||
for k, v in checkpoint['model'].items() if k in model_dict
|
||||
}
|
||||
# 2. overwrite entries in the existing state dict
|
||||
model_dict.update(pretrained_dict)
|
||||
# 3. load the new state dict
|
||||
model.load_state_dict(model_dict)
|
||||
if use_cuda:
|
||||
model = model.cuda()
|
||||
criterion.cuda()
|
||||
|
|
Loading…
Reference in New Issue