Error when loading converted ada-pytorch model
See original GitHub issueHello and thank you for sharing your fascinating work!
I’m trying to use restyle with a pretrained stylegan-ada-pytorch model. I followed the conversion script (thanks btw!) and have my .pt model file ready. Unfortunately, when I’m trying to run training using the following command
python scripts/train_restyle_psp.py --dataset_type=buildings --encoder_type=BackboneEncoder --exp_dir=experiment/restyle_psp_ffhq_encode --workers=8 --batch_size=8 --test_batch_size=8 --test_workers=8 --val_interval=5000 --save_interval=10000 --start_from_latent_avg --lpips_lambda=0.8 --l2_lambda=1 --w_norm_lambda=0 --id_lambda=0.1 --input_nc=6 --n_iters_per_batch=5 --output_size=512 --stylegan_weights=F:\Experimentation\Generative_models\GANs\StyleGAN2\pretrained_models\rosalinity\buildings_5kimg_upsampled.pt
I get the following error when loading the pretrained model
File "scripts/train_restyle_psp.py", line 30, in <module>
main()
File "scripts/train_restyle_psp.py", line 25, in main
coach = Coach(opts)
File "F:\Experimentation\Generative_models\GANs\StyleGAN2\GAN_editing\restyle-encoder\training\coach_restyle_psp.py", line 31, in __init__
self.net = pSp(self.opts).to(self.device)
File "F:\Experimentation\Generative_models\GANs\StyleGAN2\GAN_editing\restyle-encoder\models\psp.py", line 25, in __init__
self.load_weights()
File "F:\Experimentation\Generative_models\GANs\StyleGAN2\GAN_editing\restyle-encoder\models\psp.py", line 52, in load_weights
self.decoder.load_state_dict(ckpt['g_ema'], strict=True)
File "C:\Users\user\miniconda3\envs\archelites\lib\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 Generator:
Missing key(s) in state_dict: "style.3.weight", "style.3.bias", "style.4.weight", "style.4.bias", "style.5.weight", "style.5.bias", "style.6.weight", "style.6.bias", "style.7.weight", "style.7.bias", "style.8.weight", "style.8.bias".```
Any idea why I get a mismatch here? Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
Any chance you can check how many mapping layers you used when training your generator? I see in the stylegan-ada-pytorch repo the following configs:
If you used
auto
, this may explain why you’re missing the keys related to styles 3 - 8.If this is the case, the easiest fix I see is changing the definition of the generator in this repo (using the generator you converted to rosinality’s format) https://github.com/yuval-alaluf/restyle-encoder/blob/ecc797c44587b9848a5f9f3570263ec1ed566177/models/psp.py#L22
Try changing the above lines to:
Interested to see if this is indeed the difference we’re seeing.
Changing export_weights.py with these lines seems to have worked for me: