yunjey / pytorch-tutorial

PyTorch Tutorial for Deep Learning Researchers
MIT License
30.36k stars 8.14k forks source link

size mismatch for pretrained models #223

Open itongworld opened 4 years ago

itongworld commented 4 years ago

In image_captioning tutorial, I followed every step in the README.md file but error occurs when loading the pretrained model:

root@localhost:~/captioning/pytorch-tutorial/tutorials/03-advanced/image_captioning# python3 sample.py --image='png/example.png'
Downloading: "https://download.pytorch.org/models/resnet152-b121ed2d.pth" to /root/.cache/torch/checkpoints/resnet152-b121ed2d.pth
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 230M/230M [00:22<00:00, 10.5MB/s]
Traceback (most recent call last):
  File "sample.py", line 81, in <module>
    main(args)
  File "sample.py", line 44, in main
    decoder.load_state_dict(torch.load(args.decoder_path))
  File "/anaconda3/envs/fewshot/lib/python3.8/site-packages/torch/nn/modules/module.py", line 829, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for DecoderRNN:
    size mismatch for embed.weight: copying a param with shape torch.Size([9956, 256]) from checkpoint, the shape in current model is torch.Size([9948, 256]).
    size mismatch for linear.weight: copying a param with shape torch.Size([9956, 512]) from checkpoint, the shape in current model is torch.Size([9948, 512]).
    size mismatch for linear.bias: copying a param with shape torch.Size([9956]) from checkpoint, the shape in current model is torch.Size([9948]).

Is there any problems in the pretrained models?

Matten95 commented 3 years ago

I encounter the same question, anyone solved?

aileenz20 commented 1 year ago

Have you solved this problem? @itongworld