liveBook · Manning

Visual encoder

As explained in Build a Text-to-Image Generator (from Scratch)

An image encoder is a neural-network component that maps an image to a numerical representation.

A visual encoder is a neural-network component that converts an image into a numerical image embedding. In CLIP, it produces embeddings with the same dimension as text embeddings, allowing images and descriptions to be compared. section 8.5

A visual encoder participates in two related pipelines:

  • CLIP encodes paired images and captions, then uses contrastive learning to increase similarity for matching pairs and decrease it for nonmatching pairs. section 8.5
  • Latent diffusion applies the CLIP image encoder to low-resolution latent images, helping align generated images with text embeddings while a U-Net denoises them. section 9.1.2

Image selection by text

After training, compare a text embedding with image embeddings using cosine similarity to select the image in a dataset that best matches a description. section 8.5

Figure 9.3 How a trained LDM generates an image based on a text prompt. The text prompt shown at the top-left corner is first encoded into a text embedding. To generate an image in the lower-dimensional space (latent space), we start with an image of pure noise (bottom left). We use the trained U-Net to iteratively denoise the image, conditional on the text embedding so the generated image matches the text prompt, with the guidance of a trained CLIP model. The generated latent image (bottom right) is presented to a trained VAE to convert it to a high-resolution image, which is the final output (top right).

Trace the encoder's role in text-to-image generation: latent noise is denoised conditionally, then a VAE converts the generated latent image into a high-resolution image. section 9.1.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Traces embeddings, contrastive losses, and latent-image conditioning, but does not specify the encoder's internal neural-network layers.
Examples
Uses image selection from Flickr 8k and latent diffusion examples involving text-guided image generation and modification.
What it assumes
Assumes images, captions, embeddings, cosine similarity, and paired versus nonmatching examples; introduces their roles within CLIP.
What you can do after
Apply it via CLIP to compare images and text or guide latent diffusion toward text-matching generated images.
How it connects
Connects visual encoders to CLIP, text encoders, image embeddings, contrastive learning, variational autoencoders, latent diffusion, and U-Nets.

Also explained in

Compare how 4 books explain visual encoder →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.