csjliang / DASR

Official implementation of the paper 'Efficient and Degradation-Adaptive Network for Real-World Image Super-Resolution' in ECCV 2022
Apache License 2.0
128 stars 9 forks source link

error when loading pretrained models #3

Closed anse3832 closed 2 years ago

anse3832 commented 2 years ago

I downloaded the pretrained models as you said, and the file name is "net_g.pth" and "net_p.pth", However, when I tried to load "net_g.pth" using train_DASR.yml, it shows an error as below.

Traceback (most recent call last): File "./dasr/train.py", line 15, in train_pipeline(root_path) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/train.py", line 128, in train_pipeline model = build_model(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/init.py", line 27, in build_model model = MODEL_REGISTRY.get(opt['model_type'])(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/dasr/models/DASR_model.py", line 20, in init super(DASRModel, self).init(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/srgan_dynamic_model.py", line 41, in init self.load_network_init_alldynamic(self.net_g, load_path, self.opt['num_networks'], self.opt['path'].get('strict_load_g', True), load_key) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/base_model.py", line 372, in load_network_init_alldynamic load_net = load_net[param_key] KeyError: 'params'

I think that the pretrained model weights (similar as dictionary?) has no key 'params'. 캡처 So, I add the key 'params', and this code shows another error. 캡처 캡처

Could you tell me what the problem is?

csjliang commented 2 years ago

Hi,

Thanks for your attention to our work. You can avoid the code of load_net = load_net[param_key] to load model. I will also update the function later. Thanks!

anse3832 commented 2 years ago

I think the code needs a pre-trained weight file as below, but I cannot get the file. image

csjliang commented 2 years ago

I think the code needs a pre-trained weight file as below, but I cannot get the file. image

Hi,

This is the pretrained model of MSRResNet. Please get the file from the BasicSR project. Thanks.

anse3832 commented 2 years ago

As you said, I used the pretrained model of MSRResNet from BasicSR project (The link is https://drive.google.com/drive/folders/1XN4WXKJ53KQ0Cu0Yv-uCt8DZWq6uufaP) However, when I run the code, it shows an error as below.

Traceback (most recent call last): File "./dasr/train.py", line 15, in train_pipeline(root_path) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/train.py", line 128, in train_pipeline model = build_model(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/init.py", line 27, in build_model model = MODEL_REGISTRY.get(opt['model_type'])(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/dasr/models/DASR_model.py", line 20, in init super(DASRModel, self).init(opt) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/srgan_dynamic_model.py", line 41, in init self.load_network_init_alldynamic(self.net_g, load_path, self.opt['num_networks'], self.opt['path'].get('strict_load_g', True), load_key) File "/nas/workspace/anse/code/pytorch/SR/DASR/basicsr/models/base_model.py", line 389, in load_network_init_alldynamic net.load_state_dict(load_net_repeated, strict=strict) File "/usr/local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1052, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for MSRResNetDynamic: Missing key(s) in state_dict: "conv_first.weight", "conv_first.bias", "body.0.conv1.weight", "body.0.conv1.bias", "body.0.conv2.weight", "body.0.conv2.bias", "body.1.conv1.weight", "body.1.conv1.bias", "body.1.conv2.weight", "body.1.conv2.bias", "body.2.conv1.weight", "body.2.conv1.bias", "body.2.conv2.weight", "body.2.conv2.bias", "body.3.conv1.weight", "body.3.conv1.bias", "body.3.conv2.weight", "body.3.conv2.bias", "body.4.conv1.weight", "body.4.conv1.bias", "body.4.conv2.weight", "body.4.conv2.bias", "body.5.conv1.weight", "body.5.conv1.bias", "body.5.conv2.weight", "body.5.conv2.bias", "body.6.conv1.weight", "body.6.conv1.bias", "body.6.conv2.weight", "body.6.conv2.bias", "body.7.conv1.weight", "body.7.conv1.bias", "body.7.conv2.weight", "body.7.conv2.bias", "body.8.conv1.weight", "body.8.conv1.bias", "body.8.conv2.weight", "body.8.conv2.bias", "body.9.conv1.weight", "body.9.conv1.bias", "body.9.conv2.weight", "body.9.conv2.bias", "body.10.conv1.weight", "body.10.conv1.bias", "body.10.conv2.weight", "body.10.conv2.bias", "body.11.conv1.weight", "body.11.conv1.bias", "body.11.conv2.weight", "body.11.conv2.bias", "body.12.conv1.weight", "body.12.conv1.bias", "body.12.conv2.weight", "body.12.conv2.bias", "body.13.conv1.weight", "body.13.conv1.bias", "body.13.conv2.weight", "body.13.conv2.bias", "body.14.conv1.weight", "body.14.conv1.bias", "body.14.conv2.weight", "body.14.conv2.bias", "body.15.conv1.weight", "body.15.conv1.bias", "body.15.conv2.weight", "body.15.conv2.bias", "upconv1.weight", "upconv1.bias", "upconv2.weight", "upconv2.bias", "conv_hr.weight", "conv_hr.bias", "conv_last.weight", "conv_last.bias". Unexpected key(s) in state_dict: "params".

Maybe the weights name of MSRResNet (in BasicSR) is different from those of MSRResNetDynamic (in your repo).

csjliang commented 2 years ago

Please show me your yml file and the command you run. Thanks. The code has been checked, and should work if you exactly follow our instructions.

Lvhhhh commented 2 years ago

when i using the net_g model they offered as pre-trained model i change the loading model code from "self.load_network_init_alldynamic" to "self.load_network"

anse3832 commented 2 years ago

@csjliang Here are the yml file and running code (sh file) I used. DASR.zip

anse3832 commented 2 years ago

@Lvhhhh When I used net_g model (instead of using MSRResNet in BasicSR), your suggestion is helpful. Thanks!

csjliang commented 2 years ago

@csjliang Here are the yml file and running code (sh file) I used. DASR.zip

Please use the attached pre-trained model. Thanks. MSRResNet_x4_f64b16_DIV2K_1000k_B16G1_net_g_1000000.zip

anse3832 commented 2 years ago

@csjliang The error occurred because of my code modification. The problem is not related to the weight file. Anyway, it works well. Thanks!

csjliang commented 2 years ago

Thanks.

csguoh commented 7 months ago

I want to remind possible reproduce in the future that the function self.load_network_init_alldynamic is still necessary if one want to train DASR as this paper did. Since the weight value of the 'net_g.pth' is NOT the same as init_weight in MSRResNet_x4_f64b16_DIV2K_1000k_B16G1_net_g_1000000.zip provided in BasicSR. net_g.pth is used for testing only. So, one need to modify the yml file of number_networks from 0 to 5, and then use the self.load_network_init_alldynamic function to reproduce the training process of this paper.