Home

Awesome

Adversarial autoencoders

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/nw_architecture.png" alt="Cover"/>

This repository contains code to implement adversarial autoencoder using Tensorflow.

Medium posts:

  1. A Wizard's guide to Adversarial Autoencoders: Part 1. Autoencoders?

  2. A Wizard's guide to Adversarial Autoencoders: Part 2. Exploring the latent space with Adversarial Autoencoders.

  3. A Wizard's guide to Adversarial Autoencoders: Part 3. Disentanglement of style and content.

  4. A Wizard's guide to Adversarial Autoencoders: Part 4. Classify MNIST using 1000 labels.

Installing the dependencies

Install virtualenv and creating a new virtual environment:

pip install virtualenv
virtualenv -p /usr/bin/python3 aa

Install dependencies

pip3 install -r requirements.txt

Note:

Dataset

The MNIST dataset will be downloaded automatically and will be made available in ./Data directory.

Training!

Autoencoder:

Architecture:

To train a basic autoencoder run:

    python3 autoencoder.py --train True

To load the trained model and generate images passing inputs to the decoder run:

    python3 autoencoder.py --train False

Adversarial Autoencoder:

Architecture:

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/AAE%20Block%20Diagram.png" alt="Cover"/>

Training:

    python3 adversarial_autoencoder.py --train True

Load model and explore the latent space:

    python3 adversarial_autoencoder.py --train False

Example of adversarial autoencoder output when the encoder is constrained to have a stddev of 5.

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/AAE%20dist%20match.png" alt="Cover"/>

Matching prior and posterior distributions.

Adversarial_autoencoder Distribution of digits in the latent space.

Supervised Adversarial Autoencoder:

Architecture:

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/Supervised%20AAE.png" alt="Cover"/>

Training:

    python3 supervised_adversarial_autoencoder.py --train True

Load model and explore the latent space:

    python3 supervised_adversarial_autoencoder.py --train False

Example of disentanglement of style and content: <img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/disentanglement%20of%20style%20and%20content.png" alt="Cover"/>

Semi-Supervised Adversarial Autoencoder:

Architecture:

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/semi_AAE%20architecture.png" alt="Cover"/>

Training:

    python3 semi_supervised_adversarial_autoencoder.py --train True

Load model and explore the latent space:

    python3 semi_supervised_adversarial_autoencoder.py --train False

Classification accuracy for 1000 labeled images:

<img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/semi_aae_accuracy_with_NN.png" alt="Cover"/> <img src="https://raw.githubusercontent.com/Naresh1318/Adversarial_Autoencoder/master/README/cat_n_gauss_dist_real_obtained.png" alt="Cover"/>

Note:

Thank You

Please share this repo if you find it helpful.