加载预训练参数时,明明已经使用了strict=false,可还是报错,显示加载的参数维度不对
RuntimeError: Error(s) in loading state_dict for InceptionResnetV1:
size mismatch for logits.weight: copying a param with shape torch.Size([8631, 512]) from checkpoint, the shape in current model is torch.Size([340, 512]).
size mismatch for logits.bias: copying a param with shape torch.Size([8631]) from checkpoint, the shape in current model is torch.Size([340])
解决:当预训练参数的key和你改了维度的后的key相同时,参数会被强制加载进来,这种错误往往是因为修改num_classes,遇到这种问题解决办法是::把修改维度的层名字换一个就行!
2021-10-16
最新推荐文章于 2023-12-20 09:33:51 发布