-
Notifications
You must be signed in to change notification settings - Fork 156
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
Error when loading converted ada-pytorch model #1
Comments
Hi @TheodoreGalanos , Regardless, I noticed your running on a building StyleGAN if I'm not mistaken. But I see that you're using the |
Thanks @yuval-alaluf, let me know what you find once you find time to look into it! I hadn't seen the thread, will follow that one as well! And thanks for the feedback on the options, I started with a more or less copy/paste :) Will adjust it with your recommendations. |
Any chance you can check how many mapping layers you used when training your generator?
If you used Line 22 in ecc797c
Try changing the above lines to:
Interested to see if this is indeed the difference we're seeing. |
Hi @yuval-alaluf I just realized this today from a discussion in a discord server I'm in. I think I trained my model with 'auto' so I have 2 vs 8 mapping networks! Good catch! Will go ahead and try that in a bit (after the morning coffee) |
So I tried this and it obviously by passed the issue, however it apparently fails to find the latent_avg
|
Ok so it seems like the stylegan-ada-pytorch conversion script is missing some features that rosinality implemented when converting from the tensorflow versions. If we take a look at rosinality's conversion script, he does the following: with open(args.path, "rb") as f:
generator, discriminator, g_ema = pickle.load(f)
...
latent_avg = torch.from_numpy(g_ema.vars["dlatent_avg"].value().eval())
...
ckpt = {"g_ema": state_dict, "latent_avg": latent_avg}
# some more conversions You can see that he saves state_dict = {"g_ema": state_ros}
torch.save(state_dict, output_file) Taking a look at the pytorch code, it seems like the latent average is stored in g_ema.mapping.w_avg # seems like `g_ema` is stored as `G_nvidia` is the export script So you can try adding state_dict = {"g_ema": state_ros, "latent_avg": latent_avg}
torch.save(state_dict, output_file) and see if this solves the problem with the latent average. Let me know if this works. I didn't test it and just looked at the code so I may have missed something. |
Thank you will try this soon! Apologies have been swamped the last 2 days and forgot this. |
Changing export_weights.py with these lines seems to have worked for me:
|
Thanks, this actually solved the problem with latent_avg |
Thanks @AleksiKnuutila for the snippet! 😄 |
Thanks @yuval-alaluf for your amazing work. # Initialize network
self.net = pSp(self.opts).to(self.device)
if self.net.latent_avg is None:
self.net.latent_avg = self.net.decoder.mean_latent(int(1e5))[0] # set a very large number for estimation |
Estimate latent_avg via dense sampling if latent_avg is not available
Thanks all. I’ve added this to the |
Thanks for the update @dvschultz! |
Hello 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
The text was updated successfully, but these errors were encountered: