Fastai学习者未加载

M09*_*009 8 model machine-learning resnet pytorch fast-ai

所以我试图使用以下方式加载模型:

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

但我收到以下错误

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]).
Run Code Online (Sandbox Code Playgroud)

唯一不同的是,我添加了stage-2.1模型中不存在的随机验证拆分,当我删除该拆分并且没有经过验证的集时,因为stage-2.1经过训练的一切进展顺利。

发生了什么?

小智 2

实际上你的 torch.Size([5004, 2048]) 来自检查点,当前模型中的形状是 torch.Size([4542, 2048]) 你必须改变它。