Skip to content

Enhances faces on images and automatically beautifies them using StyleGan2 and latent space exploration

License

Notifications You must be signed in to change notification settings

ju-leon/RetouchML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RetouchML — Beautify faces on images using StyleGan2

Python 3.6 TensorFlow 1.15 cuDNN 10.0 License CC BY-NC

Beautify images using StyleGan2.

Faces on images are recognized, normalised and converted into the corrensponding StyleGan2 Vector.

Afterwards, the vector will be optimized to "beautify" the face.

The face is then stiched back into the original image.

Before/After examples:

All after images were generated entirely without human input.

merkel-ba

© Raimond Spekking / CC BY-SA 4.0​

pexel-ba

couco-ba

© Gage Skidmore / CC BY-SA 3.0

Manual Editing

Latent space representations allow for manual changes to the output image.

manual

How does it work?

process

1. Latent space encoding

First, the image is encoded into latent space. A latent vector is found that closely represents out input image. The encoder used is based on StyleGan2 Encoder.

2. Latent vector optimisation

Now to the fun part. Using a neural network that judges attractiveness of latent vectors, that face is optimized by the neural network.

Using a gradient ascent approach, the latent vector is slightly changed in the direction of steepest ascent, meaning we "make our face pretty".

We'll get a new latent vector that generates a "prettier" version of the original face.

3. Generate output image

The new latent vector is now converted back into an image by StyleGan2. The generated image is then stiched back into the original image.

Want to try it for yourself?

Clone the Repo(it needs an Nvidia GPU with Cuda and Tensorflow) or use Google Colab. To get started follow Beautify.ipynb

Releases

No releases published

Packages

No packages published