CNNs Explained — Convolutional Neural Networks in a Minute
CNN architecture in one read: kernel, stride, padding, pooling, flattening — how images flow from pixels to predictions.
What Is a CNN?
CNNs — also called ConvNets — are a specialized kind of neural network for processing data with grid-like topology. Time-series data is a 1D grid (samples over time). Images are 2D grids (pixels in rows and columns).
Unlike fully connected networks that treat every input feature independently, CNNs exploit spatial structure. Nearby pixels are related — a CNN learns that and encodes it into learned filters. For sequence data without grid structure — language above all — the modern counterpart is the transformer, which swaps convolution for self-attention.
Core Components
1 Kernel (Filter)
A kernel is a small weighted matrix — typically 3×3 or 5×5 — that slides across the input. At each position, it performs element-wise multiplication with the covered region, then sums the results to produce one output value. Stacking these output values across all positions produces a feature map.
Each kernel learns to detect a specific pattern: one might detect vertical edges, another horizontal, another curves. A typical conv layer applies many kernels in parallel — producing many feature maps.
2 Stride
Stride is the step size of the kernel as it slides across the input — how many pixels it moves at each step. Stride 1: kernel moves one pixel at a time, maximum resolution output. Stride 2: kernel jumps two pixels, halving the spatial dimensions of the output. Larger stride = smaller feature map = less computation, but lower resolution.
3 Padding
Extra pixels added around the input border before convolution:
- Valid padding: No extra pixels. Output is smaller than input. Border information is lost.
- Same padding: Zeros added around the border. Output has the same spatial dimensions as input.
4 Pooling
A downsampling operation that reduces spatial dimensions while retaining important information. Pooling controls overfitting and reduces the number of parameters.
- Max Pooling: Takes the maximum value from each region. Retains the strongest activation — the most prominent feature.
- Average Pooling: Takes the mean across each region. Smoother, retains overall activation level.
5 Flattening
After multiple conv+pool layers, the feature maps are 3D tensors (height × width × channels). Flattening converts this into a 1D vector so it can be passed to fully connected (dense) layers for the final classification or regression.
Standard CNN Architecture
A typical CNN processes an image through this sequence:
- Input Layer — raw pixel values (e.g., 224×224×3 for an RGB image)
- Convolutional Layer — applies N kernels, produces N feature maps
- Activation (ReLU) — applies non-linearity:
max(0, x) - Pooling Layer — downsample feature maps (typically 2×2 max pool)
- Repeat Conv+Pool — stack multiple blocks for deeper feature extraction
- Flatten — reshape 3D feature maps into 1D vector
- Fully Connected Layers — learn the mapping from features to output classes
- Output Layer — softmax for classification, sigmoid for binary
Key Takeaways
- CNNs exploit spatial structure — nearby pixels are related, and kernels learn to encode that.
- Kernels are learned — not hand-crafted. The network discovers what patterns to look for.
- Pooling reduces computation and adds partial translation invariance.
- Stack depth = abstraction level — deeper networks detect higher-level concepts.
- CNNs are the backbone of image classification, object detection, segmentation, and video analysis.
Frequently Asked Questions
What is a Convolutional Neural Network?
A CNN is a specialized neural network for grid-like data — primarily images (2D pixel grids) and time series (1D). CNNs automatically learn hierarchical features through convolutional layers, detecting simple edges at low levels and complex objects at higher levels.
What does a kernel (filter) do in a CNN?
A kernel is a small weighted matrix (e.g., 3×3) that slides across the input performing element-wise multiplication and summation at each position. This produces a feature map highlighting specific patterns — edges, textures, shapes — depending on the learned weights.
What is the difference between valid and same padding?
Valid padding adds no extra pixels — output is smaller than input. Same padding adds zeros around the border so output has the same spatial dimensions as the input.
What is max pooling and why is it used?
Max pooling takes the maximum value from each region of the feature map, reducing spatial dimensions while retaining the strongest activations. It reduces computation, controls overfitting, and adds partial translation invariance.
What is the standard CNN architecture?
Input → Conv Layer → ReLU → Pooling → (repeat) → Flatten → Fully Connected → Output. Multiple conv+pool stacks extract progressively abstract features before the fully connected layers make the final prediction.