8.8 KiB
Synthetic Defect Factory: Automated Optical Inspection (AOI) Digital Twin
An end-to-end industrial digital twin and computer vision pipeline for automated optical inspection (AOI) in sheet-metal manufacturing. Synthesizes millimeter-accurate physical defect variations on CAD brackets in Pixar OpenUSD, renders photorealistic scenes with Blender OptiX raytracing, projects 100% mathematical 2D YOLO bounding boxes, trains deep neural networks (YOLOv8), and runs real-time edge inference with an automated conveyor rejection HUD.
🏭 Overview & Engineering Motivation
Modern industrial stamping and machining lines operate at defect rates below 0.1% (>99.9% yield). While optimal for plant throughput, this creates an AI Training Deadlock: gathering 1,000 real-world defect images requires inspecting over 1,000,000 physical parts, taking months of line time and thousands of dollars in manual labeling.
Synthetic Defect Factory solves this bottleneck through a physics-calibrated 3D digital twin and procedural defect engine:
- 100% Automated Ground-Truth: 2D YOLO bounding boxes are derived analytically from 3D vertex deformation math ($0 labeling cost, 0 human error).
- Pixar OpenUSD Compliance: 118 station CAD primitives validated with 0 errors and 0 warnings under Pixar's
UsdValidationsuite. - Photorealistic Optics: OptiX hardware-accelerated raytracing, physical LED ring illuminator, 50mm C-mount lens simulation, and domain randomization (yaw jitter
\pm 3^\circ, lighting intensity\pm 10\%). - Closed-Loop Physical Simulation: Conveyor translation, photoelectric sensor triggering, real-time machine vision inspection HUD, and pneumatic cylinder rejection into a scrap chute.
📸 Inspection Workstation & AI Detection HUD
🔬 Procedural Defect Classes
The engine injects four physical defect categories directly into CAD bracket geometry alongside nominal parts:
📊 Quantitative Benchmarks & Model Performance
The model was trained on 1,000 synthetic inspection scenes (800 train / 200 validation) across balanced defect distributions:
| Metric | Overall Performance |
|---|---|
| mAP@50 (Overall) | 85.43% |
| mAP@50-95 (Overall) | 84.00% |
| Overall Precision | 83.88% |
| Overall Recall | 93.75% |
| Inference Latency | ~12.8 ms / frame (~78 FPS) |
Per-Class Validation Breakdown
- Dent (Class 1):
99.50%mAP@50 - Missing Part (Class 2):
99.50%mAP@50 - Scratch (Class 0):
96.14%mAP@50 - Misplaced Part (Class 3):
40.87%mAP@50 (subtle 24° tilt detection)
Detailed metrics exported to reports/model_metrics.json.
🏗️ System Architecture
graph TD
subgraph S1["1. OpenUSD Stage Authoring"]
A["make_base_usd.py"] --> B["station.usda (118 Prims)"]
C["defects.py"] --> D["Procedural USD Overrides"]
end
subgraph S2["2. Headless Simulation & Rendering"]
B & D --> E["Blender 5.2 (Cycles / EEVEE)"]
E --> F["station.blend (Interactive Digital Twin)"]
E --> G["render_dataset_batch.py (1,000 Scenes)"]
end
subgraph S3["3. Mathematical Ground Truth"]
D --> H["Analytical 3D-to-2D Projection"]
H --> I["YOLO Labels (800 Train / 200 Val)"]
end
subgraph S4["4. Deep Learning & Edge Vision"]
G & I --> J["YOLOv8 Nano Training (train.py)"]
J --> K["best.pt (Trained Weights)"]
K --> L["infer_video.py (Real-Time In-Line Inspection HUD)"]
end
📁 Repository Structure
├── blender/
│ ├── create_station_blend.py # Imports USD & builds Blender digital twin
│ ├── render_dataset_batch.py # Headless batch renderer for synthetic scenes
│ ├── render_animation_video.py # Compiles conveyor simulation into broadcast MP4
│ └── test_render_single.py # Single-frame render verification
├── config/
│ └── project_config.yaml # Global seeds, class IDs, optical specs, paths
├── dataset/
│ ├── data.yaml # YOLOv8 dataset configuration
│ └── labels/ # 1,000 mathematically projected 2D YOLO annotations
├── renders/
│ ├── animation/ # 24 FPS broadcast inspection videos
│ ├── final/ # Real-time AI-inferred HUD video
│ └── samples/ # High-resolution benchmark renders & keyframes
├── reports/
│ ├── base_usd.md # USD 118-primitive engineering specification
│ ├── defects_engine.md # Procedural deformation mathematical documentation
│ └── model_metrics.json # Quantitative validation benchmarks
├── src/
│ ├── make_base_usd.py # Procedural OpenUSD workstation CAD generator
│ ├── defects.py # Mathematical defect injection & 2D projection
│ ├── generate_scenes.py # Dataset manifests & YOLO label batch creator
│ ├── train.py # YOLOv8n GPU training pipeline
│ ├── infer_video.py # Edge video inference & HUD overlay engine
│ └── verify_labels.py # Ground-truth geometry & distribution validator
├── station.blend # Master 3D digital twin workstation scene (~293 KB)
├── usd/
│ ├── base/station.usda # Validated base OpenUSD inspection station
│ └── manifests/ # 1,000 JSON scene metadata records
├── .gitignore
├── requirements.txt
└── README.md
🚀 Quickstart & Reproduction Guide
1. Environment Setup
# Clone the repository
git clone https://github.com/omkarande14/synthetic-defect-factory.git
cd synthetic-defect-factory
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
2. Generate Base USD Station & Defect Manifests
# Generate the 118-primitive OpenUSD workstation
python src/make_base_usd.py
# Generate 1,000 balanced scene manifests and exact 2D YOLO labels
python src/generate_scenes.py
# Verify label bounding box integrity
python src/verify_labels.py
3. Render Synthetic Imagery (Headless Blender)
# Batch render 1,000 synthetic inspection scenes (800 train, 200 val)
blender station.blend --background --python blender/render_dataset_batch.py
4. Train YOLOv8 Model
# Train YOLOv8 Nano on dedicated GPU
python src/train.py
5. Run In-Line Video AI Inference
# Process conveyor inspection stream with machine vision HUD
python src/infer_video.py
📜 License
Distributed under the MIT License. See LICENSE for more information.






