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 weights

See original GitHub issue

KeyError: 'unexpected key "module.features.conv0.weight" in state_dict'

I’m using densenet-201-kinetics.pth file with the densenet.py file from models folder.

net = densenet.densenet201(sample_size=64, sample_duration=30, num_classes=400)
pretrained_weights = torch.load(pretrained_path)
net.load_state_dict(pretrained_weights['state_dict'])

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kenshoharacommented, Dec 22, 2017

I could reproduce the error and solve it. I trained the model using GPUs. So, the model is wrapped by nn.DataParallel. You have to wrap the model using nn.DataParallel before load_state.

import torch
from torch import nn
import densenet
net = densenet.densenet201(sample_size=64, sample_duration=30, num_classes=400)

net = nn.DataParallel(net, device_ids=None)

pretrained_weights = torch.load('densenet-201-kinetics.pth')
net.load_state_dict(pretrained_weights['state_dict'])
0reactions
skrish13commented, Dec 22, 2017

woohoo. thanks a lot! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in loading the model with load_weights in Keras
A Model is more than just the weights, including architecture, losses, metrics and etc. You have two solutions: 1) Go with saving the...
Read more >
Why is there a problem when loading saved weights on a model
However when loading the weights, the fit isn't doing anything. The loss stagnates during the entire training.
Read more >
OSError: Unable to load weights from pytorch checkpoint file
Hi, everyone. I need some help. I have been developing the Flask website that has embedded one of Transformer's fine-tuned models within it....
Read more >
Model saving & serialization APIs - Keras
Only topological loading ( by_name=False ) is supported when loading weights from the TensorFlow format. Note that topological loading differs slightly between ...
Read more >
Error while converting keras model to tensorflow saved model
I'm not sure I understand your question correctly. Does the error occur when you are saving the keras model into .h5 file or...
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