Defect detection on metal parts by comparison with normal samples
The model learns only what normal metal nuts look like and flags any part whose image patches differ from all normal patches, with a heatmap showing where.

- 90 of 93Defective parts flagged
- 2 of 22Normal parts flagged by mistake
- 0.988Image AUROC on 115 test photos
- 17 msMedian time per image on a GPU
Problem
Defects are rare, so a factory rarely has enough labelled examples of every fault to train a classifier. A model that only needs photos of good parts can be set up much faster.
Method
ResNet18 features from small patches of normal photos are stored as a memory bank. A new photo is scored by the distance from each of its patches to the nearest normal patch. The flag threshold was set on normal calibration photos only, before looking at test results.
Results
Of 93 defective parts, 90 were flagged: all bent and flipped nuts, 21 of 22 with colour change and 21 of 23 with scratches. Two of 22 normal parts were flagged by mistake. All five errors can be opened in the demo.
Use
A first screening step that sends unusual parts to a human inspector.
Interactive
Limitations
What these results should not be used for.
- One product type from one public dataset.
- Not tested on a production line with a real camera, conveyor or changing light.
- The model locates unusual regions but does not name the defect type.