This is the repository for Streamlit’s FaceGAN demo, built on Shaobo Guan’s TL-GAN project for image synthesis of faces with controllable parameters like gender, age, baldness, skin tone, and smile.
Progressively Growing Generative Adversarial Networks (PG-GANs) are a cutting edge method for creating random synthetic images. Examples of amazingly realistic faces generated from a PG-GAN trained on celebrities can be seen in NVidia's PG-GAN demo. For each random vector in the generative network's latent space, it outputs a different face. Shaobo Guan's TL-GAN project uses automated face categorizers to identify directions in the latent space that correspond to desired modifications of the generated image, making it older, balder, more female, or dozens of other possible transformations. Streamlit gives us a rapidfire way to explore TL-GAN in an interactive web app. Using @st-cache with the hash_funcs variable, we can make sure that our TensorFlow session and trained GAN model are preserved each time the app re-runs, making for snappy, responsive execution even when we're hacking away at the code.
This demo requires a CUDA-compatible GPU and Python 3.6 (TensorFlow is not yet compatible with Python 3.7 or 3.8).
- Clone this repository:
git clone https://github.com/streamlit/streamlit_tl_gan_demo.git - Create a new Python 3.6 virtual environment using venv, virtualenv, pyenv, or conda
- From the project’s root directory, install dependencies:
pip install -r requirements.txt - Download Nvidia's pre-trained pg-GAN model and Shao Bo's pre-fitted feature model
- Decompress in the project's root directory:
tar xvzf asset_model.tar.gz; tar xzvf asset_results.tar.gz
-
From the project's root directory, type
streamlit run src/tl_gan/streamlit_tl_demo.py -
Your default web browser should pop up with an interactive app that will let you play with the model.
-
Have fun! Notice that faces you've seen before generate faster, thanks to Streamlit's handy built-in cache.
Generative Adversarial Networks, or GANs, are one of the most exciting recent developments in machine learning. In order for a generative neural network to learn how to generate random samples from a complicated distribution---for instance, photorealistic images of human faces---the network is pitted in competition against a discriminative network which gets better and better at distinguishing the generative network's fakes from the real thing. NVidia recently extended the GAN framework with Progressively-Growing GAN, or PG-GAN, training networks on very low-resolution images at first and then incrementally extending them to higher resolutions.