Fastai学习器无法加载

9

我正在尝试使用以下代码加载模型:

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被训练得很好。发生了什么?
2个回答

4
使用 cnn_learner 方法和最新的 Pytorch 以及最新的 FastAI。由于出现了 重大变化 和不连续性,所以您现在遇到了问题。
fastai 网站有很多示例,例如 这个
learn = cnn_learner(data, models.resnet50, metrics=accuracy)

2

实际上,你从检查点中得到的 torch.Size([5004, 2048]) 形状与当前模型的形状不同,应该进行更改为 torch.Size([4542, 2048])。

"Original Answer" 翻译成中文是 "最初的回答"。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接