MNIST VAE

class deepobs.mnist.mnist_vae.set_up(batch_size=64, n_latent=8, weight_decay=None)[source]

Class providing the functionality for a Variational Autoencoder (VAE) adapted from here on MNIST.

Parameters:
  • batch_size (int) -- Batch size of the data points. Defaults to 64.
  • n_latent (int) -- Size of the latent space of the encoder. Defaults to 8.
  • weight_decay (float) -- Weight decay factor. In this model there is no weight decay implemented. Defaults to None.
data_loading

Data loading class for MNIST, mnist_input.data_loading.

Type:deepobs.data_loading
losses

Tensor of size batch_size containing the individual losses per data point.

Type:tf.Tensor
accuracy

Tensor containing the accuracy of the model. As there is no accuracy when the loss function is given directly, we set it to 0.

Type:tf.Tensor
train_init_op

A TensorFlow operation to be performed before starting every training epoch.

Type:tf.Operation
train_eval_init_op

A TensorFlow operation to be performed before starting every training eval epoch.

Type:tf.Operation
test_init_op

A TensorFlow operation to be performed before starting every test evaluation phase.

Type:tf.Operation
decoder(sampled_z, phase, n_latent)[source]

The decoder for the VAE. It uses two dense layers, followed by three deconvolutional layers (each with dropout= 0.8) a final dense layer. The dense layers use the leaky ReLU activation (except the last one, which uses softmax), while the deconvolutional ones use regular ReLU.

Parameters:
  • sampled_z (tf.Variable) -- Sampled z from the encoder of the size n_latent.
  • phase (tf.Variable) -- Phase variable, determining if we are in training or evaluation mode.
  • n_latent (int) -- Size of the latent space of the encoder. Defaults to 8.
Returns:

A tensor of the same size as the original images (28 by 28).

Return type:

tf.Variable

encoder(X, phase, n_latent)[source]

Encoder of the VAE. It consists of three convolutional and one dense layers. The convolutional layers use the leaky ReLU activation function. After each convolutional layer dropout is appleid with a keep probability of 0.8.

Parameters:
  • X (tf.Variable) -- Input to the encoder.
  • phase (tf.Variable) -- Phase variable, determining if we are in training or evaluation mode.
  • n_latent (int) -- Size of the latent space of the encoder. Defaults to 8.
Returns:

Output of the encoder, z, the mean and the standard deviation.

Return type:

tupel

generate(sess, sampled_z=None)[source]

Function to generate images using the decoder. Images are ploted directly.

Parameters:
  • sess (tf.Session) -- A TensorFlow session.
  • sampled_z (tf.Variable) -- Sampled z with dimensions latent size times number of examples. Defaults to None which uses five randomly sampled z from a normal with stddev = 1.0.
get()[source]

Returns the losses and the accuray of the model.

Returns:Tupel consisting of the losses and the accuracy.
Return type:tupel
lrelu(x, alpha=0.3)[source]

Leaky ReLU activation function.

Parameters:
  • x (tf.Variable) -- Input to the activation function.
  • alpha (float) -- Factor of the leaky ReLU. Defines how leaky it is. Defauylts to 0.3.
Returns:

Output after the activation function.

Return type:

tf.Variable

set_up(weight_decay=None, n_latent=8)[source]

Sets up the test problem.

Parameters:
  • weight_decay (float) -- Weight decay factor. In this model there is no weight decay implemented. Defaults to None.
  • n_latent (int) -- Size of the latent space of the encoder. Defaults to 8.
Returns:

Tupel consisting of the losses and the accuracy.

Return type:

tupel