mit-han-lab / gan-compression

[CVPR 2020] GAN Compression: Efficient Architectures for Interactive Conditional GANs
Other
1.1k stars 148 forks source link

My Own Full model apply problem #54

Closed qiaozhuocheng closed 3 years ago

qiaozhuocheng commented 3 years ago

l have a pretrained full cyclegan model from the project "junyanz/pytorch-CycleGAN-and-pix2pix", but when l run bash scripts/cycle_gan/loldataset/test_full.sh RuntimeError: Error(s) in loading state_dict for ResnetGenerator: Missing key(s) in state_dict: "model.10.conv_block.6.weight", "model.10.conv_block.6.bias", "model.11.conv_block.6.weight", "model.11.conv_block.6.bias", "model.12.conv_block.6.weight", "model.12.conv_block.6.bias", "model.13.conv_block.6.weight", "model.13.conv_block.6.bias", "model.14.conv_block.6.weight", "model.14.conv_block.6.bias", "model.15.conv_block.6.weight", "model.15.conv_block.6.bias", "model.16.conv_block.6.weight", "model.16.conv_block.6.bias", "model.17.conv_block.6.weight", "model.17.conv_block.6.bias", "model.18.conv_block.6.weight", "model.18.conv_block.6.bias". Unexpected key(s) in state_dict: "model.10.conv_block.5.weight", "model.10.conv_block.5.bias", "model.11.conv_block.5.weight", "model.11.conv_block.5.bias", "model.12.conv_block.5.weight", "model.12.conv_block.5.bias", "model.13.conv_block.5.weight", "model.13.conv_block.5.bias", "model.14.conv_block.5.weight", "model.14.conv_block.5.bias", "model.15.conv_block.5.weight", "model.15.conv_block.5.bias", "model.16.conv_block.5.weight", "model.16.conv_block.5.bias", "model.17.conv_block.5.weight", "model.17.conv_block.5.bias", "model.18.conv_block.5.weight", "model.18.conv_block.5.bias". Do you know how to solve it?

qiaozhuocheng commented 3 years ago

Another question is that : following your llite pipeline , l got the compressed model , I want test in the project "junyanz/pytorch-CycleGAN-and-pix2pix" AttributeError: 'Conv2d' object has no attribute 'conv' I think it caused because the different version of pytorch, but it could not work even i changed my pytorch version.

lmxyy commented 3 years ago

l have a pretrained full cyclegan model from the project "junyanz/pytorch-CycleGAN-and-pix2pix", but when l run bash scripts/cycle_gan/loldataset/test_full.sh RuntimeError: Error(s) in loading state_dict for ResnetGenerator: Missing key(s) in state_dict: "model.10.conv_block.6.weight", "model.10.conv_block.6.bias", "model.11.conv_block.6.weight", "model.11.conv_block.6.bias", "model.12.conv_block.6.weight", "model.12.conv_block.6.bias", "model.13.conv_block.6.weight", "model.13.conv_block.6.bias", "model.14.conv_block.6.weight", "model.14.conv_block.6.bias", "model.15.conv_block.6.weight", "model.15.conv_block.6.bias", "model.16.conv_block.6.weight", "model.16.conv_block.6.bias", "model.17.conv_block.6.weight", "model.17.conv_block.6.bias", "model.18.conv_block.6.weight", "model.18.conv_block.6.bias". Unexpected key(s) in state_dict: "model.10.conv_block.5.weight", "model.10.conv_block.5.bias", "model.11.conv_block.5.weight", "model.11.conv_block.5.bias", "model.12.conv_block.5.weight", "model.12.conv_block.5.bias", "model.13.conv_block.5.weight", "model.13.conv_block.5.bias", "model.14.conv_block.5.weight", "model.14.conv_block.5.bias", "model.15.conv_block.5.weight", "model.15.conv_block.5.bias", "model.16.conv_block.5.weight", "model.16.conv_block.5.bias", "model.17.conv_block.5.weight", "model.17.conv_block.5.bias", "model.18.conv_block.5.weight", "model.18.conv_block.5.bias". Do you know how to solve it?

I think this issue is caused by the Dropout layer. The dropout in junyanz/pytorch-CycleGAN-and-pix2pix is controlled by a boolean argument use_dropout: if it is True, the model will contain some dropout layers with dropout rate 0.5; otherwise, it doesn't have the dropout layer. While in our model definition, I replace use_dropout with a more flexible float argument dropout_rate, but it will add the dropout layers no matter what value you set. The generator of CycleGAN does not need dropout layers, so the generator in junyanz/pytorch-CycleGAN-and-pix2pix does not have drouput layers. But the generator in our repo does have the dropout layers but with dropout rate 0. All you need to do is to remove the dropout layers in our repo mannually so that you could load your pre-trained full model.

lmxyy commented 3 years ago

Another question is that : following your llite pipeline , l got the compressed model , I want test in the project "junyanz/pytorch-CycleGAN-and-pix2pix" AttributeError: 'Conv2d' object has no attribute 'conv' I think it caused because the different version of pytorch, but it could not work even i changed my pytorch version.

Sorry, I do not know what cause your problem. Maybe you could provide your running commands, complete error logs and version information so that I could take a deeper look.

qiaozhuocheng commented 3 years ago

Another question is that : following your llite pipeline , l got the compressed model , I want test in the project "junyanz/pytorch-CycleGAN-and-pix2pix" AttributeError: 'Conv2d' object has no attribute 'conv' I think it caused because the different version of pytorch, but it could not work even i changed my pytorch version.

Sorry, I do not know what cause your problem. Maybe you could provide your running commands, complete error logs and version information so that I could take a deeper look.

Great appreciation for your reply, there is my running command
python test.py --dataroot ./datasets/lol --name lolcompress --model cycle_gan

error logs: loading the model from ./checkpoints/lolcompress/latest_net_G_A.pth Traceback (most recent call last): File "test.py", line 47, in model.setup(opt) # regular setup: load and print networks; create schedulers File "/home/xuwei/下载/pytorch-CycleGAN-and-pix2pix-master/models/base_model.py", line 88, in setup self.load_networks(load_suffix) File "/home/xuwei/下载/pytorch-CycleGAN-and-pix2pix-master/models/base_model.py", line 197, in load_networks self.patch_instance_norm_state_dict(state_dict, net, key.split('.')) File "/home/xuwei/下载/pytorch-CycleGAN-and-pix2pix-master/models/base_model.py", line 173, in patch_instance_norm_state_dict self.patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/home/xuwei/下载/pytorch-CycleGAN-and-pix2pix-master/models/base_model.py", line 173, in patch_instance_norm_state_dict self.patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/home/xuwei/下载/pytorch-CycleGAN-and-pix2pix-master/models/base_model.py", line 173, in patch_instance_norm_state_dict self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) [Previous line repeated 2 more times] File "/home/xuwei/anaconda3/envs/gancompression/lib/python3.6/site-packages/torch/nn/modules/module.py", line 576, in getattr type(self).name, name)) AttributeError: 'Conv2d' object has no attribute 'conv'

lmxyy commented 3 years ago

It seems that this is also caused by the dropout. I think a good way to debug this is to print the network structure of the two models, so that you could tell the differences between the two models.

qiaozhuocheng commented 3 years ago

It seems that this is also caused by the dropout. I think a good way to debug this is to print the network structure of the two models, so that you could tell the differences between the two models.

Thank you, I will try it.