Fastai learner not loading
Asked Answered
N

2

9

So I'm trying to load a model using:

learn = create_cnn(data, models.resnet50, lin_ftrs=[2048], metrics=accuracy) 
learn.clip_grad();
learn.load(f'{name}-stage-2.1')

But I get the following error

RuntimeError: Error(s) in loading state_dict for Sequential:
size mismatch for 1.8.weight: copying a param with shape torch.Size([5004, 2048]) from checkpoint, the shape in current model is torch.Size([4542, 2048]).
size mismatch for 1.8.bias: copying a param with shape torch.Size([5004]) from checkpoint, the shape in current model is torch.Size([4542]).

The only thing that is different thing is that I added a random validation split that wasn't there in the stage-2.1 model, when I remove the split and have no validation set as the stage-2.1 was trained all goes well.

Whats happening?

Novick answered 27/2, 2019 at 20:39 Comment(0)
U
4

Use cnn_learner method and latest Pytorch with latest FastAI. There was a breaking change and discontinuity so you suffer now.

The fastai website has many examples such as this one.

learn = cnn_learner(data, models.resnet50, metrics=accuracy)
Unbelievable answered 21/5, 2019 at 15:7 Comment(0)
G
2

Actually your torch.Size([5004, 2048]) from checkpoint, the shape in current model is torch.Size([4542, 2048]) you have to change it.

Gunning answered 22/3, 2019 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.