0% found this document useful (0 votes)
3 views17 pages

CV ImageProcessing StudyNotes

The document provides comprehensive study notes on Computer Vision and Image Processing, covering key topics such as performance metrics, class imbalance, CNN training, adversarial robustness, and feature maps. It explains essential metrics like accuracy, precision, recall, and F1-score, particularly in the context of imbalanced datasets. Additionally, it outlines strategies for handling class imbalance, the CNN training pipeline, and methods for interpreting feature maps and defending against adversarial attacks.

Uploaded by

Kay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

CV ImageProcessing StudyNotes

The document provides comprehensive study notes on Computer Vision and Image Processing, covering key topics such as performance metrics, class imbalance, CNN training, adversarial robustness, and feature maps. It explains essential metrics like accuracy, precision, recall, and F1-score, particularly in the context of imbalanced datasets. Additionally, it outlines strategies for handling class imbalance, the CNN training pipeline, and methods for interpreting feature maps and defending against adversarial attacks.

Uploaded by

Kay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Computer Vision & Image Processing

Comprehensive Postgraduate Exam Study Notes


Covers: Metrics • Class Imbalance • CNN Training • Feature Maps • Convolution • Overfitting • Hyperparameters •
Adversarial Robustness

SECTION 1 — Performance Metrics: Precision, Recall,


Accuracy & F1
▶ 1.1 The Confusion Matrix — Foundation of All Metrics
What is it? A table that shows how a model's predictions compare to the actual ground truth labels.

Term Meaning
TP — True Positive Model predicted POSITIVE and it actually IS positive.
TN — True Negative Model predicted NEGATIVE and it actually IS negative.
FP — False Positive Model predicted POSITIVE but it's actually NEGATIVE. (False
alarm)
FN — False Negative Model predicted NEGATIVE but it's actually POSITIVE. (Miss /
Type II error)

⭐ Memory Trick
FP = False Alarm | The test said YES but reality said NO.
FN = The Miss | The test said NO but reality said YES.
In medical imaging: FN (missing a tumour) is usually FAR more dangerous than FP
(unnecessary biopsy).

▶ 1.2 Core Metric Formulas


Accuracy = (TP + TN) / (TP + TN + FP + FN)
ACCURACY
Overall correctness — proportion of all predictions that were right.

Precision = TP / (TP + FP)


PRECISION Of everything the model called POSITIVE, how many actually were?
Punishes false alarms.
Recall = TP / (TP + FN)
RECALL Of all actual POSITIVES, how many did the model catch? Punishes
misses.

F1 = 2 × (Precision × Recall) / (Precision +


Recall)
F1-SCORE
Harmonic mean of Precision and Recall. Best single metric for
imbalanced datasets.

Specificity = TN / (TN + FP)


SPECIFICITY
Of all actual NEGATIVES, how many did the model correctly identify?

▶ 1.3 Fully Worked Example


⭐ Scenario — Medical Tumour Detection
Given: TP = 40, FP = 10, TN = 45, FN = 5 (Total = 100 patients)

Step 1 — Accuracy: (40 + 45) / 100 = 85/100 = 0.85 (85%)


Step 2 — Precision: 40 / (40 + 10) = 40/50 = 0.80 (80%)
Step 3 — Recall: 40 / (40 + 5) = 40/45 = 0.889 (88.9%)
Step 4 — F1: 2 × (0.80 × 0.889) / (0.80 + 0.889) = 1.422 / 1.689 = 0.842 (84.2%)

Interpretation: Accuracy looks good at 85%, but 5 patients had their tumours MISSED
(FN=5). Recall of 88.9% means 11.1% of actual tumours were missed — this matters
clinically. F1=84.2% gives a balanced view.

▶ 1.4 When to Use Which Metric


Situation Preferred Metric(s)
Balanced classes (roughly equal Accuracy is safe to use
positives & negatives)
Imbalanced classes (e.g. fraud, F1, Precision, Recall — NOT accuracy alone
disease)
Missing a positive is very costly Maximise RECALL
(disease, defect)
False alarms are very costly (spam Maximise PRECISION
filter)
Need one balanced number for Use F1-Score
comparison
Binary classifier threshold tuning ROC-AUC (area under curve)

⭐ Exam Trap — Accuracy Can Lie!


Dataset: 950 healthy patients, 50 sick patients. A model that ALWAYS predicts 'healthy'
gets:
Accuracy = 950/1000 = 95% — but it catches ZERO sick patients!
Recall = 0/50 = 0. F1 ≈ 0. This model is useless. Always report F1/Precision/Recall for
imbalanced data.

SECTION 2 — Class Imbalance: Understanding &


Handling
▶ 2.1 What Is Class Imbalance?
Class imbalance occurs when one class (the majority class) vastly outnumbers another (the minority
class). The model learns to bias its predictions toward the majority class, achieving high accuracy while
ignoring the rare-but-important class.

Real-World Domain Imbalanced Classes


Medical imaging Normal scans (thousands) vs. Cancerous scans (dozens)
Fraud detection Legitimate transactions (millions) vs. Fraudulent (hundreds)
Defect detection (factory) Good products vs. Defective products
Autonomous driving Clear road (majority) vs. Pedestrian/obstacle (minority)

▶ 2.2 How to Detect Class Imbalance


• Check class distribution: Count samples per class before training.
• Monitor metrics: If Accuracy is high but Recall/F1 is very low, imbalance is likely the culprit.
• Confusion matrix: Look for all predictions falling in one class (e.g., entire column of zeros for
minority class).

▶ 2.3 Strategies to Handle Class Imbalance


A) Data-Level Strategies (Resampling)
Strategy How It Works & When to Use
Oversampling (minority) Duplicate or generate new minority-class samples. Risk:
overfitting if just duplicating.
SMOTE (Synthetic Minority Generates SYNTHETIC new samples by interpolating
Oversampling) between existing minority samples. Better than simple
duplication.
Undersampling (majority) Remove samples from the majority class. Risk: losing useful
data. Only viable with very large datasets.
Combined sampling Oversample minority + undersample majority. Often best
balance.

⭐ SMOTE — How It Works (Step by Step)


1. Pick a minority sample (e.g., a positive tumour scan)
2. Find its K nearest neighbours (other minority samples in feature space)
3. Generate a new synthetic sample at a random point along the line between the
sample and one of its neighbours
4. Repeat until desired balance is achieved
Result: More diverse minority examples, reducing overfitting compared to simple duplication.

B) Algorithm-Level Strategies
Strategy Explanation
Class weights Penalize the model MORE for getting minority class wrong.
Pass class_weight='balanced' in most frameworks.
Focal Loss Modified cross-entropy that down-weights easy majority
examples, focusing training on hard minority examples. Used
in object detection (RetinaNet).
Threshold adjustment Lower the decision threshold (e.g., from 0.5 to 0.3) so the
model is more sensitive to predicting positives.
Ensemble methods BalancedBaggingClassifier, EasyEnsemble — train multiple
models on balanced subsets.

C) Evaluation-Level Strategies
• Never use accuracy alone for imbalanced problems.
• Use F1, Precision-Recall curves, ROC-AUC.
• Use stratified k-fold cross-validation to ensure each fold has the same class ratio.

⭐ Exam Scenario — What Would You Do?


Situation: You build a CNN to detect rare eye disease from retinal scans. Dataset: 9,800
healthy, 200 diseased. Your model gets 98% accuracy but Recall = 0.12.
Analysis: The model is just predicting 'healthy' for everything. 98% accuracy = the trivial
baseline.
Solution:
5. Apply SMOTE to generate more diseased scan examples
6. Use class weights (weight the 'diseased' class ~49x higher)
7. Switch loss to Focal Loss
8. Lower decision threshold to 0.2 instead of 0.5
9. Evaluate with F1-score and Recall as primary metrics

SECTION 3 — How CNN Models Are Trained


▶ 3.1 The Full Training Pipeline
Stage What Happens
1. Data Preparation Collect, clean and label data. Resize images to fixed size.
Normalize pixel values (e.g. divide by 255 or use mean/std).
2. Data Split Split into Train (e.g. 70%) / Validation (15%) / Test (15%).
Validation is used for tuning; Test is used ONCE for final
evaluation.
3. Data Augmentation Apply random transforms to training images only (never
validation/test). Flips, crops, brightness, rotation, etc.
4. Model Architecture Choose backbone (ResNet, EfficientNet, etc.) + task head
(classifier, detector, segmenter).
5. Loss Function Binary cross-entropy (binary), cross-entropy (multi-class), focal
loss (imbalanced).
6. Optimizer SGD+momentum or Adam. Sets how weights are updated.
7. Forward Pass Image goes through network → prediction (logits/probabilities).
8. Loss Computation Compare prediction to ground truth → loss value.
9. Backpropagation Compute gradients of loss with respect to every weight using chain
rule.
10. Weight Update Optimizer adjusts weights: w = w − lr × gradient.
11. Repeat Steps 7–10 repeat for each mini-batch. One full pass over training
data = 1 epoch.
12. Validation After each epoch, evaluate on validation set. Watch for overfitting.
13. Checkpointing Save model weights whenever validation metric improves.
14. Early Stopping Stop training if validation metric doesn't improve for N epochs
(patience).

w_new = w_old − (learning_rate × ∂Loss/∂w)


Weight Update
Rule The gradient (∂Loss/∂w) tells us which direction to move weights. The
learning rate scales how big that step is.
▶ 3.2 Transfer Learning — Best Practice for Limited Data
Instead of training from scratch, start with a model already trained on a large dataset (e.g. ImageNet
with 1.2 million images).

Phase What You Do


Phase 1 — Freeze Keep pretrained weights frozen. Only train the new classification
backbone head you added. Use normal learning rate.
Phase 2 — Fine-tune Unfreeze top few layers of the backbone. Train with a SMALL
learning rate (10-100x smaller) to avoid destroying learned
features.

⭐ Why Transfer Learning Works


Early CNN layers learn universal features: edges, corners, textures. These are useful for
ANY image task. Only the deeper layers specialize to ImageNet categories. So we reuse the
universal parts and retrain the task-specific parts.

SECTION 4 — Adversarial Robustness


▶ 4.1 What Are Adversarial Attacks?
An adversarial example is an input (image) that has been deliberately, and often subtly, modified to
cause a model to make a wrong prediction — while appearing unchanged to human eyes.

⭐ Classic Example
A stop sign with a small sticker added in a specific location causes a self-driving car's
CNN to classify it as a speed limit sign. The human eye sees a normal stop sign with a
sticker; the model is completely fooled.

▶ 4.2 Types of Adversarial Attacks


Attack Type Description
FGSM — Fast Gradient Sign Adds small perturbation ε in the direction of the gradient of
Method the loss. Simple, fast, white-box attack.
PGD — Projected Gradient Iterative version of FGSM. Stronger attack, more iterations.
Descent
White-box attack Attacker has full access to model architecture and weights.
Black-box attack Attacker can only query the model with inputs and observe
outputs.
Targeted attack Force the model to predict a SPECIFIC wrong class.
Untargeted attack Just make the model predict ANYTHING wrong.

x_adv = x + ε × sign(∇ₓ L(θ, x, y))


FGSM Attack ε = perturbation magnitude. sign() gives direction. ∇ₓ L = gradient of
loss w.r.t. input pixels.

▶ 4.3 Defences Against Adversarial Attacks


Defence How It Works
Adversarial Training Include adversarial examples in the training set. The model
learns to correctly classify both clean and perturbed inputs.
Most effective defence.
Input preprocessing Apply Gaussian blur, JPEG compression, or image smoothing
to remove adversarial noise before inference.
Randomised smoothing Add random Gaussian noise to input and aggregate
predictions. Provides certified robustness guarantees.
Feature squeezing Reduce image color depth or apply spatial smoothing. Detects
inputs that change prediction under squeezing.
Certified defences Mathematical guarantees that the model is robust within a
defined perturbation radius.

⭐ Real-World Importance
Adversarial robustness is critical in: autonomous vehicles, medical AI (misdiagnosis), face
recognition (security systems), content moderation. A model that is 99% accurate but fails
catastrophically on adversarial examples cannot be trusted in safety-critical deployments.

SECTION 5 — Feature Maps: Interpretation &


Applications
▶ 5.1 What Is a Feature Map?
When a convolutional filter slides across an input image, it produces a 2D grid of responses — one
value per spatial position. This 2D grid is called a feature map (also called an activation map). Each
filter produces ONE feature map. With 32 filters, you get 32 feature maps.

CNN Depth What Feature Maps Detect


Early layers (conv1, conv2) Simple patterns: edges, lines, corners, color blobs
Middle layers Textures, patterns, simple shapes (circles, grids)
Deep layers Complex concepts: eyes, wheels, tumour boundaries,
anatomical structures

▶ 5.2 Interpreting a Feature Map from a Medical Image


⭐ Scenario — Brain MRI Feature Map Interpretation
You are given a feature map output from layer 3 of a CNN trained to detect brain
tumours.
High activation regions (bright areas): These are areas the filter responds to strongly. In
a tumour-detection CNN, bright activation in an irregular, asymmetric region suggests the
model has identified a suspicious area.
Diffuse, symmetric activation: Likely normal tissue structure (e.g., grey matter).
Zero/dark activation: This filter is not responding to anything at these positions.

How to read it: Overlay the feature map on the original MRI as a heatmap. Bright red/yellow
= high activation. These correspond to the CNN's 'attention'. If this aligns with the
radiologist's annotation, the model is learning correctly.
Practical tool: Grad-CAM (Gradient-weighted Class Activation Mapping) produces these
heatmaps to explain CNN decisions on medical images.

▶ 5.3 Feature Map Shape Calculation


If input is H × W × C_in and you apply C_out filters of size K × K:
Output shape = H_out × W_out × C_out
Where H_out and W_out are calculated with the convolution formula (see Section 6).

Example: Input: 64 × 64 × 3 (RGB image). Convolution layer: 32 filters, 3×3 kernel, padding=1,
stride=1.
• H_out = (64 − 3 + 2×1)/1 + 1 = 64
• Output: 64 × 64 × 32 → 32 feature maps, each 64×64

SECTION 6 — Convolution: Formulas & Output Size


Calculations
▶ 6.1 The Master Formula
OUTPUT SIZE Output = ⌊ (W − K + 2P) / S ⌋ + 1
W = input size | K = kernel size | P = padding | S = stride Apply
FORMULA
SEPARATELY to Height and Width.

▶ 6.2 Parameter Definitions


Parameter What It Does
W — Input size Width (or height) of the input to this layer.
K — Kernel size Size of the convolutional filter (e.g., 3×3, 5×5, 1×1). Larger = more
context, more parameters.
P — Padding Zeros added around the border. P=0: 'valid' padding (shrinks
output). P=(K-1)/2: 'same' padding (preserves size for stride=1).
S — Stride Step size when sliding the kernel. S=1: move one pixel at a time.
S=2: skip every other position, halves output size roughly.
C_out — Filters Number of filters = number of output feature maps = number of
output channels.

▶ 6.3 Four Fully Worked Examples


⭐ Example 1 — Standard Convolution (Valid Padding)
Input: 28 × 28. Kernel: 5×5. Padding: 0. Stride: 1
Calculation: (28 − 5 + 2×0) / 1 + 1 = 23/1 + 1 = 24
Output: 24 × 24
Insight: With no padding and a 5×5 kernel, we lose (K-1)=4 pixels from each dimension.

⭐ Example 2 — Same Padding (Size Preserved)


Input: 64 × 64. Kernel: 3×3. Padding: 1. Stride: 1
Calculation: (64 − 3 + 2×1) / 1 + 1 = 64/1 + 1 − 1 = 64
Output: 64 × 64 (unchanged!)
Rule: For K×K kernel with stride 1, use P = (K-1)/2 to preserve spatial dimensions.

⭐ Example 3 — Strided Convolution (Downsampling)


Input: 128 × 128. Kernel: 3×3. Padding: 1. Stride: 2
Calculation: (128 − 3 + 2×1) / 2 + 1 = 128/2 + 1 − 0.5 = ⌊64⌋ + 1 = 64
Output: 64 × 64 (halved!)
Insight: Stride=2 roughly halves spatial dimensions. Used instead of pooling in modern
architectures.
⭐ Example 4 — Multi-Layer Stack (Exam Favourite)
Input: 32 × 32. Layer 1: K=3, P=1, S=1. Layer 2: K=3, P=0, S=1. Layer 3: K=2, P=0, S=2.
Layer 1: (32 − 3 + 2) / 1 + 1 = 32 × 32
Layer 2: (32 − 3 + 0) / 1 + 1 = 29/1 + 1 = 30 × 30
Layer 3: (30 − 2 + 0) / 2 + 1 = 28/2 + 1 = 14 + 1 = 15 × 15
Final output: 15 × 15

▶ 6.4 Pooling Output Size


MAX / AVG Output = ⌊ (W − K_pool) / S_pool ⌋ + 1
POOLING Same formula as convolution but padding is usually 0 for pooling.

Common case: 2×2 max pooling with stride 2 → always halves spatial dimensions.
Example: 28 × 28 input → 2×2 pool, stride 2 → (28-2)/2 + 1 = 14 → 14 × 14

▶ 6.5 Total Parameter Count


Params = K × K × C_in × C_out + C_out
CONV LAYER (biases)
PARAMS Each filter has K×K×C_in weights. C_out filters total. Plus one bias per
filter.

Example: K=3, C_in=64, C_out=128 → 3×3×64×128 + 128 = 73,728 + 128 = 73,856 parameters

SECTION 7 — Overfitting, Underfitting & The Bias-


Variance Tradeoff
▶ 7.1 Definitions & Diagnosis
Problem What It Means How to Detect
Overfitting Model memorizes training data, fails Train accuracy >> Validation
to generalize. Too complex for the accuracy. Large gap between
data. the two.
Underfitting Model is too simple. Can't learn the Both train and validation
patterns even in training data. accuracy are low.
Good fit Model generalizes well. Train and validation accuracy
are close and both high.
▶ 7.2 Solutions to Overfitting
Solution Mechanism
Dropout Randomly sets a fraction of neurons to zero during each
training step. Prevents co-adaptation. Typical rate: 0.3–0.5.
L2 Regularization (Weight Adds penalty proportional to squared weight values to the loss.
Decay) Discourages large weights. Loss = original_loss + λ||w||².
L1 Regularization Penalty proportional to absolute weight values. Encourages
sparsity (many weights → 0).
Batch Normalization Normalizes layer activations. Reduces internal covariate shift,
acts as mild regularizer.
Data Augmentation Synthetically increases training set diversity. Model can't
memorize if data keeps changing.
Early Stopping Monitor validation loss. Stop training when it stops improving.
Restore best checkpoint.
Reduce model complexity Fewer layers, fewer filters, smaller kernels. Less capacity =
harder to overfit.
More data Collect or synthesize more training examples. The best fix
when available.

⭐ Early Stopping — Step by Step


10. Monitor: validation loss after every epoch
11. Set patience: e.g., patience = 5 (wait 5 epochs with no improvement)
12. Set min_delta: minimum improvement threshold (e.g., 0.001)
13. Track best: save model weights whenever validation loss improves
14. Stop: if no improvement for 'patience' epochs, restore best weights and halt training
Example: Best val_loss at epoch 12. No improvement for 5 more epochs. Stop at epoch 17,
restore epoch 12 weights.

▶ 7.3 The Bias-Variance Tradeoff


Bias: Error from wrong assumptions (underfitting). High bias = model can't capture the true pattern.
Variance: Error from sensitivity to small fluctuations in training data (overfitting). High variance = model
memorizes noise.
Goal: Find the sweet spot where total error (bias² + variance + noise) is minimised.

Model Complexity Bias Variance Generalization


Too simple (underfitting) HIGH low poor
Just right (sweet spot) low low BEST
Too complex (overfitting) low HIGH poor

SECTION 8 — Learning Rate, Hyperparameters & Data


Augmentation
▶ 8.1 Learning Rate — The Most Important Hyperparameter
The learning rate (lr) controls how large a step the optimizer takes in the direction of the gradient during
each weight update.

Learning Rate Effect Symptoms


Too HIGH Overshoots minimum, Loss oscillates wildly or increases, NaN
diverges values
Too LOW Very slow convergence, Loss decreases extremely slowly;
may get stuck training takes too long
Just right Smooth convergence to Loss decreases steadily then plateaus
good minimum

▶ 8.2 Typical Learning Rate Ranges


Scenario Typical LR Range
Training from scratch (SGD) 0.01 – 0.1
Training from scratch (Adam) 0.0001 – 0.001
Fine-tuning a pretrained model — new 0.001 – 0.01
head
Fine-tuning a pretrained model — 0.00001 – 0.0001 (10–100x smaller)
backbone
Learning rate warmup period Start at 1e-6, ramp up over first few epochs

▶ 8.3 Learning Rate Scheduling


• Step decay: Reduce lr by a factor (e.g. ×0.1) every N epochs.
• Cosine annealing: lr follows a cosine curve, smoothly reducing to near-zero.
• ReduceLROnPlateau: Automatically reduce lr when validation metric stops improving. Very
practical.
• Cyclical learning rates: Oscillate lr between lower and upper bound. Helps escape local
minima.
• Warmup: Start with very small lr, gradually increase to target lr. Stabilises early training.
▶ 8.4 Key Hyperparameters and Their Bounds
Hyperparameter Typical Lower Typical Upper Notes
Bound Bound
Learning rate 1e-6 0.1 Log scale search
Batch size 16 512 Larger = stable but needs
more memory
Epochs 10 300+ Use early stopping
Dropout rate 0.1 0.5 0.5 for FC layers, 0.2 for conv
Weight decay (L2 λ) 1e-6 0.01 Too high = underfitting
Number of filters 16 512+ Double each layer is common
Kernel size 1×1 7×7 3×3 most common

▶ 8.5 Hyperparameter Tuning Strategies


Strategy How It Works When to Use
Grid Search Try all combinations of a Small number of
predefined grid. hyperparameters; expensive.
Random Search Randomly sample from More efficient than grid for
hyperparameter distributions. many params.
Often finds good solutions faster.
Bayesian Build a probabilistic model of the When evaluations are
Optimization objective function and choose expensive (GPU time).
next trial intelligently.
Manual Tuning Adjust lr first, then batch size, Quick experiments; when you
then regularization. understand the problem.

▶ 8.6 Data Augmentation — Detailed Guide


Data augmentation creates new training examples by applying label-preserving transformations to
existing images. It reduces overfitting, improves generalization, and effectively multiplies dataset size.

Augmentation Type Typical Range Caution / When NOT to Use


Horizontal flip 50% probability Avoid for text recognition; fine for natural
images
Vertical flip Use only if valid for Do NOT use for digits (6 vs 9), faces, medical
task images where orientation matters
Random rotation ±10° to ±30° Avoid large rotations for asymmetric objects
Random crop + Crop 80–100% of Ensure object of interest is still in crop
resize original
Brightness/contrast Factor ±0.2–0.5 Minimal for medical imaging to preserve
jitter diagnostic info
Gaussian noise σ = 0.01–0.05 Small amounts only; too much destroys
features
Cutout / Random Erase 10–30% of Forces model to use context, not single
Erasing image features
MixUp λ from Beta Linear combination of two images and labels
distribution
CutMix Patch from one Strong regularizer for classification
image pasted on
another

⭐ Key Rule: Augment TRAINING only!


NEVER apply random augmentation to validation or test sets. These sets must reflect
the real data distribution, otherwise you are evaluating on artificial data.
You may apply DETERMINISTIC preprocessing (resize, normalize) to all splits, but random
transforms like flips and crops are for training only.

SECTION 9 — Master Formula Sheet & Quick Reference


▶ 9.1 All Key Formulas in One Place
Convolution H_out = ⌊(H − K + 2P) / S⌋ + 1
Output Apply same formula for width

Conv Layer Params = K × K × C_in × C_out + C_out


Parameters Biases = one per output filter

Accuracy = (TP + TN) / (TP + TN + FP + FN)


Accuracy
Good metric only when classes are balanced

Precision = TP / (TP + FP)


Precision
High precision = few false alarms

Recall Recall = TP / (TP + FN)


(Sensitivity) High recall = few misses
F1 = 2 × (P × R) / (P + R)
F1-Score
Harmonic mean of Precision and Recall

Specificity = TN / (TN + FP)


Specificity
True Negative Rate

w ← w − α × ∂L/∂w
Weight Update
α = learning rate

L_reg = L_original + λ × Σ(w²)


L2 Loss Penalty
λ = regularization strength

x_adv = x + ε × sign(∇ₓ L(θ, x, y))


FGSM Attack
ε controls perturbation strength

▶ 9.2 Common Exam Scenarios & How to Approach Them


Exam Question Type Your Approach
Calculate output size of CNN Apply ⌊(W−K+2P)/S⌋+1. Do height and width separately.
layer
Given a feature map, interpret it Identify high-activation (bright) regions. Link to what that
layer typically learns (early=edges, deep=objects).
Model has 98% accuracy but Class imbalance. Recommend F1, SMOTE, class weights,
low recall — what's wrong? threshold tuning, focal loss.
Training loss down but Overfitting. Apply dropout, L2 regularization,
validation loss up — what's augmentation, early stopping, reduce model size.
happening?
Both losses are high — what's Underfitting. Increase model capacity, train longer, add
wrong? more layers/filters.
Loss oscillates wildly — what's Learning rate too high. Reduce by 10x. Consider warmup.
wrong?
Model works on training data Distribution shift / domain gap. Apply transfer learning,
but fails on new data from a domain adaptation, augmentation with new-domain styles.
different hospital
Describe adversarial attack in FGSM/PGD perturbation → wrong sign prediction.
self-driving car scenario Defence: adversarial training, input preprocessing.
SECTION 10 — Glossary of Key Terms
Term Definition
Activation map / Feature Output of a convolutional filter applied to an input. Shows
map where patterns were detected.
Adam optimizer Adaptive learning rate optimizer combining momentum and
RMSProp. lr ≈ 0.001 typical.
Adversarial example Input deliberately perturbed to fool a model while appearing
natural to humans.
Backpropagation Algorithm to compute gradients of loss w.r.t. all weights
using the chain rule.
Batch normalization Normalizes activations within each mini-batch. Speeds
training, mild regularizer.
Bias (model) Error from overly simplistic assumptions. High bias →
underfitting.
Class imbalance When one class has far more samples than another, causing
biased predictions.
Confusion matrix Table of TP, FP, TN, FN showing how predictions compare
to true labels.
Convolution Sliding a learnable filter over an input to compute dot
products, producing a feature map.
Dropout Randomly zeroing neuron outputs during training to prevent
co-adaptation.
Early stopping Halting training when validation metric stops improving;
restoring best weights.
Epoch One full pass over the entire training dataset.
F1-score Harmonic mean of precision and recall. Best overall metric
for imbalanced data.
False Negative (FN) Predicted negative but actually positive. A miss.
False Positive (FP) Predicted positive but actually negative. A false alarm.
Feature map 2D grid produced by applying a filter to input. Shows
detected pattern locations.
Fine-tuning Continuing training of a pretrained model on a new task with
small learning rate.
Focal Loss Loss function that down-weights easy examples to focus
training on hard minority class examples.
Gradient Partial derivatives of the loss w.r.t. model weights. Points in
direction of steepest increase.
Hyperparameter Parameter set before training (lr, batch size, dropout rate).
Not learned from data.
Kernel / Filter Small learnable weight matrix in a convolutional layer.
Learning rate (lr) Scalar controlling step size during gradient descent weight
updates.
Max pooling Downsampling by taking maximum value in each local
window.
Overfitting Model memorizes training data. High train accuracy, low
validation accuracy.
Padding Zeros added around input borders to control output size.
Precision TP / (TP + FP). Fraction of positive predictions that are
correct.
Recall / Sensitivity TP / (TP + FN). Fraction of actual positives that were found.
Receptive field Region of input that affects a neuron's value. Grows with
layer depth.
Regularization Techniques to reduce overfitting (dropout, L1/L2,
augmentation, early stopping).
ReLU Activation f(x)=max(0,x). Introduces non-linearity;
computationally efficient.
SMOTE Synthetic Minority Oversampling Technique. Generates new
minority-class examples by interpolation.
Stride Step size when sliding convolution kernel. S>1 reduces
output size.
Transfer learning Using weights pretrained on a large dataset as starting point
for a new task.
Underfitting Model is too simple. Fails to learn training data patterns.
Both train and val accuracy are low.
Variance (model) Sensitivity to training data fluctuations. High variance →
overfitting.
Weight decay L2 regularization applied by optimizer. Penalises large
weights.

Good luck on your exam! Remember: understand deeply, apply


confidently.

You might also like