Deep Learning · MT2 · section

Drill 34 Max and average pooling

MT2 numerical practice from direct to mixed

Question

Question. Pool the input A shown below with 2 × 2 windows and stride 2. Find max and average outputs.

Given matrices for this question Tap the diagram to enlarge.

Answer — step by step

Given

Input A is printed with the question.

Window size = 2 × 2; stride = 2; no padding.

To find

Find the complete max-pooling and average-pooling outputs.

Formula — which one and why

Pooling. Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.

V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.

y_{\max}=\max VLaTeX: y_{\max}=\max V
y_{\mathrm{avg}}=\frac1n\sum_{v\in V}vLaTeX: y_{\mathrm{avg}}=\frac1n\sum_{v\in V}v

Yaad rakhne ka cue: Max mein biggest; average mein total ÷ window ka count.

Solution — step by step

Formulas and meaning

Each 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.

p_{\mathrm{max}}=\max(a_1,a_2,a_3,a_4)LaTeX: p_{\mathrm{max}}=\max(a_1,a_2,a_3,a_4)
p_{\mathrm{avg}}=\frac{a_1+a_2+a_3+a_4}{4}LaTeX: p_{\mathrm{avg}}=\frac{a_1+a_2+a_3+a_4}{4}
N_{\mathrm{pool}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1LaTeX: N_{\mathrm{pool}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1

Use the input size at the pooling layer. The output keeps the same channel count.

Shape: \left\lfloor\frac{4-2}{2}\right\rfloor+1LaTeX: \left\lfloor\frac{4-2}{2}\right\rfloor+1 = 2 on each axis; channels stay unchanged.

Pooling window (1,1)

Step 1: select the entries.

[1, 4, 0, 2]

Step 2: add all selected entries.

1 + 4 + 0 + 2 = 7

Step 3: divide by the 4 entries in this window.

7/4 = 1.75. Maximum = 4

Pooling window (1,2)

Step 1: select the entries.

[2, 3, 5, 1]

Step 2: add all selected entries.

2 + 3 + 5 + 1 = 11

Step 3: divide by the 4 entries in this window.

11/4 = 2.75. Maximum = 5

Pooling window (2,1)

Step 1: select the entries.

[6, 3, 1, 7]

Step 2: add all selected entries.

6 + 3 + 1 + 7 = 17

Step 3: divide by the 4 entries in this window.

17/4 = 4.25. Maximum = 7

Pooling window (2,2)

Step 1: select the entries.

[2, 0, 4, 8]

Step 2: add all selected entries.

2 + 0 + 4 + 8 = 14

Step 3: divide by the 4 entries in this window.

14/4 = 3.5. Maximum = 8

Average output: \begin{bmatrix}1.75 & 2.75\\4.25 & 3.5\end{bmatrix}LaTeX: \begin{bmatrix}1.75 & 2.75\\4.25 & 3.5\end{bmatrix}. Max output: \begin{bmatrix}4 & 5\\7 & 8\end{bmatrix}LaTeX: \begin{bmatrix}4 & 5\\7 & 8\end{bmatrix}. Pooling normally has zero trainable parameters and reduces spatial dimensions.