Update train.py (#462)

pull/1/head
Glenn Jocher 5 years ago committed by GitHub
parent 999804fea9
commit 5e970d45c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,9 +123,12 @@ def train(hyp, tb_writer, opt, device):
# load model
try:
exclude = ['anchor'] # exclude keys
ckpt['model'] = {k: v for k, v in ckpt['model'].float().state_dict().items()
if k in model.state_dict() and model.state_dict()[k].shape == v.shape}
if k in model.state_dict() and not any(x in k for x in exclude)
and model.state_dict()[k].shape == v.shape}
model.load_state_dict(ckpt['model'], strict=False)
print('Transferred %g/%g items from %s' % (len(ckpt['model']), len(model.state_dict()), weights))
except KeyError as e:
s = "%s is not compatible with %s. This may be due to model differences or %s may be out of date. " \
"Please delete or update %s and try again, or use --weights '' to train from scratch." \

Loading…
Cancel
Save