Vibe Coding Forem

Y.C Lee
Y.C Lee

Posted on

Task:Create defect classification models

  • [-] 6.1 Create defect classification models
    • Implement CNN models for defect type classification
    • Write image preprocessing and augmentation pipelines
    • Create training data management and labeling tools
    • Implement model evaluation and confusion matrix analysis
    • Requirements: 8.5, 8.8, 2.6

Here's a clean, professional Markdown document for Task 6.1: Create Defect Classification Models, organized with clear sections, structured file mapping, and enhanced readability.


πŸ” Task 6.1: Defect Classification Models – File Mapping & System Overview

A production-ready computer vision system for semiconductor wafer defect classification, combining traditional machine learning, deep learning, and robust software engineering practices.

This document provides a comprehensive file-to-function mapping, component breakdown, and system architecture overview.


🧩 Core Implementation Files

Item File Path Content Brief
Main Classification Engine services/ai-ml/wafer-vision/src/defect_classification.py Core logic with 8 classes and 1,200+ lines of code. Implements ML/DL models, feature extraction, pattern detection, and ensemble classification for wafer defects.
FastAPI Service services/ai-ml/wafer-vision/src/wafer_vision_service.py REST API service supporting defect classification, model training, batch processing, and file uploads via HTTP endpoints.

βš™οΈ Configuration & Setup Files

Item File Path Content Brief
Service Configuration services/ai-ml/wafer-vision/config/defect_config.yaml YAML configuration with settings for models, preprocessing, defect patterns, performance tuning, and integration.
Python Dependencies services/ai-ml/wafer-vision/requirements.txt Full dependency list including: OpenCV, scikit-learn, TensorFlow, PyTorch, FastAPI, pytest, and supporting libraries.

πŸ“¦ Containerization & Deployment

Item File Path Content Brief
Docker Configuration services/ai-ml/wafer-vision/Dockerfile Multi-stage build supporting:
β€’ base (common dependencies)
β€’ development (debug tools)
β€’ production (optimized)
β€’ GPU (CUDA-enabled inference)
Service Orchestration services/ai-ml/wafer-vision/docker-compose.yml Full orchestration with 8 services:
β€’ Wafer vision API (CPU/GPU)
β€’ Redis (caching)
β€’ PostgreSQL (metadata)
β€’ Prometheus, Grafana, AlertManager (monitoring)
β€’ Dev environment & test runner

βœ… Testing & Quality Assurance

Item File Path Content Brief
Comprehensive Tests services/ai-ml/wafer-vision/tests/test_defect_classification.py Complete test suite covering:
β€’ Preprocessing & feature extraction
β€’ Model predictions
β€’ API integration
β€’ Error handling and edge cases
β€’ Performance benchmarks

πŸ“„ Documentation

Item File Path Content Brief
Complete Documentation services/ai-ml/wafer-vision/README.md 15-section guide including:
β€’ API reference
β€’ Configuration guide
β€’ Deployment steps (CPU/GPU)
β€’ Monitoring & troubleshooting
β€’ Code examples and curl commands

πŸ” Detailed Content Breakdown

1. Core Classification Engine (defect_classification.py)

πŸ—οΈ Classes (8)

  • DefectClassificationModels: Unified interface for ML/DL models
  • WaferMapPreprocessor: Image normalization, noise removal, alignment
  • FeatureExtractor: Statistical, texture, spatial, and frequency domain features
  • PatternDetector: Identifies defect spatial patterns
  • EnsembleClassifier: Combines predictions with voting/weighting
  • YieldImpactAnalyzer: Estimates yield loss from defect severity and location
  • ModelTrainer: Handles training pipeline
  • DefectVisualizer: Generates annotated output maps

πŸ€– Models

  • Traditional ML: Random Forest, SVM, Gradient Boosting, k-NN
  • Deep Learning: CNN, ResNet, EfficientNet (transfer learning)

πŸ“ Features (50+)

Category Examples
Statistical Mean, variance, skewness, kurtosis
Texture GLCM (contrast, correlation, energy), LBP
Morphological Area, perimeter, solidity, eccentricity
Spatial Radial distribution, cluster density
Frequency FFT-based spectral analysis

🎯 Defect Patterns (5)

  • Center: Concentric around wafer center
  • Edge: Ring near perimeter
  • Scratch: Linear or curved streaks
  • Donut: Circular void in center
  • Random: Scattered, non-structured

πŸ”„ Processing Pipeline

  1. Image preprocessing (noise reduction, contrast enhancement)
  2. Data augmentation (rotation, flip, zoom)
  3. Feature extraction
  4. Ensemble prediction (ML + DL fusion)
  5. Yield impact estimation

2. FastAPI Service (wafer_vision_service.py)

🌐 Endpoints (8)

Endpoint Function
POST /classify Single image classification
POST /classify/batch Batch classification with async processing
POST /upload Upload and classify image files
POST /train Trigger model retraining
GET /train/{id} Check training job status
GET /health System health check
GET /metrics Prometheus-compatible metrics
GET /patterns List supported defect patterns

πŸ›  Key Features

  • Pydantic models for request/response validation
  • Async processing for large batches
  • File upload support (PNG, TIFF, JPEG)
  • Logging & metrics integration
  • Error handling with structured responses

3. Configuration (defect_config.yaml)

Section Purpose
models Hyperparameters for ML/DL models
preprocessing Image resize, denoising, contrast settings
features Enabled feature types and extraction parameters
patterns Thresholds and rules for pattern detection
training Epochs, batch size, optimizer settings
performance GPU usage, threading, memory limits
api Rate limiting, timeout, upload size
logging Log level, format, output
database PostgreSQL connection settings
redis Caching and queue settings
monitoring Metrics export, health check intervals
integration MES/SCADA webhook URLs

4. Docker Setup (Dockerfile + docker-compose.yml)

🐳 Dockerfile (Multi-Stage)

Stage Purpose
base Common Python + system deps (OpenCV, libgcc)
development With debug tools (pdb, pytest, jupyter)
production Slim image, no dev tools
gpu CUDA-enabled (NVIDIA container toolkit)

🧩 Docker Compose Services (8)

  1. wafer-vision-api (CPU)
  2. wafer-vision-gpu (GPU-accelerated)
  3. redis
  4. postgresql
  5. prometheus
  6. grafana
  7. alertmanager
  8. dev-env (Jupyter + testing)

Includes health checks, resource limits, volume mounts, and internal networking.


5. Testing (test_defect_classification.py)

πŸ§ͺ Test Classes (6)

  • TestPreprocessor: Image normalization and alignment
  • TestFeatureExtractor: Feature correctness and stability
  • TestMLModels: Prediction accuracy and training
  • TestDLModels: CNN/ResNet inference and fine-tuning
  • TestPatternDetector: Spatial pattern recognition
  • TestIntegration: End-to-end classification workflow

βœ… Coverage

  • Unit tests for all core functions
  • Integration tests (API β†’ model β†’ output)
  • Edge cases: corrupted images, missing data, invalid formats
  • Performance benchmarks (latency, throughput)

🧩 Fixtures

  • Synthetic wafer map generator
  • Mock defect images
  • Simulated sensor noise

6. Documentation (README.md)

Section Content
1. Overview System purpose and scope
2. Architecture Component diagram
3. API Reference All endpoints with examples
4. Configuration defect_config.yaml guide
5. Deployment Docker and Kubernetes instructions
6. GPU Setup CUDA and cuDNN requirements
7. Testing How to run unit/integration tests
8. Monitoring Grafana dashboard setup
9. Troubleshooting Common issues and fixes
10. Development Local setup and debugging
11. Performance Benchmarks and optimization
12. Security API keys, rate limiting
13. Integration MES/SCADA hooks
14. Examples Python code, curl commands
15. Changelog Version history

πŸ”„ Key Relationships & Dependencies

graph TD
    A[defect_classification.py] -->|Used by| B[wafer_vision_service.py]
    B -->|Configured via| C[defect_config.yaml]
    C -->|Containerized in| D[Dockerfile + docker-compose.yml]
    D -->|Tested by| E[test_defect_classification.py]
    E -->|Documented in| F[README.md]
Enter fullscreen mode Exit fullscreen mode

This dependency flow ensures modularity, testability, and reproducibility across environments.


βœ… System Capabilities & Value

This implementation delivers a production-grade wafer defect classification system with:

  • High Accuracy: Ensemble ML/DL models for reliable defect identification
  • Scalability: Containerized, supports batch and real-time processing
  • Flexibility: Configurable for different defect types, tools, and fabs
  • Maintainability: Well-tested, documented, and modular
  • Deployability: Supports CPU and GPU environments

πŸš€ Conclusion

The Defect Classification System is now complete and ready for integration into the semiconductor manufacturing workflow.

βœ… Accurate – Combines 50+ features and multiple models

πŸ“¦ Deployable – Dockerized with full orchestration

πŸ§ͺ Reliable – Comprehensive testing and error handling

πŸ“š Maintainable – Fully documented and structured

This system enables automated, real-time defect detection and yield impact assessment, supporting higher quality and efficiency in wafer fabrication.


βœ… Status: Production-Ready

πŸ“ All components version-controlled, tested, and deployable via CI/CD.


Top comments (0)