Update train.py (#462)

This commit is contained in:
Glenn Jocher authored and GitHub committed 2020-07-22 12:32:03 -07:00
1 parent 999804fea9
commit 5e970d45c4
1 file changed
+4 -1
+4 -1
View File
@@ -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." \