Two questions open every AI defect detection project. How much data do we need? How accurate will it be? Both have exact answers, but only after you rephrase them.
This post is the engineer's version of our guide on AI defect detection. It turns both questions into arithmetic you can run on your own reject records.
How long until you can train?
The data question is a collection-time question. A defect that appears on one part in five hundred needs a lot of inspected parts before you hold enough examples.
defect_rate = 1 / 500 # from your reject records
examples_needed = 300 # per defect class
parts_per_day = 1_000
parts_to_inspect = examples_needed / defect_rate # 150,000
days = parts_to_inspect / parts_per_day # 150, about 5 months
print(parts_to_inspect, days)
Five months of production before training starts, and that is one defect class. Three levers shorten it, and none of them touch the model:
- Narrow the scope to the defect classes that carry real cost.
- Make defective samples on purpose.
- Switch to anomaly detection, trained on good parts only.
Why is 98.8 percent accuracy a bad sign?
Accuracy hides rare defects. Take 10,000 parts with 100 defects. The model catches 80 and wrongly flags 1 percent of the good parts, which is 99 false alarms.
tp, fn = 80, 20
fp = 99
tn = 10_000 - 100 - fp
accuracy = (tp + tn) / 10_000 # 0.988
recall = tp / (tp + fn) # 0.80
precision = tp / (tp + fp) # 0.45
Twenty defects reached the customer. Of the 179 parts pulled for review, 80 were bad. Recall and precision per defect class are the numbers to put in the contract.
Acceptance test checklist
- [ ] Defect classes and how often each occurs, from your own reject records
- [ ] Cost of a miss and cost of a false alarm, per class
- [ ] Recall and precision targets per class
- [ ] A held-back test set from a different week, shift and batch
- [ ] A named person who owns retraining
A problem that resists this checklist is not ready for a model.
Dev Station builds defect detection systems for manufacturers in the US and the UK, from lighting and capture to the operator review screen. The full worked example and the three methods are in the original article.

Top comments (0)