MACHINE LEARNING / FIELD GUIDEclear concepts / practical steps
Back to ML guides

FIELD GUIDE 03

CNN layers,
made visible.

Follow an image from pixels through feature maps to class scores.

In one lineLocal patterns → feature maps → scores
EXPLAIN / ML / 03
pixels▦filters→features→scores
concept → example → check
Updated September 23, 2026Beginner-first / source-linked / no hype

01 01 / Start with shape

A CNN moves
small filters.

A convolutional neural network (CNN) processes local image patterns with learned filters. Tensor dimensions help make each layer’s job concrete.

One image as a tensor

An image batch is commonly represented as batch × channels × height × width. One grayscale 28 × 28 image has shape 1 × 1 × 28 × 28: one image, one channel, 28 rows and columns.

input
1 × 28 × 28
→feature maps
8 × 28 × 28
→smaller maps
8 × 14 × 14

Channel-first layout and exact dimension rules are documented in PyTorch’s Conv2d reference. Padding, stride and kernel size determine the output shape.

02 02 / Each layer has a job

Convolution, activation,
pooling, classifier.

A common teaching network repeats feature extraction before turning the resulting maps into class scores. This is one pattern, not a universal recipe.

Convolutional neural network layers explained

  1. 01 / convolutionApply learned filters.

    A small kernel slides over local neighborhoods. Each filter produces a feature map; early maps may respond to edges or simple contrasts.

  2. 02 / activationAdd a non-linear step.

    ReLU or another activation changes the values so stacked layers can model more than a single linear mapping.

  3. 03 / poolingReduce spatial size when useful.

    Max pooling summarizes local regions and reduces height and width. Pooling is optional; strided convolutions or other designs may replace it. See PyTorch’s MaxPool2d documentation.

  4. 04 / headTurn features into scores.

    Flatten or pool the feature maps, then use a linear layer to produce one score per class. A loss compares scores with labels during training.

03 03 / Follow the dimensions

A toy 28-pixel
walkthrough.

With padding that preserves spatial size before each 2 × 2 pool, this example produces a manageable feature tensor.

Track one simple network

LayerOutput per imageWhat changed?
Input1 × 28 × 28Grayscale pixels
Conv2d(1, 8, 3, padding=1) + ReLU8 × 28 × 28Eight learned maps
MaxPool2d(2)8 × 14 × 14Half the height and width
Conv2d(8, 16, 3, padding=1) + ReLU16 × 14 × 14Sixteen maps with richer combinations
MaxPool2d(2)16 × 7 × 7Compact spatial maps
Flatten78416 × 7 × 7 values per image
Linear(784, 10)10One logit per class

In PyTorch, Flatten reshapes each example’s feature maps into a vector. The classifier outputs logits; a training loss such as cross-entropy consumes logits and target labels. The official CIFAR-10 tutorial shows one end-to-end example.

FAQ Machine learning / quick answers

Questions,
answered.

Short explanations with the limits left visible.

· informational guide

01 / answerWhat are the main convolutional neural network layers?

A common CNN includes convolution layers, nonlinear activations, optional pooling or strided downsampling, and a classification head. Normalization and dropout may also appear, depending on the design.

02 / answerDoes every CNN need pooling?

No. Pooling is one way to reduce spatial dimensions. Some models use strided convolutions or keep a different resolution schedule.

03 / answerWhat does flatten do in a CNN?

Flatten turns the spatial feature maps into a vector for a later dense layer. Global average pooling is another option that can reduce each map to one value.

04 / answerAre these CNN dimensions fixed?

No. The shapes depend on input size, channels, kernel size, padding, stride and pooling choices. The walkthrough uses one deliberately small example.

↗keep exploring

More explainAI
field guides.