Model `ema` key backward compatibility fix (#6972)

Fix for older model loading issue in d3d9cbce22 (commitcomment-68622388)
This commit is contained in:
Glenn Jocher 2022-03-14 10:54:51 +01:00 committed by GitHub
parent c13d4ce7ef
commit 2d45de617e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -94,7 +94,7 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
model = Ensemble() model = Ensemble()
for w in weights if isinstance(weights, list) else [weights]: for w in weights if isinstance(weights, list) else [weights]:
ckpt = torch.load(attempt_download(w), map_location=map_location) # load ckpt = torch.load(attempt_download(w), map_location=map_location) # load
ckpt = (ckpt['ema'] or ckpt['model']).float() # FP32 model ckpt = (ckpt.get('ema') or ckpt['model']).float() # FP32 model
model.append(ckpt.fuse().eval() if fuse else ckpt.eval()) # fused or un-fused model in eval mode model.append(ckpt.fuse().eval() if fuse else ckpt.eval()) # fused or un-fused model in eval mode
# Compatibility updates # Compatibility updates