You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using effeciencenetb0 pretrained, and when i try to load locally saved model I got a runtime error. I tried to find more information inside issues and discussion but I'm kinda stuck
def get_model(num_classes):
model = timm.create_model( 'efficientnet_b0', pretrained=True, num_classes=num_classes)
# freeze model
for param in model.parameters():
param.requires_grad = False
# unfreeze mlp
for param in model.classifier.parameters():
param.requires_grad = True
return model
def load_model_efficiencenet(path, num_classes, device):
model = timm.create_model( 'efficientnet_b0', pretrained=True, num_classes=num_classes)
for param in model.parameters():
param.requires_grad = False
for param in model.classifier.parameters():
param.requires_grad = True
model.load_state_dict(torch.load(path, map_location=device), strict=False)
model.to(device)
return model
model = get_model(200).to("cuda")
train_optim(model, epoch=5, ...)
torch.save(model.state_dict(), "test.pth")
model = load_model_efficiencenet("./test.pth", 200, 'cuda')
RuntimeError: Error(s) in loading state_dict for EfficientNet:
size mismatch for bn1.weight: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.running_mean: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.running_var: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm using effeciencenetb0 pretrained, and when i try to load locally saved model I got a runtime error. I tried to find more information inside issues and discussion but I'm kinda stuck
RuntimeError: Error(s) in loading state_dict for EfficientNet:
size mismatch for bn1.weight: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.running_mean: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
size mismatch for bn1.running_var: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]).
Beta Was this translation helpful? Give feedback.
All reactions