The explanation follows Equations (1) and (2) and Section 1.3 of the original paper. Let xi be the input to residual block i, F the branch function (in the paper, ReLU, 3×3 convolution, and batch normalization repeated twice), and Wi(1),Wi(2) the weights of the two branches.
- The starting point is a residual block that simply adds the outputs of the two branches.
xi+1=xi+F(xi,Wi(1))+F(xi,Wi(2))
- Before the training forward pass, αi is drawn from the uniform distribution on 0 to 1, and the two branches are mixed in the ratio αi:1−αi.
αi∼U(0,1),xi+1=xi+αiF(xi,Wi(1))+(1−αi)F(xi,Wi(2))
- Before the training backward pass, the coefficient is redrawn as a new random number βi. Branch 1 receives βi times the gradient from above, and branch 2 receives 1−βi times it (L is the loss).
βi∼U(0,1),∂F(1)∂L=βi∂xi+1∂L,∂F(2)∂L=(1−βi)∂xi+1∂L
- Steps 2 and 3 repeat, with fresh random numbers for every forward and backward pass.
- At inference, following the same idea as Dropout, the coefficient is fixed at its expected value of 0.5.
xi+1=xi+0.5F(xi,Wi(1))+0.5F(xi,Wi(2))
With ordinary backpropagation, a branch scaled by αi in the forward pass also receives a gradient scaled by αi in the backward pass. Shake-Shake deliberately uses a different random number here, perturbing the gradient that flows into a branch to βi/αi times its correct value (and (1−βi)/(1−αi) times for the other branch). This is why the coefficients differ between the left (forward) and middle (backward) panels of the figure above.
The paper compares combinations of how the forward and backward coefficients are chosen and the unit at which random numbers are drawn, using the following names.
| Name | Meaning |
|---|
| Shake | Draw a new random number |
| Even | Fix at 0.5 |
| Keep | Use the same coefficient in the backward pass as in the forward pass |
| Batch | Use the same coefficient for every image in the mini-batch |
| Image | Use a different coefficient for each image |
For example, "Shake-Shake-Image" means drawing new random numbers for both the forward and backward passes, per image. The method's name comes from this combination of Shake in both the forward and backward passes.
Shake-Shake multiplies the entire tensor by a single scalar αi (or 1−αi). Unlike Dropout, it does not apply a separate random number to each element. Even when drawing per image (Image), the whole feature map of one image is multiplied by the same coefficient.