Visual anomaly detection is the task of identifying images, or regions within images, that deviate from a learned notion of normality, usually by training only on defect-free examples. As a branch of anomaly detection in artificial intelligence, it is also called industrial anomaly detection, because its most common application is automated visual inspection of manufactured parts, surfaces and assemblies.
The approach suits production lines where defects are rare, diverse and unpredictable. Instead of collecting thousands of labeled scratches, cracks and contaminations, a model learns what a good part looks like and flags anything that does not fit. The output is an image-level anomaly score for accept or reject decisions and often a pixel-level anomaly map that localizes the defect.
How visual anomaly detection works
Most systems follow a one-class learning setup. During training, the model sees only normal images and builds a compact description of their appearance. At inference time, it compares each new image against that description, and the size of the mismatch becomes the anomaly score. A threshold converts the score into a decision.
Localization works the same way at a finer scale. The model scores each patch or pixel, producing a heat map in which bright regions mark likely defects. This anomaly localization step is what operators inspect, because it explains where the problem sits on the part.
The table below distinguishes the two levels of output and how each is evaluated.
| Output level | Question answered | Common metric |
|---|---|---|
| Image-level detection | Is this image anomalous | Image AUROC |
| Pixel-level localization | Which pixels are anomalous | Pixel AUROC |
| Region-level localization | Are whole defects covered | PRO score |
| Operational decision | Accept or reject the part | Miss rate at fixed false alarm rate |
Main families of methods
Methods differ in how they represent normality. Since about 2020, approaches built on pretrained feature extractors have dominated, because deep features from ImageNet-trained networks capture texture and structure far better than raw pixels.
| Family | Representative methods | Core idea | Typical strength |
|---|---|---|---|
| Memory bank | PatchCore | Nearest-neighbor distance to stored normal patch features | Very high accuracy, no training of weights |
| Distribution modeling | PaDiM | Gaussian per patch position with Mahalanobis distance | Simple and fast |
| Normalizing flows | CFlow, FastFlow | Likelihood of features under a learned density | Good localization |
| Knowledge distillation | Student-teacher, EfficientAD | Student fails to mimic teacher on anomalies | Low latency |
| Reconstruction | Autoencoders, DRAEM | High reconstruction error on defects | Intuitive, works on textures |
| Vision-language models | WinCLIP and successors | Zero-shot prompts such as damaged versus flawless | No normal training images required |
Reconstruction-based methods were popular first but have a known weakness: autoencoders often generalize well enough to reconstruct anomalies too, which hides the defect. Feature-based methods avoid this by measuring distance in an embedding space rather than pixel space.
Types of visual anomalies
Not all defects are equally difficult. Structural anomalies change local appearance and are relatively easy to detect, while logical anomalies involve parts that look normal individually but violate a rule about their arrangement or count.
- Structural defects: scratches, dents, cracks, holes, stains and contamination on otherwise regular surfaces.
- Logical defects: a missing screw, a swapped component, a wrong number of items or a misplaced label, which require global context to recognize.
- Texture anomalies: irregularities in fabrics, wood, tiles or metal finishes, typically detected well by patch-based methods.
- Object anomalies: deviations on specific objects such as bottles, transistors or cables, where alignment and pose matter.
Public benchmarks reflect this split. MVTec AD covers 15 categories with mostly structural defects, and its successor MVTec LOCO AD adds logical constraints. Top methods exceed 99 percent image AUROC on MVTec AD, yet logical anomalies remain substantially harder, which is a reminder that benchmark saturation does not equal solved inspection.
Comparison with related approaches
Visual anomaly detection is often confused with supervised defect classification and with out-of-distribution detection. The following comparison clarifies when each is appropriate.
| Approach | Training data | Detects unseen defect types | Best fit |
|---|---|---|---|
| Visual anomaly detection | Normal images only | Yes | Rare, varied defects |
| Supervised defect detection | Labeled defect examples | Poorly | Frequent, well-defined defect classes |
| Out-of-distribution detection | Labeled in-distribution classes | Partly | Rejecting inputs outside a classifier’s scope |
| Rule-based machine vision | Hand-tuned measurements | Only if rules cover them | Precise geometric checks |
In practice, many factories run a hybrid pipeline: an anomaly detector catches anything unusual, and a supervised classifier then sorts the flagged parts into known defect categories for root-cause analysis.
Deployment challenges and common mistakes
Real production conditions differ from curated benchmarks. Lighting drift, camera repositioning and normal product variation can raise anomaly scores even when parts are fine, so stable imaging is often the single most important success factor.
| Problem | Cause | Fix |
|---|---|---|
| Rising false alarms | Lighting or camera drift | Fix the optics and recalibrate thresholds |
| Missed small defects | Image resolution too low | Tile images or use higher resolution |
| Contaminated training set | Defective parts among normal samples | Review data and use robust methods |
| Unstable threshold | Too few validation defects | Set threshold on a target false alarm rate |
Threshold selection deserves particular care. AUROC summarizes ranking quality but does not choose an operating point. Teams should fix an acceptable false rejection rate, for example below 1 percent, and then measure the miss rate on a held-out set of real defects.
In plain words
Imagine a quality inspector who has looked at thousands of perfect parts. The inspector has never memorized every possible flaw. Still, a scratch or a dent stands out immediately because it looks wrong.
Visual anomaly detection gives a computer the same skill. It studies pictures of good products. Then it marks anything that does not match what it learned. It can even color the exact spot that looks strange.
This matters because defects are rare and come in many forms. The system does not need a photo of every flaw in advance.
A real-world example
A supplier of machined aluminum housings inspects 4,000 parts per shift with two human inspectors. Defects such as burrs, porosity and tool marks occur in roughly 0.5 percent of parts, so collecting labeled defect images for a supervised model would take months.
The engineering team mounts a fixed camera with diffuse dome lighting and collects about 300 images of good parts. They train a PatchCore-style model on these images and validate it on 60 real defective parts gathered over several weeks. They set the threshold so that false rejections stay below 1 percent.
In production, the system flags suspect housings within about 100 milliseconds and displays a heat map at the inspection station. Human inspectors now review only flagged parts, and escaped defects reported by the customer drop noticeably during the first quarter. Shifts in lighting after a lamp replacement caused a brief spike in alarms, which the team resolved by recalibrating the threshold.