Residual blocks: basic, bottleneck, and the shortcut
A ResNet is a stack of residual blocks: a few convolutions F, and a shortcut that adds the block’s input back, y = F(x) + x. Here are the two kinds of block He et al. use, what each costs, what the shortcut does when a block changes shape, and how the blocks stack up.
1. Two blocks
A basic block and a bottleneck block, with their costs
Left, a basic residual block: two 3 by 3 convolutions with a shortcut around them. Middle, a bottleneck block: a 1 by 1 convolution that narrows the channels, a 3 by 3, and a 1 by 1 that widens them again, with a shortcut around all three. Right, bars comparing the weights and multiply-adds of the two blocks.
compare
as in the paper (Fig. 5) same output width
basic width
64 128 256 512
bottleneck: inner width
64 128 256 512
map size
56 28 14 7
2. When the shape changes
The two kinds of shortcut when a block halves the resolution and doubles the channels
An input of C channels at H by H becomes an output of 2C channels at H/2 by H/2. Option A keeps every other pixel and pads the new channels with zeros, with no weights. Option B applies a 1 by 1 convolution at stride 2, with 2C squared weights.
shortcut
A: subsample and zero-pad B: 1×1 projection
input channels C
64 128 256
3. Blocks into stages
The stages of a ResNet
A row of blocks grouped into four stages after a stem. The first block of each stage after the first halves the resolution and doubles the channels, and its shortcut is a projection. The parameter count of the whole network is shown.
network
ResNet-18 ResNet-34 ResNet-50