A 4×4 feature map X=[1320421501322611] goes through 2×2 pooling with stride 2, giving a 2×2 output. The gradient of the loss with respect to that output is G=[2−10.54]. What is the gradient with respect to X for max pooling and for average pooling?

Deep learning, Convolutional networks
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can route gradients backwards through pooling layers, which have no weights but still affect backpropagation.

Key idea

Max pooling passes the whole upstream gradient to the position of the maximum in each window (the "winner") and zero to the others. Average pooling splits the upstream gradient equally, so each of the k2 inputs gets g/k2.

Steps

  1. Split X into four 2×2 windows. Top-left {1,3,4,2}, top-right {2,0,1,5}, bottom-left {0,1,2,6}, bottom-right {3,2,1,1}.
  2. Forward max pooling. The maxima are 4,5,6,3, so the output is [4563]. Their positions (row, column) are (2,1), (2,4), (4,2) and (3,3).
  3. Backward max pooling. Put each upstream gradient at its window's winner and zero elsewhere. ∂L/∂X21=2, ∂L/∂X24=−1, ∂L/∂X42=0.5, ∂L/∂X33=4. All other 12 entries are 0.
  4. Forward average pooling. The window means are 10/4=2.5, 8/4=2, 9/4=2.25 and 7/4=1.75. They are not needed for the backward pass.
  5. Backward average pooling. Each input in a window gets g/4, since ∂y/∂xi=1/4. The top-left window gets 0.5 in every cell, top-right −0.25, bottom-left 0.125 and bottom-right 1.
  6. Check. The sum of ∂L/∂X equals the sum of G in both cases (2−1+0.5+4=5.5), because each window passes on exactly the gradient it received.

Common mistakes

How long your answer should be

Half a page with the two 4×4 gradient matrices; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: A network uses cosine annealing without restarts from ηmax⁡=0.1 down to ηmin⁡=0 over T=100 steps: ηt=ηmin⁡+12(ηmax⁡−ηmin⁡)(1+cos⁡(πt/T)). What is the learning rate at t=0,25,50,75,100, and why is cosine decay often preferred over step decay?
Next in Deep learning: A network has two layers with no activation function. Layer 1 is h=W1x+b1 with W1=[1201], b1=(1,0)⊤. Layer 2 is y^=W2h+b2 with W2=[2011], b2=(0,1)⊤. What single layer W′x+b′ does the same job, and does it agree with the two layers at x=(1,1)⊤?