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

demo.py does not working #28

Closed
yustiks opened this issue Jan 26, 2021 · 4 comments
Closed

demo.py does not working #28

yustiks opened this issue Jan 26, 2021 · 4 comments

Comments

@yustiks
Copy link

yustiks commented Jan 26, 2021

I try to run demo.py after several epochs of training, and I have the following error:
lib/python3.7/site-packages/torch/nn/modules/module.py", line 1045, in load_state_dict self.__class__.__name__, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for DataParallel: Missing key(s) in state_dict:

any ideas what is it?

@WenjiaWang0312
Copy link
Owner

You said you only have 1 GPU? That's just the conflicts between multi-gpu model with single-gpu model. could you change the config in config/super_resolution.yaml as ngpu: 1 and try again

@yustiks
Copy link
Author

yustiks commented Jan 26, 2021

thank you, @JasonBoy1 ! I set it to be one. And it still has errors!

  batch_size: 64
  width: 128
  height: 32
  epochs: 500
  cuda: True
  ngpu: 1
  workers: 1
  resume: ''
  ckpt_dir: './ckpt/'
  voc_type: 'all' #'digits lower upper all'
  saveInterval: 200
  displayInterval: 100 #display loss
  adadelta: False
  lr: 0.001
  adam: True
  beta1: 0.5
  manualSeed: 1234
  max_len: 100
  keep_ratio: False
  down_sample_scale: 2

@yustiks
Copy link
Author

yustiks commented Jan 29, 2021

ok, I solved the problem by the next code in the interfaces/base.py:

                if self.config.TRAIN.ngpu == 1:
                    model.load_state_dict(torch.load(self.resume)['state_dict_G'])

so, I changed it to be:

                if self.config.TRAIN.ngpu == 1:
                    state_dict = torch.load(self.resume)['state_dict_G']
                    from collections import OrderedDict
                    new_state_dict = OrderedDict()

                    for k, v in state_dict.items():
                        if 'module' not in k:
                            k = 'module.'+k
                        else:
                            k = k.replace('features.module.', 'module.features.')
                        new_state_dict[k]=v

                    model.load_state_dict(new_state_dict)
                    # model.load_state_dict(torch.load(self.resume)['state_dict_G'])

@LMY199
Copy link

LMY199 commented Dec 8, 2023

ok, I solved the problem by the next code in the interfaces/base.py:

                if self.config.TRAIN.ngpu == 1:
                    model.load_state_dict(torch.load(self.resume)['state_dict_G'])

so, I changed it to be:

                if self.config.TRAIN.ngpu == 1:
                    state_dict = torch.load(self.resume)['state_dict_G']
                    from collections import OrderedDict
                    new_state_dict = OrderedDict()

                    for k, v in state_dict.items():
                        if 'module' not in k:
                            k = 'module.'+k
                        else:
                            k = k.replace('features.module.', 'module.features.')
                        new_state_dict[k]=v

                    model.load_state_dict(new_state_dict)
                    # model.load_state_dict(torch.load(self.resume)['state_dict_G'])

really thanku,i have the same problem and solved now by your code,good for u

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