Problem solved in full
-
Output map size for a 28×28 input map and 3×3 sobel-x kernel 6 steps
The layer: a 28×28 input map, a 3×3 sobel-x kernel, stride 1, padding same. Work out the size of the output map and what one pass costs in multiply-adds — then find how many such layers have to be stacked before a single output pixel depends on every pixel of the image.
-
Padding fixes the size, so settle it first. same lays a one-pixel border of zeros around the map, which is exactly enough for a 3×3 window to sit centred on a corner pixel instead of hanging off the edge. The border a kernel needs is half of it, not counting the centre.
-
Slide the window along one row. Its left edge starts at 0 and advances by the stride until its right edge reaches the end of the padded row, so counting output pixels is a fencepost count: the number of advances, plus 1 for the starting position. At stride 1 the border gives back exactly the 2 columns the kernel takes away, which is what same is named for.
-
Each of the 784 output pixels is one weighted sum of 9 input values. Add the sobel-x weights and they cancel to 0, so any window whose 9 inputs are all equal returns exactly 0 — however bright that region is. The map goes dark wherever the image is flat and responds only where the left column of the window differs from the right.
-
The arithmetic bill follows: 9 multiply-accumulates per output pixel, one output pixel per window position. The panel prints that count.
-
Depth is where it compounds. After one layer an output pixel sees 3 input pixels across. Add a second and each of those 3 was itself a window of 3 — but neighbouring windows overlap by 2, so the span reaches 5, not 9. Every further 3×3 stride-1 layer widens it by exactly 2.
-
Set the span to cover all 28 columns and solve for the depth. 13 layers reach 27 and fall one column short; the 14th is the first whose output pixels can be influenced by the whole image.
Answer
28×28 out, 7056 multiply-adds per layer, and 14 layers before one pixel sees the whole image. Now count what that reach costs. The 14 stacked layers spend 14 × 9 = 126 multiply-accumulates per output pixel. A single layer reaching just as far needs a 29×29 kernel, at 841 per output pixel — 6.7 times more arithmetic for exactly the same field of view. Depth buys reach far more cheaply than width does, which is why vision networks are long stacks of 3×3 kernels rather than short stacks of large ones.
-
References (1)
- Insight block 3 — the operation called convolution is cross-correlation: I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, ch. 9. MIT Press, 2016. ISBN 978-0-262-03561-3 — "many machine learning libraries implement cross-correlation but call it convolution".