JingyunLiang / SwinIR

SwinIR: Image Restoration Using Swin Transformer (official repository)

Home Page:https://arxiv.org/abs/2108.10257

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trained model from KAIR (40000_optimizerG.pth) gives error on testing

paragon1234 opened this issue · comments

Instead of using pre-trained models, I trained the KAIR code and used the generated model for testing.

The KAIR training code produced 3 models:
40000_optimizerG.pth
40000_G.pth
40000_E.pth

Using these models, for testing the code in this repository, I am getting error:

(pytorch-gpu) C:\Users\Downloads\SwinIR-main>python main_test_swinir.py --task classical_sr --scale 2 --training_patch_size 48 --folder_lq testsets/Set5/LR_bicubic/X2 --folder_gt testsets/Set5/HR
loading model from model_zoo/swinir/40000_optimizerG.pth
Traceback (most recent call last):
  File "C:\Users\Downloads\SwinIR-main\main_test_swinir.py", line 253, in <module>
    main()
  File "C:\Users\Downloads\SwinIR-main\main_test_swinir.py", line 42, in main
    model = define_model(args)
  File "C:\Users\Downloads\SwinIR-main\main_test_swinir.py", line 174, in define_model
    model.load_state_dict(pretrained_model[param_key_g] if param_key_g in pretrained_model.keys() else pretrained_model, strict=True)
  File "C:\Users\anaconda3\envs\pytorch-gpu\lib\site-packages\torch\nn\modules\module.py", line 1406, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for SwinIR:
        Missing key(s) in state_dict: "conv_first.weight", "conv_first.bias", "patch_embed.norm.weight", "patch_embed.norm.bias", "layers.0.residual_group.blocks.0.norm1.weight", "layers.0.residual_group.blocks.0.norm1.bias", "layers.0.residual_group.blocks.0.attn.relative_position_bias_table",

40000_G.pth
40000_E.pth
are testing fine

Do you use the latest code? We have fixed the bug as follows in KAIR (see https://github.com/cszn/KAIR/blob/60ddfc0ffb320182c82f7c93f741615dd6a7033b/main_test_swinir.py#L176) and this repo

model.load_state_dict(pretrained_model[param_key_g] if param_key_g in pretrained_model.keys() else pretrained_model, strict=True)

See more discussions here #20

Yes I am using latest code for SwinIR/main_test_swinir.py. It worked for other 2 models: 40000_G.pth and 40000_E.pth
However, 40000_optimizerG.pth is giving error.

Yes I am using latest code for SwinIR/main_test_swinir.py. It worked for other 2 models: 40000_G.pth and 40000_E.pth
However, 40000_optimizerG.pth is giving error.

The word "optimizer" in "40000_optimizerG.pth" means that it is an optimizer, not a model.
The optimizer is saved so that you can continue learning after a break.

"40000_G.pth" - is the model.
"40000_E.pth" - is the model using the EMA strategy.

The authors recommend using EMA - this model is more stable.

You only need the "40000_E.pth" (the EMA version of model) for testing.

"40000_G.pth" stores the original version of model (can also be used for testing, has similar performance as "40000_E.pth" for classical sr, but is inferior to "40000_E.pth" for GAN-based real-world image sr).

"40000_optimizerG.pth" only stores the optimizer information, no model parameters.

Thank you. Can you provide details on what is 4000_E? How does GAN came into the picture?

EMA strategy can make GAN training more stable. You can find some insights here.

ezoic increase your site revenue