Deep Learning · MT2 · section

Drill 36 Reverse a spatial formula

MT2 numerical practice from direct to mixed

Question

Question. A stride-1, valid 3 × 3 convolution outputs 18 × 18 × 12. What input spatial size is needed? Is input channel count determined?

Answer — step by step

Given

Output shape = 18 × 18 × 12.

Kernel = 3 × 3; stride = 1; valid padding P = 0.

Input channel count is not supplied.

To find

Solve for input height/width; state whether input channels and parameter count are uniquely determined.

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+1LaTeX: 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}}LaTeX: N_w=K_hK_wC_{\mathrm{in}}C_{\mathrm{out}}
N_b=C_{\mathrm{out}}LaTeX: N_b=C_{\mathrm{out}}
P=N_w+N_bLaTeX: P=N_w+N_b

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

Solution — step by step

Formula used

For stride 1 and valid padding, the output width is input width minus kernel width plus one.

N_{\mathrm{out}}=N-K+1LaTeX: N_{\mathrm{out}}=N-K+1

Step 1: substitute the known output and kernel sizes

18=N-3+1=N-2LaTeX: 18=N-3+1=N-2

Step 2: isolate the unknown input size

Add 2 to both sides. Doing the same operation to both sides preserves the equality.

18+2=N-2+2LaTeX: 18+2=N-2+2
N=20LaTeX: N=20

Step 3: interpret the channel information

The 12 output channels tell us there are 12 filters. They do not say how many channels the input has. An RGB input and a many-channel intermediate map could both feed 12 filters.

With one bias per filter, the parameter formula would be:

P=(3\times3\times C_{\mathrm{in}}+1)\times12LaTeX: P=(3\times3\times C_{\mathrm{in}}+1)\times12

Final answer: input spatial shape 20 × 20; input channel count is undetermined from these givens.