Convolutional Neural Networks (CNNs)

Neural Networks & Deep Learning

Chapter 7 · Convolutional Neural Networks (CNNs)

Every network so far has been fully connected — every neuron sees every input. This chapter covers why that breaks down for images, and delivers historyai3-4's own AlexNet story with the actual technical substance that narrative left out.

Why a Plain Fully-Connected Network Struggles With Images

A modest 224×224 color image already has 224 × 224 × 3 ≈ 150,000 input values. A fully-connected first hidden layer, even a modest one, would need roughly 150,000 weights per neuron — enormous, expensive, and prone to exactly nn1-6's own overfitting story given typical training-set sizes. Worse: a fully-connected layer treats every pixel independently, with no built-in notion that nearby pixels are related. Shift an object slightly in the frame, and the network has to essentially relearn the same pattern all over again at the new position — no built-in translation invariance.

Convolution & Kernels — Solving Both Problems at Once

A kernel (a small grid of learnable weights, commonly 3×3 or 5×5) slides across the image, computing a small, local weighted sum at each position. Crucially, the same small set of weights is reused at every position — parameter sharing.

Why this fixes both problems directly
Parameter sharing collapses the parameter count from "one weight per pixel" down to "one small kernel, applied everywhere" — dramatically fewer weights than a fully-connected layer needed. It also delivers translation invariance for free: a kernel trained to detect, say, a vertical edge detects that same edge wherever it appears in the image, because the identical weights are applied at every position rather than being learned separately for each one.

Feature Maps — Many Kernels, Many Views

Applying one kernel across the whole image produces one feature map — a grid showing where that kernel's own pattern was detected, and how strongly. A real convolutional layer runs many kernels in parallel — one might learn to detect vertical edges, another horizontal edges, another a particular color transition or texture — each producing its own feature map, together giving the network many simultaneous "views" of the same image.

Pooling — Downsampling for Efficiency and Further Invariance

Max pooling shrinks a feature map by taking the maximum value within each small region (commonly 2×2), reducing the spatial size passed to later layers. This cuts computation for everything downstream, and adds a further degree of translation invariance — a small shift in exactly where a feature sits within its own pooling region no longer changes the output at all.

Stacking Layers — From Edges to Objects

Exactly nn1-3's own "depth composes transformations" principle, now made concrete visually: early convolutional layers learn simple features (edges, color blobs); later layers combine those into increasingly complex, abstract features (textures, shapes, eventually recognizable object parts and whole objects) — a genuine, hierarchical feature-learning story built entirely from stacking the same basic operation.

Delivering historyai3-4's Own AlexNet Story, Technically

Three chapters, one real historical result
AlexNet (2012) won ImageNet by a landslide margin using an eight-layer CNN — and three specific technical choices, each one this course has now already covered, are real, documented reasons it succeeded where earlier, shallower attempts hadn't: ReLU (nn1-4) instead of sigmoid/tanh, avoiding the saturation that would have crippled training at that depth; dropout (nn1-6) to control overfitting in a network with millions of parameters; and training on GPUs using mini-batches (nn1-6), making a network of that depth practically trainable within a realistic timeframe at all.

An Honest Nod to imgai1-2's Own Diffusion U-Net

imgai1-2's own diffusion explainer described a denoising network without detailing its internal architecture. Worth naming honestly here, without overclaiming: the U-Net architecture commonly used inside a diffusion model's own denoising network is built from the same convolutional building blocks this chapter covers — convolution, feature maps, downsampling — arranged into a specific downsample-then-upsample shape suited to producing a full image rather than a single classification. Not the identical architecture this chapter describes step by step; the same underlying convolutional vocabulary, applied to a different job.

What's Next

CNNs assume 2D spatial structure — nearby pixels matter, position within the frame is what matters. Text and time-series data have a different structural assumption entirely: order matters, not 2D position. nn1-8 covers the architecture family built specifically for that.

Hands-On Exercises

Exercise 1

Explain, using this chapter's own reasoning, how parameter sharing in a convolutional kernel solves both the parameter-count problem and the translation-invariance problem at the same time.

📄 View solution
Exercise 2

Using this chapter's own finding-box, explain specifically what role ReLU, dropout, and GPU-based mini-batch training each played in AlexNet's own success, and identify which earlier chapter introduced each technique.

📄 View solution
Exercise 3

Explain why this chapter is careful to describe the diffusion U-Net as using "the same convolutional building blocks... arranged differently" rather than claiming it's the identical architecture this chapter just walked through.

📄 View solution

Chapter 7 Quick Reference

  • Fully-connected layers scale badly to images — huge parameter counts, no translation invariance
  • Kernel — a small, learnable filter, reused at every position (parameter sharing) — solves both problems at once
  • Feature map — one kernel's output across the whole image; many kernels run in parallel per layer
  • Pooling (max pooling) — downsamples, cuts computation, adds further translation invariance
  • Stacked layers build a hierarchy: edges → textures/shapes → object parts — nn1-3's own depth principle, made visual
  • AlexNet's real 2012 success combined ReLU (nn1-4), dropout (nn1-6), and GPU mini-batch training (nn1-6)
  • Diffusion's own U-Net (imgai1-2) uses this chapter's own convolutional vocabulary, arranged for a different job
  • Next chapter: Recurrent Neural Networks (RNNs) & LSTMs