liveBook · Manning

Grayscale image

As explained in Learn Generative AI with PyTorch

Images represented only by intensity values rather than color channels, used here as a simpler target for generation.

A grayscale image represents visual content with intensity values in one channel rather than separate red, green, and blue channels. A 28 × 28 image therefore contains 784 pixel values, making it a compact target for classification and generation. Grayscale clothing images support tasks such as recognizing coats, bags, sneakers, and shirts, while handwritten grayscale digits support autoencoder training. section 2.0 section 2.2.2 section 7.2.1

Working with grayscale images typically involves these steps:

  • Convert pixel integers from 0–255 into PyTorch floating-point tensors from 0.0 to 1.0 with ToTensor(). section 2.2.2
  • Normalize the single channel, often with mean 0.5 and standard deviation 0.5, producing values from –1 to 1 for more efficient gradient descent. section 2.2.2
  • Flatten or reshape the 784 values as required: classifiers and dense GANs can use vectors, while visualization restores the 28 × 28 layout. section 4.1.2 section 2.2.2
  • Use convolutional networks when moving beyond simple grayscale generation toward high-resolution color images. section 4.6

Generating a 28 × 28 clothing image

A GAN generator can begin with a 100-value random noise vector and pass it through reversed dense layers to produce 784 values. Reshaping the result gives a 28 × 28 grayscale clothing image. With Tanh activation, the generated values lie between –1 and 1, matching normalized training data. section 4.1.2

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains one-channel structure, 784-pixel dimensions, preprocessing, visualization, and dense GAN generation, while deferring high-resolution image modeling to CNNs.
Examples
Uses Fashion-MNIST clothing items, MNIST handwritten digits, 28 × 28 layouts, and a 784-output GAN generator.
What it assumes
Assumes basic PyTorch tensors and neural networks while teaching single-channel data conversion, normalization, and image dimensions explicitly.
What you can do after
Apply via PyTorch and Torchvision by loading, normalizing, reshaping, visualizing, classifying, or generating grayscale images.
How it connects
Connects grayscale images with PyTorch tensors, normalization, Fashion-MNIST, MNIST, GANs, autoencoders, and convolutional neural networks.

Also explained in

Compare how 3 books explain grayscale image →

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.