# F23 Q1d

Subject: Deep Learning

Exam: MT2

Reader: https://deep-learning-study-room.vercel.app/#mt2/read/13/mt2-c13-s1

Canonical: https://deep-learning-study-room.vercel.app/read/dl/mt2/section/mt2-c13-s1/

## Question

**Question (5 marks).** Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.

Given matrices

Input A

Input A

|  |  |  |  |
| --- | --- | --- | --- |
| 10 | 9 | 5 | 6 |
| 5 | 7 | 6 | 7 |
| 3 | 3 | 2 | 8 |
| 3 | 2 | 6 | 7 |

Kernel K

Kernel K

|  |  |  |
| --- | --- | --- |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 1 | 1 |

Stride 1; P = 0 (no padding).

## Answer — step by step

### Given

Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.

### To find

Find every convolution output cell.

### Formula — which one and why

**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.

X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.



$$
Y_{ij}=\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b
$$



**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.

### Solution — step by step

Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.

**Step 1 shape:**   $\left\lfloor\frac{4+2 \times  0-3}{1}\right\rfloor+1$  = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.

### Output position (1, 1)

Use this position's input window. Multiply corresponding entries row by row; then add all row totals.

Follow window (1, 1) into one output cell

Input rows **1–3**, columns **1–3**. The window moves **1** cell per output step.

1. Select the input window

1. Select the input window

|  |  |  |  |
| --- | --- | --- | --- |
| 10 | 9 | 5 | 6 |
| 5 | 7 | 6 | 7 |
| 3 | 3 | 2 | 8 |
| 3 | 2 | 6 | 7 |

Only the outlined cells belong to this output.

2. Match the kernel

2. Match the kernel

|  |  |  |
| --- | --- | --- |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 1 | 1 |

Same row and column positions; no matrix multiplication.

3. Multiply cell by cell

3. Multiply cell by cell

|  |  |  |
| --- | --- | --- |
| 10 | 9 | 5 |
| 5 | 14 | 6 |
| 3 | 3 | 2 |

Each cell is input × matching kernel coefficient.

4. Add the products row by row

Row 1**10 + 9 + 5 = 24**

Row 2**5 + 14 + 6 = 25**

Row 3**3 + 3 + 2 = 8**

**24 + 25 + 8 = 57**

5. Place it in the output

5. Place it in the output

|  |  |
| --- | --- |
| 57 | 59 |
| 40 | 50 |

Output row 1, column 1.

**Window row 1.**



$$
R_1=(10)\times(1)+(9)\times(1)+(5)\times(1)=24
$$



**Window row 2.**



$$
R_2=(5)\times(1)+(7)\times(2)+(6)\times(1)=25
$$



**Window row 3.**



$$
R_3=(3)\times(1)+(3)\times(1)+(2)\times(1)=8
$$



**Add the rows to obtain one output cell.**



$$
Y_{1,1}=(24)+(25)+(8)=57
$$



### Output position (1, 2)

Use this position's input window. Multiply corresponding entries row by row; then add all row totals.

Follow window (1, 2) into one output cell

Input rows **1–3**, columns **2–4**. The window moves **1** cell per output step.

1. Select the input window

1. Select the input window

|  |  |  |  |
| --- | --- | --- | --- |
| 10 | 9 | 5 | 6 |
| 5 | 7 | 6 | 7 |
| 3 | 3 | 2 | 8 |
| 3 | 2 | 6 | 7 |

Only the outlined cells belong to this output.

2. Match the kernel

2. Match the kernel

|  |  |  |
| --- | --- | --- |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 1 | 1 |

Same row and column positions; no matrix multiplication.

3. Multiply cell by cell

3. Multiply cell by cell

|  |  |  |
| --- | --- | --- |
| 9 | 5 | 6 |
| 7 | 12 | 7 |
| 3 | 2 | 8 |

Each cell is input × matching kernel coefficient.

4. Add the products row by row

Row 1**9 + 5 + 6 = 20**

Row 2**7 + 12 + 7 = 26**

Row 3**3 + 2 + 8 = 13**

**20 + 26 + 13 = 59**

5. Place it in the output

5. Place it in the output

|  |  |
| --- | --- |
| 57 | 59 |
| 40 | 50 |

Output row 1, column 2.

**Window row 1.**



$$
R_1=(9)\times(1)+(5)\times(1)+(6)\times(1)=20
$$



**Window row 2.**



$$
R_2=(7)\times(1)+(6)\times(2)+(7)\times(1)=26
$$



**Window row 3.**



$$
R_3=(3)\times(1)+(2)\times(1)+(8)\times(1)=13
$$



**Add the rows to obtain one output cell.**



$$
Y_{1,2}=(20)+(26)+(13)=59
$$



### Output position (2, 1)

Use this position's input window. Multiply corresponding entries row by row; then add all row totals.

Follow window (2, 1) into one output cell

Input rows **2–4**, columns **1–3**. The window moves **1** cell per output step.

1. Select the input window

1. Select the input window

|  |  |  |  |
| --- | --- | --- | --- |
| 10 | 9 | 5 | 6 |
| 5 | 7 | 6 | 7 |
| 3 | 3 | 2 | 8 |
| 3 | 2 | 6 | 7 |

Only the outlined cells belong to this output.

2. Match the kernel

2. Match the kernel

|  |  |  |
| --- | --- | --- |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 1 | 1 |

Same row and column positions; no matrix multiplication.

3. Multiply cell by cell

3. Multiply cell by cell

|  |  |  |
| --- | --- | --- |
| 5 | 7 | 6 |
| 3 | 6 | 2 |
| 3 | 2 | 6 |

Each cell is input × matching kernel coefficient.

4. Add the products row by row

Row 1**5 + 7 + 6 = 18**

Row 2**3 + 6 + 2 = 11**

Row 3**3 + 2 + 6 = 11**

**18 + 11 + 11 = 40**

5. Place it in the output

5. Place it in the output

|  |  |
| --- | --- |
| 57 | 59 |
| 40 | 50 |

Output row 2, column 1.

**Window row 1.**



$$
R_1=(5)\times(1)+(7)\times(1)+(6)\times(1)=18
$$



**Window row 2.**



$$
R_2=(3)\times(1)+(3)\times(2)+(2)\times(1)=11
$$



**Window row 3.**



$$
R_3=(3)\times(1)+(2)\times(1)+(6)\times(1)=11
$$



**Add the rows to obtain one output cell.**



$$
Y_{2,1}=(18)+(11)+(11)=40
$$



### Output position (2, 2)

Use this position's input window. Multiply corresponding entries row by row; then add all row totals.

Follow window (2, 2) into one output cell

Input rows **2–4**, columns **2–4**. The window moves **1** cell per output step.

1. Select the input window

1. Select the input window

|  |  |  |  |
| --- | --- | --- | --- |
| 10 | 9 | 5 | 6 |
| 5 | 7 | 6 | 7 |
| 3 | 3 | 2 | 8 |
| 3 | 2 | 6 | 7 |

Only the outlined cells belong to this output.

2. Match the kernel

2. Match the kernel

|  |  |  |
| --- | --- | --- |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 1 | 1 |

Same row and column positions; no matrix multiplication.

3. Multiply cell by cell

3. Multiply cell by cell

|  |  |  |
| --- | --- | --- |
| 7 | 6 | 7 |
| 3 | 4 | 8 |
| 2 | 6 | 7 |

Each cell is input × matching kernel coefficient.

4. Add the products row by row

Row 1**7 + 6 + 7 = 20**

Row 2**3 + 4 + 8 = 15**

Row 3**2 + 6 + 7 = 15**

**20 + 15 + 15 = 50**

5. Place it in the output

5. Place it in the output

|  |  |
| --- | --- |
| 57 | 59 |
| 40 | 50 |

Output row 2, column 2.

**Window row 1.**



$$
R_1=(7)\times(1)+(6)\times(1)+(7)\times(1)=20
$$



**Window row 2.**



$$
R_2=(3)\times(1)+(2)\times(2)+(8)\times(1)=15
$$



**Window row 3.**



$$
R_3=(2)\times(1)+(6)\times(1)+(7)\times(1)=15
$$



**Add the rows to obtain one output cell.**



$$
Y_{2,2}=(20)+(15)+(15)=50
$$



**Final output:**   $\begin{bmatrix}57 & 59\\40 & 50\end{bmatrix}$ . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.
