The Data Problem That Stops Most Teams Before They Start
Building a reliable AI model for visual defect inspection has always come down to one hard constraint: defect data is scarce. In manufacturing environments, defects are rare by design — which is exactly what makes collecting enough labelled examples such a slow, expensive process.
Teams either wait months for defects to accumulate in production, or they ship models trained on too little data and accept the accuracy trade-off. Neither is acceptable when inspection quality directly affects product yield and customer outcomes.
At CODETRACE, we addressed this challenge not by collecting more data, but by generating it with precision. At NVIDIA GTC Taipei 2026, we are showcasing how we integrated the NVIDIA Defect Image Generation skill — a few-shot, diffusion-based defect generation pipeline built on NVIDIA Cosmos, with NV-DINOv2, C-RADIOv3, and SAM2 powering the visual encoding, quality evaluation, and mask refinement stages — into our Automated Optical Inspection (AOI) pipeline. Starting from a small set of real annotated defect images, the pipeline synthesises a large, diverse, and pseudo-labelled training set, which we then use to train a production-ready inspection model — compressing what was previously a months-long data-collection cycle into days.
to start with
Codetrace AnomalyGen
for final model
Why Standard Approaches Fall Short
Modern industrial inspection increasingly relies on AI models trained to detect rare, high-impact defects. But in practice, those defects don’t show up often enough to build a robust training dataset within a reasonable product timeline.
The Defect Data Dilemma
Real defect types occur infrequently, vary widely in appearance, and lack sufficient labelled samples for supervised training. Limited production timeframes further constrain data collection — forcing teams to rely on manual inspection, which drives high operational costs and limits model accuracy under real‑world conditions.
Traditional synthetic data generation (SDG) approaches have tried to address this, but they typically struggle with realism — generated defects can look artificial, causing models trained on them to underperform when confronted with actual production defects. Physical consistency and spatial accuracy are hard to preserve without grounding the synthesis in real imagery.
This is precisely the gap that NVIDIA’s Defect Image Generation skill — part of NVIDIA’s Physical AI agent skills for Synthetic Data Generation — was built to close.
Where We Started: Direct Training on Real Images
Our in-house vision model, Codetrace DetecXion, is CODETRACE’s purpose-built engine for automated defect detection. Before integrating AnomalyGen, our standard pipeline was straightforward: collect real defect images, annotate them, post-train DetecXion directly, and deploy.
With only 10 real annotated images as our starting point, this baseline approach gave us a deployable model — but one with limited ability to generalise to defect variations it hadn’t seen in training. It was the fastest path to deployment, and it served as our reference point for measuring what synthetic augmentation could actually deliver.
Baseline Workflow — No Synthetic Data
Direct training on 10 real images · 5 stages
Scaling to 200 Images — Without a Single Additional Real Defect
Integrating NVIDIA’s Defect Image Generation skill required rethinking the data preparation phase entirely. Rather than feeding our 10 real images directly into DetecXion, we first put them through a diffusion-based inpainting workflow — Codetrace AnomalyGen orchestrating Cosmos-Predict2, SAM2, and Cosmos-Reason1 — which expands the dataset 20× before post-training in NVIDIA TAO Toolkit.
The Defect Image Generation skill is part of NVIDIA’s Physical AI agent skills for synthetic data generation, built on NVIDIA Cosmos. For a full description of the skill, see NVIDIA Cosmos.
The enhanced eight-stage pipeline works as follows:
End-to-End Pipeline — NVIDIA Defect Image Generation Skill
Real data → Synthetic augmentation → Train & deploy · 8 stages
Stages 1–2 remain unchanged from the baseline: annotate the 10 real defect images using Codetrace LabelMe and set up the Docker / CONDA / CUDA environment.
Stage 3 is where the pipeline diverges significantly. Instead of heading straight to model training, we fine-tune NVIDIA Cosmos-Predict2 (using LoRA) on our 10 annotated real images — teaching the model the visual, textural, and material distribution of the target defect type. NV-DINOv2 and C-RADIOv3 power the visual encoding and quality evaluation at this stage.
Stage 4 uses SAM2 to automatically identify and place regions of interest (ROIs) — the precise spatial locations on each image where defects can realistically appear. This ensures that synthetic defects are placed with physical plausibility, not at random.
Stage 5 is the core: the NVIDIA AnomalyGen skill leverages the trained diffusion model and SAM2 masks to generate photorealistic synthetic defect images grounded in the real image’s structure, lighting, and material characteristics — supporting PCB, metal surface, and integrated circuit device defect types. This is where our 10 images become 200.
Stage 6 runs Cosmos-Transfer1 to apply Sim2Real style transfer and lighting normalisation to align synthetic images with real factory imaging conditions, then Cosmos evaluation scripts validate image fidelity before training. Stage 7 runs SAM2 + Cosmos-Reason1 to automatically pseudo-label all 200 outputs — SAM2 produces defect masks and Cosmos-Reason1 provides semantic captions for class assignment, eliminating manual labelling overhead entirely.
Stages 7–8 bring it home: Codetrace DetecXion is post-trained on the full expanded dataset of 200 images using NVIDIA TAO, and deployed to production as a fully inference-ready model.
Baseline Pipeline vs. With Codetrace AnomalyGen
| Metric | Baseline | With AnomalyGen |
|---|---|---|
| Training images | 10 real images | 200 images (10 real + 190 synthetic) |
| Data collection time | Months of production wait | Accelerated — no additional real defects needed |
| Pipeline stages | 5 stages | 8 stages (with synthetic augmentation) |
| Manual labelling effort | 100% manual | Auto pseudo-labelled via SAM2 + COSMOS |
| Day-0 inspection readiness | Limited by data scarcity | Achievable without months of defect collection |
Measured Accuracy Results
Validated against a 100-sample running set (70 genuine good, 30 genuine NG).
| Training Set | Without AnomalyGen | With AnomalyGen | Difference % |
|---|---|---|---|
| OK | 100 | 100 | — |
| NG | 10 | 50 | +400.0% |
| TOTAL | 110 | 150 | +36.4% |
| Sample Set | Without AnomalyGen | With AnomalyGen | Difference % |
|---|---|---|---|
| TOTAL SAMPLE | 100 | 100 | — |
| Genuine Good | 70 | 70 | — |
| Genuine NG | 30 | 30 | — |
| Result | Without AnomalyGen | With AnomalyGen | Difference % |
|---|---|---|---|
| Good | 60 | 69 | +15.0% |
| Escape | 5 | 1 | −80.0% |
| False Call | 5 | 2 | −60.0% |
| NG | 25 | 28 | +12.0% |
| TOTAL | 95 | 100 | +5.3% |
| Key Metric | Without AnomalyGen | With AnomalyGen | Change (pp) |
|---|---|---|---|
| Good Rate | 63.2% | 69.0% | +5.8 pp |
| Escape Rate | 5.3% | 1.0% | −4.3 pp |
| False Call Rate | 5.3% | 2.0% | −3.3 pp |
| NG Rate | 26.3% | 28.0% | +1.7 pp |
What This Means for Industrial AI Development
This integration demonstrates something important: the bottleneck in production AI for visual inspection is rarely the model architecture — it’s the data. Codetrace AnomalyGen tackles this directly: Cosmos-Predict2 and SAM2 inpaint defects into real product images, and Cosmos-Reason1 validates every synthetic sample before it enters training — yielding a 20× dataset expansion grounded in genuine factory imagery.
Faster Model Readiness
Day-0 inspection capability without waiting months for real defect samples to accumulate in production.
20× Training Data Expansion
Starting from 10 real defect images, the pipeline generates 200 training samples — NG class expanded from 10 to 50 (+400%), enough to post-train a production-grade model with confidence.
Better Generalisation
Good Rate improved from 63.2% → 69.0% (+5.8 pp) — more products correctly passed without unnecessary rejection.
Reduced Manual Overhead
Automated pseudo-labelling via SAM2 + Cosmos-Reason1 eliminates the annotation burden across all 200 generated images.
Production-Grade Realism
Synthetic defects are grounded in real image structure via NVIDIA Cosmos, with Sim2Real style transfer via Cosmos-Transfer1 and fidelity validation by the Cosmos Evaluator.
Multi-Material Scalability
The same pipeline applies across PCB, metal surface, and integrated circuit devices inspection — without rebuilding the workflow for each material type.
Escape Rate −80%
Escape Rate dropped from 5.3% → 1.0% (−4.3 pp) — significantly fewer defective units slipping through inspection undetected.
False Call Rate −60%
False Call Rate dropped from 5.3% → 2.0% (−3.3 pp) — substantially fewer incorrect detections, reducing unnecessary line stoppages.
“The real breakthrough is not generating more data — it is generating the right data. NVIDIA’s Defect Image Generation skill gave us synthetic defects that are physically grounded, spatially accurate, and realistic enough to meaningfully improve a production model.”
— Mr. Jason Ng, CEO of CODETRACE Sdn Bhd
Expanding Across Defect Types and Materials
The current pipeline has been validated across PCB, metal surface, and integrated circuit device defect types using the Codetrace AnomalyGen + NVIDIA Cosmos pipeline. CODETRACE will continue expanding material coverage and integrating Cosmos-Transfer1 for Sim2Real scenarios where real reference imagery is unavailable. Trained models are deployed to factory cameras through CODETRACE’s own inspection platform, Codetrace DetecXion.
For teams facing the same data scarcity challenge in their own inspection workflows, this approach represents a practical, production-tested path forward — one that eliminates the most common reason inspection AI projects stall before they ever reach deployment.
For manufacturing teams confronting the same data-scarcity challenge, this approach represents a practical, production-validated path to Day-0 inspection readiness. The full workflow — Codetrace AnomalyGen orchestrating NVIDIA Cosmos-Predict2, SAM2, Cosmos-Reason1, and TAO Toolkit, with deployment via Codetrace DetecXion — is available to manufacturers as a turnkey integration. To explore how NVIDIA Cosmos synthetic data generation and Codetrace DetecXion can accelerate your inspection AI programme, contact our team.
📍 Visit us at NVIDIA Inception Pavilion at InnoVEX 2026 — Booth S0712a, 4F, TaiNEX Hall 2, Taipei — 2 June to 4 June 2026
Ready to Accelerate Your Inspection AI?
Talk to the CODETRACE team about integrating synthetic data generation into your AOI pipeline.
Get in Touch →