MODULE 17 ยท Middle-track ยท 2.5 hours

Four thousand photos. Training from scratch will not fly

Defect detection on a packing line: why convolution saves millions of weights, and how to fine-tune a pretrained network instead of starting from zero.

Open this module in the simulator All 23 lessons

The first two modules are free, no card. The rest are $20/month.

๐Ÿข The situation

Datacore opened its own fulfillment center and installed cameras on the packing line. The operations director:

"Damaged boxes reach the customers โ€” returns, bad reviews. The inspector physically can't watch everything. The cameras photograph every box โ€” can we automatically catch crumpled and torn ones?"

Lena:

"Binary image classification: ok / defect. The dataset is small โ€” the inspectors labeled only 4,000 photos (400 with defects). The key technique here is transfer learning: don't train a network from scratch, fine-tune a pre-trained one. From scratch on 4,000 images it won't fly."

๐ŸŽฏ Your task

  1. Understand why images need convolutional networks (CNNs).
  2. Master transfer learning: fine-tuning a pre-trained model.
  3. Apply augmentations and evaluate correctly under imbalance.

๐Ÿ“š Theory

Why not a fully connected network

A 224ร—224ร—3 photo = 150,528 inputs. A dense layer of 1000 neurons โ€” 150M weights, and the net would have to learn a "crumpled corner" separately at every position in the frame. Convolution solves both problems: a small filter (e.g. 3ร—3) slides across the image and looks for the same pattern everywhere (weight sharing).

How a CNN works

CNN: a feature hierarchy from edges to "crumpledness" box photo 224ร—224 a 3ร—3 filter slides across the frame feature maps: edges, corners deeper: textures, dents, tears pooling + head (the new layer โ€” ours) ok ยท 0.08 defect ยท 0.92 transfer learning: take the conv layers pre-trained on ImageNet, train only the head โ†’ then fine-tune with a small LR
Convolutions look for the same pattern across the whole frame and build a hierarchy: edges โ†’ textures โ†’ defects. A pre-trained backbone already knows the first levels.

Transfer learning โ€” practical CV's main tool

Networks pre-trained on ImageNet (millions of images) already know how to see edges, textures, shapes. Take a pre-trained backbone (ResNet, EfficientNet), then two regimes:

  1. Feature extraction: freeze the backbone, train only the new head. For tiny datasets.
  2. Fine-tuning: unfreeze some/all layers and retrain with a small LR (10โ€“100ร— smaller than usual) so as not to destroy the pre-trained weights.

Augmentations โ€” free data

Random rotations, flips, brightness/contrast, crops โ€” from 4,000 photos we make an "infinite" stream of variations. Rules: augmentations โ€” train only; choose realistic ones (a box is never upside down on the conveyor? โ€” no vertical flip then).


What to remember

  • Convolutions search for one pattern across the whole frame โ€” hence CNNs, not dense nets.
  • Small dataset โ†’ transfer learning: the head first, then fine-tuning with a small LR.
  • Augmentations โ€” train only, and realistic only.
  • The threshold โ€” from error costs; check where the model looks (Grad-CAM).

Next in this module: Practice

Open the module โ†’

Nearby lessons

16 Meet neural networks 18 The interview in reverse: ML System Design

The whole program โ€” 23 lessons