liveBook · Manning

Latent dimension

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

A latent dimension is one coordinate in the lower-dimensional representation produced by an encoder.

A latent dimension is one coordinate in the compact representation produced by an encoder. In the VAE implementation, latent_dim = 2 makes the representation two-dimensional, with the encoder producing mean and variance values for sampling. section 8.5.2

After convolutional features are flattened, Dense layers map them to z_mean and z_log_var, while a sampling layer uses latent_dim to define the sampled vector’s shape. section 8.5.2

Two-dimensional VAE manifold

Set latent_dim to 2, sample points across a coordinate grid, and pass each two-value vector to the decoder to generate a manifold of images.

Listing 8.23 EDL_8_5_VAE.ipynb: Building latent sampling
x = Flatten()(x)                                    #1
x = Dense(16, activation='relu')(x)    
z_mean = Dense(latent_dim, name='z_mean')(x)        #2
z_log_var = Dense(latent_dim, name='z_log_var')(x)  #2
 
z = Lambda(
    sampling, 
    output_shape=(latent_dim,), 
    name='z')([z_mean, z_log_var])                  #3
 
encoder = Model(inputs, [z_mean, z_log_var, z], 
 name='encoder')                                  #4
encoder.summary()

Inspect how latent_dim determines the output shapes of z_mean, z_log_var, and the sampled z vector. section 8.5.2

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Explains shape construction through Dense and sampling layers, but does not develop a general method for selecting dimensionality.
Examples
Demonstrates two dimensions through latent_dim = 2 and a grid of sampled vectors decoded into manifold images.
What you can do after
Build it from scratch by configuring latent_dim, producing sampled latent vectors, and decoding coordinate grids into images.
How it connects
Connects latent dimensions with encoders, variational autoencoders, decoders, sampling layers, means, and variances.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.