rosinality / stylegan2-pytorch

Implementation of Analyzing and Improving the Image Quality of StyleGAN (StyleGAN 2) in PyTorch
MIT License
2.74k stars 623 forks source link

Can I project the image to latent space in this model? #315

Open VincentWu1997 opened 2 years ago

VincentWu1997 commented 2 years ago

I want to project some images into latent spaces and use the latent space as input to generate new images. Can I finish this using the demo? Thanks!

JohnnyRacer commented 2 years ago

The projection results you get by directly projecting to the latent space is usually of poor quality and of low similarity to the source. If your use case is able to utilize the (18,512) shaped latents instead of the (1,512) then I'd recommend using this : https://github.com/omertov/encoder4editing. It gives significantly higher quality results than direct projection. Hope this is helpful.

sayakpaul commented 1 year ago

I don't see any treatment when the Z-space is used, though:

https://github.com/rosinality/stylegan2-pytorch/blob/bef283a1c24087da704d16c30abc8e36e63efa0e/ppl.py#L97

@rosinality could you comment?

RewindL commented 1 year ago

You can use pSp to train an image encoder that project image into stylegan2 Z+ latent space or W+ latent space.