Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'module name can\'t contain "."' #9

Open
HungryKonata opened this issue Mar 30, 2020 · 4 comments
Open

KeyError: 'module name can\'t contain "."' #9

HungryKonata opened this issue Mar 30, 2020 · 4 comments

Comments

@HungryKonata
Copy link

How can I fix the problem?

@HungryKonata
Copy link
Author

Thank you
With your help I have solved the problem

@sguphil
Copy link

sguphil commented Oct 28, 2020

Thank you
With your help I have solved the problem

how to fix this issue?

@kubitz
Copy link

kubitz commented Apr 24, 2022

The new version of Pytorch does not support module names with a "." in their name.

You can either use an older version, or patch the state_dict file, as well as the model definition.

You can patch it using this for example:

x = torch.load("netG.pth", map_location=lambda storage, loc: storage)
def change_key(state_dict, old, new):
    for _ in range(len(state_dict)):
        k, v = state_dict.popitem(False)
        state_dict[new if old == k else k] = v

change_key(x, "main.extra-layers-0.64.conv.weight", "main.extra-conv-0.weight")
change_key(x, "main.extra-layers-0.64.batchnorm.weight", "main.extra-bn-0.weight")
change_key(x, "main.extra-layers-0.64.batchnorm.bias", "main.extra-bn-0.bias")
change_key(x, "main.extra-layers-0.64.batchnorm.running_mean", "main.extra-bn-0.running_mean")
change_key(x, "main.extra-layers-0.64.batchnorm.running_var", "main.extra-bn-0.running_var")
change_key(x, "main.final_layer.deconv.weight", "main.final-deconv.weight")

@kubitz
Copy link

kubitz commented Apr 24, 2022

Also see issue #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants