/VAE-Tensorflow

Variational Autoencoder Tensorflow Implementation

Primary LanguagePython

Variational Auto-Encoder (VAE) Tensorflow

An implementation of variational auto-encoder (VAE) for MNIST and FreyFace descripbed in the paper: Auto-Encoding Variational Bayes, ICLR2014 by Kingma et al.

Requirements

  • tensorflow 1.10.0
  • python 3.5.5
  • numpy 1.14.2
  • matplotlib 2.2.2
  • scipy 0.19.1
  • pillow 5.0.0

Applied VAE Structure

Results

1. MNIST Reconstruction

  • 2-D latent space

  • 5-D latent space

  • 10-D latent space

  • 20-D latent space

2. Frey Face Reconstruction

  • 2-D latent space

  • 5-D latent space

  • 10-D latent space

  • 20-D latent space

3. MNIST Denoising

  • 2-D latent space

  • 5-D latent space

  • 10-D latent space

  • 20-D latent space

4. Learned MNIST Manifold and Distribution of Labeled Data

5. Learned Frey Face Manifold

Documentation

Download Dataset

Download 'FreyFace' dataset from the link that mentioned in the VAE paper. 'MNIST' dataset can be downloaded automatically from the code.

Directory Hierarchy

.
│   VAE
│   ├── src
│   │   ├── dataset.py
│   │   ├── vae.py
│   │   ├── main.py
│   │   ├── solver.py
│   │   ├── tensorflow_utils.py
│   │   └── utils.py
│   Data
│   ├── mnist
│   └── freyface

src: source codes of the VAE

Training VAE

Use main.py to train a VAE network. Example usage:

python main.py
  • gpu_index: gpu index, default: 0

  • batch_size: batch size for one feed forward, default: 128

  • dataset: dataset name from [mnist, freyface], default: mnist

  • is_train: training or inference mode, default: True

  • add_noise: boolean for adding salt & pepper nooise to input image, default: False

  • learning_rate: initial learning rate for Adam, default: 0.001

  • z_dim: dimension of z vector, default: 20

  • iters: number of interations, default: 20000

  • print_freq: print frequency for loss, default: 100

  • save_freq: save frequency for model, default: 5000

  • sample_freq: sample frequency for saving image, default: 500

  • sample_batch: number of sampling images for check generator quality, default: 100

  • load_model: folder of save model that you wish to test, (e.g. 20181107-2106_False_20). default: None

Test VAE

Use main.py to test a VAE network. Example usage:

python main.py --is_train=false --load_model=folder/you/wish/to/test/e.g./20181107-2106_False_20

Please refer to the above arguments.

Citation

  @misc{chengbinjin2018vae,
    author = {Cheng-Bin Jin},
    title = {VAE-Tensorflow},
    year = {2018},
    howpublished = {\url{https://github.com/ChengBinJin/VAE-Tensorflow},
    note = {commit xxxxxxx}
  }

Attributions/Thanks

License

Copyright (c) 2018 Cheng-Bin Jin. Contact me for commercial use (or rather any use that is not academic research) (email: sbkim0407@gmail.com). Free for research use, as long as proper attribution is given and this copyright notice is retained.