Skip to content

a1302z/GenerativeModels

Repository files navigation

Playground project for generative models in PyTorch

In this project I want to implement and try several approaches on generating artificial data from scratch.

About data

As these are all Machine Learning models they learn from given data. We are using two different datasets until now. MNIST and CelebA. However, it is straightforward to extend implementation to other datasets.

1. Autoencoders

Architecture details

Autoencoder architecture is fully described by a set of parameters:

  • base_channels: Number of channels after first convolution
  • conv_blocks_per_decrease: Convolutions in each downsizing module
  • channel_increase_factor: Factor by which channels increase after each downsizing module
  • encode_factor: Number of downsizing modules
  • latent_dim: Dimension of encoding vector
  • initial_upsample_size: Start resolution in decoder
  • skip_connections: Use ResNet like skip connections in downsizing modules
  • auxillary: Allow encoder to also learn class labels (makes training easier)

For a more exact description see configs folder

A model summary can be retrieved by running python -m models.Autoencoder -h. Note: parameters in summary are currently hardcoded.

Convolutional model with linear hidden dimension

Autoencoder, that encodes to a n-dimensional linear feature vector. n is dependent on architecture parameters. Standard is 128.


Reconstructions results for standard Autoencoder (128 dimensions)
Linear autoencoder result
MNIST

t-SNE representation of hidden space

To see how well the model is seperating classes, we sample from the test set and visualize their hidden represention using t-SNE. We use MNIST as we have class labels.
TSNE of hidden representation for linear autoencoder on MNIST

Variational Autoencoders (VAE)

Variational autoencoders similarily to Autoencoders trying to find a good hidden encoding for reconstruction of input data. However, they encode to a mean and variance, where the minimization of KL-divergence to a standard normal distribution is part of optimization objective. Thus artificial data can be generated by sampling from a standard normal distribution and decode these.
Reconstruction of given test samples

Reconstructed samples VAE MNIST
MNIST

Randomly generated artificial samples

Artificial MNIST

Reconstructed samples from linear grid in two dimensions
VAE generated samples MNIST

2. Generative Adverserial Networks (GANs)

Vanilla GAN

Original GANs (Goodfellow et al) that are based upon linear layers in generator and discriminator. MNIST_Vanilla_result

DC GAN

Concept of GANs that utilize convolutional layers in generator and discriminator. MNIST_DCGAN_result

Auxillary GAN

DC GAN but labels of dataset are used as generator input and discriminator output. MNIST_AUX_DCGAN_result

About

Playground for generative pytorch models.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published