David H. Simangunsong
Back to Computer Vision

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.

Year
2025
Study area
MVTec AD metal nut category
Period
Benchmark images
Methods
Anomaly detectionDeep learningComputer vision
Stack
PythonPyTorchResNet18FastAPISQLite
Metal nut photo, model heatmap and true defect outline side by side
  • 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

Normal patch memory, scoring and evaluation.
Normal patch memory, scoring and evaluation.

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

Inspection viewer with heatmaps

Self contained HTML, served from this site

Open in a new tab

Limitations

What these results should not be used for.

  1. One product type from one public dataset.
  2. Not tested on a production line with a real camera, conveyor or changing light.
  3. The model locates unusual regions but does not name the defect type.