Giter Club home page Giter Club logo

Comments (6)

yifanjiang19 avatar yifanjiang19 commented on July 20, 2024 2

I've pushed a new version. You can directly pull the new version to avoid this problem.

from enlightengan.

nelaturuharsha avatar nelaturuharsha commented on July 20, 2024

Fix :

In models/base_model.py replace the load_network with the following:

def load_network(self, network, network_label, epoch_label):
save_filename = '%s_net_%s.pth' % (epoch_label, network_label)
save_path = os.path.join(self.save_dir, save_filename)
state_dict = torch.load(save_path)
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k[7:] # remove module.
new_state_dict[name] = v
network.load_state_dict(new_state_dict)

from enlightengan.

Dear-Mr avatar Dear-Mr commented on July 20, 2024

您好,在经过上述修改后,
并将 new_state_dict = OrderedDict() 修改为 new_state_dict = collections.OrderedDict() 后,
出现KeyError: 'unexpected key "conv10.bias" in state_dict',该如何解决?

from enlightengan.

nelaturuharsha avatar nelaturuharsha commented on July 20, 2024

Is your python 3.5, pytorch 0.3.1? And are you trying to run via CPU or GPU?

from enlightengan.

yifanjiang19 avatar yifanjiang19 commented on July 20, 2024

@Dear-Mr @SreeHarshaNelaturu
This problem is about torch.nn.DataParallel(). Normally DataParallel() will cover the original model, which means you can only use model.module to access the original model. And also, if you directly save the model covered by DataParallel, the key of saved model will be module.conv.weight instead of conv.weight.
You can simply use DataParallel to cover the model before you load the pre-trained model to solve this problem.

Eg.

model = ResNet()
parallel_model = torch.nn.DataParallel(model)
print(parallel_model.module)
# Here parallel_model.module is equal to model

from enlightengan.

Dear-Mr avatar Dear-Mr commented on July 20, 2024

Is your python 3.5, pytorch 0.3.1? And are you trying to run via CPU or GPU?

Thanks for your reply.
My workspace is python 3.5, PyTorch 0.3.1, torchvision 0.2.0. And i tried to run via GPU.

from enlightengan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.