Skip to main content

Image Classification and CNN Feature Maps

Follow an image through convolution, ReLU, pooling and class scores. Inspect a transparent toy CNN and learn what classification can and cannot predict.

Image classification assigns an image-level label, such as a scene category or the main object type. A convolutional classifier first builds spatial features, then combines their evidence into class scores. That final compression is useful when location is irrelevant, but it cannot by itself tell you where each object is.

Inspect the whole forward pass

The example below recognizes three synthetic patterns. Every filter and classifier weight is authored, so the computation can be inspected without downloading a model. Choose a shape and shift it. Watch the response maps move while the pooled evidence often stays unchanged.

From spatial responses to one image label
Input shape
0 px

Vertical filter weights

-12-1-12-1-12-1

Horizontal filter weights

-1-1-1222-1-1-1
Input · 7 × 7

7 rows, 7 columns. Values range from 0 to 1. Open numeric values to inspect each row and column.

Numeric values
Input · 7 × 7: rows and columns start at 0; values rounded to four decimals.
Row / column0123456
00001000
10001000
20001000
30001000
40001000
50001000
60001000
Vertical response + ReLU

5 rows, 5 columns. Values range from 0 to 6. Open numeric values to inspect each row and column.

Numeric values
Vertical response + ReLU: rows and columns start at 0; values rounded to four decimals.
Row / column01234
000600
100600
200600
300600
400600
Horizontal response + ReLU

5 rows, 5 columns. Every pixel is 0. Open numeric values to inspect each row and column.

Numeric values
Horizontal response + ReLU: rows and columns start at 0; values rounded to four decimals.
Row / column01234
000000
100000
200000
300000
400000
Max pooled (v, h)
6, 0
Vertical
score 6.0 → 99.3%
Horizontal
score -6.0 → 0.0%
Cross
score 1.0 → 0.7%

Calculated toy classifier with authored filters and weights, not a trained CNN. Scores come from pooled responses; softmax turns them into a distribution over these three labels. These percentages are not measured accuracy or calibrated certainty.

The vertical filter rewards a bright center column with darker neighbors. The horizontal filter is its transpose. Each 3 × 3 filter slides over the 7 × 7 input, producing a 5 × 5 response map. ReLU replaces negative responses with zero; it does not rescale the positive ones.

For a vertical line through the middle of a patch, each kernel row contributes 2, giving a response of 6. A flat patch contributes zero because the positive and negative weights cancel. These values come from the displayed pattern and the authored filter, not measured recognition performance.

Feature maps preserve where evidence occurs

A feature map contains a response at each valid spatial location. Multiple filters produce multiple output channels. An RGB input has three color channels; a deeper layer might have dozens of learned feature channels whose meanings are not color components.

CNNs reuse weights across image locations. Nonlinearities and stacked layers combine local responses into more complex functions, while the receptive field determines which input locations can influence a feature. Pooling or strided layers reduce spatial resolution. Stanford CS231n: convolutional networks

The toy model takes the maximum response in each map, giving two values, vv and hh. This global max operation keeps the strongest evidence and discards its location. It illustrates why translating a pattern can preserve the class score, but it does not prove translation invariance for arbitrary CNNs: borders, sampling, padding, and the chosen architecture all matter.

Scores are not yet probabilities

The authored classification head computes three logits:

zvertical=v−h,zhorizontal=h−v,zcross=v+h2−2z_{\text{vertical}} = v-h, \quad z_{\text{horizontal}} = h-v, \quad z_{\text{cross}} = \frac{v+h}{2}-2

Softmax converts these scores into a distribution over the three mutually exclusive labels:

pk=ezk∑jezjp_k = \frac{e^{z_k}}{\sum_j e^{z_j}}

Increasing one score changes every probability because they share a denominator. A high softmax value means the model favors that class relative to its alternatives. It does not establish calibrated certainty, especially for inputs outside the model's training distribution.

For a real classifier, training adjusts filters and head weights using labeled examples and an objective such as cross-entropy. The demo performs no optimization and has no held-out test set. Its percentages describe its forward computation only.

Choose the output that matches the question

Single-label classification chooses one class. Multi-label classification can assign several independent labels to one image and commonly uses per-class sigmoid outputs instead. Neither output identifies individual object locations without additional machinery.

If two cars appear in an image, a classification label of “car” does not count them or distinguish them. Object detection adds boxes and an object-level prediction list. Segmentation asks for labels or object membership at individual pixels.

Before comparing classifiers, keep the data split, label definitions, preprocessing, and evaluation set fixed. Check errors by class and by conditions such as lighting or viewpoint; a single accuracy number can hide a weak class behind many easy examples.

If you found this explanation helpful, consider sharing it with others.

Mastodon