Models / ResNet-18
code
account_treeResidual Network · 03

CIFAR-100 ResNet-18

Eighteen layers, four stages, and one structural trick — an identity shortcut around every pair of convolutions — that is the difference between a network that trains and one that doesn't. This page walks the basic residual block, watches gradients survive depth on a live probe, and points the interpretability and robustness tools at the model that reached 76.61% on 100 classes.

analytics76.6% Acc11M paramsCIFAR-100
Concepts in play
play_circleOne input image flowing through all four residual stages to 100 class scores
  1. A 32×32 CIFAR-100 image enters the stem and is lifted to 64 channels. The first stage runs two basic residual blocks at full 32×32 resolution — each block's identity shortcut is drawn as an arc running alongside its two 3×3 convolutions.
  2. At each stage boundary the spatial size halves and the channel count doubles — 64→128→256→512 — while a 1×1 projection shortcut matches the new shape so the addition hl+1=hl+F(hl)h_{l+1} = h_l + F(h_l) still holds.
  3. After stage 4 the feature map is 4×4×512. Global average pooling collapses it to a single 512-length vector, one number per channel, and a linear layer maps it to 100 class scores.
  4. Then the cinnamon gradient pulse runs the other way — right to left through every block's two-3×3 trunk and every shortcut arc, at full strength with no attenuation. That intact backward signal is the residual fix in action; the Gradient Flow tab measures the same thing on a real backward pass.
scienceOpen Workspace

ResNet-18 is built from one repeated unit: the basic residual block. Each block runs the input through two 3×3 convolutions (each followed by batch norm and a ReLU), then adds the block's input back to that result before a final ReLU. In symbols, hl+1=ReLU(hl+F(hl))h_{l+1} = \text{ReLU}\bigl(h_l + F(h_l)\bigr) where FF is the two-conv branch — exactly the form the Vanishing Gradients page calls the residual fix. When a block also needs to change the number of channels or halve the spatial size, the shortcut itself becomes a 1×1 convolution with stride 2 — a projection shortcut — so the addition still has matching shapes on both sides.

Eighteen layers count as: 1 stem convolution, 4 stages of 2 basic blocks each (2 convs per block = 4×2×2=164 \times 2 \times 2 = 16 convs), and 1 final linear layer — 1+16+1=181 + 16 + 1 = 18. The four stages widen channels and shrink space in lockstep:

StageOutput shapeBlocksChannels
Stem (3×3 conv)32×32×64—3 → 64
Stage 132×32×642 basic blocks64 → 64
Stage 216×16×1282 basic blocks64 → 128
Stage 38×8×2562 basic blocks128 → 256
Stage 44×4×5122 basic blocks256 → 512
GAP + FC100 (logits)—512 → 100
Spatial resolution halves at the start of stages 2-4 (stride-2 first block, projection shortcut); channel width doubles at the same point. By stage 4 the 32×32 input has become a 4×4 map — a 64× reduction in spatial area for an 8× increase in channel depth.

Why this shape? Each halving of spatial size is paired with a doubling of channels so the amount of computation per stage stays roughly constant — fewer spatial positions, but each one now costs roughly 4× as much (a 3×3 conv's cost scales with Cin⋅CoutC_{\text{in}} \cdot C_{\text{out}}, and both doubled). This is the same convolution parameter-count formula, params=Cout(k⋅k⋅Cin+1)\text{params} = C_{\text{out}}(k \cdot k \cdot C_{\text{in}} + 1), applied four times at increasing width: a stage-1 3×3 conv at 64→64 channels costs 64×(9×64)≈36.964 \times (9 \times 64) \approx 36.9K parameters, while the corresponding stage-4 conv at 512→512 costs 512×(9×512)≈2.36512 \times (9 \times 512) \approx 2.36M — about 64× more, tracking the 8×88 \times 8 growth in Cin⋅CoutC_{\text{in}} \cdot C_{\text{out}}. Stack all four stages' convolutions, the stem, and the 512→100 classifier and the total lands at about 11 million parameters — small enough to train from scratch in hours, large enough to reach real accuracy on a 100-class problem.

Each halving also doubles the receptive field relative to the input, on top of the growth each 3×3 conv already contributes within a stage — by the receptive-field arithmetic, a stride-2 layer doesn't just shrink the map, it doubles the input-pixel footprint of every neuron downstream. By stage 4, a single 4×4 output cell already depends on a large fraction of the original 32×32 image — which is exactly what global average pooling needs: by the time the spatial map is collapsed to one vector, each of its 16 positions has already integrated information from most of the image.

Trained from scratch, this network reached 76.61% validation top-1 at epoch 99 of 100 — 100 epochs of SGD with an initial learning rate of 0.1 on a cosine schedule decaying smoothly toward zero. The curve below is the real per-epoch validation accuracy from that run, not a schematic: notice the late-training jump from the high-60s to the mid-70s as the cosine schedule's low-LR tail lets the model settle into a sharper minimum.

0%20%40%60%80%120406080100Training epoch76.48%
Validation top-1 accuracy vs. epoch, sampled every 5 epochs across the full 100-epoch run. Early epochs climb fast (11.87% → 54.52% by epoch 20); the middle stretch is a long, noisy plateau in the 55-70% range; the cosine LR's final decay drives the late jump to 76.61% by epoch 99.
view_in_arConcept refresherStride and the receptive fieldStride-2 convolutions don't just downsample — they double the input-pixel footprint of every neuron downstream, which is how 4 stages turn a 32×32 image into a 4×4 map that already sees most of it.Revisitarrow_forward

Sources & further reading