Back to paper library
Paper notesarXiv 2016BMVC 2016

Wide ResNet

Wider, Not Deeper

Original paper

Wide Residual Networks

Paper authors

Sergey Zagoruyko · Nikos Komodakis

Publication
BMVC 2016Conference
First submitted to arXiv
arXiv:1605.07146
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{classiccnnswideresnet2016,
  title = {{Wide Residual Networks}},
  author = {Sergey Zagoruyko and Nikos Komodakis},
  year = {2016},
  eprint = {1605.07146},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1605.07146}
}
On this page

In the first half of 2016, ResNets kept getting deeper and deeper.

The ResNet authors switched the residual unit to pre-activation and trained a 1001-layer network on CIFAR-10; around the same time, Stochastic Depth stacked a network up to 1202 layers.

More layers did give better results; they just kept getting more expensive. Going from 110 to 1001 layers, the pre-activation ResNet's CIFAR-10 error fell from 6.37% to 4.92%. The layer count went up ninefold, the error came down by less than one and a half percentage points, and training time stretched out along with it.

Sergey Zagoruyko and Nikos Komodakis of École des Ponts ParisTech in France thought about it from another angle. Does a ResNet really have to be this thin?

They made the network wider and shallower.

Defining the Problem

ResNets Keep Getting Thinner

The ResNet authors favored thin, deep networks, trading the parameters they saved for more layers. The later bottleneck block first reduces dimensionality with a 1×11\times1 convolution, runs the 3×33\times3 convolution, and then expands back up, making each block thinner still.

Take the ResNet used on CIFAR. Its three stages have just 16, 32, and 64 channels. VGG and Inception, which came before it, all had far more channels than that.

The Shortcut Is Too Easy

The authors point out that the identity shortcut, which lets ResNets train to a thousand layers and beyond, is also their weakness.

Gradients can travel all the way back along the shortcut, and nothing forces them through the weights of the residual branch. After training, perhaps only a few blocks have learned anything useful, or many blocks each contribute just a little. The authors call this phenomenon diminishing feature reuse.

The authors cite Stochastic Depth as evidence. Randomly switching off entire residual blocks during training actually makes the network better, which, as the authors see it, shows that many blocks weren't doing much in the first place.

Thin Networks Aren't Fast Either

GPUs are good at processing large tensors in one go, but a thin, deep network is a long chain of small convolutions that have to be computed one layer after another. As the authors note in the abstract, each small gain in accuracy requires nearly doubling the number of layers, so training gets slower and slower.

So the authors wanted to work out whether the same parameters are better used to make the network deeper or wider. Just how wide should a ResNet be?

Solving the Problem

What Can Be Changed

The authors start from ResNet v2's pre-activation block, where BN and ReLU come before every convolution. There are roughly three ways to make a residual block more expressive:

  1. Put more convolutional layers in the block.
  2. Widen the convolutions with more channels.
  3. Make the kernels larger.

The third is ruled out up front, since work on VGG and the Inception family has already shown how effective small 3×33\times3 kernels are. For the remaining two, the authors define one factor each. The deepening factor ll is the number of convolutional layers in a block, and the widening factor kk is how many times the channel count is multiplied. The original block is l=2l=2, k=1k=1.

Diagrams of four residual blocks. In each, the gray shortcut is on the left and the residual branch on the right, and the two are added at the bottom. (a) basic: two conv3x3; (b) bottleneck: conv1x1, conv3x3, conv1x1, with the middle conv3x3 narrower; (c) basic-wide: two wider conv3x3; (d) wide-dropout: a dropout layer sandwiched between two wider conv3x3
Figure 1 from the paper, excerpted from page 2 of the v4 PDF. The four kinds of residual block used in the paper. Every convolution is preceded by BN and ReLU, which the figure omits.

The width of each box in the figure represents the channel count. (a) is the original basic block; (c) has the same structure, only with both convolutions widened. The bottleneck in (b) is the tool ResNet uses to make networks thinner, the opposite of the widening this paper studies, so the authors leave it out and build everything from the basic block. (d) adds dropout between the two convolutions; we'll come back to it later.

WRN-n-k

The network's skeleton follows ResNet v2's design for CIFAR, with the widening factor kk as the only addition:

Table: Compiled from Table 1 of the paper. The first layer of conv3 and of conv4 halves the feature map size; k=1k=1 is the original pre-activation ResNet.
GroupOutput sizeContents
conv132×3232\times323×33\times3 convolution, 16 channels
conv232×3232\times32NN blocks, each with two 3×33\times3 convolutional layers, 16k16k channels
conv316×1616\times16NN blocks, 32k32k channels
conv48×88\times8NN blocks, 64k64k channels
avg-pool1×11\times18×88\times8 average pooling, followed by the classification layer

The authors denote a network as WRN-nn-kk, where nn is the total number of convolutional layers and kk is the widening factor. The official code requires n=6N+4n=6N+4, so WRN-28-10 is a network with N=4N=4 blocks per group and channel counts multiplied by 10.

kk affects the parameter count quadratically. A 3×33\times3 convolution whose input and output both have CC channels has 9C29C^2 weights, so doubling the channels quadruples the weights. Let's build a few networks following the table above and count their parameters:

Python
import torch.nn as nn

class Block(nn.Module):
    """BN-ReLU-conv3×3-BN-ReLU-conv3×3; the shortcut uses a 1×1 convolution when the shape changes"""
    def __init__(self, cin, cout, stride):
        super().__init__()
        self.body = nn.Sequential(
            nn.BatchNorm2d(cin), nn.ReLU(), nn.Conv2d(cin, cout, 3, stride, 1, bias=False),
            nn.BatchNorm2d(cout), nn.ReLU(), nn.Conv2d(cout, cout, 3, 1, 1, bias=False))
        self.shortcut = (nn.Identity() if cin == cout and stride == 1
                         else nn.Conv2d(cin, cout, 1, stride, bias=False))

    def forward(self, x):
        return self.shortcut(x) + self.body(x)

def wrn(n, k, num_classes=10):
    N = (n - 4) // 6                       # blocks per group
    widths = [16 * k, 32 * k, 64 * k]
    layers, cin = [nn.Conv2d(3, 16, 3, 1, 1, bias=False)], 16
    for width, stride in zip(widths, (1, 2, 2)):
        for i in range(N):
            layers.append(Block(cin, width, stride if i == 0 else 1))
            cin = width
    layers += [nn.BatchNorm2d(cin), nn.ReLU(), nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(cin, num_classes)]
    return nn.Sequential(*layers)

for n, k in [(40, 1), (40, 2), (40, 4), (16, 8), (22, 8), (28, 10)]:
    params = sum(p.numel() for p in wrn(n, k).parameters())
    print(f"WRN-{n}-{k}: {(n - 4) // 6} blocks per group, channels {16*k}/{32*k}/{64*k}, {params / 1e6:.1f}M parameters")
Text
WRN-40-1: 6 blocks per group, channels 16/32/64, 0.6M parameters
WRN-40-2: 6 blocks per group, channels 32/64/128, 2.2M parameters
WRN-40-4: 6 blocks per group, channels 64/128/256, 8.9M parameters
WRN-16-8: 2 blocks per group, channels 128/256/512, 11.0M parameters
WRN-22-8: 3 blocks per group, channels 128/256/512, 17.2M parameters
WRN-28-10: 4 blocks per group, channels 160/320/640, 36.5M parameters

These numbers match the parameter counts in the paper's tables. At the same 40 layers, as kk goes from 1 to 2 to 4, the parameters go from 0.6M to 2.2M to 8.9M, roughly four times as many at each step. Looked at the other way, WRN-16-8 has only 16 layers, yet it already has more parameters than the 40-layer WRN-40-4.

What Goes Inside a Block

Should some 1×11\times1 convolutions be mixed in, as in NiN? The authors write a block's structure as B(M)B(M), where MM lists the kernel sizes of the block's convolutional layers. For example, B(3,3)B(3,3) is the original basic block, and B(3,1,3)B(3,1,3) inserts an extra 1×11\times1 layer between the two 3×33\times3 layers.

These experiments all use k=2k=2, with the depth adjusted to keep the parameter counts similar, and each configuration is run 5 times on CIFAR-10, taking the median:

Table: Excerpted from Table 2 of the paper.
BlockDepthParametersOne epoch (s)CIFAR-10 error
B(1,3,1)B(1,3,1)401.4M85.86.06%
B(3,1)B(3,1)401.2M67.55.78%
B(1,3)B(1,3)401.3M72.26.42%
B(3,1,1)B(3,1,1)401.3M82.25.86%
B(3,3)B(3,3)281.5M67.55.73%
B(3,1,3)B(3,1,3)221.1M59.95.78%

B(3,3)B(3,3) is the best, but only by a small margin; B(3,1)B(3,1) and B(3,1,3)B(3,1,3) have fewer parameters and score almost the same. From this, the authors judge that blocks with similar parameter counts perform about the same, and from then on they use 3×33\times3 convolutions throughout.

How many layers should go in a block? The authors fix WRN-40-2's total layer count and parameter count (2.2M) and vary only the number of layers per block, ll:

Table: Excerpted from Table 3 of the paper.
ll1234
CIFAR-10 error6.69%5.43%5.65%5.93%

With the total layer count fixed, a larger ll means fewer blocks, and therefore fewer residual connections. The authors speculate that l=3l=3 and l=4l=4 are worse because the network, with fewer residual connections, is harder to optimize; l=1l=1, with a single layer per block, is clearly worse still. Two layers is just right, which is the original B(3,3)B(3,3).

After trying all of that, the block's internals end up right back where they started, and the only thing left to change is the width kk.

Putting Dropout Inside the Block

Widening makes the parameter count balloon, which calls for regularization. BN has a regularizing effect of its own, but it usually needs heavy data augmentation alongside it, and the authors didn't want to rely on that.

They add a dropout layer between the block's two convolutions, after the ReLU, as in Figure 1(d). In code, that's one extra nn.Dropout after the second ReLU of the Block above:

Python
        self.body = nn.Sequential(
            nn.BatchNorm2d(cin), nn.ReLU(), nn.Conv2d(cin, cout, 3, stride, 1, bias=False),
            nn.BatchNorm2d(cout), nn.ReLU(), nn.Dropout(0.3),   # between the two convolutions
            nn.Conv2d(cout, cout, 3, 1, 1, bias=False))

ResNet v2 had also tried dropout in the residual block, but on the shortcut, and results got worse. Here the dropout touches only the residual branch, and the shortcut stays clean. The dropout probability is chosen by cross-validation, 0.3 for CIFAR and 0.4 for SVHN.

Discussion

Apart from ImageNet, every experiment uses the pre-activation ResNet as the baseline. CIFAR-10 and CIFAR-100 consist of small 32×3232\times32 color images, each with 50,000 for training and 10,000 for testing, in 10 and 100 classes, respectively; the only data augmentation is horizontal flips and random crops. SVHN contains street-view house numbers, about 600,000 images, with no augmentation at all.

Splitting Between Width and Depth

Table: Excerpted from Table 4 of the paper. CIFAR test error, with images preprocessed by ZCA whitening.
DepthkkParametersCIFAR-10CIFAR-100
4010.6M6.85%30.89%
4022.2M5.33%26.04%
4048.9M4.97%22.89%
40835.7M4.66%–
281036.5M4.17%20.50%
281252.5M4.33%20.43%
22817.2M4.38%21.22%
221026.8M4.44%20.75%
16811.0M4.81%22.07%
161017.1M4.56%21.59%

First, hold the depth fixed. For the 40-, 22-, and 16-layer networks, a larger kk generally means a lower error. The only small exception is the 22-layer network going from k=8k=8 to k=10k=10, where the CIFAR-10 error rises slightly from 4.38% to 4.44% while the CIFAR-100 error keeps falling.

Now hold the width fixed. At k=8k=8, going from 16 to 22 layers helps, but going further to 40 layers actually hurts, and WRN-40-8 loses to WRN-22-8. WRN-40-8 has 35.7M parameters, and the authors' view is that when depth and width grow together, once the parameter count passes a certain point, stronger regularization is needed.

Taking On the Thousand-Layer ResNet

Next comes a head-to-head comparison with the strongest thin networks of the time. These experiments switch to plain mean/std normalization, matching the preprocessing in the ResNet papers, and none of them use dropout:

Table: Excerpted from Table 5 of the paper. The number in parentheses is ResNet v2's result with a batch size of 64; all other numbers use a batch size of 128.
NetworkDepth-kkParametersCIFAR-10CIFAR-100
Original ResNet1101.7M6.43%25.16%
Original ResNet120210.2M7.93%27.82%
Stochastic Depth120210.2M4.91%–
pre-act ResNet1641.7M5.46%24.33%
pre-act ResNet100110.2M4.92% (4.64%)22.71%
WRN40-48.9M4.53%21.18%
WRN16-811.0M4.27%20.43%
WRN28-1036.5M4.00%19.25%

WRN-40-4 and ResNet-1001 have similar parameter counts (8.9M and 10.2M), yet with a twenty-fifth of the layers, WRN-40-4 wins on both datasets. From this, the authors conclude that at this parameter scale, depth brings no more regularization than width does.

WRN-28-10 has 3.6 times as many parameters as ResNet-1001. The common belief at the time was that depth has a regularizing effect while width invites overfitting, and by that logic it should overfit. In fact, at the same batch size, it wins by 0.92 percentage points on CIFAR-10 and 3.46 percentage points on CIFAR-100.

Wide Networks Run Faster

Bar chart with time (ms) on the vertical axis. The two blue bars on the left are thin networks: 164 layers at 85 ms and a thousand layers at 512 ms. The three red bars on the right are wide networks: WRN-40-4 at 68 ms, WRN-16-10 at 164 ms, and WRN-28-10 at 312 ms. Each bar is labeled with its CIFAR-10 test error
Figure 4 from the paper, excerpted from page 12 of the v4 PDF. Time for one forward and backward pass at a batch size of 32 (Titan X, cuDNN v5). The horizontal axis shows the depth, or depth-kk.

Blue is thin and red is wide. The thousand-layer thin ResNet takes 512 ms per batch (when a thousand layers have to queue up, nothing moves fast), while WRN-40-4, with about the same accuracy, needs only 68 ms, more than seven times faster. The most accurate one, WRN-28-10, has several times as many parameters and is still 1.6 times faster than the thousand-layer network.

The gap comes from the GPU behavior mentioned earlier. A wide convolutional layer processes a big block of tensor at once, keeping the GPU's parallel compute fully busy; a thin network is a thousand small convolutions lined up in a row, with each layer waiting for the previous one to finish.

The Effect of Dropout

Table: Excerpted from Table 6 of the paper. Mean/std preprocessing; the CIFAR numbers are medians of 5 runs.
DepthkkDropoutCIFAR-10CIFAR-100SVHN
1645.02%24.03%1.85%
164✓5.24%23.91%1.64%
28104.00%19.25%–
2810✓3.89%18.85%–
5216.43%29.89%2.08%
521✓6.28%29.78%1.70%

On CIFAR, the gains are small. With dropout, WRN-28-10's error drops by 0.11 percentage points on CIFAR-10 and 0.4 percentage points on CIFAR-100; WRN-16-4, which has fewer parameters, even does slightly worse on CIFAR-10.

On SVHN, the effect is clear, with both the wide and the thin networks improving by 0.2 to 0.4 percentage points. SVHN gets no data augmentation at all, and the authors think BN overfits here; without dropout, the training loss falls to very low values.

The authors also noticed that after the first learning-rate drop, the loss and validation error would suddenly rise together and oscillate at high values until the next learning-rate drop. They traced the cause to weight decay, but lowering the weight decay noticeably hurt accuracy. In most cases, dropout partially removes this effect.

The authors also list their best single-model results on each dataset. WRN-40-10 with dropout reaches 3.8% on CIFAR-10 and 18.3% on CIFAR-100, and WRN-16-8 with dropout reaches 1.54% on SVHN.

On ImageNet, Widen the Middle Layer

On ImageNet, the authors first widen basic-block networks such as ResNet-18 and ResNet-34 by 1.5 to 3 times. Widening helps here too, and networks with similar parameter counts reach similar accuracy even when one is twice as deep as the other. But these networks have anywhere from tens of millions to over a hundred million parameters, and they still can't match bottleneck networks with far fewer. For example, WRN-34 widened twofold has 86.0M parameters and a top-1 error of 23.39%, while ResNet-101 gets 22.44% with just 44.5M parameters.

The authors suspect that either the bottleneck is simply better suited to ImageNet, or this task needs a deeper network. So they start from ResNet-50 instead and widen only the 3×33\times3 convolution in the middle of the bottleneck by a factor of two, giving WRN-50-2-bottleneck:

Table: Excerpted from Table 8 of the paper. ILSVRC-2012 validation set, single crop; times are for a batch size of 16.
NetworkTop-1 errorTop-5 errorParametersTime per batch (ms)
ResNet-5024.01%7.02%25.6M49
ResNet-10122.44%6.21%44.5M82
ResNet-15222.16%6.16%60.2M115
WRN-50-2-bottleneck21.9%6.03%68.9M93
pre-ResNet-20021.66%5.79%64.7M154

With only 50 layers, WRN-50-2 beats ResNet-152 and is faster too; compared with the 200-layer pre-activation ResNet, its error is slightly higher, but it needs only 93 ms per batch versus 154 ms. The authors also say frankly that larger bottleneck networks need an 8-GPU machine to train, so they didn't try any.

This network is wide_resnet50_2 in torchvision. Compared with the last block of ResNet-50, the block's input and output still have 2048 channels; only the middle layer goes from 512 to 1024. The whole network grows from 25.6M to 68.9M parameters, matching the paper's table.

The authors also entered the COCO 2016 object detection challenge with WRN-34-2, a 34-layer network widened twofold, reaching 35.2 mAP as a single model and beating models built on ResNet-152 and Inception-v4 backbones.

Conclusion

Back to the question from the start. Does a ResNet really have to be this thin? This paper's answer is no. On CIFAR, the same parameters do more good as width than as depth; a 16-layer WRN already beats the thousand-layer ResNet and trains several times faster. Inside that thousand-layer ResNet, it looks like quite a few layers were slacking off.

This conclusion comes mainly from CIFAR. On ImageNet, the authors only went up to 50 layers, for the practical reason that larger networks need an 8-GPU machine to train.

WRN later became one of the most common backbones on CIFAR; the semi-supervised FixMatch, for example, uses WRN-28-2. Next time you see that name in a paper, you'll know it's a 28-layer network widened twofold.