ShakeDrop is a regularization method that strongly perturbs the output of a residual block's branch by multiplying it by different random numbers in the forward and backward passes, and switches that perturbation on and off probabilistically using the mechanism of Stochastic Depth. Yamada and colleagues at Osaka Prefecture University and Preferred Networks presented it at an ICLR workshop in 2018 and published the full paper in IEEE Access in 2019.
It builds on Shake-Shake, which was known as a strong regularizer. Because Shake-Shake mixes the outputs of two branches in a random ratio, it only works with two-branch architectures such as ResNeXt, and why it works was not clear. The ShakeDrop paper tackles both issues: after interpreting how Shake-Shake works, it reformulates the method so that it also works with single-branch ResNet, Wide ResNet, and PyramidNet.
The key was a way to stabilize training. Applying Shake-Shake's style of perturbation to a single-branch network makes training fail. So the method uses the mechanism of Stochastic Depth (called RandomDrop in the paper), which randomly drops residual blocks, as a switch that decides "perturb or not." On CIFAR-100, it lowered the error rate of PyramidNet-110 from 18.01% to 15.78%.
The Two Methods It Builds On
The ShakeDrop formula combines the formulas of Shake-Shake and Stochastic Depth. Following the equations in Section 2 of the paper, the two are shown side by side. Let x be the input to a residual block, G(x) its output, and F the output of a branch.
Shake-Shake (Equation (2)) mixes two branches F1,F2 with α in the forward pass and a separate random number β in the backward pass, and uses the expected value 0.5 at inference (α,β∼U(0,1)).
The next figure shows a Shake-Shake residual block: the training forward pass on the left, the backward pass in the middle, and inference on the right. The coefficients applied to the branches differ between the forward and backward passes.
Stochastic Depth (Equations (4) and (5)) keeps the branch of the l-th residual block with probability pl and drops it entirely with probability 1−pl. bl∈{0,1} is a Bernoulli random variable, and the same value is used in the forward and backward passes.
L is the number of blocks; pl is close to 1 for blocks near the input and reaches pL at the last block (linear decay). The paper recommends pL=0.5.
Theory (The ShakeDrop Procedure)
The explanation follows Equations (6)–(8) of the paper. The target is a single-branch residual block G(x)=x+F(x).
For each block l, draw a switch bl that decides whether to perturb. bl=1 means "do not perturb."
bl∼Bernoulli(pl),pl=1−Ll(1−pL)
Draw the forward coefficient α and the backward coefficient β from independent uniform distributions. The ranges the paper found best come in two variants, depending on the network's structure.
In the training forward pass, multiply the branch output by bl+α−blα.
G(x)=x+(bl+α−blα)F(x)
In the training backward pass, multiply the gradient flowing into the branch by bl+β−blβ (bl is the same value as in the forward pass).
At inference, fix the coefficient at its expected value.
G(x)=x+E[bl+α−blα]F(x)
The coefficients in steps 3 and 4 switch with the value of bl as follows (Equations (7) and (8)).
Switch
Probability
Forward coefficient
Backward coefficient
Meaning
bl=1
pl
1
1
Same as the original network
bl=0
1−pl
α
β
Strongly perturbs the branch computation
Because bl and α are independent, the expected value in step 5 is pl+(1−pl)E[α]. In both ranges above, E[α]=0, so the inference coefficient becomes pl, the same as Stochastic Depth at inference.
α and β can be drawn at four granularities: per mini-batch, per image, per channel, or per element. In the paper's experiments (Table 3), per element gave the best results. Setting α=β=0 makes ShakeDrop identical to Stochastic Depth.
Why It Works (How ShakeDrop Was Derived)
Starting from an interpretation of Shake-Shake, the paper derives ShakeDrop in three steps.
Interpreting Shake-Shake: Interpolating the two branches with α in the forward pass amounts to creating plausible augmented data in feature space. Using a separate random number β in the backward pass appears to shake up parameter updates and keep them from getting trapped in local minima.
A single branch breaks it: In feature space, augmented data can be created not only by interpolation but also by adding noise. So the authors tried multiplying the output of a single-branch block by α and β (Single-branch Shake), and PyramidNet-110 on CIFAR-100 reached an error rate of 77.99%: training failed. In Shake-Shake, the backward gradient becomes β/α times its correct value, which grows very large when α is near 0 or 1. Even so, because the two branches' coefficients are α and 1−α, when one branch is badly perturbed, the other branch's learning is protected. A single branch has no such safeguard.
Using Stochastic Depth as a switch: Weakening the perturbation also weakens the regularization, so training had to be stabilized while keeping the perturbation strong. The solution was to choose the original network (where learning proceeds correctly) with probability pl and the strongly perturbed network (which escapes local minima) with probability 1−pl.
As an analogy, it is like practicing normally most of the time and only occasionally practicing on unsteady ground. Practicing only on unsteady ground leads nowhere, but mixed with normal practice it builds a resilience that normal practice alone cannot.
Section 4.3 of the paper also examines what the values of α and β mean.
β=0: The weights of a block chosen for perturbation are not updated in that step.
Negative α: The sign of the branch output flips in the forward pass, and this perturbation propagates to later layers. If the backward coefficient is then positive (β=1), the weights of the perturbed block are updated in the direction opposite to the correct one for the computation actually performed in the forward pass, which tends to break training.
The combination α=−1 and β=0: Strongly perturbs the forward pass while skipping the fragile update, which proved effective.
On PyramidNet, restricting (α,β) to just the two choices (1,1) and (−1,0) gave an error rate of 16.24%, nearly the same as drawing from the ranges (16.22%). The paper concludes that random sampling from a range is not itself the main reason the method works.
ShakeDrop is a different kind of regularization from input data augmentation such as Mixup, so the two can be combined. In Table 8 of the paper, PyramidNet-110 on CIFAR-100 went from 17.47% with Mixup alone to 15.04% with ShakeDrop added. For ResNet-110, however, it got slightly worse, from 23.79% to 24.12%.
Experimental Results
CIFAR results from Table 5 of the paper. Values are error rates (%, lower is better). Some CIFAR-100 entries (ResNet-110 and PyramidNet-110) are averages over 4 runs, and the "None" entry for PyramidNet-272 is the value from prior work. ShakeDrop draws random numbers per element, with pL=0.5, and training runs for 300 epochs.
Network
Regularization
CIFAR-10
CIFAR-100
ResNet-110
None
6.59
27.42
ResNet-110
Stochastic Depth
5.51
24.07
ResNet-110
ShakeDrop
4.56
23.74
PyramidNet-110 α270
None
3.85
18.01
PyramidNet-110 α270
Stochastic Depth
3.63
17.74
PyramidNet-110 α270
ShakeDrop
3.33
15.78
PyramidNet-272 α200
None
3.53
16.35
PyramidNet-272 α200
Stochastic Depth
3.41
15.94
PyramidNet-272 α200
ShakeDrop
3.08
14.96
ResNeXt-29 2-4-64d
None
5.39
21.19
ResNeXt-29 2-4-64d
Shake-Shake
4.64
19.16
ResNeXt-29 2-4-64d
ShakeDrop
3.91
18.27
For ResNeXt-29, ShakeDrop is applied to each of the two branches (Type B in the paper). Even on a two-branch architecture, it achieved lower error rates than Shake-Shake.
On ImageNet, 152-layer networks gave the following results (Table 6, top-1 error rate, pL=0.9).
Network
None
Stochastic Depth
ShakeDrop
ResNet-152
21.72
21.33
20.88
ResNeXt-152
20.49
20.45
20.34
PyramidNet-152 α300
21.54
21.23
20.94
Furthermore, when a ResNet-152 trained on ImageNet served as the feature extractor for object detection on COCO, the detection average precision (AP) of Mask R-CNN rose from 39.7 without regularization to 40.9 with ShakeDrop (Table 7). This shows that ShakeDrop improves not only classification but also the quality of features used for other tasks.
Practical Considerations
Adjust the ranges of α and β to the network's structure. With the wrong ranges, training does not converge. In Table 2 of the paper, using α∈[−1,1], β∈[0,1] (the best for PyramidNet) on the original ResNet-110 did not converge, and conversely using α=0, β∈[0,1] (the best for ResNet) on PyramidNet did not converge either. Use the former for networks whose branch ends with batch normalization, and the latter otherwise. Wide ResNet failed to train unless batch normalization was added at the end of the branch (CIFAR-10 error rate 87.6%).
Draw random numbers per element: On ResNet-110, drawing per image gave an error rate of 99.00% and per channel 66.30%; training failed. Per element (23.74%) and per mini-batch (23.77%) trained successfully.
Use a larger pL for shallow networks: As with Stochastic Depth, ShakeDrop tends to help more in deeper networks, and shallow networks did better with a larger pL (Table 9). On a 28-layer Wide ResNet, it did not beat Stochastic Depth. The ImageNet experiments use pL=0.9.
Do not combine with Shake-Shake: The paper notes that regularizers of the same kind (those that create new data in feature space from a single example), such as ShakeDrop and Shake-Shake, may not work together. They can be combined with regularizers of a different kind, such as Mixup.
Multiply by the expected value at inference: In PyTorch, implement it so that model.eval() switches the behavior (see the code example below). With the ranges above, the inference coefficient is pl.
Comparison with Other Methods
The table compares regularizers that apply random numbers to the branches of residual blocks, from the same viewpoints.
Choose ShakeDrop for deep single-branch residual networks (ResNet, PyramidNet) when stronger regularization than Stochastic Depth is needed.
Even on two-branch architectures, ShakeDrop often achieved lower error rates than Shake-Shake in the paper.
ShakeDrop is sensitive to three settings: α, β, and pL. Without room to explore them, starting with Stochastic Depth, whose only setting is pL, is the safe choice.
PyTorch example
▶Show code
python
import torch
import torch.nn as nn
def uniform_like(t, low, high):
# When low == high (e.g., α = 0), fill with that value
return torch.empty_like(t).uniform_(low, high) if low < high else torch.full_like(t, low)
class ShakeDropFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, x, p_l, alpha_range, beta_range):
b = torch.bernoulli(torch.tensor(p_l)).item() # b_l: 1 means no perturbation (probability p_l)
ctx.b, ctx.beta_range = b, beta_range
if b == 1:
return x
alpha = uniform_like(x, *alpha_range) # per-element α (the best granularity in the paper)
return alpha * x
@staticmethod
def backward(ctx, grad_output):
if ctx.b == 1:
return grad_output, None, None, None
beta = uniform_like(grad_output, *ctx.beta_range) # β drawn separately from α
return beta * grad_output, None, None, None
class ShakeDrop(nn.Module):
"""Multiply the branch output by (b_l + α − b_l α); the backward pass uses (b_l + β − b_l β)"""
def __init__(self, p_l, alpha_range=(-1.0, 1.0), beta_range=(0.0, 1.0)):
super().__init__()
self.p_l, self.alpha_range, self.beta_range = p_l, alpha_range, beta_range
def forward(self, x):
if self.training:
return ShakeDropFunction.apply(x, self.p_l, self.alpha_range, self.beta_range)
# Inference: E[b_l + α − b_l α] = p_l + (1 − p_l) E[α] (with the ranges above, E[α] = 0, giving p_l)
mean_alpha = sum(self.alpha_range) / 2
return (self.p_l + (1 - self.p_l) * mean_alpha) * x
class PyramidStyleBlock(nn.Module):
"""A residual block whose branch ends with BN (PyramidNet style). Uses α ∈ [−1, 1], β ∈ [0, 1]"""
def __init__(self, channels, p_l):
super().__init__()
self.branch = nn.Sequential(
nn.BatchNorm2d(channels),
nn.Conv2d(channels, channels, 3, padding=1, bias=False),
nn.BatchNorm2d(channels),
nn.ReLU(),
nn.Conv2d(channels, channels, 3, padding=1, bias=False),
nn.BatchNorm2d(channels),
)
self.shake_drop = ShakeDrop(p_l, alpha_range=(-1.0, 1.0), beta_range=(0.0, 1.0))
def forward(self, x):
return x + self.shake_drop(self.branch(x))
# p_l decays linearly: p_l = 1 − (l / L)(1 − p_L), p_L = 0.5
L, p_L = 4, 0.5
model = nn.Sequential(*[PyramidStyleBlock(32, 1 - (l / L) * (1 - p_L)) for l in range(1, L + 1)])
x = torch.randn(8, 32, 16, 16)
model.train() # training: draw b_l, α, and β every time
model(x).sum().backward()
model.eval() # inference: multiply the branch output by p_l (same output every time)
with torch.no_grad():
print(torch.allclose(model(x), model(x))) # True
# If the branch does not end with BN, as in the original ResNet, use α = 0, β ∈ [0, 1]
resnet_style = ShakeDrop(p_l=0.5, alpha_range=(0.0, 0.0), beta_range=(0.0, 1.0))
FAQ
Q. How should p_L be chosen?
A.
Following Stochastic Depth, the paper uses p_L = 0.5 as the default, with 0.5 for CIFAR and 0.9 for ImageNet. p_L is the probability that the last block is not perturbed, so smaller values mean stronger regularization. Shallow networks did better with a larger (weaker) p_L. Choose a value in the range 0.5–0.9 while watching the validation error.
Q. Which ranges of α and β should I use?
A.
For networks whose branch ends with batch normalization (PyramidNet, the EraseReLU variant of ResNet with the ReLU removed, etc.), use α ∈ [−1, 1], β ∈ [0, 1]. For networks with a ReLU after the branch, like the original ResNet, use α = 0, β ∈ [0, 1]. In the paper, swapping the two made training fail to converge.
Q. What does it improve over Shake-Shake?
A.
Mainly two things. First, it works with single-branch ResNet, Wide ResNet, and PyramidNet. Second, even on two-branch ResNeXt, where Shake-Shake applies, it lowered the error rate in many cases. For example, on CIFAR-100 with ResNeXt-29 2-4-64d, ShakeDrop scored 18.27% versus 19.16% for Shake-Shake.