Skip to content

Generate MNIST hand-written numbers with VAE, DCGAN and RealNVP

License

Notifications You must be signed in to change notification settings

zhongyuchen/generative-models

Repository files navigation

generative-models

Train with MNIST and generate hand-written numbers with generative models including VAE, DCGAN and RealNVP.

Generative Models

The following generative models are included, with configs in config.ini:

  • VAE (Variational Auto-Encoder) in vae.py
  • DCGAN (Deep Convolutional Generative Adversarial Networks) in dcgan.py
  • RealNVP (Real-valued Non-Volume Preserving) in realnvp.py

Prerequisites

  • Install the required packages by:
pip install -r requirements.txt

Data: MNIST

  • Sample

sample

  • Dataset
MNIST Train Dev Test
Amount 48000 12000 10000

VAE

Model

vae

Command Line

  • Run
bash run_vae.sh
  • Log with Tensorboard
tensorboard --logdir=log/vae/

Loss

Train Batch Loss Train Epoch Loss
vae_train_batch_loss vae_train_epoch_loss
Dev Loss with best epoch 62 Test Loss
vae_dev_epoch_loss 102.0952

Reconstructed Result

Epoch 1 Epoch 10 Epoch 20
rec_1 rec_10 rec_20
Epoch 30 Epoch 40 Epoch 50
rec_30 rec_40 rec_50
Epoch 64 Test Result
rec_64 rec_test

Generated Result

Epoch 1 Epoch 10 Epoch 20
sam_1 sam_10 sam_20
Epoch 30 Epoch 40 Epoch 50
sam_30 sam_40 sam_50
Epoch 64
sam_64

Reference

Auto-Encoding Variational Bayes

Link

VAE in pytorch/examples

DCGAN

Model

Generator(
  (main): Sequential(
    (0): ConvTranspose2d(100, 512, kernel_size=(4, 4), stride=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace)
    (3): ConvTranspose2d(512, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (4): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (5): ReLU(inplace)
    (6): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (7): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (8): ReLU(inplace)
    (9): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (10): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (11): ReLU(inplace)
    (12): ConvTranspose2d(64, 1, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (13): Tanh()
  )
)
Discriminator(
  (main): Sequential(
    (0): Conv2d(1, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): LeakyReLU(negative_slope=0.2, inplace)
    (2): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (3): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (4): LeakyReLU(negative_slope=0.2, inplace)
    (5): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (6): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (7): LeakyReLU(negative_slope=0.2, inplace)
    (8): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (9): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (10): LeakyReLU(negative_slope=0.2, inplace)
    (11): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), bias=False)
    (12): Sigmoid()
  )
)

Command Line

  • Run
bash run_dcgan.sh
  • Log with Tensorboard
tensorboard --logdir=log/dcgan/

Generated Result

Epoch 1 Epoch 10 Epoch 20
fake_1 fake_10 fake_20
Epoch 30 Epoch 40 Epoch 50
fake_30 fake_40 fake_54
Epoch 64
fake_64

Reference

Link

DCGAN in pytorch/examples

RealNVP

Command Line

  • Run
bash run_realnvp.sh
  • Log with Tensorboard
tensorboard --logdir=log/realnvp/

Reference

Density Estimation using Real NVP

Link

Related Lectures

Author

Zhongyu Chen

About

Generate MNIST hand-written numbers with VAE, DCGAN and RealNVP

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published