MAI5063 Advances in Deep Learning · Lab 4 · Week 4 companion lab

Deeper nets and borrowed features

Build a VGG-style network and a mini-ResNet from scratch, then reuse a pretrained EfficientNetB0 in two ways: frozen as a feature extractor, and partly unfrozen for fine-tuning. The demos here explain why each design works before you compare them in Colab.

Platform Colab + TensorFlow/Keras Runtime GPU recommended Data Fashion-MNIST, 28×28 grayscale, 10 classes

By the end you can

  • Write a VGG-style block and a residual block in Keras.
  • Explain why Y = F(x) + x helps gradients reach early layers.
  • Attach a new head to EfficientNetB0, freeze it, then fine-tune the top layers.
  • Compare accuracy, parameters and convergence across all four approaches.
  • Choose a transfer strategy from dataset size and domain similarity.

Before the lab

This version uses Fashion-MNIST instead of CIFAR-10. It downloads in seconds and fits in memory when resized for the pretrained network.

Lecture link · Architecture families

Each architecture fixed one problem

Pick an architecture to see the idea it introduced, the equation behind it and where it appears in this lab.

EfficientNet compound scaling

depth × α^φ width × β^φ resolution × γ^φ α = 1.2, β = 1.1, γ = 1.15 α · β² · γ² ≈ 1.92 ≈ 2
Task 4 · VGG blocks, 1×1 convolution and GAP

Small kernels, stacked, and a lighter head

VGG replaces one large kernel with several 3×3 layers. Global Average Pooling replaces Flatten, so the head no longer depends on the map size.

Stacked 3×3 versus one large kernel

Flatten versus Global Average Pooling

Parameters in Dense(256) after the last feature map.

GAP(A_f) = (1 / H·W) · Σᵢⱼ A_f(i, j)

1×1 convolution

O(i, j, f) = Σ_c I(i, j, c) · K(c, f) + b_f
Task 5 · Residual blocks

The block learns a correction, not the whole mapping

Y = F(x) + x gives the gradient a direct path back through the identity. When the shape changes, a 1×1 projection makes the shortcut match.

Gradient reaching early layers

An idealised illustration, not a measurement. Plain: the gradient is multiplied by g at every layer. Residual: the identity path always contributes 1, so it cannot vanish.

plain stack, log₁₀ gradientwith identity shortcuts

Which shortcut do you need?

Tasks 4 and 5 · Count before you train

The two scratch models, layer by layer

Both take a 28×28×1 image and end in Global Average Pooling. Compare your counts with model.summary().

Tasks 6 to 8 · Transfer learning

Freeze, then carefully unfreeze

A pretrained backbone has already learned edges, textures and parts from millions of images. Feature extraction keeps it fixed and trains only the new head. Fine-tuning then lets the top layers adapt.

EfficientNetB0 parameters

Why fine-tuning needs a small learning rate

Illustrative curves: 8 epochs of frozen training, then fine-tuning at the chosen rate.

Fine-tune lr
validation accuracyfrozen only

Which strategy fits your data?

Your data
Domain vs ImageNet
Task 9 · Compare all approaches

Predict the ranking before you run it

The curves are a simulation of typical behaviour on Fashion-MNIST at 64×64. The fine-tuned curve continues after the frozen run, as in Task 9. Your numbers will differ, and the gap between frozen and scratch models may be smaller than you expect, because clothing photos look unlike ImageNet.

Test accuracies are typical ranges, not promises. Report your own Colab values.

Hands-on · Google Colab

The Colab tasks

Copy each cell into Colab and run them in order. The code differs from the printed lab sheet in a few places: it uses Fashion-MNIST and a tf.data pipeline for the 64×64 transfer images, and it defines the test label arrays that the sheet's code uses but never creates.

Reflection

Write it in your own words

Answers are saved in this browser only. Open a hint after you have tried.