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(s) in loading state_dict for Net: Missing key(s) in state_dict

See original GitHub issue

Hi, thanks for your codes. I trained a checkpoint model named carn_m_180000.pth, but when I testing it by sample.py, I got following error, could you give me some suggestions?

$ python3 carn/sample.py --model=carn_m --ckpt_path=./checkpoint/carn_m/carn_m_180000.pth --sample_dir=./sample/
using this model
{
    "ckpt_path": "./checkpoint/carn_m/carn_m_180000.pth",
    "cuda": false,
    "group": 1,
    "model": "carn_m",
    "sample_dir": "./sample/",
    "scale": 2,
    "shave": 20,
    "test_data_dir": "dataset/DIV2K_valid_LR_bicubic/X2"
}
Traceback (most recent call last):
  File "carn/sample.py", line 122, in <module>
    main(cfg)
  File "carn/sample.py", line 110, in main
    net.load_state_dict(new_state_dict)
  File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 719, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Net:
	Missing key(s) in state_dict: "upsample.up2.body.0.bias", "upsample.up2.body.0.weight", "upsample.up3.body.0.bias", "upsample.up3.body.0.weight", "upsample.up4.body.0.bias", "upsample.up4.body.0.weight", "upsample.up4.body.3.bias", "upsample.up4.body.3.weight". 
	Unexpected key(s) in state_dict: "upsample.up.body.0.weight", "upsample.up.body.0.bias". 

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
Jee-Kingcommented, Jan 16, 2019

@wydwww https://github.com/nmhkahn/CARN-pytorch/blob/160a4bc444dd0acfa4bbe93e5f8e45e9cd551c22/carn/sample.py#L96 It missed a parameter scale=cfg.scale. And multi-scale should beFalseif you did not use cfg.multi_scale

0reactions
wydwwwcommented, Jan 16, 2019

@Ji-qing Which parameter is missed? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: Error(s) in loading state_dict for Net #100 - GitHub
Hi Mr. Zhang: When I test pre-trained model on MINC-2500 using: python main.py --dataset minc --model deepten --nclass 23 --resume ...
Read more >
RuntimeError: Error(s) in loading state_dict for Generator
You saved the weights with the wrong names. That is you saved the generator's weights as dcgan_d.pth and likewise, saved the descriminator's ...
Read more >
Missing keys & unexpected keys in state_dict when loading ...
After that I would like to infer some images using my model, it fails with the follow error: RuntimeError: Error(s) in loading state_dict...
Read more >
RuntimeError: Error(s) in loading state_dict for DynamicUnet
Here, I aim to load the model and weights to run inference with new ... in loading state_dict for DynamicUnet: Missing key(s) in...
Read more >
RuntimeError: Error in loading state_dict for SSD: Unexpected ...
This is the complete error: RuntimeError: Error(s) in loading state_dict for SSD: Unexpected key(s) in state_dict: “base_net.1.0.weight”, ...
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