Why Not Just Use Dense Layers for Images?
A small 224 x 224 color photo has 150,528 numbers. A dense layer with 1000 neurons would need over 150 million weights. It would be slow, easy to overfit, and it would ignore the fact that nearby pixels belong together. CNNs fix this by looking at small patches and reusing the same weights everywhere.
Images are Tensors
| Image type | Shape (height, width, channels) |
|---|---|
| Grayscale 28 x 28 | (28, 28, 1) |
| Color 224 x 224 | (224, 224, 3) for red, green, blue |
The Convolution Operation
A filter (or kernel) is a tiny grid of weights, for example 3 x 3. It slides across the image. At each position it multiplies the pixels under it by its weights and adds them up, producing one number. All those numbers form a feature map.
The middle column has large values (3.0) because that is where the bright area meets the dark area: an edge.
Stride and Padding
| Term | Meaning |
|---|---|
| Stride | How many pixels the filter moves each step. Stride 2 makes the output smaller |
Padding valid | No padding, output shrinks |
Padding same | Add zeros around the image so output size stays the same |
Pooling
Pooling shrinks the feature map. Max pooling keeps the largest value in each small window (usually 2 x 2). It makes the network faster and less sensitive to the exact position of things.
The Typical CNN Recipe
- Conv2D + ReLU (find patterns)
- MaxPooling2D (shrink)
- Repeat the two steps with more filters
- Flatten or GlobalAveragePooling
- Dense layers for the final answer
- Early layers see edges
- Middle layers see textures and shapes
- Deep layers see object parts
Conclusion
CNNs share small filters across the image, so they need far fewer weights than dense networks and understand local patterns. Next, we will build one.

