FP16 to FP32 ckpt load
This commit is contained in:
1 parent
14523bb030
commit
6fb5ff014c
1 file changed
+2
-2
+2
-2
@@ -32,8 +32,8 @@ def create(name, pretrained, channels, classes):
|
|||||||
if pretrained:
|
if pretrained:
|
||||||
ckpt = '%s.pt' % name # checkpoint filename
|
ckpt = '%s.pt' % name # checkpoint filename
|
||||||
google_utils.attempt_download(ckpt) # download if not found locally
|
google_utils.attempt_download(ckpt) # download if not found locally
|
||||||
state_dict = torch.load(ckpt, map_location=torch.device('cpu'))['model'].state_dict()
|
state_dict = torch.load(ckpt, map_location=torch.device('cpu'))['model'].float().state_dict() # to FP32
|
||||||
state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].numel() == v.numel()} # filter
|
state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].shape == v.shape} # filter
|
||||||
model.load_state_dict(state_dict, strict=False) # load
|
model.load_state_dict(state_dict, strict=False) # load
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user