liveBook · Manning

Convolutional layer

As explained in Deep Learning with Python, Third Edition

A two-dimensional convolution layer used here with a 1×1 kernel to project a residual to a matching shape.

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

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains patch-wise transformation and feature-map dimensions, contrasting convolution with Dense layers and max pooling.
Examples
Uses MNIST digit classification and dogs-versus-cats classification to show Conv2D stacks.
What it assumes
Builds on familiarity with Dense-based classification while explaining image tensors and feature-map axes.
What you can do after
Apply it via Keras Conv2D to assemble an image classifier and inspect changing feature-map shapes.
How it connects
Links convolutional layers to feature maps, Dense layers, max pooling, and residual connections.

Also explained in

Compare how 14 books explain convolutional layer →

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.