首页 > 解决方案 > Fastai 学习者未加载

问题描述

所以我正在尝试使用以下方法加载模型:

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训练一切顺利。

发生了什么?

标签: machine-learningmodelpytorchresnetfast-ai

解决方案


使用cnn_learner方法和最新Pytorch与最新FastAI。有一个breaking change不连续的,所以你现在受苦了。

fastai 网站有很多例子,例如this one.

learn = cnn_learner(data, models.resnet50, metrics=accuracy)

推荐阅读