Portfolio / Projects / adversarial-ml

Adversarial machine learning · Academic team project

Measure CNN robustness, not just clean accuracy.

We trained a PyTorch classifier on MNIST, applied FGSM at three perturbation budgets, then compared a baseline model with a model trained on adversarial examples.

99.00%Clean accuracybaseline
96.95%Robust accuracybaseline · ε=8/255
97.85%Robust accuracydefended · ε=8/255
−38%Attack success2.07% → 1.29%

Tools & technologies

PythonPyTorchCNNFGSM

01 / Question & finding

Clean accuracy does not tell us how the model behaves under a perturbation designed to fool it.

The project starts from a 99% accurate MNIST CNN and asks a simple question. Can an almost invisible pixel perturbation change its decision? And can adversarial training reduce that risk without hurting normal accuracy? An adversarial example is deliberately modified to trigger a model error while remaining visually close to the original input.

Baseline99.00%

Clean-image accuracy: the starting model is already highly accurate.

FGSM · ε=8/25596.95%

Robust accuracy drops under attack, showing why clean accuracy alone is incomplete.

After defense97.85%

Adversarial training recovers 0.90 percentage point while clean accuracy remains 99.13%.

Main finding: the defense helps in this protocol, but the absolute gain is modest. Attack success falls from 2.07% to 1.29% at ε=8/255, a 0.78-point drop even though the relative reduction is about 38%.

02 / Setup

A controlled experiment with fixed parameters and saved artifacts.

Data

MNIST

60,000 training images and 10,000 test images.

Model

CNN · 3,274,634 parameters

Two convolution layers, two fully connected layers and dropout.

MNIST originals, FGSM perturbations and adversarial examples
Original image, perturbation and adversarial example at ε=8/255.

03 / Experiment

The same protocol compares the model before and after defense.

FGSM (Fast Gradient Sign Method) uses the model gradient to modify each pixel within a limit ε. Here ε is 2/255, 4/255 or 8/255: the larger ε becomes, the more freedom the attacker has to perturb the image.

01

Measure the baseline

Train the CNN for five epochs on clean images and measure normal test accuracy.

02

Attack it

Generate FGSM examples at the three ε levels and measure how much accuracy drops.

03

Harden and retest

Retrain for eight epochs with 50% clean and 50% adversarial examples at ε=8/255, then replay the exact same tests.

04 / Results & interpretation

The hardened model is more robust at every tested attack level without sacrificing clean accuracy.

FGSM robustness comparison for the MNIST models
As ε increases, the attack becomes stronger. The adversarially trained model stays above the baseline, with the clearest gap at ε=8/255.
MetricBaselineHardenedChange
Clean accuracy99.00%99.13%+0.13 pt
Robust accuracy · 2/25598.68%98.92%+0.24 pt
Robust accuracy · 4/25598.35%98.65%+0.30 pt
Robust accuracy · 8/25596.95%97.85%+0.90 pt
Attack success · 8/2552.07%1.29%−0.78 pt

The useful conclusion is not that the model becomes invulnerable. Controlled exposure to adversarial examples improves FGSM robustness, especially at the strongest tested perturbation, without a visible clean-accuracy trade-off. From a security perspective, the experiment also shows why clean accuracy is not enough: a model should be tested against inputs deliberately designed to fool it.

05 / Reproducibility

Parameters, models, results and plots were saved.

The parameters, models, results and plots used for the evaluation were preserved in the project artefacts. Controls include L∞ bounds, input-gradient availability and visual inspection of perturbations. A public repository will be added after the original source has been recovered, cleaned and verified.

06 / Limits

FGSM is a useful first baseline, not a complete robustness evaluation.

Attack strengthSingle-step baseline

Stronger iterative attacks such as PGD and broader suites such as AutoAttack are needed before making general robustness claims.

BenchmarkMNIST is educational

Results do not automatically transfer to complex images or production models.

07 / Conclusion

The experiment shows a real improvement, but only within the tested protocol.

The baseline CNN was already robust on MNIST. Adversarial training improves it further, but the absolute gain remains below one accuracy point under FGSM at ε=8/255.

Main takeaway

A robustness claim should always name the attack, its intensity and the clean-performance trade-off. Here the conclusion is useful because it stays bounded: FGSM on MNIST validates an experimental approach, not general robustness against all adversarial attacks.

Next project

Digital Forensics Investigation: move from model robustness to digital investigation reconstruction.