sanghyun-son / EDSR-PyTorch

PyTorch version of the paper 'Enhanced Deep Residual Networks for Single Image Super-Resolution' (CVPRW 2017)
MIT License
2.42k stars 668 forks source link

test EDSR_x2.pt error #28

Closed xuanzhangyang closed 6 years ago

xuanzhangyang commented 6 years ago

I download pre-train model and test like this:

python main.py --data_test Demo --scale 2 --pre_train ../experiment/model/EDSR_x2.pt --test_only --save_results

but i get an error

Making model...
Loading model from ../experiment/model/EDSR_x2.pt
Traceback (most recent call last):
  File "/home/x00346096/code/pytorch/EDSR-PyTorch/code/model/edsr.py", line 64, in load_state_dict
    own_state[name].copy_(param)
RuntimeError: invalid argument 2: sizes do not match at /pytorch/torch/lib/THC/THCTensorCopy.cu:31

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    model = model.Model(args, checkpoint)
  File "/home/x00346096/code/pytorch/EDSR-PyTorch/code/model/__init__.py", line 40, in __init__
    cpu=args.cpu
  File "/home/x00346096/code/pytorch/EDSR-PyTorch/code/model/__init__.py", line 110, in load
    strict=False
  File "/home/x00346096/code/pytorch/EDSR-PyTorch/code/model/edsr.py", line 70, in load_state_dict
    .format(name, own_state[name].size(), param.size()))
RuntimeError: While copying the parameter named head.0.weight, whose dimensions in the model are torch.Size([64, 3, 3, 3]) and whose dimensions in the checkpoint are torch.Size([256, 3, 3, 3]).
sanghyun-son commented 6 years ago

Hello.

You have to put additional arguments(--n_resblocks, --n_feats, and --res_scale) to test that model.

Please refer to this line!

Also, I recommend you to use --chop argument if there is any trouble with GPU memory.

Thank you.

sanghyun-son commented 6 years ago

**Additional description

This happens because PyTorch does not save model structure when we make checkpoints.

It means that pre-trained models only contain parameters, but not structures.

Therefore, we have to build the model first to load those parameters.

Default setting is EDSR_baseline_x4, which has 16 resblocks and 64 channels per layer.

If you do not specify those arguments, an error occurs because you are trying to load the parameters from the model with 32 resblocks and 256 channels per layer.

xuanzhangyang commented 6 years ago

The problem has been solved.

Thank you.