liveBook · Manning

Feature vector

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

A feature vector is a numerical vector whose components encode properties of an input or intermediate representation.

A feature vector is a numerical vector whose components encode properties of an input or intermediate representation. In VQGAN, an encoder converts a 384 × 384 image into a 24 × 24 grid containing 576 feature vectors, each with 256 values. Each vector represents one spatial patch in the latent image. section 11.5.2

Feature vectors participate in a sequence of transformations:

  • The encoder applies four strided convolutional layers, reducing spatial resolution by a factor of 16 and producing the 24 × 24 latent grid. section 11.5.2
  • A codebook stores 1,024 learnable 256-dimensional vectors. Quantization replaces each continuous latent feature vector with its nearest codebook vector. section 11.5.2 section 11.3.2
  • The selected codebook position becomes an integer index, turning the 576 feature vectors into a sequence of 576 integers. section 11.5.2
  • Looking up those indices reconstructs the quantized latent representation, which the decoder uses to reconstruct the image. section 11.5.2

Inspecting and reconstructing latent vectors

For a cat image, encode the image and inspect a latent tensor with shape [1, 256, 24, 24]. Quantize its 576 vectors, obtain indices such as 873 and 862, then retrieve the corresponding codebook vectors and pass them through the decoder. Reconstructions from the quantized vectors and from the integer sequence can be compared directly. section 11.5.2 section 11.5

z=model.encoder(image1.to(device))
z=model.quant_conv(z) 
print(f"the shape of the latent representation is {z.shape}")

Inspect the encoder output directly to connect tensor dimensions with the number and size of feature vectors. section 11.5.2

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

How deep it goes
Explains dimensions, spatial layout, codebook matching, index conversion, and reconstruction, but not vector-training mathematics.
Examples
Uses a cat image, a 24 × 24 latent grid, 256-value vectors, 1,024 codebook entries, and integer indices such as 873 and 862.
What it assumes
Assumes familiarity with images, tensors, encoders, decoders, and latent representations while establishing feature-vector dimensions concretely.
What you can do after
Apply VQGAN to inspect latent feature vectors, convert them into codebook indices, and reconstruct an image from those indices.
How it connects
Connects feature vectors to latent representations, encoders, codebooks, quantization, decoders, VQ-VAE, and VQGAN.

Also explained in

Compare how 2 books explain feature vector →

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.