liveBook · Manning

Decode

As explained in Deep Learning with Python, Third Edition

The part of an autoencoder or variational autoencoder that maps a latent representation back into an output space such as images.

An image encoder turns an image into a latent representation; decoding takes that representation back into image space. In a classical autoencoder, the decoder produces an output with the same dimensions as the input, and training uses the input image as the reconstruction target. The practical question is whether the latent representation retains enough information to make that reconstruction useful. section 17.1.2

A variational autoencoder (VAE) changes what reaches the decoder. Its encoder produces a mean and variance rather than one fixed code. A sampling step draws a latent point from the resulting distribution, and the decoder turns that point into an image. This arrangement supports a continuous, structured latent space that can be sampled for image generation. section 17.1.2 section 17.1.3

Decode an MNIST digit

A Keras VAE uses a two-dimensional latent point as decoder input. A Dense layer expands it to 7 × 7 × 64 values, Reshape makes those values image-shaped, and two Conv2DTranspose layers enlarge the feature maps. A final Conv2D layer with sigmoid activation produces an image matching the 28 × 28 × 1 input shape. After training, passing points from a two-dimensional grid to vae.decoder.predict produces a grid of digit images. This makes the latent space visible: nearby sampled points can be compared through their decoded outputs. section 17.1.3

Listing 17.3 VAE decoder network, mapping latent space points to images
latent_inputs = keras.Input(shape=(latent_dim,))                      #1
x = layers.Dense(7 * 7 * 64, activation="relu")(latent_inputs)        #2
x = layers.Reshape((7, 7, 64))(x)                                     #3
x = layers.Conv2DTranspose(64, 3, activation="relu", strides=2, padding="same")(
    x                                                                 #4
)                                                                      #4
x = layers.Conv2DTranspose(32, 3, activation="relu", strides=2, padding="same")( #4
    x                                                                  #4
)                                                                      #4
decoder_outputs = layers.Conv2D(1, 3, activation="sigmoid", padding="same")(x) #5
decoder = keras.Model(latent_inputs, decoder_outputs, name="decoder")

The decoder listing shows the concrete path from a latent vector through Dense, Reshape, and convolutional layers to an image output. section 17.1.3

Rule of thumb: distinguish reconstructing an encoded image from generating an image at a chosen latent point. The same decoder handles both; the source of its latent input changes. “Decoder” also appears in sequence-to-sequence models, but there it predicts target tokens from earlier target tokens and an encoded source sequence. A decoder-only language model removes that separate encoder and generates from a single sequence instead. section 17.1.2 section 17.1.3 section 15.2 section 16.2.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Works through a Keras decoder architecture, VAE sampling, training, and a latent-space grid rather than stopping at a definition.
Examples
Uses an MNIST digit VAE and a grid of two-dimensional latent points decoded into images.
What it assumes
Introduces autoencoders through image reconstruction while drawing on Keras convolution layers and previously established custom-training workflows.
What you can do after
Build it from scratch in Keras to reconstruct MNIST digits and generate images from sampled latent points.
How it connects
Links decoding to autoencoders, variational autoencoders, latent spaces, reconstruction, and image generation; distinguishes sequence-to-sequence token decoding.

Also explained in

Compare how 15 books explain decode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.