Find the defects nobody labelled
A model that learned this real scan's normal texture inspects it: wherever it can't reproduce what it sees, it flags a defect. Click any patch to interrogate it.
Where do you draw the line?
Reconstruction error of clean patches vs. patches with a seeded defect, the two histograms the threshold has to separate. The suggested cut maximises true positives against a tight false-positive budget; that's how the thesis picked its operating point from the ROC curve.
the numbers behind these charts
Patch under the microscope
What the model saw, what it reconstructed, and where the two disagree: the same input · reconstruction · difference triptych the thesis used to debug the network.
It never saw a defect
Defects on production parts are rare, varied, and almost never labelled, so instead of teaching a model what defects look like, the thesis taught it what normal looks like, and treated everything it couldn't explain as suspect.
- Learn normal. Train on thousands of small patches cut from defect-free surfaces. The model must compress each patch through a narrow bottleneck and reconstruct it, which means it can only get good at the patterns it keeps seeing.
- Reconstruct. Show it a new patch. If the patch is ordinary machined texture, the model reproduces it almost perfectly; that's all it knows how to draw.
- Score the surprise. A defect never fit through the bottleneck, so the model redraws the texture it expected instead. The pixel-wise error between input and reconstruction becomes the anomaly score: no defect labels needed, and it catches defect types nobody anticipated.
What "normal" looks like to the model
The components the model learned from this page's clean surfaces, live. Every reconstruction is built from just these; a defect simply has no ingredients here, which is why it can't be redrawn.
Same patch, with and without a defect
Two patches from the scan; the right one is given a small seeded defect. Watch the reconstruction stay stubbornly "normal", and the error jump.
What's simplified here
The thesis used convolutional autoencoders: deep networks trained for hours on an HPC cluster. This page swaps them for their linear cousin, PCA reconstruction (a linear autoencoder), which trains in milliseconds in your browser. The paradigm (learn normal, compress through a bottleneck, score the reconstruction error) is the same one, end to end. The surface you inspect is a real microscope scan from the thesis work; the full industrial dataset it belongs to stays confidential.
What the real thing did
MSc thesis, 2019–2020: unsupervised defect detection for the quality control of precision-machined metal parts, developed with an industrial dataset.
The data
Grayscale microscope scans of machined metal surfaces, each measured for roughness (Ra, RSm, Rt, Rz). Defective examples were scarce and unlabelled in production; a small set with hand-drawn defect boxes existed only for evaluation, never for training.
One model per surface finish
"Normal" depends on the finish: a rough surface's healthy texture looks like a defect on a fine one. So the images were binned by measured roughness and a separate autoencoder was trained per band, each learning the normal texture of its own finish.
Two ways to learn normal
- Patch autoencoder: compress a small patch through a bottleneck and reconstruct it; the reconstruction error is the anomaly score. (The approach this demo reproduces.)
- Context autoencoder, a harder exam: the network sees a patch's 3×3 neighbourhood with the centre blanked out and must predict the centre from its surroundings. Healthy texture is predictable from context; a defect isn't: it can't be guessed from clean neighbours.
From patch scores to an inspection
To inspect a full scan, the system sampled on the order of a thousand random patches per image, scored each one, and marked every location above threshold with a red square, the same flags you see on the Inspect tab. The threshold came from ROC analysis on the labelled evaluation set: reconstruction-error histograms of clean vs. defected patches, and the operating point that maximised true positives minus false positives.
The machinery behind it
- Keras / TensorFlow convolutional autoencoders; NumPy + pandas for the dataset plumbing; scikit-learn for ROC / AUC; TensorBoard for train-vs-validation curves.
- Trained on a university HPC cluster whose queue allowed under an hour per job, so training was built as a relay: each grid-engine job trained for its slot, saved the model, and submitted the next job that picked up where it left off.
- A procedural surface generator (families of machining lines + seeded elliptical defects) provided unlimited controlled data to probe the method's behaviour; this demo instead runs the method on one real scan from the work.
The scan on this page is real; every model, score and figure is computed live in your browser, and no number here is a claim about the wider industrial dataset, which stays confidential.