glenn-jocher commited on
Commit
6fb5ff0
1 Parent(s): 14523bb

FP16 to FP32 ckpt load

Browse files
Files changed (1) hide show
  1. hubconf.py +2 -2
hubconf.py CHANGED
@@ -32,8 +32,8 @@ def create(name, pretrained, channels, classes):
32
  if pretrained:
33
  ckpt = '%s.pt' % name # checkpoint filename
34
  google_utils.attempt_download(ckpt) # download if not found locally
35
- state_dict = torch.load(ckpt, map_location=torch.device('cpu'))['model'].state_dict()
36
- state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].numel() == v.numel()} # filter
37
  model.load_state_dict(state_dict, strict=False) # load
38
  return model
39
 
 
32
  if pretrained:
33
  ckpt = '%s.pt' % name # checkpoint filename
34
  google_utils.attempt_download(ckpt) # download if not found locally
35
+ state_dict = torch.load(ckpt, map_location=torch.device('cpu'))['model'].float().state_dict() # to FP32
36
+ state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].shape == v.shape} # filter
37
  model.load_state_dict(state_dict, strict=False) # load
38
  return model
39