A convolutional layer learns patterns in small, local windows rather than across an entire image at once. Its input and output are feature maps with height, width, and channels. The same learned transformation is applied at each location, helping a ConvNet recognize a pattern wherever it appears. section 8.1.1
Start with a digit classifier
For a 28 × 28 grayscale digit, `layers.Conv2D(filters=64, kernel_size=3, activation="relu")` produces 64 output channels. Alternating Conv2D with MaxPooling2D builds features while reducing their spatial size; global average pooling and a Dense layer then produce class probabilities. section 8.1
Listing 8.1 Instantiating a small ConvNet
import keras from keras import layers inputs = keras.Input(shape=(28, 28, 1)) x = layers.Conv2D(filters=64, kernel_size=3, activation="relu")(inputs) x = layers.MaxPooling2D(pool_size=2)(x) x = layers.Conv2D(filters=128, kernel_size=3, activation="relu")(x) x = layers.MaxPooling2D(pool_size=2)(x) x = layers.Conv2D(filters=256, kernel_size=3, activation="relu")(x) x = layers.GlobalAveragePooling2D()(x) outputs = layers.Dense(10, activation="softmax")(x) model = keras.Model(inputs=inputs, outputs=outputs)
The complete MNIST model shows where convolutional layers sit relative to pooling and the classifier. section 8.1
Do not confuse convolution with max pooling. Convolution learns a transformation of each patch; max pooling takes a fixed maximum and commonly halves the feature map’s height and width. In a deeper image classifier, channel counts can rise as spatial dimensions fall. section 8.1.2 section 8.2.3
A 1 × 1-kernel Conv2D can instead serve as a projection when a residual needs a matching shape. Check the resulting feature-map dimensions before combining paths: a convolutional layer’s output channel count is configurable, while height and width are separate dimensions. section 8.1.1 section 9.0













