# Drill 33 Padding stride and channels

Subject: Deep Learning

Exam: MT2

Reader: https://deep-learning-study-room.vercel.app/#mt2/read/17/mt2-c17-s33

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

## Question

**Question.** Input 31 × 31 × 3; 5 × 5 convolution,8 filters, stride 2, padding 1. Find shape, weights, biases, total.

## Answer — step by step

### Given

Input shape = 31 × 31 × 3.

Filter size = 5 × 5; number of filters = 8.

Stride S = 2; padding P = 1 per side; one bias per filter.

### To find

Find output shape, weights, biases and total parameters.

### Formula — which one and why

**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.

N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.



$$
N_{\mathrm{out}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1
$$



**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.

**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.

K\_h,K\_w = filter height/width; C\_in = input channels; C\_out = number of filters and output channels. Spatial output positions reuse these weights.



$$
N_w=K_hK_wC_{\mathrm{in}}C_{\mathrm{out}}
$$





$$
N_b=C_{\mathrm{out}}
$$





$$
P=N_w+N_b
$$



**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.

### Solution — step by step

### Meaning of each given value

The input has height 31, width 31 and 3 channels. K = 5 is the filter width/height; S = 2 is the stride; P = 1 is padding on each side. Eight filters create eight output channels.

### Formulas used



$$
N_{\mathrm{out}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1
$$





$$
\text{weights}=K^2C_{\mathrm{in}}C_{\mathrm{out}},\quad \text{biases}=C_{\mathrm{out}}
$$





$$
\text{parameters}=\text{weights}+\text{biases}
$$



### Step 1: find the output height and width

Padding adds one cell on each side, so the padded width is 31 + 2 × 1 = 33.



$$
N_{\mathrm{out}}=\left\lfloor\frac{31+2(1)-5}{2}\right\rfloor+1
$$





$$
N_{\mathrm{out}}=\left\lfloor\frac{28}{2}\right\rfloor+1=14+1=15
$$



The height uses the same calculation. **Output shape = 15 × 15 × 8.**

### Step 2: count weights in one filter

Each filter covers 5 × 5 positions in each of 3 channels.



$$
5\times5\times3=75\text{ weights per filter}
$$



### Step 3: count all filters and their biases



$$
\text{weights}=75\times8=600
$$





$$
\text{biases}=8,\qquad \text{total}=600+8=608
$$



**Final answer:** shape 15 × 15 × 8; 600 weights; 8 biases; 608 parameters. The 15 × 15 output locations reuse those weights.
