liveBook · Manning

Digital image

As explained in Deep Learning with Python, Third Edition

Data in which each example is a 2D image with one or more color channels, typically stored as a rank-3 tensor per sample.

A digital image is a 2D grid of pixels. Each pixel holds a vector of channel values. Keeping the grid intact makes one image a rank-3 tensor with axes for height, width, and channels; a batch adds a samples axis, giving shape (samples, height, width, channels). section 2.2.8

When the grid is flattened

For a Dense-layer digit classifier, each 28 × 28 image is reshaped into 784 values. The resulting training and test arrays have shapes (60000, 784) and (10000, 784). Converting them to float32 and dividing by 255 prepares the values used by the model. These are still images as input examples, but their tensor shape no longer preserves separate height and width axes. section 2.5

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype("float32") / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype("float32") / 255

The reshape and scaling code shows how image examples become two-dimensional sample-by-feature arrays. section 2.5

An image’s channel values are also a representation choice. RGB and HSV encode the same color image differently: selecting red pixels is simpler in RGB, while reducing saturation is simpler in HSV. For a pretrained image model, apply its model-specific preprocessing so input values match the range used during pretraining. section 1.4 section 10.2

Images need not be fixed inputs. To inspect a convolutional filter, start with a blank image and adjust its values to increase that filter’s activation. The resulting image displays a pattern the filter responds to. section 10.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines image tensor axes and demonstrates flattening and scaling, without detailing image-file storage.
Examples
Uses flattened handwritten-digit images, RGB versus HSV color encoding, and blank images optimized to activate filters.
What you can do after
Apply image reshaping and scaling in a NumPy and Keras workflow, and understand why pretrained models need matching preprocessing.
How it connects
Connects images to tensors, color representations, Dense layers, convolutional filters, and model-specific preprocessing.

Also explained in

Compare how 16 books explain digital image →

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.