How Many Defect Samples Does AI Vision Sensor Validation Need?
EDGE AI
To claim a miss rate of 1 % or less at 95 % confidence, the sensor must miss none of 299 defect samples that were never used for training.
More AI vision sensors now train on a few images, but statistics sets the number of defect samples validation needs. I worked out how the sample count grows with each miss and how long a line takes to supply those samples.
About 14 min read
If you show 30 defect samples to an AI vision sensor and it catches all 30, the most you can say about its miss rate1 is "at most 9.5 %." To claim a miss rate of 1 % or less at a 95 % confidence level2, the sensor must miss none of 299 defect samples it never saw in training, and a single miss raises that to 473. Training may finish with a few images, but the target miss rate sets the number of defect samples validation needs, so this number has to be worked out first for the equipment schedule to hold.
Baumer’s VeriSens AI smart vision sensor, announced on November 19, brought this question back. Baumer says the sensor uses few-shot learning3 so that inspections "can be trained and evaluated using just a few sample images," runs up to 40 inspections per second, and keeps images and AI models inside the company with no cloud connection. The announcement does not state how many images training takes or what the sensor resolution is.
The example target is a scratch on a matte ABS molded housing. A matte surface returns light mostly as diffuse reflection4, so the background brightness shifts little when the light angle changes, but how much the contrast5 of a shallow scratch will exceed the surface grain cannot be guaranteed before a sample test. The calculation below assumes that contrast is secured and the defect is imaged across enough pixels, and asks only how many parts must be tested before the result can be stated as a number.
The few images used for training are not reused as validation samples
Training and validation are different jobs. Testing again on the images used for training says nothing about the miss rate. The model has already seen those images and drew its decision line around them, so catching them all is close to reading back a memorized answer. That is why, the fewer images a sensor trains on, the more firmly I split training and validation samples into separate boxes from the start, and I open the validation box only after the decision rule is final.
The number of images for training and the number of parts for validation answer different questions. The training count is about how quickly the model learns the look of good and bad, and the strengths and limits of starting from a few images are covered in Can Five Defect Samples Stand Up a Few-Shot Anomaly Detection Line?. The validation count puts a number on how often the trained result misses a defect it has never seen, so the number of trials sets the bound however clever the model is.
When a trial ends in either a catch or a miss and is repeated many times, the number of misses follows a binomial distribution6. Working backward from this distribution gives the upper confidence bound7 on the miss rate after k misses in n trials, and the NIST statistics handbook recommends this exact binomial calculation when samples are small or failures are rare. Every number below comes from that exact calculation.
Catching all 30 defects still leaves the miss rate open up to 9.5 %
With no missed defect, the bound comes from a simple formula. If the miss rate is p, the probability of catching all n is (1 − p)n, and the p at which that probability falls to 5 % is the 95 % upper bound. With n of 30, p stays open up to 9.5 %; with 10 it is 25.89 %, and with 5 it is 45.07 %, so a test the size of a few training images barely constrains the miss rate.
45.07%
Miss-rate bound after catching all 5 defects
9.5%
Miss-rate bound after catching all 30 defects
2.95%
Miss-rate bound after catching all 100 defects
The rule of three8 is the easy-to-remember form of this formula. If an event never occurs in n trials, it takes 3/n as the 95 % upper bound on its rate; Hanley and Lippman-Hand set it out in JAMA in 1983, and it is now widely used in medical statistics. For 30 parts, 3/30 = 10.0 %, almost the same as the exact 9.5 %.
If the marked face is a missed defect, more rolls lower the edge of "not very large." The curve below shows, with no missed defect, how the bound falls as the number of tested parts grows, drawn with both the exact calculation and the rule of three.

The place to look is where the curves meet the 1 % line. The exact calculation reaches it at 299 parts and the rule of three at 300, and past 100 the two lines nearly overlap. It is the same as firing a film camera’s shutter thirty times without the curtain ever catching: you still cannot promise it will not catch even once in a thousand.
Claiming a 1 % miss rate takes 299 defects with no miss
Once the target miss rate is set, the required count follows directly from n = ln(0.05) ÷ ln(1 − p). A 5 % miss rate needs 59 parts, 1 % needs 299, and 0.1 % needs 2995, so each tenfold tightening of the target multiplies the defect samples by almost ten. All of these must be defects never used in training, and the condition is that none of them is missed.
Missing one during the test means more samples for the same target. The exact binomial calculation with k misses gives 473 parts for one miss and 628 for two at a 1 % target. Turned around, if you test 299 and miss two, the observed miss rate is 0.67 %, yet the bound you can state rises to 2.09 %.

The graph plots, on a log scale, the defect samples needed for 0, 1 and 2 misses as the target miss rate on the horizontal axis tightens from 5 % to 0.1 %. The three lines climb in parallel because the sample count is inversely proportional to the target, and the gaps show that the first miss multiplies the samples by 1.58 and the second by another 1.33. So in a validation plan I write "zero misses allowed" next to the target miss rate, and when a miss appears I move that defect to training only after tracing its cause. One miss is expensive.
The opposite error follows the same arithmetic. Claiming a false reject9 rate of 1 % or less takes 299 good parts with no wrong reject, and 0.1 % takes 2,995. Good parts come off the line in any number, so they are easy to collect, but as the light slowly dims, false rejects creep up under the same decision line, exactly as calculated in When the Light Dims by 5 %, How Many Good Pixels Turn Into Defects?.
On a line with 0.2 % defects, collecting 299 defects takes 41.5 hours
Collecting defect samples naturally from the line takes time. Take an example line with a 0.2 % defect rate and a 1-second takt: collecting 299 defects needs 149,500 parts, or 41.5 hours of production. Aiming at a 0.1 % miss rate with 2,995 defects needs 1,497,500 parts, which is 17.3 days even running nonstop.
The defects that arrive are also not all the same kind. When scratches, short shots and black specks come mixed, each kind has to be counted separately, and the rarer a kind is, the slower its samples fill. When I plan validation, I write a separate target miss rate for each defect kind and start by counting how many hours of production it takes for the rarest kind to appear once. That sets the schedule.
Filling the shortfall with deliberately made defects is common. Scratching parts from the same mold with a blade can produce hundreds in a day, but scratches made by hand can differ in depth and direction from real process defects, so a bound computed from them should be read as a number about the made defects. My order would be to tune the decision line on made defects and compute the final miss rate on real defects collected from the line.
Defects imaged smaller than three pixels stay out of the sample count
One more condition is easy to miss when counting samples. A defect imaged too small measures the limit of the optics whether the model catches it or not, so mixing it into the algorithm’s miss-rate samples blurs the number. Following NI’s guidance to give the smallest feature at least 2 px and Vision-Doctor’s advice of 3 to 4 px for clean detection, I set three pixels per side as the threshold for entering the sample. Where the three-pixel rule comes from is worked out in When Magnified Shots Beat One High-Resolution Camera.
For example, putting a 40 mm field of view10 on a sensor 2,448 px wide gives a pixel resolution11 of 16.34 μm, and the smallest defect that meets the three-pixel rule is 49.0 μm. On the same frame a 30 μm scratch covers only 1.84 pixels. If such a defect is tested and missed, the miss is fixed by narrowing the view or adding pixels, and no tuning of the decision line adds pixels to it.

The 49 μm defect on the left fills three pixels and stands as a blob, while the 30 μm defect on the right spreads over two pixels as a smudge that cannot be told from the surface grain. When picking validation samples, I measure each defect first, move anything under 49 μm into a separate "optics check" box, and fill the 299 only with defects above that threshold.
An inspection station that ties sample count and decision rule into one validation plan
Tying these numbers into one station fixes the positions of the sensor and light first, and the sample boxes come after. A ring or diffuse light covering the 40 mm view sits between the camera and the housing, so whether the WD12 clears the light height must be confirmed against the sensor datasheet. Only images taken after that check go into training and validation, and changing the light or the height means counting validation again.

What to check in the photo is how the camera, light ring and bench are placed. If that arrangement changes during validation, the background brightness and the scratch contrast change with it, and the results of samples already collected cannot be carried forward. Writing the values from defect size to decision line and sample count in one table gives the following.
| Item | Value | Basis | In plain words |
|---|---|---|---|
| ① Minimum defect size | 49.0 μm or larger (3 px per side) | 40 mm FOV ÷ 2,448 px = 16.34 μm/px (example) | Smaller defects stay out of the sample count |
| ② Optical setup | 40 mm FOV, ring or diffuse light for matte ABS, WD confirmed against the datasheet to clear the light height | Changing light or height restarts validation | Fix the imaging conditions first |
| ③ Algorithm parameters | Target miss rate 1 % (95 % confidence), 299 unseen defects with 0 misses; 2,995 good parts with 0 wrong rejects bounds false rejects at 0.1 % | 473 for 1 miss, 628 for 2 | The number of misses resets the sample count |
Of the three rows, the last to finish is the third row’s 299 defects. A few training images take a day, but on a 0.2 % defect line those samples wait for 41.5 hours of production, so the last slot of the equipment schedule belongs to validation, not training. On the other hand, if the decision comes down to a single dimensional threshold, a rule-based algorithm may have the advantage. Checking the threshold itself with reference samples of known size reduces the need to collect hundreds of rare defects, and I set out how to choose between the two in Deep Learning vs. Rule-Based Algorithms, When to Use Which. Still, which approach the grain of matte ABS will push into more false rejects cannot be guaranteed before a sample test.
What this leaves for the engineer drawing up the validation plan is the habit of asking for the target miss rate and the line defect rate together when requesting equipment quotes. In cost terms, a sensor that trains on a few images shortens the time to gather training images but not the time to gather validation samples, and that time grows longer the better the line and the lower its defect rate. Why Edge AI Vision Fails on the Factory Floor, which looks at why edge AI underdelivers on site, deals with the same point. This article explains technology and is not investment advice. See our Disclaimer.
Field Note
To set up housing scratch inspection with this sensor, I prepare three defect boxes before shooting any training images. One is for training, one for validation, and one is an "optics check" box for anything smaller than 49 μm, and the validation box stays closed until the decision line is set. When validation produces a miss, I measure that defect’s size and contrast before moving it to training, to separate an optics problem from a decision-line problem, and if I change the decision line I refill the validation box with new defects. Once a box has been used up, I no longer treat its defects as ones the model has never seen.
Field Checkpoints
With the sample boxes split, what remains is to match the imaging conditions and the numbers once before validation starts. I suggest going through the following items in order.
- Is WD secured to the top of the housing even with the light in place? (datasheet working distance minus light height)
- Are the target miss rate and confidence level set as numbers? (1 % at 95 % means 299 defects with no miss)
- Was not a single validation defect used in training? (training and validation boxes split from the start)
- Is every validation defect imaged at three pixels or more per side? (49.0 μm or larger on the example frame)
- Did you calculate the collection time from the line defect rate? (41.5 hours at 0.2 % and a 1-second takt)
- Did you count samples separately for each defect kind? (the rarest kind sets the schedule)
- Did you test enough good parts for the false-reject target? (2,995 with no wrong reject for 0.1 %)
- Did the light, height and exposure stay unchanged during validation? (a change restarts validation)
Glossary
- [1] Miss rate escape rate
The share of real defects that the inspection passes as good. Detection rate is one minus this value, and it directly measures the risk of defects reaching the customer. ↩ - [2] Confidence level confidence level
The share of repeated tests in which the computed interval would contain the true value. At 95 %, one test in twenty may produce an interval that misses the true value. ↩ - [3] Few-shot learning few-shot learning
A training approach that fits a model with only a few example images. It adds a handful of site images on top of a model already trained on many images to set the decision rule. ↩ - [4] Diffuse reflection diffuse reflection
Reflection in which light scatters in many directions from a rough surface. Matte surfaces are mostly diffuse, so their brightness changes little when the light direction shifts. ↩ - [5] Contrast contrast
The brightness difference between the target and its surroundings. However many pixels a defect covers, it cannot be separated if this difference is smaller than the noise. ↩ - [6] Binomial distribution binomial distribution
The distribution of failure counts when a pass-or-fail trial is repeated with the same probability. Catching or missing one defect is such a trial. ↩ - [7] Upper confidence bound upper confidence bound
The boundary above which the observed results say the true value is unlikely to lie. In inspection it states how high the miss rate could be at most. ↩ - [8] Rule of three rule of three
An approximation that bounds a rate at 3/n with 95 % confidence when an event never occurred in n trials. Above about 30 trials it nearly matches the exact calculation. ↩ - [9] False reject overkill
The error of judging a good part as defective. It is the opposite error to a miss and costs re-inspection labor and scrapped good parts. ↩ - [10] FOV field of view
The object-side area a camera captures in one frame. With the same pixel count, a wider view makes each pixel cover more. ↩ - [11] Pixel resolution pixel resolution, μm/px
The length on the object covered by one pixel. It is the field-of-view width divided by the number of pixels in that direction. ↩ - [12] WD working distance
The distance from the front of the lens to the surface under inspection. The light must fit in that gap, so this distance sets most of the setup height. ↩
References
- Baumer, Baumer VeriSens AI: all-in-one Smart Vision Sensor for inspection tasks (November 19, 2026; trained on a few sample images, up to 40 inspections per second, resolution not stated)
- J. A. Hanley, A. Lippman-Hand, "If nothing goes wrong, is everything all right?", JAMA 249(13), 1743–1745, 1983, doi:10.1001/jama.1983.03330370053031 (rule of three)
- Wikipedia, Rule of three (statistics) (0 to 3/n is a 95 % confidence interval when no event occurs)
- NIST/SEMATECH, e-Handbook of Statistical Methods 7.2.4.1 Confidence intervals (exact binomial limits for small samples and rare failures)
- Vision-Doctor, Resolution of sensors (3 to 4 px or more for clean detection)
- NI, Setting Up Your Imaging System (at least 2 px on the smallest feature)
- European patent EP4145401A1, MVTec Software GmbH, Method for detecting anomalies in images using a plurality of machine learning programs (published March 8, 2023; scores anomalies from output differences between programs trained on good images)
- Formulas: with 0 misses, n = ln(1 − confidence) ÷ ln(1 − target miss rate); with k misses, the exact binomial bound satisfying P(X ≤ k | n, p) = 0.05; rule-of-three bound ≈ 3 ÷ n; parts to collect = defects needed ÷ defect rate; pixel resolution = FOV ÷ pixel count
Related reading — Does Memory-Bank Anomaly Detection Need to Remember Every Normal Patch? · Can Five Defect Samples Stand Up a Few-Shot Anomaly Detection Line? · When the Light Dims by 5 %, How Many Good Pixels Turn Into Defects?


