RuntimeError:的加载状态中出错ResNet:大小不匹配为fc.重量以及fc.偏差

2024-10-02 20:40:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试过几种可行的解决办法,但都不管用。有谁能帮忙解决这个问题吗?在

Preprocessing..
Loading dataset...
Calculating mean & dev std...
Calculated mean and standard deviation!
Preprocessing finished!
Traceback (most recent call last):
  File "main.py", line 226, in <module>
    resnet152_model = resnet.resnet152(pretrained=True, **classes)
  File "/home/aqsa/anaconda3/envs/VGG/lib/python3.7/site-packages/torchvision/models/resnet.py", line 279, in resnet152
    **kwargs)
  File "/home/aqsa/anaconda3/envs/VGG/lib/python3.7/site-packages/torchvision/models/resnet.py", line 218, in _resnet
    model.load_state_dict(state_dict)
  File "/home/aqsa/anaconda3/envs/VGG/lib/python3.7/site-packages/torch/nn/modules/module.py", line 841, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for ResNet:
    size mismatch for fc.weight: copying a param with shape torch.Size([1000, 2048]) from checkpoint, the shape in current model is torch.Size([3, 2048]).
    size mismatch for fc.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([3]).

Tags: inpyhomesizemodellinetorchdict