Three Generations of Inspection
| Gen 1 · Rule-based | Gen 2 · Supervised learning | Gen 3 · Normal-only learning | |
|---|---|---|---|
| Training data | None (a person designs the rules) | Thousands of defect images + labels | Tens to hundreds of normal images, no labels |
| Defects never seen before | Pass if not in the rules | Weak on types unseen in training | Detected as "different from normal" |
| Setup time | Weeks (expert tuning) | Weeks to months (collecting defects) | Days |
On a factory floor the defect rate is usually low. Collecting thousands of defect images takes a long wait, and new types appear while you wait. Anomaly detection turns this problem around. Show the model enough normal examples, and treat everything that departs from normal as an anomaly. Some few-shot methods start with as few as 2 to 30 normal images.
Common Processing Flow
All 11 algorithms in fineAi AD Workbench follow the same frame. Only ③ and ④ differ between algorithms.
PatchCore: A Memory of Normal Pieces
PatchCore has high precision, so AD Workbench recommends it by default. The idea is surprisingly simple.
Training: collect normal patches
- Feed the normal images to a neural network pretrained on large-scale images (WideResNet50-2) and take the feature maps of the middle layers (layer2, layer3). One cell of a feature map summarizes one small piece (patch) of the original image as a vector of numbers.
- Collect the patch vectors of all patches of all normal images into a memory bank.
- A bank that is too large makes search slow, so keep only a subset that represents the whole distribution (coreset sampling).
The network weights are not trained again. The method only scans the normal images once and collects, so training takes a few seconds to a few minutes.
Inspection: distance to the nearest normal
- Extract patch vectors from the new image in the same way.
- For each patch, find the k nearest normal patches (k=3) in the memory bank and measure the distance.
- A patch that looks like normal has a small distance. A patch with a scratch has no similar normal patch, so its distance is large. This distance is the anomaly value at that position.
- Scale the per-patch anomaly values up to the original size and smooth them to get the heatmap. The heatmap maximum (or the mean of the top few %), normalized to 0–1, is the image score.
Thresholds and the Gray Zone
Once you have a score, you compare it with a threshold to decide. Lowering the threshold reduces missed defects (escapes, or missed defects) but increases good parts flagged as defective (false rejects, or overkill). Raising it does the opposite. The lesson Model Evaluation and Field Operations covers this balance.
fineAi uses dual thresholds.
- A score below the low threshold is OK.
- A score above the high threshold is NG.
- Between them is Gray, which a person checks.
A person's decision on a Gray image becomes training data again. The more you operate, the fewer Gray images remain.
Where Anomaly Detection Fits Poorly
- Targets with large variation in normal itself — If the range of normal is wide, as with produce whose shapes all differ, it is hard to tell defects apart.
- When you need the name and location of a defect — Anomaly detection tells you "this spot is abnormal", but it does not classify "this is a scratch". In that case, use Object Detection alongside it.
The next lesson, Choosing an Anomaly Detection Algorithm, covers how to choose among the 11 algorithms.