4 The Architecture of Sight
How Researchers Redesigned the CNN—and What They Built Instead
Part II · Vision Systems
4.1 Opening Narrative
4.1.1 The Day Deeper Got Worse
In the spring of 2015, a team of researchers at Microsoft Research Asia ran an experiment that should not have produced the results it did.
They were studying convolutional neural networks — the architecture that had dominated image recognition since AlexNet's landmark 2012 victory, which we encountered in Chapter 2. The hypothesis was reasonable, almost obvious: if deeper networks learn more complex features, then a 56-layer network should outperform a 20-layer network on the same image classification task. More layers meant more representational power. More power meant better performance. This was the received wisdom of the field.
What Kaiming He and his colleagues found instead stopped them cold.
The 56-layer network was worse. Not just slightly worse — measurably, consistently worse, on both the training data and the test data. And this was the strange part: it was not the kind of failure that comes from overfitting, where a model memorizes training examples and performs poorly on new ones. Both training error and test error were higher for the deeper network. Something fundamental was going wrong during the learning process itself. Adding more capacity was making the network less capable.
He's team called this the degradation problem, and it was genuinely puzzling. In theory, a deeper network should be able to solve any problem that a shallower one can — after all, the deeper network could simply learn to ignore its extra layers, setting their weights so they act as identity functions that pass their input straight through. But in practice, the optimization process — the gradient descent and backpropagation machinery we explored in Chapter 3 — could not find that solution. The extra layers were not being ignored; they were distorting the signal.
The insight that resolved this came from a deceptively simple question: what if, instead of asking each layer to learn the full transformation from its input to its output, we asked it to learn only the correction — the difference between where the network currently is and where it needs to be?
The fix was a small architectural change. Before the output of a block of layers is computed, add a shortcut that bypasses those layers entirely and adds the original input directly to their output. Now each block does not have to learn an arbitrary mapping \(H(x)\). It only has to learn the residual \(F(x) = H(x) - x\) — the adjustment on top of what was already there. If the optimal adjustment is zero, the block can simply learn to output zeros, and the identity shortcut carries the input forward unchanged. Gradient descent has no trouble finding this solution.
The result — published as "Deep Residual Learning for Image Recognition" — won the 2015 ImageNet competition, the COCO detection competition, the COCO segmentation competition, and the ImageNet localization competition simultaneously. The winning network had 152 layers. Two years earlier, that depth would have been inconceivable.
This is the story of this chapter: not just the architectures that emerged after the basic CNN, but the problems that forced their invention. Every design we will study this week is an answer to a specific question. What are those questions? Why did the answers take the forms they did? And when you face a new problem, which answer should you reach for?
By the end of this chapter, you will be able to answer all three.
4.2 Learning Objectives
After completing this chapter, you will be able to:
Explain the degradation problem in deep convolutional networks — what it is, why it happens, and why it is distinct from the vanishing gradient problem explored in Chapter 3.
Describe residual connections and explain, both intuitively and mathematically, why learning the residual \(F(x) = H(x) - x\) stabilizes training in very deep networks.
Explain the design logic of Inception modules, including the role of parallel multi-scale processing and the dimensionality-reducing 1×1 convolution.
Describe EfficientNet's compound scaling principle — why coordinated scaling of depth, width, and resolution outperforms scaling any single dimension independently.
Explain how Vision Transformers process images, from patch embedding through positional encoding and self-attention, and articulate the tradeoffs between CNN and Transformer-based vision.
Select an appropriate architecture given a specific combination of task complexity, dataset size, and resource constraint — and justify that selection with principled reasoning.
Apply transfer learning by loading a pre-trained backbone and adapting it to a new classification task, understanding which layers to freeze and when to unfreeze them.
Reason about the ethical dimensions of architecture selection — including how model efficiency, compute access, and deployment context intersect with equity of access and real-world impact.
4.3 Key Terms and Concepts
| Term | Plain-Language Definition |
|---|---|
| Degradation Problem | The counterintuitive failure mode in which adding more layers to a plain deep network makes performance worse — not because of overfitting, but because the optimization process cannot effectively navigate the deeper loss landscape. |
| Residual Connection (Skip Connection) | A shortcut pathway in a neural network that adds a layer's input directly to its output, bypassing the layer's learned transformation. This allows the network to learn corrections on top of what already exists, rather than learning full transformations from scratch. |
| Residual Block | A standard building block of ResNets. Contains two or more convolutional layers plus a skip connection from input to output. The output is \(F(x)\) + x, where \(F(x)\) is what the layers learned and x is the original input. |
| Bottleneck Block | A three-layer variant of the residual block (1×1 → 3×3 → 1×1 convolutions) used in deeper ResNets to reduce computational cost while preserving representational capacity. The 1×1 layers compress and then restore the channel dimension around the expensive 3×3 convolution. |
| Inception Module | A building block that applies multiple convolutional filters of different sizes (1×1, 3×3, 5×5) in parallel to the same input and concatenates their outputs. Allows the network to simultaneously detect features at multiple scales without committing to a single filter size. |
| Compound Scaling | EfficientNet's method for scaling neural networks by jointly increasing depth (more layers), width (more channels), and input resolution — using a fixed compound coefficient — rather than scaling any single dimension in isolation. |
| Depthwise Separable Convolution | A factorized alternative to standard convolution that separates spatial filtering (applied independently to each input channel) from channel mixing (a 1×1 convolution across channels). Dramatically reduces computation while preserving expressive power. |
| Vision Transformer (ViT) | An architecture that processes images by dividing them into fixed-size patches, treating each patch as a token (similar to a word in a sentence), and applying a standard Transformer encoder with self-attention to model relationships between patches. |
| Patch Embedding | The first step in a Vision Transformer: each image patch is flattened into a vector and linearly projected into a lower-dimensional embedding space, preparing it for Transformer processing. |
| Positional Encoding | Information added to patch embeddings to indicate each patch's location in the image. Necessary because self-attention, unlike convolution, has no built-in notion of spatial position. |
| Self-Attention | A mechanism that allows each element in a sequence to attend to — and be influenced by — every other element simultaneously. In Vision Transformers, this gives every image patch a global view of the entire image from the very first layer. |
| Transfer Learning | The practice of using weights learned on a large source task (typically ImageNet classification) as the starting point for a new, smaller task. The lower-level features learned — edges, textures, shapes — are genuinely transferable across visual domains. |
| Feature Extraction | Using the early and middle layers of a pre-trained network as a fixed feature computer. The backbone's weights are frozen; only a new classification head placed on top is trained. |
| Fine-Tuning | A second stage of transfer learning in which some or all of the backbone's weights — initially frozen — are unfrozen and allowed to adjust with a very low learning rate, adapting to the specifics of the new task. |
| Global Average Pooling | An operation applied before the classification head that reduces each feature map to a single number by averaging all its spatial values. Produces a compact feature vector while reducing the number of parameters compared to fully-connected layers. |
| Batch Normalization | A technique that normalizes the activations within each layer during training, keeping them in a stable range. Enables faster training, supports higher learning rates, and acts as a mild regularizer — introduced in Chapter 3 and used heavily in the architectures here. |
| Feature Pyramid | A hierarchical multi-scale representation in which the same backbone is used to extract features at multiple spatial resolutions simultaneously, enabling detection of objects of different sizes. |
| Knowledge Distillation | A compression technique in which a smaller "student" network is trained to mimic the output behavior of a larger, more accurate "teacher" network, transferring the teacher's learned knowledge into a more deployable form. |
| Model Compression | A family of techniques — including pruning (removing unnecessary weights), quantization (reducing numerical precision), and distillation — aimed at reducing a model's size and computational cost while minimizing accuracy loss. |
| Multi-Head Attention | The version of self-attention used in practice: the attention computation is split into multiple independent "heads," each attending to different aspects of the input. The outputs are concatenated and projected. In Vision Transformers, this allows each patch to simultaneously attend to nearby patches, distant patches, and patches with similar content. |
4.4 Why Depth Alone Isn't Enough
4.4.1 The Promise of Depth — and Its Limits
Before we tour the architectural innovations that define modern computer vision, it is worth pausing on a question that might seem too basic to ask: why do we need advanced architectures at all?
You already know from Chapter 2 that depth is powerful. More layers allow a network to build increasingly abstract representations — from pixel intensities to edges, from edges to shapes, from shapes to objects. AlexNet's 2012 victory was in part a demonstration of what depth could do when paired with sufficient data and compute. The obvious next step seemed clear: go deeper.
The problem is that going deeper, in the most straightforward way, breaks things.
Consider what happens when you chain together many layers of standard convolutions. Each layer has to be learned from scratch. During backpropagation — the process that assigns credit or blame to each weight based on the final prediction error — the gradient signal has to travel backward through every layer. In Chapter 3, we discussed how gradients can vanish as they propagate through many layers, shrinking toward zero and leaving early layers barely learning. But the degradation problem He et al. discovered is subtler than this. Even in networks where vanishing gradients have been addressed through batch normalization and careful initialization, plain deep networks still perform worse as they get deeper. The optimization process simply cannot find a good solution in the high-dimensional space of a very deep network.
4.4.2 Three Common Failure Modes
When practitioners tried to move beyond the basic architectures of Chapter 2, they consistently ran into three categories of problem. Each became the motivation for a different architectural innovation.
Failure Mode 1: Training becomes unstable or stalls in deep networks. Adding more layers increases representational power in theory, but in practice it makes optimization harder. Gradient signals weaken, training slows, and performance degrades. This motivated ResNet's residual connections, which give gradients an unobstructed path backward through any depth.
Failure Mode 2: Fixed filter sizes miss features at different scales. A single 3×3 convolution can only look at one scale of the image at a time. Objects in real photographs appear at wildly different sizes — a face might occupy an entire image or a single pixel cluster. Choosing the wrong filter size means missing important information. This motivated Inception's parallel multi-scale processing.
Failure Mode 3: Scaling a model efficiently is guesswork. When a model works well and you want to make it better, the naive approach is to add more layers, or increase the number of channels, or use higher-resolution inputs — one at a time, hoping for improvement. This produces irregular, unpredictable results. This motivated EfficientNet's compound scaling method.
There is a fourth failure mode that arrived as a realization rather than a breakdown: the convolutional inductive bias — the assumption that important features are local and spatially repetitive — might be wrong for some tasks and at some scales. This motivated Vision Transformers, which abandon the convolution entirely in favor of global attention.
Each of these solutions, in roughly chronological order, forms the architecture landscape of this chapter.
4.5 The CNN Family — From Pioneer to Present
4.5.1 A Brief History, Quickly Told
It is worth tracing the lineage quickly before diving into the architectures that matter most for practice, because the history is not mere trivia — it reveals a continuous logic of problem-solving.
LeNet-5 (1989/1998): Yann LeCun and his colleagues at Bell Labs built LeNet-5 to read handwritten ZIP codes on envelopes. It demonstrated the fundamental CNN pattern — alternating convolutional and pooling layers, followed by fully connected layers at the end — and proved that gradient-based learning could produce reliable character recognition. For its era, this was remarkable. By modern standards, LeNet-5 is a teaching example: seven layers, roughly 60,000 parameters, trained on grayscale 28×28 images. Its importance is historical, not practical. We honor it as the ancestor of every architecture in this chapter, but we will not linger here.
AlexNet (2012): Chapter 2 opens with the moment AlexNet walked into the ImageNet competition and changed everything. We will not retell that story here — you know it well. What matters for this chapter is what AlexNet did not solve: it was only eight layers deep, and attempts to make it deeper produced the degradation problem He et al. later characterized. AlexNet marked the beginning of the deep learning era; the architectures that follow in this chapter mark its maturation.
From this point forward, we will treat each architecture not as a catalogue entry but as an argument — a researcher's answer to a specific, concrete problem.
4.5.2 ResNet: The Art of Learning What's Left
4.5.3 The Problem It Was Built to Solve
Recall the Microsoft Research experiment in our opening narrative. The 56-layer plain network — with nothing but stacked convolutional layers — performed worse than the 20-layer network on both training and test data. The deeper network was not overfitting; it was simply failing to optimize. The question was: why can't a deeper network at least match a shallower one? After all, the deeper network has strictly more capacity. A worst-case solution would be to learn an identity function in all the extra layers — pass the input forward unchanged — and match the shallow network's performance exactly. But the optimization could not find that solution.
He et al.'s insight was to make that worst-case solution easy to find by construction. Instead of asking the network to learn \(H(x)\) directly, add a skip connection and ask it to learn \(F(x) = H(x) - x\). If the optimal \(H(x)\) is close to the identity, then \(F(x)\) is close to zero, and learning approximately-zero outputs is far easier for gradient descent than learning an identity transformation through multiple stacked linear-plus-nonlinear operations.
This is not just a mathematical trick. It is a change in what each layer is responsible for. A standard layer says: "Given my input, produce the right output." A residual layer says: "Given what's already been computed, what correction should I add?" The second framing is almost always the right framing when you are building on top of a good prior computation.
4.5.4 How Residual Blocks Work
A residual block takes an input x, passes it through two (or three) convolutional layers to produce \(F(x)\), and then adds x back to \(F(x)\) before the final activation. The output is:
\[ y = \operatorname{ReLU}\!\left(F(x) + x\right) \]
The critical feature is the addition operation — it creates two paths through the network during both forward computation and backward gradient flow. Gradients do not have to pass through the convolutional layers to travel backward; they can flow through the skip connection directly. This guarantees that no matter how many layers a ResNet has, there is always a gradient path that doesn't diminish through learned transformations.
Analogy: Think of writing an essay. A standard convolutional layer is like being asked to write a new essay entirely from scratch using your input as reference material. A residual layer is like being given a first draft (the input x) and asked only to mark what should change (\(F(x)\)). The second task is almost always easier — the corrections are smaller in magnitude, smoother in the optimization landscape, and more stable to learn.
4.5.5 The Bottleneck: Efficiency at Depth
For deeper ResNets (50 layers and beyond), the standard two-layer residual block is replaced with a bottleneck block: a sequence of three convolutions in the pattern 1×1 → 3×3 → 1×1. The first 1×1 convolution reduces the channel dimension (say, from 256 to 64), the 3×3 convolution performs the main spatial computation on this cheaper representation, and the final 1×1 convolution restores the original channel count. The result has far fewer parameters and FLOPs than a two-layer block operating at the full channel dimension, enabling ResNets of 50, 101, and 152 layers to be both deeper and computationally feasible.
4.5.6 The ResNet Family
ResNets come in standard depths, each tuned for different precision-efficiency tradeoffs:
ResNet-18 and ResNet-34: Lighter networks using standard (not bottleneck) residual blocks. Appropriate when compute is limited or when the task is simple enough that extreme depth is unnecessary.
ResNet-50: The workhorse. Bottleneck blocks, 25 million parameters, and strong performance across a wide range of tasks. The default choice for transfer learning in most practical settings.
ResNet-101 and ResNet-152: Progressively more accurate, progressively more expensive. Used when maximum accuracy is required and compute is available.
ResNet-50's 2015 ImageNet top-5 error rate of 5.25% surpassed human-level performance on that benchmark for the first time. More importantly, the residual connection became a fundamental architectural primitive that you will encounter again in Transformers (Chapter 8), generative models (Chapter 11), and nearly every major architecture developed after 2015.
4.5.7 Inception: Seeing at Every Scale
4.5.8 The Problem It Was Built to Solve
Imagine you are a doctor looking at a chest X-ray. You need to notice fine-grained textures at the level of lung tissue, larger patterns like the shape of opacities, and coarse features like overall lung volume — all in the same image. A doctor's eye moves between these scales naturally. A convolutional neural network with a fixed 3×3 filter cannot. It looks at the world through one magnifying glass at a time.
The Inception architecture, introduced by Szegedy et al. in 2014 as GoogLeNet, proposed a different approach: instead of choosing one filter size per layer, run several in parallel on the same input and let the network learn how to weight their contributions.
4.5.9 How Inception Modules Work
An Inception module takes a single input and routes it through four parallel branches:
A 1×1 convolution (capturing channel-wise relationships at a single point)
A 1×1 convolution followed by a 3×3 convolution (medium-scale features)
A 1×1 convolution followed by a 5×5 convolution (large-scale features)
A max pooling layer followed by a 1×1 convolution (spatial summary)
The outputs of all four branches are concatenated along the channel dimension and passed to the next module. Each branch's depth (number of filters) is a design choice, optimized to balance accuracy and compute.
Analogy: Imagine a panel of medical specialists reviewing the same scan simultaneously — a pathologist examining cellular-level texture, a radiologist studying mid-scale patterns, and a surgeon considering organ-level structure. Each brings different analytical tools. The Inception module is that panel. The 1×1 convolutions before the 3×3 and 5×5 branches are the efficient briefing that gives each specialist only the information they need, preventing the meeting from running all day.
4.5.10 The Role of 1×1 Convolutions
The 1×1 convolution deserves special attention because it is easy to underestimate. A 1×1 convolution does not look at any spatial neighborhood — it looks only at a single point across all channels. Its role is dimensionality reduction: by reducing the number of channels before the more expensive 3×3 and 5×5 operations, it makes multi-scale processing computationally feasible. Without these bottleneck convolutions, the naive Inception module would be prohibitively expensive in both memory and compute. The 1×1 convolution is a small architectural idea with outsized practical impact.
4.5.11 Inception's Evolution
Subsequent versions of Inception refined the module further:
Inception-v3 introduced factorized convolutions — replacing a single 5×5 filter with two sequential 3×3 filters, which are mathematically equivalent but require fewer parameters — and added batch normalization throughout.
Inception-ResNet combined Inception modules with residual connections, gaining the benefits of both multi-scale processing and stable gradient flow in deep networks.
4.5.12 EfficientNet: The Science of Balanced Scaling
4.5.13 The Problem It Was Built to Solve
After ResNet and Inception demonstrated that better architecture design dramatically improved performance, a natural question arose: given a working architecture, how should you scale it up when you need more capability?
The naive approaches are to make the network deeper (more layers), wider (more channels per layer), or to use higher-resolution inputs. Each of these works to some extent, but each also hits diminishing returns quickly when done in isolation. A very deep but narrow network processes features through many stages but compresses information too aggressively at each step. A very wide but shallow network captures many features in parallel but cannot build sufficiently abstract representations. High resolution inputs contain more spatial detail but benefit diminishingly if the network architecture cannot take advantage of that detail.
Tan and Le at Google Brain asked: is there a principled way to scale all three dimensions together such that each dollar of compute is spent optimally?
4.5.14 The Compound Scaling Solution
EfficientNet's answer begins with a small "baseline" network (EfficientNet-B0) discovered through neural architecture search — a method that uses optimization to automatically find an effective architecture for a given compute budget. This baseline is then scaled up using a compound coefficient φ that jointly controls all three dimensions:
Depth scales as \(\alpha^\phi\)
Width scales as \(\beta^\phi\)
Resolution scales as \(\gamma^\phi\)
The constants α, β, and γ are determined by a constrained grid search on the baseline model such that α × β² × γ² ≈ 2 (ensuring that each increment of φ roughly doubles the compute). The result is a family of eight models (EfficientNet-B0 through EfficientNet-B7) that span a wide range of size and accuracy — each one the optimal allocation of compute at its scale.
Analogy: Think of a photographer upgrading their equipment. They could buy a better lens (more resolution), a larger sensor (more capture area), or upgrade the camera body (more processing). Any one of these improvements helps, but the best photographs come from a balanced system — where the lens, sensor, and body are matched to each other's capabilities. Upgrading one without the others creates a bottleneck. Compound scaling is the engineering equivalent of a coherent, balanced equipment upgrade.
4.5.15 Why EfficientNet Matters in Practice
EfficientNet-B0, the smallest member of the family, achieves accuracy comparable to much larger ResNets with dramatically fewer parameters. EfficientNet-B7 achieves state-of-the-art accuracy (at the time of publication) while requiring eight times fewer parameters than the best competing models. For deployment on constrained hardware — mobile phones, embedded medical devices, drones — this matters enormously.
The architecture also uses MBConv blocks (mobile inverted bottlenecks with depthwise separable convolutions) as its basic building block, which further reduces computation by separating spatial and channel operations. This combination of smart baseline design, compound scaling, and efficient operations makes EfficientNet a frequent first choice for resource-constrained applications.
4.5.16 Vision Transformers: When the Grid Is the Wrong Abstraction
4.5.17 The Problem It Was Built to Solve
Every architecture we have discussed so far shares a fundamental assumption: the convolutional one. Convolutions detect features in local neighborhoods and build global understanding by composing local detections over many layers. This is a powerful inductive bias — a useful assumption built into the architecture's structure. It works because images do have local structure: neighboring pixels tend to be related, and objects are usually spatially coherent.
But consider what convolution cannot easily do. Relating a feature in the top-left corner of an image to a feature in the bottom-right requires many layers of composition. Long-range dependencies — the relationship between the word "it" and the noun it refers to three paragraphs earlier — are exactly what Transformer architectures excel at in language. Dosovitskiy et al. asked in 2020: what if we applied that same architecture directly to images?
4.5.18 The ViT Pipeline
The Vision Transformer begins by cutting the image into a grid of fixed-size patches — typically 16×16 pixels. Each patch is flattened into a vector of pixel values and linearly projected into an embedding space. A special [CLS] (classification) token is prepended to the sequence. These patch embeddings, plus a learned positional encoding that tells the model where each patch sits in the original image, are then fed into a standard Transformer encoder.
The Transformer encoder applies multi-head self-attention across all patch tokens simultaneously. This means that from the very first layer, every patch has direct access to information from every other patch, regardless of how far apart they are in the image. There is no gradual, layer-by-layer accumulation of receptive field — the receptive field is global immediately.
At the end of the encoder, the [CLS] token's representation is passed through a linear classification head to produce the final prediction.
Analogy: A CNN reads a comic strip one panel at a time, building understanding of the story progressively as it moves from panel to panel. A Vision Transformer reads all the panels simultaneously and immediately starts reasoning about how each one relates to all the others. For simple, locally-structured images, the panel-by-panel approach works just fine. But for images where the meaning depends on relationships between distant regions — a radiological scan where the significance of a shadow in one lung depends on what is happening in the other, or a scene where the relevance of an object depends on what it is positioned near — the global view is a genuine advantage.
4.5.19 Positional Encoding: Telling the Transformer Where Things Are
Unlike convolution, self-attention has no built-in notion of position. If you shuffled the patch order randomly, a standard Transformer would produce the same output (it would just see a different permutation of the same tokens). To prevent this — to give the model the spatial layout of the image — positional encodings are added to the patch embeddings before they enter the encoder. These can be fixed sinusoidal functions or learned embeddings; both work in practice, and the choice has surprisingly little effect on final performance.
4.5.20 The ViT Tradeoff: Power at a Price
Vision Transformers are not uniformly superior to CNNs. They have two well-documented weaknesses.
First, they require far more training data than CNNs to match their performance. The convolutional inductive bias — the assumption of locality and translation invariance — acts as a regularizer that helps CNNs generalize from small datasets. ViT lacks this bias, which means it has more to learn from scratch. Models like DeiT (Data-efficient image Transformers) address this through careful training procedures and distillation, but the data hunger remains larger than for CNNs of equivalent capacity.
Second, they are computationally expensive. Self-attention scales quadratically with the number of tokens — if you double the number of patches, you quadruple the attention cost. This makes high-resolution ViT inference expensive and has motivated a generation of efficient attention variants (Swin Transformer, PVT, etc.) that impose local attention windows before allowing global attention.
For large datasets and complex tasks — especially tasks where long-range spatial relationships matter — ViTs and their successors are state of the art. For smaller datasets and resource-constrained deployment, CNNs remain highly competitive. You will want to carry both tools.
4.6 Choosing the Right Architecture
Knowing the architectures is necessary but not sufficient. The practitioner's skill lies in selecting the right one for a given situation. This section provides a framework for that reasoning.
4.6.1 Four Questions to Ask Before You Choose
4.6.2 Question 1: How much data do you have?
Data volume is perhaps the single most important factor in architecture selection. CNNs — ResNets and EfficientNets in particular — generalize well from relatively small datasets, especially with transfer learning. Vision Transformers need substantial data (typically more than 14 million training examples to train from scratch without distillation). For problems where data is scarce — medical imaging with rare conditions, industrial defect detection, specialized scientific imagery — a pre-trained CNN fine-tuned on your task will almost always outperform a ViT trained from scratch.
4.6.3 Question 2: What is your deployment target?
The context where your model will run determines how much compute and memory it can use. A model running on a cloud server with a high-end GPU has very different constraints than one running on a hospital's aging workstation, on a smartphone in a rural clinic, or on an embedded processor in a drone. EfficientNet's family exists precisely to serve this spectrum — B0 for the constrained end, B7 for the unconstrained end. ResNet-18 and ResNet-34 serve the medium-constraint tier. ViT is, in its standard form, a data-center-scale architecture.
4.6.4 Question 3: What kind of task is it?
Image classification, object detection, and semantic segmentation each place different demands on the feature extractor. For classification, global representations are usually sufficient — any backbone with a classification head works. For detection and segmentation (which we will explore in Chapter 5), you need rich spatial feature maps at multiple scales, which is a strength of ResNet + Feature Pyramid Network combinations. For tasks requiring understanding of long-range spatial relationships — whole-slide pathology images, scene understanding, visual question answering — ViT-style architectures offer genuine advantages.
4.6.5 Question 4: Is this a new training job or fine-tuning?
If you have a large, labeled dataset specific to your task, you have more freedom to experiment with architecture depth and width — depth and width are most impactful when the model is trained from scratch on sufficient domain-specific data. If you are adapting a pre-trained model to a new task with limited data, architectural sophistication matters less than the quality of the pre-training. A well-pre-trained ResNet-50 will typically outperform a poorly-initialized ViT-L on a small fine-tuning dataset.
4.6.6 The Selection Framework in Practice
The table below summarizes the main architectures and their appropriate use cases. Think of it not as a rigid rulebook but as a set of starting assumptions, each of which can be overridden by task-specific evidence.
| Architecture | Best When | Watch Out For |
|---|---|---|
| LeNet / simple CNN | Small datasets, simple patterns, prototyping | Limited expressiveness; will underfit complex tasks |
| AlexNet | Historical reference; occasional lightweight baselines | Outperformed by everything else; rarely the right choice today |
| ResNet-18/34 | Limited compute, moderate datasets | May underfit on highly complex tasks |
| ResNet-50 | The reliable default; strong transfer learning performance | Heavier than EfficientNet for equivalent accuracy |
| ResNet-101/152 | High accuracy requirements with available compute | Expensive; consider EfficientNet-B5+ as an alternative |
| EfficientNet-B0–B3 | Mobile, edge, or resource-constrained deployment | Slightly more sensitive to hyperparameter choices |
| EfficientNet-B4–B7 | Accuracy-maximizing settings with full compute | Memory-intensive; slower training than ResNet |
| Vision Transformer (ViT) | Large datasets; long-range dependency tasks; SOTA research | Data-hungry; expensive; poor small-dataset performance |
| Hybrid (CNN+ViT) | When you want spatial locality AND global context | More complex to train and deploy |
4.7 Transfer Learning — Standing on the Shoulders of Giants
4.7.1 Why Not Train from Scratch?
Training a ResNet-50 from scratch requires ImageNet: 1.28 million labeled images across 1,000 categories, weeks of GPU time, and careful hyperparameter tuning. Most real-world projects do not have those resources. Even when data is available, starting from a randomly initialized network discards an enormous amount of useful prior knowledge.
The alternative — and in most practical settings, the strongly preferred approach — is transfer learning. Load the weights from a model pre-trained on ImageNet, remove its original classification head, and add a new head suited to your task. The visual features the backbone learned — edges and textures in the early layers, shapes and parts in the middle layers, semantic concepts in the deep layers — transfer remarkably well to new domains.
This transferability is not accidental. It reflects something real about visual structure: the same features that distinguish cats from dogs are related to the features that distinguish benign from malignant tissue, defective from intact components, and healthy from diseased crops. Lower-level visual features are nearly universal. The deeper you go, the more task-specific they become — which is why the standard approach is to freeze the early layers and fine-tune the deeper ones.
4.7.2 The Two-Stage Protocol
4.7.3 Stage 1: Feature Extraction (Frozen Backbone)
Load the pre-trained backbone and freeze all its weights. Add a new classification head appropriate to your task: typically a global average pooling layer, followed by a dropout layer, followed by a dense layer with a softmax activation over your target classes. Train only the head. This is computationally cheap, fast to converge, and produces a solid baseline performance with minimal overfitting even on small datasets.
4.7.4 Stage 2: Fine-Tuning (Selective Unfreezing)
After Stage 1 has converged, selectively unfreeze the final few blocks of the backbone and resume training with a significantly reduced learning rate — typically one-tenth of the Stage 1 rate, often combined with a cosine annealing schedule (as discussed in Chapter 3). The lower learning rate is essential: the pre-trained weights are already in a good region of the parameter space, and large gradient updates would destroy that prior knowledge rather than refine it.
A useful rule of thumb: unfreeze progressively from the top (closest to the output) downward, and stop as soon as validation performance stops improving. The lower layers encode universal visual features that are rarely worth overwriting. The higher layers encode domain-specific features that benefit most from adaptation.
Analogy: Imagine hiring an experienced chef to work at your restaurant. They arrive knowing how to slice, sauté, and manage a kitchen (the universal skills — the frozen early layers). In their first weeks, you only ask them to learn your specific menu (the new classification head). Once they know the menu, you work with them on adapting their sauces to your local ingredients (fine-tuning the upper layers). You do not ask them to unlearn how to chop vegetables — that foundational knowledge is an asset, not a liability.
4.7.5 What Transfer Learning Reveals About Representations
Transfer learning works because neural network features are representations — compressed, structured encodings of input data that capture semantically meaningful relationships. A ResNet-50 feature vector for an image of a golden retriever is close, in the 2048-dimensional embedding space, to the feature vector for a labrador — because they share visual structure. This is not something that was explicitly programmed; it emerged from training.
This idea — that learned representations are reusable, transferable, and structured — is one of the deepest and most consequential insights in modern deep learning. It is what makes pre-training on large datasets valuable beyond the original task. It is what makes multimodal systems possible: if you can represent images and text in the same embedding space, you can compare them, combine them, and reason across them. We will return to this idea extensively in Chapter 10, when we study multimodal systems.
4.8 Ethics in Architecture — The Choices That Shape What AI Sees
Architecture selection is not a purely technical decision. The choices you make about which model to use, how large to make it, and where to deploy it carry real-world consequences that are worth thinking through deliberately.
4.8.1 The Efficiency Equity Problem
EfficientNet's name promises efficiency, and by the standard measure — accuracy per parameter, or accuracy per FLOP — it delivers. But "efficient" is a relative term. Efficient for whom, running where, on what hardware?
A model that performs well on a cloud GPU is not automatically efficient on the aging laptop in a rural clinic. A model that achieves 90% validation accuracy on a balanced benchmark dataset may achieve far lower accuracy on the tail of the distribution — the rare classes, the underrepresented demographics, the unusual presentations that are not well-represented in ImageNet or in the fine-tuning dataset. The populations most in need of AI-assisted diagnosis or monitoring are often the populations least represented in training data and least likely to have access to the compute required by the most accurate models.
Architecture selection that ignores deployment context is not neutral — it encodes assumptions about who the system is for.
4.8.2 The Transferability of Bias
Transfer learning transfers representations. But representations reflect the data they were learned from, and that data reflects the world that produced it. ImageNet, the pre-training dataset for almost every vision model, was curated in the United States, predominantly reflects objects and scenes from affluent Western contexts, and carries documented disparities in how it represents people across demographic groups.
When you load ImageNet weights and fine-tune on a new task, you are not starting from a blank slate. You are inheriting those representations — including their biases. A skin lesion classifier fine-tuned from ImageNet weights may carry an implicit bias toward lighter skin tones, because the texture and color statistics of lighter skin are more represented in the pre-training features. A facial recognition system fine-tuned on a demographically imbalanced fine-tuning set may show disparate accuracy across groups for reasons that trace partly to what ImageNet taught the backbone to attend to.
This is not an argument against transfer learning. The benefits are real and substantial. It is an argument for examining what you are transferring, auditing performance across demographic subgroups, and being honest about the limitations of models deployed in high-stakes contexts.
4.8.3 Compute Access and Scientific Progress
The Vision Transformer's superior performance comes at a cost that is worth naming explicitly: it requires massive pre-training datasets and significant computational resources to realize its advantages. The organizations best positioned to develop and deploy state-of-the-art ViT systems are large technology companies and well-resourced research institutions. Smaller hospitals, agricultural cooperatives, NGOs, and academic researchers in lower-resource settings operate with different constraints.
Architecture selection is, in part, a statement about whose problems you are trying to solve. A practitioner who always defaults to the largest, most accurate model available is implicitly designing for the best-resourced users. Practitioners who care about equitable access to AI capability need to consider the full efficiency spectrum — including the computationally humble models that can run on a Raspberry Pi, a mid-range smartphone, or a shared cloud instance with a tight budget.
4.9 Hands-On Exploration
4.9.1 Architecture Archaeology: What Do These Models Actually See?
4.9.2 The Goal
This activity is not about training models. It is about interrogating them — asking a pre-trained ResNet, an EfficientNet, and a simpler baseline to look at the same images and comparing their behavior. The aim is to build intuition about what each architecture has actually learned, not just to read about it.
4.9.3 Setup
Use Google Colab (no local setup required). A starter notebook is provided (hands_on_ch4.ipynb) that loads three models via torchvision.models or tensorflow.keras.applications:
A 5-layer CNN trained from scratch on a small dataset (provided in the notebook)
ResNet-50 pretrained on ImageNet (frozen, inference only)
EfficientNet-B0 pretrained on ImageNet (frozen, inference only)
The notebook also includes a pre-written GradCAM function — a technique that visualizes which regions of an image most influenced a prediction. You do not need to write or understand this function for this activity; you only need to call it and interpret its output.
4.9.4 Part 1: The Same Image, Three Models
Feed five images to all three models: a clearly-lit golden retriever, a blurry cat photograph, a cat photographed from behind, a dog in a Halloween costume, and a grayscale photograph of an animal presented in a clinical-scan style. Record the top-3 predictions and confidence scores for each model on each image.
Answer these questions in your notebook:
On which images do all three models agree? What does agreement tell you about those images?
On which images does the simple CNN fail but ResNet succeeds? What is structurally different about those images?
Are there images where ResNet is more confident than EfficientNet, or vice versa? Can you hypothesize why?
4.9.5 Part 2: Attention Maps
Using the provided GradCAM utility, generate attention heatmaps for ResNet-50 and EfficientNet-B0 on two images: the clearly-lit golden retriever and the costumed dog.
Answer these questions:
What regions does ResNet-50 attend to for the golden retriever? Are they what you would expect?
Does it attend to the same regions for the costumed dog? What changed?
Does EfficientNet attend to different regions? Are those regions more or less semantically meaningful?
4.9.6 Part 3: Confidence Under Noise
Gradually degrade the golden retriever image by adding Gaussian noise in five steps (σ = 0, 0.1, 0.3, 0.5, 1.0). At each step, record each model's top-1 confidence score.
Answer these questions:
Which model loses confidence fastest as noise increases?
Which model is most resistant to noise? Is resistance always desirable?
At what noise level do models begin predicting incorrect classes? Is the transition sudden or gradual?
4.9.7 Reflection
Write three sentences: (1) What surprised you most about how the models differed? (2) What would you need to see to feel confident deploying one of these models in a medical imaging context? (3) What does the confidence calibration exercise reveal about the relationship between model confidence and model accuracy — and why does that relationship matter?
4.9.8 Why This Activity Matters
You will come away from this activity having observed the behavioral differences between architectures, rather than simply having read about them. Concepts like "better feature extraction" and "more robust to occlusion" will be legible to you as evidence, not assertion. The skill of interrogating a model's behavior — asking it hard questions and interpreting its answers — is as important as the skill of building the model in the first place.
4.10 Case Study
4.10.1 AlphaFold 2 and the Architecture of Biological Understanding
4.10.2 The Problem
For fifty years, the protein folding problem was considered one of the hardest open challenges in biology. Proteins are sequences of amino acids — the molecular machines that perform virtually every function in living cells, from catalyzing chemical reactions to defending the body against infection. The three-dimensional shape a protein folds into determines its function. Disruptions to that shape cause diseases ranging from Alzheimer's to cystic fibrosis to cancer. Figuring out which 3D shape a given amino acid sequence would adopt had resisted decades of experimental and computational effort. Experimental methods like X-ray crystallography and cryo-electron microscopy were accurate but slow and expensive — a single protein structure could take years to determine.
4.10.3 Why Deep Learning
DeepMind's AlphaFold 2, published in 2021, solved this problem with accuracy matching or exceeding experimental methods — and did it in minutes. The architecture draws directly on the principles of this chapter in ways that are worth tracing explicitly.
At AlphaFold 2's core is a deep residual network processing pairwise representations of amino acid distances. The skip connections from ResNet enable training across many hundreds of layers of this network without the degradation problem. More importantly, the system's central module — the Evoformer — uses a form of self-attention directly analogous to what we discussed in the Vision Transformer section: each amino acid in the sequence attends to every other amino acid, allowing the model to capture long-range dependencies between residues that are far apart in the linear chain but adjacent in the folded 3D structure. This global attention capability — the same feature that distinguishes ViT from CNN — is essential for fold prediction, because a protein's final shape is determined by complex, non-local interactions that local receptive fields cannot capture.
Transfer learning also played a role: the model was pre-trained on multiple sequence alignments — evolutionary data showing how the same protein varies across species — before fine-tuning on known structural data. The pre-training representation of evolutionary co-variation turned out to be rich enough to constrain the structural prediction problem dramatically.
4.10.4 What Changed
AlphaFold 2's predictions were made freely available for nearly every known protein — over 200 million structures released to the research community. The impact on drug discovery, vaccine development, enzyme engineering, and basic biological research has been compared to the publication of the human genome. Researchers who previously spent years determining a single structure can now query AlphaFold in seconds.
4.10.5 Tradeoffs and Limitations
AlphaFold 2 predicts static, idealized structures — the shape a protein takes under specific, modeled conditions. Real proteins exist in crowded, dynamic cellular environments; they change shape as they bind to other molecules; they function differently in different pH and temperature conditions. A predicted structure is a valuable starting point, not a complete picture.
There are also important questions about access. AlphaFold 2's development required resources available only to a major industrial AI laboratory. The model is open-access for academic use, but the capacity to develop similar systems in the future — to build on AlphaFold's foundation — is concentrated among a small number of organizations. The architecture innovations in this chapter, when combined with sufficient compute and data, are capable of contributing to fundamental scientific breakthroughs. That potential is not evenly distributed.
4.10.6 What This Case Study Teaches
AlphaFold 2 demonstrates two things that are easy to lose sight of when studying convolutional architectures for image classification. First, the architectural principles of this chapter — residual connections, attention mechanisms, transfer learning — are not specialized tools for computer vision. They are general computational principles that apply wherever high-dimensional structured data needs to be understood. Second, the gap between a working model and a transformative one is often not in the architecture itself, but in the specificity and depth of the scientific question it is pointed at.
4.11 Chapter Summary
This chapter began with a paradox — a deeper network that performed worse — and ended with a network that solved one of biology's fifty-year-old mysteries. Between those two poles, we traced four architectural innovations that together define the modern landscape of computer vision.
ResNet resolved the degradation problem by introducing residual connections: skip pathways that add the input directly to the output of each block, making it trivially easy for each layer to learn corrections rather than full transformations. This enabled networks of 50, 101, and 152 layers that previously would have been untrainable, and the residual connection became one of the most widely reused ideas in all of deep learning.
Inception addressed the multi-scale feature detection problem by running parallel branches of different filter sizes simultaneously and concatenating their outputs. The 1×1 convolution emerged as a key enabler — a cheap operation that compresses channel dimensionality before expensive spatial operations, making multi-scale processing computationally feasible.
EfficientNet tackled the scaling problem by establishing a principled compound coefficient that jointly governs depth, width, and input resolution. The result is a family of models — B0 through B7 — that achieves state-of-the-art accuracy-per-parameter across a wide range of compute budgets, making powerful vision capabilities accessible in resource-constrained settings.
Vision Transformers challenged the deepest assumption of CNN design — that spatial locality is always the right inductive bias — by treating images as sequences of patches and applying global self-attention from the first layer. ViTs excel on large datasets and tasks requiring long-range spatial reasoning, at the cost of greater data hunger and computational expense.
We also explored the architecture selection framework — how to reason about task complexity, dataset size, deployment constraints, and accuracy requirements when choosing among these options — and transfer learning, the practice of inheriting pre-trained representations that transforms a limited-data problem into a manageable fine-tuning problem.
Finally, we stepped back to consider what architecture selection means beyond benchmark accuracy: whose problems these systems are designed to solve, what biases travel invisibly through pre-trained weights, and what it means to design for equity of access rather than assuming the most powerful model is automatically the best model.
The architectures in this chapter will reappear throughout the course — as backbones in detection and segmentation systems (Chapter 5), as vision encoders in multimodal models (Chapter 10), and as one half of the generative pipelines explored in Chapters 11 and 12. Understanding them deeply now is an investment that will compound.
4.12 Review Questions
The degradation problem revealed that deeper is not automatically better. ResNet fixed this for CNNs using residual connections. Are there domains or tasks where you would expect very deep architectures to fail even with residual connections? What does this suggest about the limits of depth as a general scaling strategy?
EfficientNet is praised for achieving high accuracy with fewer parameters. "Efficiency" here is measured in FLOPs and parameter count on standard benchmarks. But is a model that runs efficiently on a cloud GPU "efficient" for a doctor in a rural clinic with a shared laptop? What does it mean for efficiency to be context-dependent — and who bears the cost when it isn't?
Vision Transformers require substantially more training data than CNNs to match their performance. This means ViT's advantage is, in practice, available mainly to organizations with access to massive labeled datasets. Does this create a structural advantage for large technology companies in building computer vision applications? If so, what are the implications for who gets to deploy state-of-the-art AI?
Transfer learning carries invisible inheritance. When you load ImageNet weights and fine-tune on a new task, you inherit the visual representations — and the biases — of what ImageNet contains. Can you think of specific real-world applications where ImageNet's biases would cause systematic failures? What would it look like to audit a fine-tuned model for these kinds of transferred biases?
The Inception module was designed to let the network "choose" which feature scale to attend to by running multiple filter sizes in parallel. Is this a principled design choice, or is it an admission that the designers did not know which scale matters? Is there a meaningful philosophical difference between "designing flexibility into an architecture" and "letting the network figure it out"?
AlphaFold 2 used architectural principles — residual connections, attention, transfer learning — originally developed for image classification to help solve a fundamental biology problem. What does this suggest about the generality of deep learning techniques? Are there problems in your own field of interest that might be addressable using these same architectural tools applied to a different data structure?
Consider a scenario: a hospital in a low-resource setting needs to deploy a chest X-ray triage system. Their radiologist workload is 10× their capacity, and false negatives (missed diagnoses) are more costly than false positives. Which architecture would you recommend — and why? How would your recommendation change if they had intermittent internet access and hardware that is five years old?
The residual connection's insight — learning a correction \(F(x)\) rather than a full transformation \(H(x)\) — is a principle that shows up in many places beyond CNNs. Can you think of analogies in human learning, scientific method, or engineering where incremental correction outperforms starting from scratch? What does this suggest about why the residual connection worked so well?
4.13 Further Reading
4.13.1 Foundational Papers
He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 770–778. The paper that introduced ResNet. Read at minimum the introduction and the degradation problem section — the writing is unusually clear for a landmark paper.
Szegedy, C., Liu, W., Jia, Y., Sermanet, P., Reed, S., Anguelov, D., ... & Rabinovich, A. (2015). Going deeper with convolutions. CVPR. The original GoogLeNet/Inception paper. Note how the authors frame the design constraints before proposing the solution.
Tan, M., & Le, Q. (2019). EfficientNet: Rethinking model scaling for convolutional neural networks. Proceedings of the 36th International Conference on Machine Learning (ICML). Pay particular attention to the section describing the compound scaling derivation.
Dosovitskiy, A., Beyer, L., Kolesnikov, A., Zoran, D., Unterthiner, T., Dehghani, M., ... & Houlsby, N. (2021). An image is worth 16×16 words: Transformers for image recognition at scale. ICLR. The ViT paper. The discussion of data requirements and the comparison with CNN performance at different dataset scales is essential context.
4.13.2 Transfer Learning and Representation Learning
Yosinski, J., Clune, J., Bengio, Y., & Lipson, H. (2014). How transferable are features in deep neural networks? NeurIPS. The foundational empirical study of which features transfer and which do not.
Kornblith, S., Shlens, J., & Le, Q. V. (2019). Do better ImageNet models transfer better? CVPR. Examines the relationship between ImageNet accuracy and transfer learning performance across domains.
4.13.3 Architecture Efficiency and Deployment
Howard, A., Sandler, M., Chu, G., Chen, L. C., Chen, B., Tan, M., ... & Adam, H. (2019). Searching for MobileNetV3. ICCV. Demonstrates efficient architecture design for mobile deployment.
Frankle, J., & Carlin, M. (2019). The lottery ticket hypothesis: Finding sparse, trainable neural networks. ICLR. A conceptually important paper about what a trained network actually contains.
4.13.4 Ethics and Bias in Vision Systems
Buolamwini, J., & Gebru, T. (2018). Gender shades: Intersectional accuracy disparities in commercial gender classification. Proceedings of the Conference on Fairness, Accountability and Transparency (FAccT). A foundational study demonstrating systematic performance disparities in deployed facial analysis systems.
Yang, K., Qinami, K., Fei-Fei, L., Deng, J., & Russakovsky, O. (2020). Towards fairer datasets: Filtering and balancing the distribution of the People Subtree in the ImageNet hierarchy. FAccT. Documents biases in ImageNet and efforts to address them.
4.13.5 The AlphaFold 2 Case Study
- Jumper, J., Evans, R., Pritzel, A., Green, T., Figurnov, M., Ronneberger, O., ... & Hassabis, D. (2021). Highly accurate protein structure prediction with AlphaFold. Nature, 596(7873), 583–589. Read the methods section alongside this chapter's ViT discussion to see exactly how the attention mechanism was adapted for biological sequence data.