question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: Error(s) in loading state_dict for InceptionNet

See original GitHub issue

trying 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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chufengtcommented, Dec 19, 2021

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.

1reaction
chufengtcommented, Dec 18, 2021

With the prefix module_, it’s a nn.DataParallel model.

Converting the model to nn.DataParallel before loading can solve the problem: model = torch.nn.DataParallel(model).cuda()

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found