Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

CNN architecture

Clear, exam-focused notes on convolutional neural network architectures: VGG, GoogLeNet (Inception), ResNet and DenseNet, with definitions, formulas, exam-style derivations and model answers.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Convolutional neural network (CNN) architectures are the backbone of modern computer-vision systems used in engineering tasks such as image classification, object detection and feature extraction. Knowing how VGG, GoogLeNet (Inception), ResNet and DenseNet are built helps an engineer choose or design models that trade off accuracy, memory and speed for deployment on devices or servers.

Key ideas

Define terms first (simple English):

  • Convolution: an operation that slides a small weight window (kernel) across an input tensor to produce a feature map. It learns local patterns.
  • Kernel / filter: the small weight matrix used by a convolution. Typical sizes: 1×1, 3×3, 5×5.
  • Stride: step size when sliding the kernel. Stride >1 reduces spatial size.
  • Padding: extra border values (often zeros) added to control output size; 'same' padding keeps the size unchanged.
  • Feature map: output channel of a convolution; shows where a learned pattern fires.
  • Channel: depth dimension of an image or feature tensor (e.g., RGB has 3 channels).
  • Receptive field: area in the input image that affects a single output unit.
  • Pooling: downsampling operation (e.g., max or average) that reduces spatial size and increases invariance.
  • Bottleneck: a layer (often 1×1 conv) that reduces channel count to lower parameters and computation.
  • Skip connection: a direct pathway from an earlier activation to a later layer; in ResNet it is identity addition y = F(x) + x, while in DenseNet it is concatenation (which increases channels).

Principles used across architectures:

  • Use small kernels (3×3) stacked to obtain larger receptive field with fewer parameters compared to a single large kernel. Derivation exam-style: two stacked 3×3 convs with nonlinearities have effective receptive field 5×5 but fewer params than one 5×5.
  • Use 1×1 convs to change channel dimension without affecting spatial size (used for bottleneck and for mixing channels).
  • Replace large fully connected (FC) blocks by global average pooling to reduce parameters and overfitting.
  • Introduce architectural motifs that ease training as depth increases: Inception uses parallel paths and bottlenecks; ResNet uses residual identity connections to allow training hundreds of layers; DenseNet uses dense concatenation to improve feature reuse and gradient flow.

VGG (visual geometry group) — exact idea:

  • VGG uses repeated stacks of 3×3 convolutions (same padding) and occasional pooling. The rule: replace a larger kernel by several 3×3 kernels. Example design: blocks of two or three 3×3 convs followed by 2×2 max pooling.
  • Assumptions: stride=1 inside block, ReLU activation after each conv, spatial downsampling only at pool layers.
  • Draw (diagram to draw for exam): horizontal sequence of blocks. For each block draw labeled boxes: Conv3×3, channels (e.g., 64), Conv3×3, channels, Pool2×2. At end draw FC layers (large) then softmax.

GoogLeNet / Inception (v1) — exact idea:

  • Inception module: parallel branches with 1×1 conv (bottleneck) -> 3×3 conv; 1×1 -> 5×5; 3×3 maxpool -> 1×1; and pure 1×1. The outputs are concatenated along channels.
  • Purpose: capture multi-scale features while controlling parameter growth via 1×1 reductions. GoogLeNet v1 also uses auxiliary classifiers (intermediate softmax heads) during training to improve gradient flow and regularization; these are discarded at test time.
  • Draw: a block showing parallel lanes labeled 1×1, 1×1+3×3, 1×1+5×5, pool+1×1 then arrows merging by concatenation.

ResNet (residual networks) — exact idea and theorem-like statement:

  • Definition (Residual mapping): A residual block computes y = F(x) + x where F(x) is the residual function (sequence of conv, BN, ReLU).
  • Key property (why it helps): The gradient through the addition retains a direct path: dL/dx = dL/dy · (dF/dx + I). This identity term prevents vanishing gradients and allows training of very deep nets.
  • Assumptions: Addition requires same spatial and channel dimensions; if channels differ, use a linear projection W_s x (1×1 conv) for the skip.
  • Bottleneck residual block (for deeper ResNets): 1×1 reduce channels, 3×3 conv, 1×1 expand channels. This reduces computation.
  • Diagram to draw: input x, three conv boxes in series (1×1, 3×3, 1×1) labeled with channel sizes, then add arrow from x to after third conv, output y.

DenseNet — exact idea:

  • Definition: In a dense block, each layer receives as input the concatenation of outputs from all preceding layers in that block. If layers have growth rate k (output channels per layer), then input channels to layer l = initial_channels + k·(l−1).
  • Benefit: Feature reuse and implicit deep supervision; reduces need for very large number of filters per layer.
  • Compression and transition layers (1×1 conv + pooling) reduce size between dense blocks.
  • Diagram: show multiple small conv layers with arrows from each earlier layer concatenated into each later layer.

Important exam derivations asked often:

  1. Parameter count for conv layer: see Formulas. 2) Receptive field growth: RF_{L} = RF_{L−1} + (k_L − 1)·jump_{L−1}, where jump_{L} = jump_{L−1}·stride_{L}. Derive step-by-step in answers.
  2. Show residual gradient path: derivative through addition yields identity term—write dL/dx = dL/dy·(I + dF/dx).

Formulas

Params_conv = k_h · k_w · C_in · C_out + C_out — parameters in a convolutional layer (with bias). k_h, k_w: kernel height and width (unit: unitless counts), C_in: input channels (count), C_out: output channels (count). Applies when using a separate bias per output channel. If no bias (common with batch norm), drop + C_out. Computation (MACs) for a convolutional layer: MACs ≈ H_out · W_out · C_out · (k_h · k_w · C_in); if counting multiply and add separately as FLOPs, multiply by 2.

Output_H = floor((H_in + 2·pad_h − k_h)/stride_h) + 1 — output spatial height. H_in: input height (pixels, count), pad_h: padding (pixels, count), stride_h: stride (pixels, count), k_h: kernel height (pixels, count).

ReceptiveField_Layer = ReceptiveField_{L−1} + (k_L − 1) · jump_{L−1} — receptive field of layer L. jump is cumulative stride (pixels) from input to previous layer.

RF_start = 1, jump_start = 1; jump_L = jump_{L−1} · stride_L — base values.

Residual_block: y = F(x) + x — F(x) is residual function (conv, BN, ReLU sequence). Applies when input and output dims match.

Dense_in_l = C_0 + k · (l − 1) — input channels to l-th layer inside a dense block; C_0: channels entering block, k: growth rate (channels per layer).

VGG_params_approx ≈ many parameters end up in FC layers — qualitative note: VGG-16 total params ≈ 138000000 (verify exact value for exam use).

Units: channels and spatial sizes are dimensionless counts (pixels are counts, not meters). Note: SI unit for pixel is not applicable; treat all such quantities as dimensionless counts.

Worked examples

Model answer 1 — Parameter count for a VGG-like block Question: Compute parameters for two stacked conv layers: Conv1: 3×3, C_in=64, C_out=128; Conv2: 3×3, C_in=128, C_out=128. Include biases. Answer: Step 1: Params Conv1 = 3·3·64·128 + 128 = 9·64·128 + 128 = 73728 + 128 = 73856. Step 2: Params Conv2 = 3·3·128·128 + 128 = 9·128·128 + 128 = 147456 + 128 = 147584. Step 3: Total params = 73856 + 147584 = 221440.

Model answer 2 — Receptive field after stacked layers Question: Input image 224×224. Two conv layers: both 3×3, stride=1, padding=1 (same). Then a 2×2 maxpool with stride 2. What is receptive field of units after pool? Answer: Step 1: For conv1 (k=3, s=1): RF1 = 1 + (3−1)·1 = 3. Step 2: For conv2: RF2 = RF1 + (3−1)·1 = 3 + 2 = 5. Step 3: After 2×2 pool with stride 2: RF_pool = RF2 + (2−1)·jump_before_pool. jump_before_pool = 1 (so far). So RF_pool = 5 + 1 = 6 pixels. (Alternate full formula: compute jumps: jump1=1, jump2=1, jump_pool=2; RF_pool = RF2 + (2−1)·jump2 = 5 + 1·1 = 6.)

Model answer 3 — Why residual helps (short proof expected in exams) Question: Show how residual connection improves gradient flow. Answer: Let loss be L(y). y = F(x) + x. Using chain rule: dL/dx = dL/dy · dy/dx = dL/dy · (dF/dx + I). Thus the gradient received by x has two terms: through F and directly through identity I. Even if dF/dx is small, the identity term preserves gradient magnitude, reducing vanishing. This allows deeper networks to train.

Common mistakes

  • For receptive field, students add kernel sizes rather than using the jump/stride multiplier rule.
  • For ResNet, writing y = F(x) × x (multiplicative) instead of y = F(x) + x.
  • For DenseNet, confusing concatenation with addition; they are different operations and change channel counts.
  • Stating that deeper is always better without noting optimisation issues (vanishing gradient, computing cost).

For your exam

Question types you will see:

  • Definitions and short notes: explain residual block, inception module, dense block. Full-marks answer must include a short diagram and the reason (training stability, parameter efficiency).
  • Derivations: derive receptive field formula or parameter count; show step-by-step numeric example.
  • Long question: compare two architectures (e.g., ResNet vs DenseNet) — include diagrams, parameter and computational trade-offs, and pros/cons for deployment.
  • Numericals: compute output dimension, parameter counts, receptive field after L layers.
  • Diagrams: draw an Inception module, a residual block, and a dense block with labels.

What full-marks answers include: clear definitions of terms used, labeled diagrams (draw boxes for layers, arrows for data flow), step-by-step algebra for formulas, and final numeric answers boxed/bolded. State assumptions (bias present or not, padding type) before computation.

Quick check

  1. What is the main operation that differentiates ResNet from VGG?
  2. In DenseNet, if growth rate k=12 and block entry channels C_0=24, what is input channels to 4th layer in block?
  3. For a conv with kernel 5×5, stride 1, no padding, what is increase in receptive field compared to kernel 3×3 (one layer)? Answers: 1) Residual (identity) addition y = F(x)+x (skip connection). 2) C_in = 24 + 12·(4−1) = 60. 3) 5×5 gives RF increase 4 vs 2 for 3×3; single 5×5 adds 4 pixels to RF while 3×3 adds 2, so increase = 2 pixels more.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?