RuntimeError: Error(s) in loading state_dict for InceptionNet
See original GitHub issuetrying to run inference using simple script
import model as models
import torch
import logging
logging.basicConfig(level=logging.INFO)
attr_num = 51
model = models.__dict__['inception_iccv'](
pretrained=True, num_classes=attr_num)
checkpoint = torch.load('rap_epoch_9.pth.tar')
model.load_state_dict(checkpoint['state_dict'])
logging.info("loaded model checkpoint")
got RuntimeError: Error(s) in loading state_dict for InceptionNet
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
RuntimeError: Error(s) in loading state_dict for ResNet
I was using Pytorch 0.4.1 but Jupyter Notebook which I loaded uses 0.4.0. So I added strict=False attribute to load_state_dict().
Read more >RuntimeError: Error(s) in loading state_dict for Net #100 - GitHub
Hi Mr. Zhang: When I test pre-trained model on MINC-2500 using: python main.py --dataset minc --model deepten --nclass 23 --resume ...
Read more >RuntimeError: Error(s) in loading state_dict for Inception3
Hello, I have trained my model using this code !python train_bap.py train\ --model-name inception \ --batch-size 12 \ --dataset car ...
Read more >pytorch加载模型报错RuntimeError:Error(s) in loading ...
RuntimeError :Error(s) in loading state_dict for DataParallel: Unexpected key(s) in state_dict:“module.resnet.bn1.num_batches_tracked” ...
Read more >Error(s) in loading state_dict for BertForTokenClassification
7/dist-packages/torch/nn/modules/module.py", line 1407, in load_state_dict self.__class__.__name__, "\n\t".join(error_msgs))) RuntimeError ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the pre-trained model is good enough to address this problem. If the problem still occurs, you can keep the attribute with the largest confidence only.
With the prefix
module_
, it’s ann.DataParallel
model.Converting the model to
nn.DataParallel
before loading can solve the problem:model = torch.nn.DataParallel(model).cuda()