M3-097M3: Deep Learning FoundationsConvolution & Vision FoundationsEasy
⚡Flashcard Drill➔Mastery:

Calculating Convolutional Layer Parameter Count and Output Spatial Dimensions

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M3-098 →
📐 Mathematical Definition
params=k2CinCout+Cout;Hout=⌊H+2P−kS⌋+1\text{params}=k^2 C_{in}C_{out}+C_{out};\qquad H_{out}=\left\lfloor\frac{H+2P-k}{S}\right\rfloor+1
⚡ One-Sentence Core Answer
Output spatial dimension is ⌊W−K+2PS⌋+1\lfloor \frac{W - K + 2P}{S} \rfloor + 1; total parameters equal K2⋅Cin⋅Cout+CoutK^2 \cdot C_{\text{in}} \cdot C_{\text{out}} + C_{\text{out}} (with bias).

📌 Key Takeaways

  • •
    Output spatial formula: O=⌊I−K+2PS⌋+1O = \lfloor \frac{I - K + 2P}{S} \rfloor + 1, where II is input size, KK kernel, PP padding, SS stride
  • •
    Parameter count formula: Params=Kh⋅Kw⋅Cin⋅Cout+Cout\text{Params} = K_h \cdot K_w \cdot C_{\text{in}} \cdot C_{\text{out}} + C_{\text{out}} (with bias)
  • •
    Input size independence: convolutional parameter counts are strictly independent of input image spatial height HH and width WW

📐 Mathematical Derivations

Exact Mathematical Formulas:
① Output Spatial Dimensions:
Given input height HinH_{\text{in}}, width WinW_{\text{in}}, kernel size Kh×KwK_h \times K_w, padding Ph,PwP_h, P_w, dilation Dh,DwD_h, D_w, and stride Sh,SwS_h, S_w:
Effective kernel size with dilation: K~=D(K−1)+1\tilde{K} = D(K - 1) + 1.
Hout=⌊Hin−K~h+2PhSh⌋+1H_{\text{out}} = \left\lfloor \frac{H_{\text{in}} - \tilde{K}_h + 2 P_h}{S_h} \right\rfloor + 1, Wout=⌊Win−K~w+2PwSw⌋+1\quad W_{\text{out}} = \left\lfloor \frac{W_{\text{in}} - \tilde{K}_w + 2 P_w}{S_w} \right\rfloor + 1.
- Same Padding Condition (S=1,Hout=HinS=1, H_{\text{out}} = H_{\text{in}}): Requires 2P=K−1  ⟹  P=K−122P = K - 1 \implies P = \frac{K - 1}{2} (for odd kernel KK).
② Parameter Count:
Each output channel requires a 3D kernel of shape (Kh,Kw,Cin)(K_h, K_w, C_{\text{in}}) plus 1 scalar bias.
Params=Cout×(Kh×Kw×Cin+1)\text{Params} = C_{\text{out}} \times (K_h \times K_w \times C_{\text{in}} + 1).
③ Computational FLOPs (Multiply-Adds):
FLOPs=Hout×Wout×Cout×(Kh×Kw×Cin)\text{FLOPs} = H_{\text{out}} \times W_{\text{out}} \times C_{\text{out}} \times (K_h \times K_w \times C_{\text{in}}). Notice that FLOPs scale directly with output spatial resolution HoutWoutH_{\text{out}} W_{\text{out}}, whereas parameters do not.

🏭 Production Trade-offs

Calculated Example: For an input of shape (3,224,224)(3, 224, 224) processed by a Conv2D layer with Cout=64,K=7,S=2,P=3C_{\text{out}} = 64, K=7, S=2, P=3:
- Output size: ⌊224−7+2(3)2⌋+1=⌊2232⌋+1=111+1=112\lfloor \frac{224 - 7 + 2(3)}{2} \rfloor + 1 = \lfloor \frac{223}{2} \rfloor + 1 = 111 + 1 = 112. Output shape is (64,112,112)(64, 112, 112).
- Parameters: 7×7×3×64+64=9,408+64=9,4727 \times 7 \times 3 \times 64 + 64 = 9,408 + 64 = 9,472.
⚠️ Common Interview Pitfalls
  • ✕
    Forgetting to floor the division ⌊… ⌋\lfloor \dots \rfloor, leading to off-by-one errors in asymmetric stride calculations
  • ✕
    Confusing parameter count (independent of H,WH, W) with computational FLOPs (proportional to H×WH \times W)
🎯 Interviewer Follow-up Inquiries
  • ?
    How does dilated (atrous) convolution expand receptive field without adding a single trainable parameter?
  • ?
    What padding value PP is required to preserve exact spatial resolution for an odd kernel of size KK with stride S=1S=1?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM3-096: Parameter Sharing in Deep Learning: Forms, Mechanisms, and Regularizing Impact📋 Back to BankNext →M3-098: Recursive Calculation of Receptive Field in Convolutional Networks