Skip to content

StyleGAN Encoder - converts real images to latent space

License

Notifications You must be signed in to change notification settings

maxisawesome/stylegan-encoder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StyleGAN — Encoder for Official TensorFlow Implementation

Python 3.6 TensorFlow 1.10 cuDNN 7.3.1 License CC BY-NC

Welcome to KUNGFU.AI's 2019 SXSW StyleGAN demo. First off much thanks to Dmitry Nikitko (Puzer) from whom we forked the repo. Our demo is mostly focused in the jupyter notebook "StyleGAN demo.ipynb." You might need to edit "aei.py" and point it to the correct directory. Latent codes for a few celebrities along with some supremely handsome KUNGFU.AI employees can be found in /latent_codes (shocker), and the previews of them can be seen in img_gen. If you have questions, concerns, criticisms, or jokes, please open a pull request or issue! Even just adding latent codes would be very welcomed.

The following text is Puzer's README explaining latent code recovery.

Teaser image

These people are real – latent representation of them was found by using perceptual loss trick. Then this representations were moved along "smiling direction" and transformed back into images

Short explanation of encoding approach: 0) Original pre-trained StyleGAN generator is used for generating images

  1. Pre-trained VGG16 network is used for transforming a reference image and generated image into high-level features space
  2. Loss is calculated as a difference between them in the features space
  3. Optimization is performed only for latent representation which we want to obtain.
  4. Upon completion of optimization you are able to transform your latent vector as you wish. For example you can find a "smiling direction" in your latent space, move your latent vector in this direction and transform it back to image using the generator.

New scripts for finding your own directions will be realised soon. For now you can play with existing ones: smiling, age, gender. More examples you can find in the Jupyter notebook

Generating latent representation of your images

You can generate latent representations of your own images using two scripts:

  1. Extract and align faces from images

python align_images.py raw_images/ aligned_images/

  1. Find latent representation of aligned images

python encode_images.py aligned_images/ generated_images/ latent_representations/

  1. Then you can play with Jupyter notebook

Feel free to join the research. There is still much room for improvement:

  1. Better model for perceptual loss
  2. Is it possible to generate latent representations by using other model instead of direct optimization ? (WIP)

Stay tuned!

About

StyleGAN Encoder - converts real images to latent space

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 99.0%
  • Python 1.0%