ApplicationsGuide

Deep learning defect inspection: how many samples you really need

How many good and defect samples a deep learning inspection model needs, which network task fits each defect type, and the capture, labeling and test rules.

LumaSpec Vision12 min read Share on LinkedIn

On this page 9 sections
  1. 01When does a defect check need deep learning at all?
  2. 02How many samples do you need to train a defect model?
  3. 03What camera and lens do you need to see the defects?
  4. 04How do you capture a training set on the line?
  5. 05How do you label, split and augment the images?
  6. 06How long does training take, and how do you validate it?
  7. 07When do these numbers stop working?
  8. 08What should you check before you commit?
  9. 09Questions

Deep learning finds the random scratch, dent or smear that defeats a tuned blob tool — if you feed it enough of the right images. This guide is for engineers sizing a first deep-learning defect station: it gives the sample counts per network task, the camera and lens math that makes a defect visible, and the capture, labeling, training and test rules that get a model released. The worked example is a 60 mm metal part with a 0.25 mm defect on a 150 mm/s belt, and its arithmetic transfers to any line. Every number is a starting commitment; where one moves with defect size, part finish or line speed, the text says by how much.

When does a defect check need deep learning at all?

Stay classical while the defect has a fixed shape, contrast or position: a blob or template tool tuned on 10 to 50 reference images wins on speed, traceability and set-up time. Move to deep learning when defect shape, position and brightness are random, and the classical tool misses real defects in your reject log.

The decision is a two-week experiment, not a preference. Run the classical set-up — dark contaminant detection on dark surfaces is a typical lighting-plus-blob configuration — and log every miss. If the misses are describable ("smudge top left", "edge burr"), fix the lighting or optics and stay classical. If the misses are random scratches, dents and handling marks with no shared geometry, the tool has no rule to learn, and a network trained on examples is the right instrument.

Two boundary cases appear constantly on production lines. Parts with natural appearance variation — grain, fibers, cast texture — starve classical tools of a stable background, the situation covered in AI defect inspection for products with natural appearance variability. And if cameras are already mounted, adding AI surface defect inspection to existing cameras is usually cheaper than a new station. For the device-side trade-off, read AI vs rule-based smart camera inspection.

How many samples do you need to train a defect model?

Commit to these starting counts: 300 good-part images minimum for good-only anomaly detection (500 to 1,000 comfortable), 100 to 300 labeled defect images per class for classification, and 100 to 200 masked defect images for segmentation, against 10 to 50 references for classical matching.

Task Defect images to train Good images Label time
Blob / template match (classical) 0 10-50 references minutes
Anomaly detection, good-only 0 300 min, 500-1,000 comfortable none per image
Classification 100-300 per class one balanced good class seconds per image
Object detection 100+ per class 200-300 good, boxed about 1 min per box
Segmentation 100-200 with masks 200-300 good about 3 min per mask

Where the floors come from: annotation-tool vendors recommend at least 100 annotated images for a single-class object detector, and practitioners report 100 images as workable for a focused, well-defined task — plan at the table floors, not below them. Good-only anomaly detection needs its 300 good images because the model must learn the full range of normal, not one example of it; the public benchmark sets that seeded the method run to 5,354 images of good and anomalous parts with scratches and dents. Factory models do not start from zero: you fine-tune a pretrained backbone, which is why hundreds of images work where research sets use thousands.

Defect images are the scarce item, and line arithmetic shows why. At a 0.5 percent defect rate you photograph 20,000 parts to harvest 100 defect images: 100 ÷ 0.005 = 20,000. Do not wait for the line to make them — pull rejects from the quarantine bin and the rework scrap, where defect density is close to 100 percent.

What camera and lens do you need to see the defects?

Give the smallest defect at least 3 pixels across, 4 to be safe: pixel size on target must stay at or under defect size divided by 4, which is 0.0625 mm for a 0.25 mm defect. Sensor, lens and working distance all follow from that one number.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Work it through for the example part. The part is 60 mm wide; add 20 percent for positioning tolerance and the field of view is 72 mm. A camera in the area scan cameras class covers it easily. The LS-CMR-0166 is a 12 MP USB3 camera with a 1/1.7" IMX226 sensor and 4000 × 3000 resolution.

pixel on target = field of view / sensor pixels m = sensor width / field of view WD = f × (1 + m) / m DOF ≈ 2 × f-number × blur circle / m²

The arithmetic, step by step:

  • Pixel on target: 72 mm ÷ 4,000 px = 0.018 mm/px. The 0.25 mm defect spans 0.25 ÷ 0.018 = 14 pixels, comfortably above the 4-pixel floor.
  • Sensor width: a 1/1.7"-type sensor is about 7.5 mm across (7.5 ÷ 4,000 = 1.9 µm pixels).
  • Magnification: m = 7.5 ÷ 72 = 0.104.
  • Working distance with a 25 mm lens: WD = 25 × 1.104 ÷ 0.104 = 265 mm.
  • Depth of field for ±3 mm part height: with a 2-pixel blur circle (0.0038 mm), DOF ≈ 2 × f-number × 0.0038 ÷ 0.104² ≈ 0.7 × f-number mm. You need at least 6 mm total, so 6 ÷ 0.7 = 8.6 — set f/11, which gives about 7.7 mm. The formula is an approximation; the direction (stop down for height variation) is exact.

Check your own numbers with the lens focal length calculator, or run it in the tool below.

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

For a triggered, stationary part, the LS-CMR-0166 gives 12 MP at 30 fps over USB3:

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

If you want crop margin for large parts, the MV-CS200-10UM carries 20 MP on a 1" IMX183 sensor. More pixels only pay when the defect is the limiter; when the lighting is, spend the money there first.

How do you capture a training set on the line?

Lock the light, lens, exposure and trigger to production values before capturing a single image: in the worked example that is a 60 µs strobed exposure at f/11 and a 265 mm working distance, because the network learns your lighting as thoroughly as it learns the part.

Motion sets the exposure. At 150 mm/s, half a pixel of blur is 0.5 × 0.018 mm = 0.009 mm, so exposure must be 0.009 ÷ 150 = 60 µs or shorter. A rolling shutter smears at that speed, so fit a global-shutter camera for anything on a belt. The MV-CH120-11UC pairs a 12 MP IMX304 sensor with a global shutter behind a C-mount over USB3:

Area scan camerasHikrobot MV-CH120-11UC 12 MP Area Scan Camera, USB3, IMX304, High-speed version, ColorMV-CH120-11UC
Sensor format
1.1"
Lens mount
C-mount
Interface
USB3
Resolution
12 MP
$2,339.00 · quotedView and quoteBuild a system with it

Capture arithmetic is short: 500 good images at one image per part and 300 parts an hour is 500 ÷ 300 = 1.7 hours of production. Save raw or lossless files, not camera-sharpened JPEG, and record exposure, gain, light current and part ID in the folder path — the layout in anomaly detection custom dataset training is the structure to copy before you own 5,000 images with meaningless names. The full capture-and-approve loop is laid out in tire classification with deep learning: capture and validate.

How do you label, split and augment the images?

Split the set 80/10/10 — of 300 defect images that is 240 to train, 30 to validate, 30 to test — and keep near-duplicates in the same split, because the same scratch appearing in train and test inflates accuracy by tens of points.

Labeling is a budget line, not a detail: a whole-image label takes seconds, a bounding box about a minute, a pixel mask about 3 minutes — so 150 masks is 150 × 3 = 7.5 hours of work. Use the polygon workflow in drawing and filling segmentation label polygons; hand-painting masks is where dataset projects stall.

Augment to cover what the part genuinely does: rotation and mirroring when orientation is truly random, brightness shifts of about ±10 percent for line drift. Do not blur, warp or synthesize defects — augmentation multiplies the variety you captured, it does not create information you never photographed. Cap the multiplier at about five virtual images per real one; beyond that you train the model on your generator instead of your line.

How long does training take, and how do you validate it?

Transfer learning from a pretrained backbone trains a defect model in roughly 10 to 60 minutes on one modern GPU, a few hours on a CPU; compact good-only anomaly models often train in minutes. Compute is rarely the bottleneck — image count is.

The hardware choice is covered in machine vision deep learning setup: choosing CPU or GPU; one mid-range GPU on a bench PC covers most defect projects, and a published compact unsupervised set-up trains and infers in about 90 seconds on a single-board computer. Model size is small; your 300 to 1,000 images are what take the week.

Stop on validation loss, not when accuracy looks good — the failure mode is shown in anomaly detection early stopping with high training loss. Then test on held-out images the model has never seen. Sanity-check heatmaps first; anomaly detection without ground truth: test and heatmap setup shows the check. Then count:

  • Test set: at least 50 defect images and 200 good images, none used in training.
  • Release gate: zero or one missed defect out of 50 (98 to 100 percent recall), false rejects under 2 percent on the good images.
  • Arithmetic honesty: with 50 defect images one miss is 98 percent and the interval is wide; when a miss triggers a field recall, buy the line time to reach 100 defect test images.

For the floor acceptance itself, commissioning AI vision inspection for defect detection covers the hand-over side: shift trials, golden samples and sign-off.

When do these numbers stop working?

The counts fail when good parts themselves vary — grain, fibers, cast texture — because 300 good images no longer cover the normal range: budget 500 to 1,000 good images, or one model per product family.

The named failure modes, each with its fix:

  • Defect under 3 pixels. At 14 pixels a scratch trains well; at 2 pixels no dataset rescues it. Fix the optics first — smaller field of view, more pixels — before collecting a single image.
  • Natural material variation. Wood, leather and cast surfaces need the larger good-image count and often a class per supplier.
  • Lighting drift. A model trained at one strobe current will false-reject at another; lock the light controller and retrain when the source ages.
  • Many products through one model. The trade-offs in training anomaly detection across multiple product classes apply as soon as the part mix changes weekly.
  • Defect classes under 50 real images. Do not stretch a classifier; switch to good-only anomaly detection and use the held-out defects to set the threshold.

What should you check before you commit?

Run this list before buying hardware: smallest defect in pixels, harvestable image count, label hours, the machine you will train on, and the release gate you will sign. Five lines decide the project.

  • Smallest defect spans at least 3 pixels (4 preferred) at the chosen field of view — the calculators above do it in one pass.
  • 300 good images reachable in under two hours of production, or from the quarantine bin.
  • Defect count per class at or above 100, or the plan is explicitly good-only anomaly detection.
  • Label budget accepted: about 1 minute per box, 3 minutes per mask.
  • One GPU available for the 10-60 minute training runs, or the CPU schedule accepted in writing.
  • Test protocol fixed: 50 defects, 200 good images, 98 percent recall floor, under 2 percent false rejects.
  • Light, exposure and trigger locked at production values before the first capture.

Decisions by case:

  • Random cosmetic defects, few defect parts on hand — good-only anomaly detection on 300 good images, threshold set with 30 held-out defects.
  • A defect catalog with 100 or more labeled examples per class — classification, with boxes when location matters.
  • Defect size or position reported in millimeters — segmentation with 100 to 200 masks.
  • A defect you can describe in one sentence — classical blob or template matching on 10 to 50 references; revisit when the reject log says otherwise.
  • A defect under 3 pixels — optics first; data will not fix it.

For inference on the device at one station, smart cameras run the frozen model without a PC — the MV-SC5060XM-08M-WBN is an SC5000X series smart camera with 6 MP mono and an 8 mm focal length M12 lens on GigE:

Smart cameras & vision sensorsHikrobot MV-SC5060XM-08M-WBN SC5000X series Smart Camera, 6 MP, Mono, 8 mm focal length, M12-mountMV-SC5060XM-08M-WBN
Interface
GigE
Resolution
6-10 MP
Sensor format
1/2.4"
Shutter
Rolling
$1,629.00View part

Next steps: filter the camera finder by resolution and shutter type, start a build at the system configurator, or ask the applications team to size the set-up from your defect sample.

Questions

Can I train a defect model with good parts only?

Yes — that is anomaly detection, and it is the right choice when real defects are scarce. Train on 300 or more good images (500 to 1,000 when part appearance varies), then set the anomaly-score threshold on held-out rejects. Even though training never sees a defect, keep 30 to 50 defect parts reserved to prove the threshold actually fires on real flaws.

Is 50 defect images enough if I augment heavily?

No. Augmentation multiplies the variety you photographed; it does not create defects you never saw, and heavy synthetic defects teach the model your generator instead of your line. At 100 annotated images per class a single-class detector reaches its published floor — below that, switch to good-only anomaly detection and spend the label time on good images instead.

How often does a defect model need retraining?

Retrain when good-part appearance changes, not on a calendar: a new material supplier, a finish change or tooling wear shifts the normal range and drives false rejects. In steady production, pull 100 fresh images each quarter and watch the weekly false-reject rate; retrain when it drifts past the 2 percent release gate, and rerun the 50-defect test set after every retrain.

Can a smart camera run the trained model on the device?

Yes, for inference. Train on a PC with a GPU, export the model, and run it on a smart camera at line speed — the MV-SC5060XM-08M-WBN carries 6 MP mono images over GigE with the inspection logic on board. Keep the training images and the retraining loop on the PC; the camera only needs the frozen model and your thresholds.

What defect recall is good enough to release?

Set the gate from cost: a missed defect that ships versus a good part rejected. A defensible floor for cosmetic inspection is zero or one miss on 50 held-out defect images — 98 to 100 percent recall — with false rejects under 2 percent on 200 good images. When a miss triggers a customer recall instead of a rework ticket, widen the test set to 100 defects so one miss reads as a real 99 percent, not noise.