End-to-End Deep Learning Microservice for Inline Wafer Defect Pattern Classification in High-Volume Semiconductor Manufacturing
Targeting Applications in Advanced Process Control (APC) & Yield Engineering at Semiconductor Fabs
(LAM Research Β· Micron Technology Β· Applied Materials Β· GlobalFoundries)
- π Executive Summary & Key Results
- π Fab Yield Economics & Business Impact
- πΌοΈ Dataset & Defect Pattern Visualizations
- π§ Model Architecture & Training
- π Evaluation & Model Explainability (Grad-CAM)
- π Repository Structure
- π» Tech Stack
- π Quick Start Guide
- π REST API Endpoints
- π License
In semiconductor manufacturing, silicon wafers undergo hundreds of photolithography, etching, and chemical-mechanical planarization (CMP) steps. Spatial defect patterns on wafer maps (e.g., Center, Donut, Edge-Ring, Scratch) directly signal specific process equipment faults.
This project delivers a PyTorch Convolutional Neural Network (CNN) pipeline capable of classifying 9 distinct wafer defect patterns from raw sensor die maps, exposed as a FastAPI microservice and an interactive Streamlit dashboard.
| Metric | Score / Benchmark | Note |
|---|---|---|
| Overall Accuracy | 94.2% | Evaluated on WM-811K benchmark test split |
| Macro F1-Score | 0.91 | Robust performance across extreme class imbalance |
| Inference Latency | < 25 ms | Per wafer map (single-channel 64x64 tensor) |
| Input Map Resolution | 64 Γ 64 | Single-channel spatial tensor representation |
| Supported Defect Classes | 9 Classes | Center, Donut, Edge-Loc, Edge-Ring, Loc, Near-full, Random, Scratch, none |
- Early Scrap Reduction: Detecting systematic tool failure signatures inline (e.g., CMP slurry scratches or edge-bead removal ring defects) prevents processing damaged wafers through costly downstream processing steps.
- Financial Savings: At an average wafer manufacturing cost of $5,000 per wafer in modern 300mm fabs, catching 100 defective wafers daily saves up to $500,000 per day ($180M+ annually).
- Automated Root-Cause Diagnosis: Replaces manual inspection by fab yield engineers, reducing mean-time-to-detection (MTTD) from hours to milliseconds.
The system is trained on the benchmark WM-811K dataset, containing 811,457 real semiconductor wafer maps from high-volume production.
Below are representative spatial heatmaps of the 9 defect categories:
Raw dataset analysis revealed an extreme 5,275:1 imbalance ratio (785,938 none wafers vs 149 Near-full wafers).
To solve this:
-
Stratified Undersampling: Reduced dominant
nonesamples to 10,000 representative maps. -
Inverse-Frequency Loss Weighting: Implemented custom weighted Cross-Entropy Loss (
$\text{weight}_c \propto \frac{1}{N_c}$ ) in PyTorch to ensure rare defect classes (Donut, Scratch) are penalized heavily during backpropagation.
The core architecture (WaferCNN) consists of 4 convolutional blocks with Batch Normalization, Max Pooling, and Dropout for regularization:
[Input: 1 x 64 x 64]
β
βββ Conv2D(1β32, 3x3) ββ BatchNorm ββ ReLU ββ MaxPool(2x2) β [32 x 32 x 32]
βββ Conv2D(32β64, 3x3) ββ BatchNorm ββ ReLU ββ MaxPool(2x2) β [64 x 16 x 16]
βββ Conv2D(64β128, 3x3) ββ BatchNorm ββ ReLU ββ MaxPool(2x2) β [128 x 8 x 8]
βββ Conv2D(128β256, 3x3) ββ BatchNorm ββ ReLU ββ MaxPool(2x2) β [256 x 4 x 4]
β
βββ Flatten (4096)
βββ Dropout(0.5) ββ Dense(512) ββ ReLU
βββ Dense(9) ββ Softmax β [Class Probabilities]
The confusion matrix below highlights strong class separation across all 9 defect types, with low misclassification rates even among topographically similar classes (e.g., Edge-Loc vs Edge-Ring).
Semiconductor engineers require explainable AI before deploying models in production. Grad-CAM (Gradient-weighted Class Activation Mapping) extracts feature maps from the final convolutional layer (conv4), overlaying heatmaps to confirm the network focuses precisely on the die failure regions.
wafer-defect-detection/
βββ api.py # FastAPI inference microservice
βββ dashboard.py # Streamlit interactive visualization dashboard
βββ Dockerfile # Production Docker container configuration
βββ requirements.txt # Python environment dependencies
βββ label_mapping.json # Class label integer-to-name mapping
βββ best_wafer_model.pth # Saved PyTorch CNN model weights (~9.9 MB)
βββ defect_samples.png # Visual sample grid
βββ training_curves.png # Loss and accuracy curves
βββ confusion_matrix.png # Evaluation confusion matrix
βββ gradcam_visualization.png # Grad-CAM model explainability plot
βββ LICENSE # MIT Open Source License
βββ LINKEDIN_POST.md # LinkedIn post template for project showcase
βββ README.md # Project documentation
- Deep Learning Framework: PyTorch 2.7+ (CUDA GPU accelerated)
- Computer Vision: OpenCV, Pillow
- Web API / Serving: FastAPI, Uvicorn, ASGI
- Frontend Dashboard: Streamlit, Plotly Express
- Containerization: Docker
- Data Engineering: Pandas, NumPy, Scikit-learn, Matplotlib, Seaborn
# Clone repository
git clone https://github.com/yourusername/wafer-defect-detection.git
cd wafer-defect-detection
# Activate environment & install requirements
conda activate wafer-env
pip install -r requirements.txt
# Terminal 1: Launch FastAPI backend server
uvicorn api:app --reload --port 8000
# Terminal 2: Launch Streamlit frontend dashboard
streamlit run dashboard.pyAccess the Streamlit Dashboard at http://localhost:8501 and FastAPI interactive Swagger documentation at http://localhost:8000/docs.
# Build Docker image
docker build -t wafer-defect-api .
# Run container
docker run -p 8000:8000 wafer-defect-api
# Health check
curl http://localhost:8000/healthReturns microservice operational status and model version.
{
"status": "healthy",
"model": "WaferCNN v1.0"
}Accepts an uploaded wafer image file (multipart/form-data) and returns predicted defect class with confidence distribution.
Sample JSON Response:
{
"predicted_class": "Edge-Ring",
"confidence": 0.9842,
"all_probabilities": {
"Center": 0.0011,
"Donut": 0.0005,
"Edge-Loc": 0.0082,
"Edge-Ring": 0.9842,
"Loc": 0.0021,
"Near-full": 0.0001,
"Random": 0.0008,
"Scratch": 0.0015,
"none": 0.0015
}
}Distributed under the MIT License. See LICENSE for more information.



