因此,我尝试使用以下命令加载模型:
learn = create_cnn(data, models.resnet50, lin_ftrs=[2048], metrics=accuracy)
learn.clip_grad();
learn.load(f'{name}-stage-2.1')但是我得到了以下错误
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]).唯一不同的是,我添加了一个stage-2.1模型中没有的随机验证拆分,当我删除拆分并且没有设置验证集时,因为stage-2.1已经训练好了,一切都很顺利。
发生什么事了?
发布于 2019-05-21 23:07:44
使用cnn_learner方法和带有最新FastAI的最新Pytorch。有一个breaking change和中断,所以你现在受苦了。
fastai网站有很多例子,比如this one。
learn = cnn_learner(data, models.resnet50, metrics=accuracy)发布于 2019-03-22 19:17:11
实际上你的torch.Size(5004,2048)来自检查点,当前模型中的形状是torch.Size(4542,2048),你必须更改它。
https://stackoverflow.com/questions/54914106
复制相似问题