
Most factories have plenty of images of good parts and very few images of defects. Anomaly detection turns that into an advantage: the model learns what “good” looks like and flags anything that doesn’t fit, so you can start inspecting without first collecting and labelling hundreds of examples of every defect.
The defect-data problem
Classic supervised deep learning needs labelled examples of each defect type: scratches, dents, missing parts, wrong labels. On a well-run line, defects are rare, so collecting enough examples can take weeks or months. Some defects may never have happened yet, which means a model trained only on known defects can’t be expected to catch them.
How anomaly detection works
- Collect good images. Capture images of parts that passed quality checks, under the same camera, lens and lighting as production.
- Learn normal appearance. The model builds a representation of what good parts look like, including their normal variation.
- Score new parts. Each new image is compared with that learned normal. Regions that differ get a high anomaly score.
- Set a threshold. Parts above the threshold are flagged as defective. The threshold is tuned on validation data so real defects are caught without rejecting good parts.
- Localise. Most methods also produce a heat map showing where on the part the anomaly is, which helps operators confirm a reject quickly.
Where it works well
- Rare or unpredictable defects: contamination, unusual damage or one-off process faults that no one thought to collect examples of.
- New lines and new products: inspection can start as soon as good parts are available.
- High-mix production: each product variant gets its own model of “good”, trained from good images.
- Consistent parts: labels, packaging, machined and pressed parts, where good units look much alike.
Where to be careful
- Natural variation: wood grain, castings or food products vary a lot from unit to unit. The good image set must cover that variation, or normal parts will be flagged.
- Imaging changes: a moved camera, a dimmer light or a new background changes what “normal” looks like. Keep the imaging setup stable, or retrain when it changes.
- Defect grading: anomaly detection says “this is different”, not “this is a scratch of grade B”. If you need defect types sorted into classes, add a supervised step on top.
- Threshold tuning: a threshold that is too tight raises false rejects; too loose and small defects pass. Validate on real production before going live.
Anomaly detection vs supervised classification
| Anomaly detection | Supervised classification | |
|---|---|---|
| Training data | Good images only | Labelled examples of each defect class |
| Catches unseen defects | Yes, if they look different from good parts | Only defects similar to what it was trained on |
| Time to first model | Short: as soon as good images exist | Longer: depends on collecting defect examples |
| Output | Pass/fail, anomaly score and location | Defect class and confidence |
| Best for | Detecting any deviation on consistent parts | Sorting and grading known defect types |
Many lines use both: anomaly detection to catch anything abnormal, and a classifier for the defect types that need to be reported separately.
A practical checklist before you start
- Fix the camera position, lens and lighting first. The model can only learn what the images show consistently.
- Collect good images across shifts, batches and material lots, so normal variation is represented.
- Keep a set of known defects, even a small one, to validate the threshold.
- Run in parallel with your current inspection before letting the system reject parts.
- Plan how the reject signal reaches the line, usually through the PLC.
How DeepVision uses anomaly detection
DeepVision is built on anomaly detection. It trains on as few as 200 images of good parts with no defect labelling, runs on an edge computer beside the line, and sends pass/fail to Siemens, Allen-Bradley or Mitsubishi PLCs. On an FMCG packaging line it cut label defects from 9,400 to 1,150 per million and was live on day 7. See the case study, our accuracy methodology and PLC integration.
Frequently asked questions
How many good images does anomaly detection need?
It depends on how much good parts vary. Consistent parts need fewer images; parts with natural variation need more. DeepVision can start from as few as 200 good images.
Can anomaly detection find defects it has never seen?
Yes, as long as the defect makes the part look different from the good parts it learned from. That is its main advantage over supervised models.
Does it replace defect classification?
Not always. It tells you a part is abnormal and where. If you need defects sorted into named types, combine it with a supervised classifier.