Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Own Full model apply problem #54

Closed
qiaozhuocheng opened this issue Nov 23, 2020 · 6 comments
Closed

My Own Full model apply problem #54

qiaozhuocheng opened this issue Nov 23, 2020 · 6 comments

Comments

@qiaozhuocheng
Copy link

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
Copy link
Author

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
Copy link
Collaborator

lmxyy commented Nov 23, 2020

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
Copy link
Collaborator

lmxyy commented Nov 23, 2020

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
Copy link
Author

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
Copy link
Collaborator

lmxyy commented Nov 23, 2020

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants