Deep Learning · MT2 · section
Faculty example: a complete binary-image convolution
Convolutional neural networks
Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)
Given
Image X = LaTeX:
\begin{bmatrix}1 & 1 & 1 & 0 & 0\\0 & 1 & 1 & 1 & 0\\0 & 0 & 1 & 1 & 1\\0 & 0 & 1 & 1 & 0\\0 & 1 & 1 & 0 & 0\end{bmatrix}.
Filter K = LaTeX:
\begin{bmatrix}1 & 0 & 1\\0 & 1 & 0\\1 & 0 & 1\end{bmatrix}. These are the values in the Unit 4 lecture example.
To find
The output shape and all nine feature-map values.
Formula — which one and why
The output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.
N_{\mathrm{out}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1Here N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter's coefficients.
Y_{ij}=\sum_{u,v}X_{iS+u,jS+v}K_{uv}+bFor this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always top-left, top-right, centre, bottom-left, bottom-right within the current window.
Solution — step by step
Step 1: find the shape. (5 − 3)/1 + 1 = 3. The output is 3 × 3.
Step 2: top-left output, showing all nine products. 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = 4.
Step 3: top-middle output. Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = 3.
Step 4: top-right output. Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = 4.
Step 5: middle-left output. Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = 2.
Step 6: middle-middle output. Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = 4.
Step 7: middle-right output. Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = 3.
Step 8: bottom-left output. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = 2.
Step 9: bottom-middle output. Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = 3.
Step 10: bottom-right output. Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = 4.
Final answer: Y = LaTeX:
\begin{bmatrix}4 & 3 & 4\\2 & 4 & 3\\2 & 3 & 4\end{bmatrix}. All nine outputs use the same nine filter weights. They do not introduce nine different filters.
Yaad rakho: Window badalta hai; filter ke numbers same rehte hain.