Definition
ResNet is the family of ImageNet CNNs of He, Zhang, Ren and Sun, "Deep Residual Learning for Image Recognition" (CVPR 2016): ResNet-18, 34, 50, 101 and 152. Each is a stem, four stages of residual blocks that halve the grid and double the width, global average pooling and one fully connected layer. Only the block type and the number of blocks per stage change between depths. This article covers the architecture: the layouts, shortcut options, costs and later variants. Why residual blocks make deep nets trainable is covered in Residual neural network (ResNet).
In 2015 networks had become deeper (VGG-19, GoogLeNet's 22 layers), but plain networks stopped improving beyond about 20–30 layers: deeper ones had higher training error. ResNet fixed this by letting each block learn a correction added to an identity shortcut. That made depth cheap to use, and the paper went from 34 to 152 layers on ImageNet. An ensemble of ResNets, including two 152-layer models, reached 3.57% top-5 error on the ILSVRC-2015 test set and won the classification task. The same backbones won the ImageNet detection and localization tasks and COCO detection and segmentation in 2015.
The layout followed simple rules taken from VGG: mostly convs; within a stage every block has the same number of filters; when the grid is halved, the number of filters is doubled, so the cost per block stays about the same. Downsampling is done by a stride-2 conv at the start of each stage, not by pooling layers. Compared with VGG-19 (19.6G multiply-adds), ResNet-34 needs only 3.6G.
At a glance
- Paper
- He, Zhang, Ren, Sun, CVPR 2016 (arXiv Dec. 2015)
- Stages
- conv2_x–conv5_x at (strides 4, 8, 16, 32 for a input)
- Blocks
- basic for 18/34; bottleneck with 4× expansion for 50/101/152
- ResNet-50
- [3, 4, 6, 3] bottlenecks; 25,557,032 params; 4.09 GFLOPS (torchvision; the paper's layout: 3.8G)
- ILSVRC-2015
- 1st place, 3.57% top-5 test error (ensemble); ResNet-152 single model 4.49% top-5 (val, multi-scale)
- Training (paper)
- SGD, momentum 0.9, batch 256, lr 0.1 ÷ 10 on plateaus, weight decay , BN after every conv, no dropout
- In PyTorch
torchvision.models.resnet18 … resnet152; ResNet-50 V2 weights: 80.86% top-1
Layouts: basic and bottleneck
The basic block is two convs. The bottleneck block uses a conv to reduce the width 4× (256 → 64 in conv2_x), a conv at the reduced width, and a conv to expand back. At 256 channels it has 17× fewer weights than two convs, which is what lets ResNet-50 be deeper than ResNet-34 at almost the same cost. Counting conv and fc layers:
- number of blocks in stage : [2,2,2,2] for 18, [3,4,6,3] for 34 and 50, [3,4,23,3] for 101, [3,8,36,3] for 152
- the stem conv and the final fc layer
- multiply-accumulates of one conv layer; the paper and torchvision both call these FLOPs
So ResNet-50 has layers and ResNet-34 has , with the same [3,4,6,3] stage layout. Doubling the width while halving the grid keeps a block's cost constant: . In ResNet-18 the last three stages each cost 411.0M multiply-adds.
| Model | Block | Blocks per stage | Params | GFLOPS (torchvision) | GFLOPs (paper) | Top-1 (V1) |
|---|---|---|---|---|---|---|
| ResNet-18 | basic | 2, 2, 2, 2 | 11,689,512 | 1.81 | 1.8 | 69.76% |
| ResNet-34 | basic | 3, 4, 6, 3 | 21,797,672 | 3.66 | 3.6 | 73.31% |
| ResNet-50 | bottleneck | 3, 4, 6, 3 | 25,557,032 | 4.09 | 3.8 | 76.13% |
| ResNet-101 | bottleneck | 3, 4, 23, 3 | 44,549,160 | 7.80 | 7.6 | 77.37% |
| ResNet-152 | bottleneck | 3, 8, 36, 3 | 60,192,808 | 11.51 | 11.3 | 78.31% |
Shortcuts: options A, B and C
The add needs matching shapes. At the first block of conv3_x–conv5_x the grid halves and the width doubles; in a bottleneck net, the first block of conv2_x also changes the width (64 → 256). The paper compared three choices for the shortcut:
- option A: subsample by 2 and pad the extra channels with zeros; no parameters
- a conv (stride 2 where the grid halves): the projection shortcut
- the standard choice, used by the paper's deeper nets and by torchvision
On ResNet-34, 10-crop ImageNet top-1 error was 25.03% for A, 24.52% for B and 24.19% for C (paper, Table 3). B is better than A because the zero-padded channels do no residual learning. C is only marginally better than B, and the paper attributes that to its extra parameters. Since identity shortcuts are free, B became the standard. In bottleneck nets C is expensive: projections on all 16 blocks raise ResNet-50 from 25.6M to 40.1M parameters and from 4.09G to 6.56G multiply-adds (figure).
Worked example: where ResNet-50 spends its budget
| Stage | Output | Blocks | Params | Share | Mult-adds |
|---|---|---|---|---|---|
| stem: 7×7/2 conv, max-pool | 64 × 56² | – | 9,536 | 0.04% | 118.0M |
| conv2_x | 256 × 56² | 3 | 215,808 | 0.8% | 667.9M |
| conv3_x | 512 × 28² | 4 | 1,219,584 | 4.8% | 1,027.6M |
| conv4_x | 1024 × 14² | 6 | 7,098,368 | 27.8% | 1,464.3M |
| conv5_x | 2048 × 7² | 3 | 14,964,736 | 58.6% | 809.2M |
| avg-pool + fc 2048 → 1000 | 1000 | – | 2,049,000 | 8.0% | 2.0M |
The first block of conv5_x (1024 × 14² → 2048 × 7²)
- 1, 1024 → 512 at : parameters, M mult-adds.
- 2/2, 512 → 512, output : parameters, M.
- 3, 512 → 2048: parameters, 51.4M.
- 4Projection shortcut /2, 1024 → 2048: parameters, 102.8M. Block total 6,039,552.
- 5The two identity blocks have 4,462,592 each, so conv5_x has : 58.6% of the parameters, but only 20% of the compute, because it runs on a grid. conv4_x does the most work (1.46G).
Variants: v1.5, v2, ResNet-D and better training
Stride placement ("v1.5"). The paper puts the stride-2 of a bottleneck on its first conv, which simply skips three out of four input positions. torchvision, and most code since, puts it on the conv instead. This costs 4.09G instead of 3.86G multiply-adds for ResNet-50 and is somewhat more accurate; Bag of Tricks calls it ResNet-B.
ResNet v2, pre-activation (He et al., "Identity Mappings in Deep Residual Networks", ECCV 2016). The block becomes BN → ReLU → conv → BN → ReLU → conv, with nothing after the addition, so the shortcut path is a pure identity from input to output. This helps most for very deep nets: a 1001-layer ResNet reached 4.62% error on CIFAR-10, and on ImageNet a pre-activation ResNet-200 had 20.7% top-1 error versus 21.8% for the original (single crop).
ResNet-C and ResNet-D (He, Zhang, Zhang, Zhang, Xie & Li, "Bag of Tricks for Image Classification", CVPR 2019). ResNet-C replaces the stem with three convs (32, 32, 64 channels). ResNet-D fixes the downsampling shortcut: a strided conv ignores 3/4 of its input, so it becomes a average pool followed by a conv. With the paper's training setup, ResNet-50 went from 76.21% to 77.16% top-1 with B + C + D, at about 4.3G multiply-adds.
Training, not architecture. Much of what later architectures gained over ResNet came from better training. Wightman, Touvron and Jégou's "ResNet strikes back" (2021) trained an unchanged ResNet-50 for 600 epochs with LAMB, a binary cross-entropy loss, Mixup, CutMix, RandAugment, repeated augmentation and Stochastic depth, and reached 80.4% top-1 at , versus 76.1% for the original recipe. torchvision's IMAGENET1K_V2 weights for the same network, trained with a similar modern recipe, reach 80.86%.
1import torch, torch.nn as nn2from torchvision.models import resnet50, ResNet50_Weights3from torchvision.models.feature_extraction import create_feature_extractor45weights = ResNet50_Weights.IMAGENET1K_V2 # 80.858% top-1 (V1: 76.13%)6model = resnet50(weights=weights).eval()7print(sum(p.numel() for p in model.parameters())) # 255570328preprocess = weights.transforms() # resize 232, center-crop 224, normalize910# One feature map per stage: strides 4, 8, 16, 32 (used by FPN detectors)11fx = create_feature_extractor(model, return_nodes={"layer1": "c2", "layer2": "c3",12 "layer3": "c4", "layer4": "c5"})13with torch.no_grad():14 feats = fx(torch.randn(1, 3, 224, 224))15print({k: tuple(v.shape) for k, v in feats.items()})16# {'c2': (1, 256, 56, 56), 'c3': (1, 512, 28, 28), 'c4': (1, 1024, 14, 14), 'c5': (1, 2048, 7, 7)}1718print(model.layer4[0].downsample) # the option-B projection: 1x1 conv stride 2 + BN1920# Fine-tune on 10 classes: new head, smaller learning rate for the backbone21model.fc = nn.Linear(model.fc.in_features, 10) # 2048 -> 1022opt = torch.optim.SGD([23 {"params": [p for n, p in model.named_parameters() if not n.startswith("fc.")], "lr": 1e-3},24 {"params": model.fc.parameters(), "lr": 1e-2}], momentum=0.9, weight_decay=1e-4)2526# Dense prediction: keep stride 8 by dilating the last two stages instead of striding27seg_backbone = resnet50(weights=weights, replace_stride_with_dilation=[False, True, True])Use when
- +One block type and four numbers define the whole network; easy to scale from 18 to 152 layers.
- +Identity shortcuts are free; bottlenecks make 50+ layers cost about as much as ResNet-34.
- +Strong, well-understood backbone with a multi-scale feature pyramid; pretrained weights everywhere.
- +Trains with plain SGD and BatchNorm; robust to hyperparameters.
Avoid when
- −Most parameters sit in the last stage (58.6% in conv5_x for ResNet-50), much of it redundant.
- −The stem and strided- shortcuts discard information; fixed by ResNet-C/D.
- −Depends on BatchNorm, which behaves poorly with very small batches.
- −At equal FLOPs, newer designs (EfficientNet, RegNet, ConvNeXt) are more accurate, though partly due to training recipes.
Check yourself
ResNet-34 and ResNet-50 use the same stage layout [3, 4, 6, 3]. Why is ResNet-50 deeper but only slightly more expensive (3.6G vs 3.8G multiply-adds in the paper)?
Check yourself
In ResNet-50, which stage holds most of the parameters, and which does the most multiply-adds?
Remember
- ✓ResNet = stem + four stages (grid , width doubles as the grid halves) + global average pool + fc; depth .
- ✓Basic blocks (two ) for 18/34; bottlenecks ( reduce, , expand ×4) for 50/101/152 with [3,4,6,3], [3,4,23,3], [3,8,36,3].
- ✓Shortcuts: identity where shapes match, 1×1 projection where they change (option B). A zero-pads, C projects everywhere; B is the standard.
- ✓ResNet-50: 25,557,032 params, 4.09 GFLOPS (torchvision, stride on the 3×3) or 3.8G (paper); ILSVRC-2015 won with 3.57% top-5.
- ✓Variants: pre-activation v2, ResNet-B/C/D from Bag of Tricks; with a modern recipe the same ResNet-50 reaches 80.4% (ResNet strikes back).