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
