Visual anomaly detection

Also known as: industrial anomaly detection

On this page 7

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 levelQuestion answeredCommon metric
Image-level detectionIs this image anomalousImage AUROC
Pixel-level localizationWhich pixels are anomalousPixel AUROC
Region-level localizationAre whole defects coveredPRO score
Operational decisionAccept or reject the partMiss rate at fixed false alarm rate
Output levels of visual anomaly detection

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.

FamilyRepresentative methodsCore ideaTypical strength
Memory bankPatchCoreNearest-neighbor distance to stored normal patch featuresVery high accuracy, no training of weights
Distribution modelingPaDiMGaussian per patch position with Mahalanobis distanceSimple and fast
Normalizing flowsCFlow, FastFlowLikelihood of features under a learned densityGood localization
Knowledge distillationStudent-teacher, EfficientADStudent fails to mimic teacher on anomaliesLow latency
ReconstructionAutoencoders, DRAEMHigh reconstruction error on defectsIntuitive, works on textures
Vision-language modelsWinCLIP and successorsZero-shot prompts such as damaged versus flawlessNo normal training images required
Families of visual anomaly detection methods

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.

Visual anomaly detection is often confused with supervised defect classification and with out-of-distribution detection. The following comparison clarifies when each is appropriate.

ApproachTraining dataDetects unseen defect typesBest fit
Visual anomaly detectionNormal images onlyYesRare, varied defects
Supervised defect detectionLabeled defect examplesPoorlyFrequent, well-defined defect classes
Out-of-distribution detectionLabeled in-distribution classesPartlyRejecting inputs outside a classifier’s scope
Rule-based machine visionHand-tuned measurementsOnly if rules cover themPrecise geometric checks
Visual anomaly detection compared with neighboring tasks

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.

ProblemCauseFix
Rising false alarmsLighting or camera driftFix the optics and recalibrate thresholds
Missed small defectsImage resolution too lowTile images or use higher resolution
Contaminated training setDefective parts among normal samplesReview data and use robust methods
Unstable thresholdToo few validation defectsSet threshold on a target false alarm rate
Typical deployment problems and fixes

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.