pacifinapacific / StyleGAN_LatentEditor

240 stars 52 forks source link

can not encode another resolution image except 1024x1024 #4

Closed BERYLSHEEP closed 4 years ago

BERYLSHEEP commented 4 years ago

https://github.com/pacifinapacific/StyleGAN_LatentEditor/blob/3695fb4d78b1ef33bba5b4b249da630b97a937df/encode_image.py#L33

I try to use my own image like a cat which resolution is 512x512. I didn't run the aline_images command because I don't want my orignial image to be resized and the human face detector cannot detect the cat face too. But when I set the command args.resolution=512, g_all.load_state_dict() get wrong. The Pytorch weight is still the same as "./karras2019stylegan-ffhq-1024x1024.pt" when i run on resolution 1024x1024.

Below is the wrong information.

python encode_image.py --src_im sample.png --iteration 10 --resolution 512 Traceback (most recent call last): File "encode_image.py", line 123, in main() File "encode_image.py", line 37, in main g_all.load_state_dict(torch.load(args.weight_file, map_location=device)) File "/home/beryl/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 839, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Sequential: Unexpected key(s) in state_dict: "g_synthesis.blocks.1024x1024.conv0_up.weight", "g_synthesis.blocks.1024x1024.conv0_up.bias", "g_synthesis.blocks.1024x1024.conv0_up.intermediate.kernel", "g_synthesis.blocks.1024x1024.epi1.top_epi.noise.weight", "g_synthesis.blocks.1024x1024.epi1.style_mod.lin.weight", "g_synthesis.blocks.1024x1024.epi1.style_mod.lin.bias", "g_synthesis.blocks.1024x1024.conv1.weight", "g_synthesis.blocks.1024x1024.conv1.bias", "g_synthesis.blocks.1024x1024.epi2.top_epi.noise.weight", "g_synthesis.blocks.1024x1024.epi2.style_mod.lin.weight", "g_synthesis.blocks.1024x1024.epi2.style_mod.lin.bias". size mismatch for g_synthesis.torgb.weight: copying a param with shape torch.Size([3, 16, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 32, 1, 1]).

pacifinapacific commented 4 years ago

Once the network weight is trained at 1024x1024, it cannot be used at other resolutions. That argument is used when using pre-trained weights of 512x512(other resolutions)