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.

Error while loading pretrained Inception (v 0.2.1)

See original GitHub issue

Dimension mismatch error while loading a pretrained Inception v3

Environment

0.2.1 with Anaconda, python3.6, Ubuntu 16

code

from torchvision.models.inception import Inception3, inception_v3
model = inception_v3(num_classes=1, pretrained=True, aux_logits=False)

error

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-31-e0b4dcd6b958> in <module>()
----> 1 model = inception_v3(num_classes=1, pretrained=True, aux_logits=False)

/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/models/inception.py in inception_v3(pretrained, **kwargs)
     25             kwargs['transform_input'] = True
     26         model = Inception3(**kwargs)
---> 27         model.load_state_dict(model_zoo.load_url(model_urls['inception_v3_google']))
     28         return model
     29 

/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
    719         if len(error_msgs) > 0:
    720             raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
--> 721                                self.__class__.__name__, "\n\t".join(error_msgs)))
    722 
    723     def parameters(self):

RuntimeError: Error(s) in loading state_dict for Inception3:
	Unexpected key(s) in state_dict: "AuxLogits.conv0.conv.weight", "AuxLogits.conv0.bn.weight", "AuxLogits.conv0.bn.bias", "AuxLogits.conv0.bn.running_mean", "AuxLogits.conv0.bn.running_var", "AuxLogits.conv1.conv.weight", "AuxLogits.conv1.bn.weight", "AuxLogits.conv1.bn.bias", "AuxLogits.conv1.bn.running_mean", "AuxLogits.conv1.bn.running_var", "AuxLogits.fc.weight", "AuxLogits.fc.bias". 
	While copying the parameter named "fc.weight", whose dimensions in the model are torch.Size([1, 2048]) and whose dimensions in the checkpoint are torch.Size([1000, 2048]).
	While copying the parameter named "fc.bias", whose dimensions in the model are torch.Size([1]) and whose dimensions in the checkpoint are torch.Size([1000]).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kachakhiladicommented, Apr 27, 2019

I have the same error as the original poster.

The error is not due to the num_classes. It is due to aux_logits=False instead of the default aux_logits=True. Any leads ?

0reactions
luciagancommented, Sep 13, 2019

Dear Shirley,

Thanks for your reply.

Best, Lei Gan

On Sep 1, 2019, at 16:24, ShirleyLuo <notifications@github.commailto:notifications@github.com> wrote:

You should not modify the “model = models.inception_v3(pretrained=True)”, because if you change the code here, it will have errors in “load_state_dict”. Try: "model = models.inception_v3(pretrained=True) model.aux_logits = False num_ftrs = model.fc.in_features model.fc = nn.Linear(num_ftrs, nclasses) "

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/pytorch/vision/issues/480?email_source=notifications&email_token=AF4RU5HI2H2AHQ7WJSX6QDDQHN327A5CNFSM4E4ZSJUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5T5KHA#issuecomment-526898460, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF4RU5HE2S5MX5TM7NMSTQDQHN327ANCNFSM4E4ZSJUA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keras inception v3 retraining and finetuning error
When I run this I get the following error. I already tried to update pillow to the newest version but still the same...
Read more >
module 'torchvision' has no attribute '__version__' - You.com
I tried to install the second PyTorch version in a venv (python -m venv --system-site-packages myenv) and there I get the same error...
Read more >
tf.keras.applications.inception_v3.InceptionV3 - TensorFlow
This function returns a Keras image classification model, optionally loaded with weights pre-trained on ImageNet.
Read more >
timm - PyPI
I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code...
Read more >
Cat vs. Dog Image Classification - | notebook.community
In our case, we will use the Inception V3 model developed at Google, and pre-trained on ImageNet, a large dataset of web images...
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