liveBook · Manning

Label arithmetic

As explained in Learn Generative AI with PyTorch

A conditioning technique that forms an intermediate label by weighted averaging two labels to smoothly vary a generated attribute.

Label arithmetic forms intermediate conditioning labels by weighted averaging two labels. In a conditional GAN, these labels guide a generator between attributes, such as faces with and without eyeglasses, so the attribute changes gradually. section 5.0 section 5.6

It differs from vector arithmetic: label arithmetic changes the conditioning label, while vector arithmetic averages latent noise vectors. Combining both controls separate characteristics at once, such as eyeglasses and male-to-female facial features. section 5.0 section 5.5.3

Fading eyeglasses with interpolated labels

Create labels_g for eyeglasses and labels_ng for no eyeglasses. For weights 0, 0.25, 0.5, 0.75, and 1, compute label = w*labels_ng + (1-w)*labels_g. Concatenate each reshaped label with the same latent vector, pass it to the trained generator, and plot the five outputs. The glasses gradually fade as the weight moves toward the no-eyeglasses label. section 5.5.1

The same idea scales to a grid: interpolate the label across columns and the latent vector across rows. A 6×6 grid can therefore show eyeglasses fading horizontally while facial features change vertically. section 5.5.3

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains weighted-label interpolation through PyTorch code and visual output, while deferring label-training details.
Examples
Uses eyeglasses, male and female facial features, five-step interpolations, and a 6×6 image grid.
What it assumes
Assumes a trained cGAN, conditional labels, latent noise vectors, and generator inputs shaped for concatenation.
What you can do after
Apply it via PyTorch by averaging labels, concatenating them with latent noise, and generating an attribute-transition sequence.
How it connects
Connects conditional GANs with vector arithmetic, latent noise vectors, and independent attribute selection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.