Level 4 — ApplicationConvolutional Neural Networks

Convolutional Neural Networks

60 minutes60 marksprintable — key stays hidden on paper

Level: 4 — Application (novel problems, no hints) Time limit: 60 minutes Total marks: 60

Answer all questions. Show all working. Use ...... notation for mathematics where required.


Question 1 — Spatial Dimension & Cost Analysis (14 marks)

A network processes an RGB input of size 224×224×3224 \times 224 \times 3.

The first block applies:

  • Conv-A: 64 filters, kernel 7×77\times 7, stride 22, padding 33
  • MaxPool: kernel 3×33\times 3, stride 22, padding 11
  • Conv-B: 128 filters, kernel 3×33\times 3, stride 11, dilation 22, padding 22

(a) Compute the output spatial size (H×W)(H\times W) and number of channels after each of the three layers. Use O=I+2pd(k1)1s+1O = \left\lfloor \frac{I + 2p - d(k-1) - 1}{s} \right\rfloor + 1. (6)

(b) Compute the number of learnable parameters (including biases) in Conv-A and Conv-B. (4)

(c) Compute the number of multiply–accumulate (MAC) operations required by Conv-B (ignore bias). (4)


Question 2 — Receptive Field Design (12 marks)

A designer stacks convolution layers, each 3×33\times 3, stride 11, no pooling.

(a) Derive/state the receptive field size after stacking nn such layers, and compute it for n=5n=5. (4)

(b) The designer needs a receptive field of at least 31×3131\times 31 using only 3×33\times3 stride-1 layers. What is the minimum number of layers? (3)

(c) Explain quantitatively why stacking three 3×33\times3 conv layers is preferred over a single 7×77\times7 layer for the same receptive field, comparing parameter counts (assume CC input and CC output channels throughout, no bias). (5)


Question 3 — Architecture Reasoning (14 marks)

(a) An Inception module receives a 28×28×25628\times28\times256 input. It contains a 1×11\times1 conv reducing to 64 channels before a 5×55\times5 conv (padding 2, stride 1) that outputs 128 channels. Compare the MAC cost of this bottleneck path against a naive 5×55\times5 conv applied directly from 256 → 128 channels. State the reduction factor. (6)

(b) A ResNet residual block computes y=F(x)+xy = F(x) + x. Explain, with reference to gradient flow, why this helps train very deep networks, and state what must hold about the dimensions of F(x)F(x) and xx. Describe the fix used when they differ. (4)

(c) Contrast how DenseNet and ResNet combine features from earlier layers, and state one consequence for parameter efficiency. (4)


Question 4 — Detection & Segmentation Application (12 marks)

(a) A YOLO-style detector divides a 416×416416\times416 image into a 13×1313\times13 grid. Each cell predicts 3 anchor boxes, and the dataset has 20 classes. Each box predicts 4 box coordinates + 1 objectness + class scores. Compute the number of output values per cell and the total output tensor size. (5)

(b) You must segment medical images where objects are small and precise boundaries matter. Justify choosing a U-Net over a plain FCN, referencing skip connections and resolution recovery. (4)

(c) Object detection with two-stage R-CNN is accurate but slow. Give one architectural reason for the speed gap versus single-stage YOLO/SSD. (3)


Question 5 — Transfer Learning & Augmentation Strategy (8 marks)

You have 800 labelled X-ray images (2 classes) and access to an ImageNet-pretrained ResNet-50.

(a) Propose a concrete transfer-learning strategy (which layers to freeze/train, what to replace). Justify given the small dataset. (5)

(b) Give three data-augmentation transforms appropriate for X-rays, and name one common augmentation you should avoid for medical X-rays, with reasoning. (3)


Answer keyMark scheme & solutions

Question 1 (14 marks)

(a) Formula: O=I+2pd(k1)1s+1O = \left\lfloor \frac{I + 2p - d(k-1) - 1}{s} \right\rfloor + 1

Conv-A (I=224,p=3,d=1,k=7,s=2I=224, p=3, d=1, k=7, s=2): O=(224+661)/2+1=223/2+1=111+1=112O = \lfloor (224 + 6 - 6 - 1)/2\rfloor + 1 = \lfloor 223/2\rfloor + 1 = 111 + 1 = 112. → 112×112×64112\times112\times64. (2)

MaxPool (I=112,p=1,d=1,k=3,s=2I=112, p=1, d=1, k=3, s=2): O=(112+221)/2+1=111/2+1=55+1=56O = \lfloor (112 + 2 - 2 - 1)/2\rfloor + 1 = \lfloor 111/2\rfloor + 1 = 55 + 1 = 56. → 56×56×6456\times56\times64 (channels unchanged). (2)

Conv-B (I=56,p=2,d=2,k=3,s=1I=56, p=2, d=2, k=3, s=1): effective kernel =d(k1)+1=5= d(k-1)+1 = 5. O=(56+441)/1+1=55+1=56O = \lfloor (56 + 4 - 4 - 1)/1\rfloor + 1 = 55 + 1 = 56. → 56×56×12856\times56\times128. (2)

(b) Params =(k2Cin+1)Cout= (k^2 \cdot C_{in} + 1)\cdot C_{out}.

  • Conv-A: (773+1)64=(147+1)64=14864=9472(7\cdot7\cdot3 + 1)\cdot64 = (147+1)\cdot64 = 148\cdot64 = 9472. (2)
  • Conv-B: (3364+1)128=(576+1)128=577128=73856(3\cdot3\cdot64 + 1)\cdot128 = (576+1)\cdot128 = 577\cdot128 = 73856. (2)

(Dilation does not change parameter count — kernel weights unchanged.)

(c) MACs for Conv-B =HoutWoutCoutk2Cin= H_{out}\cdot W_{out}\cdot C_{out}\cdot k^2 \cdot C_{in} =5656128964=5656=3136; 3136128=401408; ×9=3,612,672; ×64=231,211,008= 56\cdot56\cdot128\cdot9\cdot64 = 56\cdot56 = 3136;\ 3136\cdot128 = 401408;\ \times9 = 3{,}612{,}672;\ \times64 = 231{,}211{,}008. → 2.31×108\approx 2.31\times10^8 MACs. (4)


Question 2 (12 marks)

(a) For stride-1 k×kk\times k layers, receptive field after nn layers: RF=1+n(k1)=1+2nRF = 1 + n(k-1) = 1 + 2n for k=3k=3. For n=5n=5: RF=1+10=11RF = 1 + 10 = 1111×1111\times11. (4)

(b) Need 1+2n312n30n151+2n \ge 31 \Rightarrow 2n \ge 30 \Rightarrow n \ge 15. Minimum 15 layers. (3)

(c) Both give RF 7×77\times7 (three 3×33\times3: 1+23=71+2\cdot3=7).

  • Three 3×33\times3: 3×(33CC)=27C23\times(3\cdot3\cdot C\cdot C) = 27C^2 params.
  • One 7×77\times7: 77CC=49C27\cdot7\cdot C\cdot C = 49C^2 params. Ratio 27/490.5527/49 \approx 0.55 → ~45% fewer parameters, plus extra non-linearities (more representational power) and less compute. (5) (2 for correct param counts, 2 for ratio, 1 for non-linearity point.)

Question 3 (14 marks)

(a) Output spatial size 28×2828\times28 (padding preserves).

  • Naive 256→128, 5×55\times5: MACs =282812825256= 28\cdot28\cdot128\cdot25\cdot256. =78412825256=784128=100352; ×25=2,508,800; ×256=642,252,800=784\cdot128\cdot25\cdot256 = 784\cdot128=100352;\ \times25=2{,}508{,}800;\ \times256=642{,}252{,}800. (2)
  • Bottleneck: 1×11\times1 (256→64) then 5×55\times5 (64→128).
  • 1×11\times1: 2828641256=78464256=12,845,05628\cdot28\cdot64\cdot1\cdot256 = 784\cdot64\cdot256 = 12{,}845{,}056.
  • 5×55\times5: 28281282564=7841282564=160,563,20028\cdot28\cdot128\cdot25\cdot64 = 784\cdot128\cdot25\cdot64 = 160{,}563{,}200.
  • Total =173,408,256= 173{,}408{,}256. (2)
  • Reduction factor =642,252,800/173,408,2563.70×= 642{,}252{,}800 / 173{,}408{,}256 \approx 3.70\times. (2)

(b) The skip connection lets gradients flow directly to earlier layers via the identity path: y/x=1+F/x\partial y/\partial x = 1 + \partial F/\partial x, so gradients don't vanish even if F/x\partial F/\partial x is small. It's easier to learn a residual (near-zero) than a full mapping, mitigating degradation in deep nets. (2) Dimensions of F(x)F(x) and xx must match (same H×W×CH\times W\times C). When they differ (e.g., stride/channel change), use a 1×11\times1 conv (projection shortcut) on xx to match dimensions. (2)

(c) ResNet adds (element-wise sum) the identity to the block output; DenseNet concatenates all previous feature maps as input to each layer. Consequence: DenseNet reuses features so each layer can be narrow (few filters), giving high parameter efficiency; ResNet's sum requires matching channel counts and doesn't grow input width. (4)


Question 4 (12 marks)

(a) Per box: 4+1+20=254 + 1 + 20 = 25 values. Per cell: 3×25=753\times25 = 75 values. (3) Total tensor: 13×13×75=169×75=12,67513\times13\times75 = 169\times75 = 12{,}675 values (or shape 13×13×7513\times13\times75). (2)

(b) U-Net's encoder–decoder with skip connections copies high-resolution feature maps from encoder to decoder, restoring fine spatial detail lost during downsampling — critical for small objects and precise boundaries. Plain FCN upsamples from coarse features with fewer/weaker skip fusions, giving blurrier boundaries. U-Net's symmetric expansive path progressively recovers resolution while combining semantic + spatial info. (4)

(c) Two-stage R-CNN first runs a region-proposal stage then classifies each proposal (many forward passes / per-region computation), whereas single-stage detectors predict boxes + classes in one dense forward pass over the grid — eliminating the separate proposal stage. (3)


Question 5 (8 marks)

(a) With only 800 images, freeze the early/mid convolutional layers (generic edge/texture features), replace the final FC/classification head with a new 2-unit (or 1-unit sigmoid) layer, and fine-tune only the head (and optionally the last conv block) at a low learning rate. Freezing prevents overfitting the many pretrained parameters on scarce data; the new head adapts to the X-ray task. (5) (Reasonable variants accepted: full fine-tune with low LR + heavy regularization noted as riskier.)

(b) Suitable: small rotations, horizontal flips (if anatomically valid), random brightness/contrast, small translations/scaling, elastic/crop. (2) Avoid: vertical flips or large arbitrary rotations / left-right flips if orientation is diagnostically meaningful — they create anatomically impossible/mislabeled images (e.g., flipping heart to wrong side). (1)


[
  {"claim":"Conv-A output spatial size is 112","code":"I=224;p=3;d=1;k=7;s=2; O=(I+2*p-d*(k-1)-1)//s+1; result=(O==112)"},
  {"claim":"Conv-B output spatial size is 56","code":"I=56;p=2;d=2;k=3;s=1; O=(I+2*p-d*(k-1)-1)//s+1; result=(O==56)"},
  {"claim":"Conv-B parameters = 73856","code":"result=((3*3*64+1)*128==73856)"},
  {"claim":"Conv-B MACs = 231211008","code":"result=(56*56*128*9*64==231211008)"},
  {"claim":"Three 3x3 vs one 7x7 param ratio 27/49","code":"result=(Rational(27,49)==Rational(3*9,49))"},
  {"claim":"Inception bottleneck reduction ~3.70x","code":"naive=28*28*128*25*256; bott=28*28*64*1*256 + 28*28*128*25*64; result=(round(naive/bott,2)==3.70)"},
  {"claim":"YOLO per-cell values = 75 and total 12675","code":"per=3*(4+1+20); tot=13*13*per; result=(per==75 and tot==12675)"}
]