A convolutional neural network (CNN) processes an image without first treating it as one long list of pixels. A fully connected network connects every neuron to every neuron in the preceding layer; for image classification, that can create many parameters while making it difficult to recognize an object in different positions. A CNN replaces some of those dense transformations with convolutions. section 8.0
A convolution applies a small kernel across an image. A hand-set kernel can blur an image or highlight vertical edges. In a CNN, training instead adjusts kernels to produce useful feature maps: successive layers turn a multichannel image into new channels representing learned features. section 8.2.2
Small kernels need help detecting larger patterns. Stacking convolutions lets later layers work with earlier features; pooling reduces the spatial size of feature maps between layers. For example, 2 × 2 max pooling keeps the largest value from each tile, changing a 32 × 32 image into a 16 × 16 feature map. section 8.2.3
Bird or airplane?
Start with a three-channel image. A convolution produces 16 channels, followed by Tanh and max pooling; a second convolution produces eight channels, followed by another Tanh and pooling. The resulting 8 × 8 feature maps must be flattened before fully connected layers can produce two classification outputs. Leaving out that reshape causes a matrix-shape error rather than a prediction. section 8.2.4
# In[23]:
model = nn.Sequential(
nn.Conv2d(3, 16, kernel_size=3, padding=1),
nn.Tanh(),
nn.MaxPool2d(2),
nn.Conv2d(16, 8, kernel_size=3, padding=1),
nn.Tanh(),
nn.MaxPool2d(2),
# ... #1
nn.Linear(8 * 8 * 8, 32),
nn.Tanh(),
nn.Linear(32, 2))
The PyTorch layer listing makes the two convolution-and-pooling stages and the final linear layers concrete. Its placeholder is important: flattening is still needed between them. section 8.2.4
The same broad architecture can be adapted beyond small 2D photographs. A first-pass tumor detector uses 3D input and a design built around repeated blocks, with additional changes for that task. section 13.4

















