我正在尝试使用以下代码加载模型:
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
被训练得很好。发生了什么?