Finding defects without a trained model: vision-language models vs anomaly detection on 659 factory images
Anyone who has tried to bring AI inspection to a production line knows the bottleneck: a good model needs labelled images, and labelling takes time. Two shortcuts sound tempting.
- Ask a general vision-language model (VLM) whether the product is OK. These models describe photos and draw boxes in impressive demos.
- Use a general anomaly detector that only learns what "normal" looks like, and let it point at the images worth a human look.
We tested both on real production images from glass, film, textile, metal and assembly lines, labelled by human inspectors. Everything ran locally (like what a factory use). Below are the numbers, the charts and what we would recommend if you are setting up inspection yourself.
The test set
We used 28 inspection jobs from our labelling platform:
- 17 defect jobs: "Is something wrong with this product, and where?" PVB interlayer film, tire cord fabric, denim, knitted and tricot fabric, car glass with heater lines, carpet, metal surfaces, dental implant screws, printed tins and pen assembly.
- 11 object jobs: "Find and box every item." Bottles on conveyors (up to about 80 per image), boxes and labels, packaging, pen parts, a scale display, an analog gauge, wiring parts and, as an outlier, microfossils under a microscope.
Each job got a fixed random sample of labelled images, with defect and defect-free images for the defect jobs: 659 images in total. Every method saw exactly the same images.
Part 1: vision-language models, no training
We ran Qwen2.5-VL 3B and 7B, two of the strongest open VLMs that fit on an 8 GB GPU. Each prompt described the product, listed the factory's defect or object names and asked for a structured answer: defect yes or no, a label and a box.
Defects: a coin flip
We report balanced accuracy, the average of "defect images caught" and "good images passed". Random guessing scores 50%, and so does calling everything a defect.
- Across all defect jobs, both models scored 49%. They flagged about half of the defect images and about half of the good ones too.
- On four jobs the small model answered "defect" for every image.
- Bright spots were large, high-contrast defects on plain backgrounds. On PVB film the 7B caught 63% of defect images with 17% false alarms. Obvious spots on denim were found almost every time.
- Thin lines in a repeating texture (knit faults, broken heater lines on glass) were mostly missed.
- Factory defect codes mean nothing to a general model. Even when a defect was flagged, the label matched the inspectors' name only about 3 times in 10.
Finding and counting objects: almost nothing
- Out of an average of 17 labelled items per image, the 3B found 0.4% and the 7B 5%.
- Dense scenes failed completely: with about 50 bottle mouths per image, 0% were found.
- The models tend to box a whole product instead of its parts.
- Large, distinct items worked a little: 41% of packaging items and 35% of gauge parts.
- The model maker's own recommended grounding prompt did no better: 3 of 214 objects found.
The 7B is better than the 3B at finding objects, and no better at defects. A bigger model helps a little; it does not change the picture.
Part 2: anomaly detection
If the goal is to decide which images deserve a human look, speed hardly matters. What matters is: does the method find the abnormal images, and does it show where the problem is?
So we tried PatchCore, a well-established unsupervised anomaly-detection method. It never sees a defect during training. It learns what normal looks like from good images of each job, then scores every new image by how far its most unusual patch is from anything normal. It also produces a heatmap of where that patch is.
The setup was deliberately plain, so you can reproduce it:
- WideResNet-50 backbone pretrained on ImageNet, features from layers 2 and 3.
- Up to 80 good images per job, kept out of the test set.
- Images resized to 384 pixels high, keeping the aspect ratio.
- Memory bank reduced to 10% by coreset sampling. No tuning per job.
- Runs in a Docker container on the same laptop GPU.
All three methods on the same images
A VLM gives a plain yes or no, so it has one fixed false-alarm rate per job. PatchCore gives a score, so we set its threshold to be no more permissive than the stricter of the two VLMs on each job. That way it never gets more false alarms than either model.
In one sentence: PatchCore caught more defects (73% vs 53-62%) while wrongly rejecting fewer good products (44% vs 52-59%), and both VLMs scored no better than guessing overall. The chart below breaks this down job by job.
How to read it:
- A good method has tall columns up and short columns down. PatchCore (green) does this on PVB film, tire cord, denim, finished tricot and heater-line glass.
- A tall column up means little if the column below it is just as tall. The 3B model "caught" every pen defect only because it also flagged every good pen.
- Panel B folds both into one number. Both VLMs average about 51%, which is guessing. PatchCore averages 64% at this strict threshold, and reaches 90% on PVB film and 81% on tire cord.
| Job | VLM 3B caught / false alarms | VLM 7B caught / false alarms | PatchCore caught / false alarms | PatchCore AUROC | Heatmap peak on the defect |
|---|---|---|---|---|---|
| PVB film | 13% / 17% | 63% / 17% | 96% / 17% | 0.98 | 79% |
| Tire cord fabric | 50% / 17% | 50% / 50% | 79% / 17% | 0.90 | 83% |
| Pen assembly | 100% / 100% | 63% / 42% | 54% / 42% | 0.56 | 75% |
| Denim | 54% / 25% | 58% / 50% | 63% / 25% | 0.76 | 79% |
| Finished tricot | 29% / 25% | 38% / 38% | 44% / 25% | 0.65 | 63% |
| Heater-line car glass | 13% / 58% | 54% / 67% | 96% / 50% | 0.64 | 38% |
| Metal surface (public dataset) | 100% / 100% | 95% / 100% | 100% / 100% | 0.75 | 60% |
| Knitted fabric | 23% / 25% | 40% / 70% | 25% / 25% | 0.55 | 63% |
| Dental implant screw | 95% / 100% | 100% / 100% | 100% / 100% | 0.83 | 70% |
| Average of 9 jobs | 53% / 52% | 62% / 59% | 73% / 44% | 0.74 | 68% |
AUROC is the chance that a random defect image scores higher than a random good image: 0.5 is random, 1.0 is perfect. "Heatmap peak on the defect" is the share of defect images where the hottest point of the heatmap falls inside a box drawn by an inspector. On the metal-surface and implant-screw jobs every method flags every image at these thresholds, so those two rows say little; use the AUROC there.
Three takeaways from the table:
- PatchCore catches more with fewer false alarms. On average, 73% of defect images at 44% false alarms, against 62% at 59% for the best VLM. Compared one VLM at a time, at exactly that VLM's false-alarm rate, it catches 78% vs 53% (3B) and 88% vs 62% (7B).
- It is excellent on uniform material. AUROC 0.98 on PVB film and 0.90 on tire cord: almost every defect image ranks above almost every good image.
- It shows where. The heatmap peak lands on the labelled defect in 68% of defect images on average, and around 80% on film, tire cord and denim. That is good enough to propose a box for a human to confirm.
What the heatmaps look like
Each picture shows the original image on the left and PatchCore's heatmap on the right. Red means most unusual, the green box is the defect an inspector marked, and the white circle is the hottest point of the heatmap. None of these defects were shown to the model during training.
Where it struggles, and how to fix it
Two kinds of job held PatchCore back, at an AUROC of about 0.55 to 0.65:
- Products that move in the frame. On the pen line each image shows the pen in a slightly different place and angle. To a method that compares patches with normal, a shifted pen looks unusual. This was the only job where a VLM came out clearly ahead.
- Material with a lot of natural variation. Knitted and tricot fabric change in shade, texture and pattern from roll to roll. With a few dozen good images, a lot of normal variation still looks new.
Both have well-known fixes:
- For moving products: find, align, then inspect. Locate the product with a small detector, crop and rotate it to a standard pose and mask out the background before comparing with normal. A pen in a new position is then no longer unusual; a missing cap still is.
- For variation: more normal, and the right normal. Collect many more good images automatically from the line. Keep a separate set of normal images per product style or colour. Inspect full-resolution tiles instead of a shrunken image, and normalise lighting before comparing.
The one requirement: good images
Anomaly detection learns from defect-free images, and most labelling workflows throw those away. In our data, several defect jobs had no spare good images at all, so they could not be tested. If you plan to use anomaly detection, start saving a steady sample of good images from every line today. It costs almost nothing, and it is the data this method needs.
Hardware and speed: neither method is a real-time inspector
Accuracy is only half the story on a production line. Inspection has to keep up with the line, and it has to run on hardware that a factory can afford to put next to every station.
- VLMs are very heavy. On our GPU they took 2.3 seconds (3B) to 3.2 seconds (7B) per image, about 0.3 to 0.4 images per second. The models alone take 3.2 GB and 6.0 GB of GPU memory, so an 8 GB card can only hold one at a time; loading both crashed the machine. To inspect one camera at 25 frames per second, a VLM would need to be roughly 60 to 80 times faster, which means data-centre GPUs for every camera.
- PatchCore is lighter, but still not real time. It took 118 ms per image (8.5 images per second) and about 1 GB of GPU memory. That is about 3 times too slow for one camera at 25 frames per second and about 14 times too slow for a 4-camera station at 30 frames per second. It also keeps a memory bank of normal patches for every product, which grows with the number of products and styles.
- Production inspection runs on compact trained models. Small detectors trained on labelled images run in milliseconds per frame on modest edge hardware. That is why both methods in this test belong next to the line, not in it.
In practice this is not a problem for the use we have in mind. Picking which images people should label does not need every frame: sampling a few frames per second from the line, or running overnight on stored images, is plenty. Real-time inspection stays with the trained models that those labels produce.
What we recommend
- Don't use a general VLM as an inspector or an auto-labeller. Without training it is a coin flip on defects and nearly blind on counting.
- Use anomaly detection as the first filter. With only good images it found most defects, beat both VLMs on almost every job and pointed at the defect. That makes it the right tool to decide which images people should label first.
- Use VLMs as helpers. Once anomaly detection has found and boxed something, a VLM can suggest a plain-English name for it (crease, scratch, spot) or write a short description for a report.
- Keep trained models for production inspection. VLMs and anomaly detection both need far more computing power per image than a real-time line allows. Compact trained models are still what turns a camera into a reliable, real-time inspector; anomaly detection makes the labels they need faster and cheaper to get.
Our next step is a labelling pipeline in which anomaly detection pre-labels new images and people confirm or correct the boxes, starting with film and fabric lines.
Want to see what vision inspection would look like on your line? Plan it in two minutes at monitait.com.