Log In Sign Up

Shake-Shake regularization

The method introduced in this paper aims at helping deep learning practitioners faced with an overfit problem. The idea is to replace, in a multi-branch network, the standard summation of parallel branches with a stochastic affine combination. Applied to 3-branch residual networks, shake-shake regularization improves on the best single shot published results on CIFAR-10 and CIFAR-100 by reaching test errors of 2.86 Experiments on architectures without skip connections or Batch Normalization show encouraging results and open the door to a large set of applications. Code is available at


Deep Isometric Learning for Visual Recognition

Initialization, normalization, and skip connections are believed to be t...

A Robust Initialization of Residual Blocks for Effective ResNet Training without Batch Normalization

Batch Normalization is an essential component of all state-of-the-art ne...

Deep Residual Networks with Exponential Linear Unit

Very deep convolutional neural networks introduced new problems like van...

Efficient AlphaFold2 Training using Parallel Evoformer and Branch Parallelism

The accuracy of AlphaFold2, a frontier end-to-end structure prediction s...

Generalizing MLPs With Dropouts, Batch Normalization, and Skip Connections

A multilayer perceptron (MLP) is typically made of multiple fully connec...

Sandwich Batch Normalization

We present Sandwich Batch Normalization (SaBN), an embarrassingly easy i...

Deep Competitive Pathway Networks

In the design of deep neural architectures, recent studies have demonstr...

Code Repositories


2.86% and 15.85% on CIFAR-10 and CIFAR-100

view repo

1 Introduction

Deep residual nets (He et al., 2016a) were first introduced in the ILSVRC & COCO 2015 competitions (Russakovsky et al., 2015; Lin et al., 2014)

, where they won the 1st places on the tasks of ImageNet detection, ImageNet localization, COCO detection, and COCO segmentation. Since then, significant effort has been put into trying to improve their performance. Scientists have investigated the impact of pushing depth

(He et al., 2016b; Huang et al., 2016a), width (Zagoruyko & Komodakis, 2016) and cardinality (Xie et al., 2016; Szegedy et al., 2016; Abdi & Nahavandi, 2016).

While residual networks are powerful models, they still overfit on small datasets. A large number of techniques have been proposed to tackle this problem, including weight decay (Nowlan & Hinton, 1992), early stopping, and dropout (Srivastava et al., 2014). While not directly presented as a regularization method, Batch Normalization (Ioffe & Szegedy, 2015)

regularizes the network by computing statistics that fluctuate with each mini-batch. Similarly, Stochastic Gradient Descent (SGD)

(Bottou, 1998; Sutskever et al., 2013)

can also be interpreted as Gradient Descent using noisy gradients and the generalization performance of neural networks often depends on the size of the mini-batch (see

Keskar et al. (2017)).

Pre-2015, most computer vision classification architectures used dropout to combat overfit but the introduction of Batch Normalization reduced its effectiveness (see

Ioffe & Szegedy (2015); Zagoruyko & Komodakis (2016); Huang et al. (2016b)). Searching for other regularization methods, researchers started to look at the possibilities specifically offered by multi-branch networks. Some of them noticed that, given the right conditions, it was possible to randomly drop some of the information paths during training (Huang et al., 2016b; Larsson et al., 2016).

Like these last 2 works, the method proposed in this document aims at improving the generalization ability of multi-branch networks by replacing the standard summation of parallel branches with a stochastic affine combination.

1.1 Motivation

Data augmentation techniques have traditionally been applied to input images only. However, for a computer, there is no real difference between an input image and an intermediate representation. As a consequence, it might be possible to apply data augmentation techniques to internal representations. Shake-Shake regularization was created as an attempt to produce this sort of effect by stochastically "blending" 2 viable tensors.

1.2 Model description on 3-branch ResNets

Let denote the tensor of inputs into residual block . and are sets of weights associated with the 2 residual units. denotes the residual function, e.g. a stack of two 3x3 convolutional layers. denotes the tensor of outputs from residual block .

A typical pre-activation ResNet with 2 residual branches would follow this equation:


Proposed modification: If

is a random variable following a uniform distribution between 0 and 1, then during training:


Following the same logic as for dropout, all are set to the expected value of 0.5 at test time.

This method can be seen as a form of drop-path (Larsson et al., 2016) where residual branches are scaled-down instead of being completely dropped (i.e. multiplied by 0).

Replacing binary variables with enhancement or reduction coefficients is also explored in dropout variants like shakeout

(Kang et al., 2016) and whiteout (Yinan et al., 2016). However, where these methods perform an element-wise multiplication between an input tensor and a noise tensor, shake-shake regularization multiplies the whole image tensor with just one scalar (or ).

1.3 Training procedure

Figure 1: Left: Forward training pass. Center: Backward training pass. Right: At test time.

As shown in Figure 1, all scaling coefficients are overwritten with new random numbers before each forward pass. The key to making this work is to repeat this coefficient update operation before each backward pass. This results in a stochastic blend of forward and backward flows during training.

Related to this idea are the works of An (1996) and Neelakantan et al. (2015). These authors showed that adding noise to the gradient during training helps training and generalization of complicated neural networks. Shake-Shake regularization can be seen as an extension of this concept where gradient noise is replaced by a form of gradient augmentation.

2 Improving on the best single shot published results on CIFAR

2.1 Cifar-10

2.1.1 Implementation details

The Shake-Shake code is based on


111 and is available at The first layer is a 3x3 Conv with 16 filters, followed by 3 stages each having 4 residual blocks. The feature map size is 32, 16 and 8 for each stage. Width is doubled when downsampling. The network ends with a 8x8 average pooling and a fully connected layer (total 26 layers deep). Residual paths have the following structure: ReLU-Conv3x3-BN-ReLU-Conv3x3-BN-Mul. The skip connections represent the identity function except during downsampling where a slightly customized structure consisting of 2 concatenated flows is used. Each of the 2 flows has the following components: 1x1 average pooling with step 2 followed by a 1x1 convolution. The input of one of the two flows is shifted by 1 pixel right and 1 pixel down to make the average pooling sample from a different position. The concatenation of the two flows doubles the width. Models were trained on the CIFAR-10 (Krizhevsky, 2009)

50k training set and evaluated on the 10k test set. Standard translation and flipping data augmentation is applied on the 32x32 input image. Due to the introduced stochasticity, all models were trained for 1800 epochs. Training starts with a learning rate of 0.2 and is annealed using a Cosine function

without restart (see Loshchilov & Hutter (2016)). All models were trained on 2 GPUs with a mini-batch size of 128. Other implementation details are as in fb.resnet.torch.

2.1.2 Influence of Forward and Backward training procedures

The base network is a 26 2x32d ResNet (i.e. the network has a depth of 26, 2 residual branches and the first residual block has a width of 32). "Shake" means that all scaling coefficients are overwritten with new random numbers before the pass. "Even" means that all scaling coefficients are set to 0.5 before the pass. "Keep" means that we keep, for the backward pass, the scaling coefficients used during the forward pass. "Batch" means that, for each residual block , we apply the same scaling coefficient for all the images in the mini-batch. "Image" means that, for each residual block , we apply a different scaling coefficient for each image in the mini-batch (see Image level update procedure below).

Image level update procedure:

Let denote the original input mini-batch tensor of dimensions 128x3x32x32. The first dimension « stacks » 128 images of dimensions 3x32x32. Inside the second stage of a 26 2x32d model, this tensor is transformed into a mini-batch tensor of dimensions 128x64x16x16. Applying Shake-Shake regularization at the Image level means slicing this tensor along the first dimension and, for each of the 128 slices, multiplying the slice (of dimensions 64x16x16) with a scalar (or ).

Forward Backward Level 26 2x32d 26 2x64d 26 2x96d
Even Even n/a 4.27 3.76 3.58


plus1fil minus1fil

Even Shake Batch 4.44 - -
Shake Keep Batch 4.11 - -
Shake Even Batch 3.47 3.30 -
Shake Shake Batch 3.67 3.07 -


plus1fil minus1fil

Even Shake Image 4.11 - -
Shake Keep Image 4.09 - -
Shake Even Image 3.47 3.20 -
Shake Shake Image 3.55 2.98 2.86
Table 1: Error rates (%) on CIFAR-10. Results that surpass all competing methods by more than 0.1% are bold and the overall best result is blue.

The numbers in Table 1 represent the average of 3 runs except for the 96d models which were run 5 times. What can be observed in Table 1 and Figure 2 is that "Shake-Keep" or "S-K" models (i.e. "Shake" Forward "Keep" Backward) do not have a particularly strong effect on the error rate. The network seems to be able to see through the perturbations when the weight update is done with the same ratios as during the forward pass. "Even-Shake" only works when applied at the "Image" level. "Shake-Even" and "Shake-Shake" models all produce strong results at 32d but the better training curves of "Shake-Shake" models start to make a difference when the number of filters of the first residual block is increased to 64d. Applying coefficients at the "Image" level seems to improve regularization.

Figure 2: Left: Training curves of a selection of 32d models. Right: Training curves (dark) and test curves (light) of the 96d models.

2.2 Cifar-100

The network architecture chosen for CIFAR-100 is a ResNeXt without pre-activation (this model gives slightly better results on CIFAR-100 than the model used for CIFAR-10). Hyperparameters are the same as in

Xie et al. (2016) except for the learning rate which is annealed using a Cosine function and the number of epochs which is increased to 1800. The network in Table 2 is a ResNeXt-29 2x4x64d (2 residual branches with 4 grouped convolutions, each with 64 channels). Due to the combination of the larger model (34.4M parameters) and the long training time, fewer tests were performed than on CIFAR-10.

Forward Backward Level Runs 29 2x4x64d
Even Even n/a 2 16.34


plus1fil minus1fil

Shake Even Image 3 15.85
Shake Shake Image 1 15.97
Table 2: Error rates (%) on CIFAR-100. Results that surpass all competing methods by more than 0.5% are bold and the overall best result is blue.

Interestingly, a key hyperparameter on CIFAR-100 is the batch size which, compared to CIFAR-10, has to be reduced from 128 to 32 if using 2 GPUs.222As per notes in Without this reduction, the E-E-B network does not produce competitive results. As shown in Table 2, the increased regularization produced by the smaller batch size impacts the training procedure selection and makes S-E-I a slightly better choice.

2.3 Comparisons with state-of-the-art results

At the time of writing, the best single shot model on CIFAR-10 is a DenseNet-BC k=40 (3.46% error rate) with 25.6M parameters. The second best model is a ResNeXt-29, 16x64d (3.58% error rate) with 68.1M parameters. A small 26 2x32d "Shake-Even-Image" model with 2.9M parameters obtains approximately the same error rate. This is roughly 9 times less parameters than the DenseNet model and 23 times less parameters than the ResNeXt model. A 26 2x96d "Shake-Shake-Image" ResNet with 26.2M parameters, reaches a test error of 2.86% (Average of 5 runs - Median 2.87%, Min = 2.72%, Max = 2.95%).

On CIFAR-100, a few hyperparameter modifications of a standard ResNeXt-29 8x64d (batchsize, no pre-activation, longer training time and cosine annealing) lead to a test error of 16.34%. Adding shake-even regularization reduces the test error to 15.85% (Average of 3 runs - Median 15.85%, Min = 15.66%, Max = 16.04%).

Method Depth Params C10 C100
Wide ResNet 28 36.5M 3.8 18.3


plus1fil minus1fil

ResNeXt-29, 16x64d 29 68.1M 3.58 17.31


plus1fil minus1fil

DenseNet-BC (k=40) 190 25.6M 3.46 17.18


plus1fil minus1fil

C10 Model S-S-I 26 26.2M 2.86 -
C100 Model S-E-I 29 34.4M - 15.85
Table 3: Test error (%) and model size on CIFAR. Best results are blue.

3 Correlation between residual branches

To check whether the correlation between the 2 residual branches is increased or decreased by the regularization, the following test was performed:

For each residual block:

  1. Forward a mini-batch tensor through the residual branch 1 (ReLU-Conv3x3-BN-ReLU-Conv3x3-BN-Mul(0.5)) and store the output tensor in . Do the same for residual branch 2 and store the output in .

  2. Flatten these 2 tensors into vectors

    and . Calculate the covariance between each corresponding item in the 2 vectors using an online version of the covariance algorithm.

  3. Calculate the variances of

    and using an online variance algorithm.

  4. Repeat until all the images in the test set have been forwarded. Use the resulting covariance and variances to calculate the correlation.

This algorithm was run on CIFAR-10 for 3 EEB models and 3 S-S-I models both 26 2x32d. The results are presented in Figure 3. The correlation between the output tensors of the 2 residual branches seems to be reduced by the regularization. This would support the assumption that the regularization forces the branches to learn something different.

Figure 3: Correlation results on E-E-B and S-S-I models.

One problem to be mindful of is the issue of alignment (see Li et al. (2016)). The method above assumes that the summation at the end of the residual blocks forces an alignment of the layers on the left and right residual branches. This can be verified by calculating the layer wise correlation for each configuration of the first 3 layers of each block.

The results are presented in Figure 4. L1R3 for residual block means the correlation between the activations of the first layer in (left branch) and the third layer in (right branch). Figure 4 shows that the correlation between the same layers on the left and right branches (i.e. L1R1, L2R2, etc..) is higher than in the other configurations, which is consistent with the assumption that the summation forces alignment.

Figure 4: Layer-wise correlation between the first 3 layers of each residual block.

4 Regularization strength

This section looks at what would happen if we give, during the backward pass, a large weight to a branch that received a small weight in the forward pass (and vice-versa).

Let be the coefficient used during the forward pass for image in residual block . Let be the coefficient used during the backward pass for the same image at the same position in the network.

The first test (method 1) is to set = 1 - . All the tests in this section were performed on CIFAR-10 using 26 2x32d models at the Image level. These models are compared to a 26 2x32d Shake-Keep-Image model. The results of M1 can be seen on the left part of Figure 5 (blue curve). The effect is quite drastic and the training error stays really high.

Tests M2 to M5 in Table 4 were designed to understand why Method 1 (M1) has such a strong effect. The right part of Figure 5 illustrates Table 4 graphically.

Table 4: Update rules for .
Figure 5: Left: Training curves (dark) and test curves (light) of models M1 to M5. Right: Illustration of the different methods in Table 4.

What can be seen is that:

  1. The regularization effect seems to be linked to the relative position of compared to

  2. The further away is from , the stronger the regularization effect

  3. There seems to be a jump in strength when 0.5 is crossed

These insights could be useful when trying to control with more accuracy the strength of the regularization.

5 Removing skip connections / Removing Batch Normalization

One interesting question is whether the skip connection plays a role. A lot of deep learning systems don’t use ResNets and making this type of regularization work without skip connections could extend the number of potential applications.

Table 5 and Figure 6 present the results of removing the skip connection. The first variant (A) is exactly like the 26 2x32d used on CIFAR-10 but without the skip connection (i.e. 2 branches with the following components ReLU-Conv3x3-BN-ReLU-Conv3x3-BN-Mul). The second variant (B) is the same as A but with only 1 convolutional layer per branch (ReLU-Conv3x3-BN-Mul) and twice the number of blocks. Models using architecture A were tested once and models using architecture B were tested twice.

Model A B C
26 2x32d E-E-B n/a 4.84 5.17 -


plus1fil minus1fil

26 2x32d S-E-I rand(0,1) 4.05 5.09 -
26 2x32d S-S-I rand(0,1) 4.59 5.20 -
14 2x32d E-E-B n/a - - 9.65


plus1fil minus1fil

14 2x32d S-E-I v1 rand(0.4,0.6) - - 8.7
14 2x32d S-E-I v2 rand(0.35,0.65) - - 7.73
14 2x32d S-E-I v3 rand(0.30,0.70) - - diverges
Table 5: Error rates (%) on CIFAR-10.
Figure 6: Training curves (dark) and test curves (light). Left: Architecture A. Center: Architecture B. Right: Architecture C.

The results of architecture A clearly show that shake-shake regularization can work even without a skip connection. On that particular architecture and on a 26 2x32d model, S-S-I is too strong and the model underfits. The softer effect of S-E-I works better but this could change if the capacity is increased (e.g. 64d or 96d).

The results of architecture B are actually the most surprising. The first point to notice is that the regularization no longer works. This, in itself, would indicate that the regularization happens thanks to the interaction between the 2 convolutions in each branch. The second point is that the train and test curves of the S-E-I and E-E-B models are absolutely identical. This would indicate that, for architecture B, the shake operation of the forward pass has no effect on the cost function. The third point is that even with a really different training curve, the test curve of the S-S-I model is nearly identical to the test curves of the E-E-B and S-E-I models (albeit with a smaller variance).

Finally, it would be interesting to see whether this method works without Batch Normalization. While batchnorm is commonly used on computer vision datasets, it is not necessarily the case for other types of problems (e.g. NLP, etc ..). Architecture C is the same as architecture A but without Batch Normalization (i.e. no skip, 2 branches with the following structure ReLU-Conv3x3-ReLU-Conv3x3-Mul). To allow the E-E-B model to converge the depth was reduced from 26 to 14 and the initial learning rate was set to 0.05 after a warm start at 0.025 for 1 epoch. The absence of Batch Normalization makes the model a lot more sensitive and applying the same methods as before makes the model diverge. To soften the effect a S-E-I model was chosen and the interval covered by was reduced from [0,1] to [0.4,0.6]. Models using architecture C and different intervals were tested once on CIFAR-10. As shown in Table 5 and Figure 6, this method works quite well but it is also really easy to make the model diverge (see model 14 2x32d S-E-I v3).

6 Conclusion

A series of experiments seem to indicate an ability to combat overfit by decorrelating the branches of multi-branch networks. This method leads to state of the art results on CIFAR datasets and could potentially improve the accuracy of architectures that do not use ResNets or Batch Normalization. While these results are encouraging, questions remain on the exact dynamics at play. Understanding these dynamics could help expand the application field to a wider variety of complex architectures.