R&D prototype · open/synthetic data
ITS AI XAI - Explainable PCB Defect Detection
Problem
PCB manufacturing quality control needs defect detection that engineers can trust and act on, not just a black-box pass/fail verdict. Sensor telemetry alone (603 raw features) and visual inspection alone each miss defects the other catches, and end-to-end deep models do not give engineers the interpretable, per-prediction feature attribution they need for root-cause analysis and process correction. The system had to combine both signal types, stay fast enough for inline use, and explain every decision in a way a process engineer could use to adjust the line — and it was built and benchmarked entirely on open/synthetic data (open SECOM sensor data + open DeepPCB images, paired synthetically), not on data from any real factory.
What I built
- Built end-to-end as the solo developer: the multimodal fusion architecture, the XGBoost meta-classifier that fuses Random Forest (sensor) and YOLO (vision) outputs into 8 fusion features, the FastAPI backend, and the Streamlit frontend (design choices below).
- Engineered the feature-reduction pipeline that cuts the 603 raw SECOM sensor features to 164 (-72.8%) via tiered missing-value handling and importance-based selection, improving prediction quality and uncertainty calibration.
- Developed the explainability layer surfaced through a 4-tab Streamlit dashboard: SHAP waterfall attribution and a counterfactual what-if interface, with Plotly visualizations for defect analysis.
Design decisions
-
XGBoost meta-classifier over end-to-end deep learning
Context: interpretable predictions are needed for root-cause analysis. Options weighed: an end-to-end neural network vs. a two-stage fusion with an XGBoost meta-classifier. Rationale: XGBoost enables SHAP feature attribution served by a dedicated /explain endpoint at 15.6 ms per request, whereas deep learning would require expensive gradient-based explanations; the tree approach delivered the accuracy targets at 67.3 ms end-to-end /predict CPU latency.
-
SHAP attribution with consistency validation against the model
Context: a single explanation method may carry biases, and the feature-importance ranking needs to be trustworthy. Rationale: SHAP feature-importance rankings were validated against the Random Forest model's own built-in importance scores, reaching a Pearson correlation above 0.95, giving confidence the explanations reflect what the model actually learned; outputs are kept domain-agnostic so real sensor names can be mapped in later.
Every prediction carries a faithful explanation: a SHAP waterfall whose feature ranking matches the model's own built-in importances (Pearson > 0.95), plus a counterfactual that turns the verdict into an actionable process change. -
Dimensionality reduction of the 603-feature sensor stream
The SECOM sensor stream carries 603 features (590 original + 13 engineered). A tiered pipeline (removing >90%-missing features, KNN/median imputation for the rest, and importance-based selection) narrowed this to 164 features (-72.8%), which cut dimensionality and inference cost while actually improving SECOM prediction quality and uncertainty calibration.
-
Two-stream fusion: Random Forest (sensor) + YOLO (vision)
Sensor telemetry is handled by a Random Forest and visual inspection by a YOLO detector (the trained YOLOv8m benchmarked at mAP@50 93.51% on the open DeepPCB dataset; a lighter YOLOv11n is used at inference time); the XGBoost meta-classifier fuses both streams into 8 features so defects visible in only one modality are still caught, reaching F1 ≈0.95 on the 236-sample hold-out test set.
In operation




Engineering foothold
| Claim | Evidence |
|---|---|
| Meta-classifier F1-score of 0.9462 on the 236-sample hold-out test set (+26% above the F1 >= 0.75 target) | FINAL_VALIDATION_REPORT.md lines 462, 468, 505-518: F1 0.9462 measured on a 236-sample hold-out test set (70/15/15 stratified split; 5-fold CV for model selection), target F1 >= 0.75 so +26% margin. Confirmed in README.md line 14/39. |
| End-to-end /predict latency of 67.3 ms on CPU (44-45% under the <120 ms target) | FINAL_VALIDATION_REPORT.md lines 604-635: mean 67.3 ms over 10 runs (P50 66.5, P95 78.2, P99 101.0) on CPU-based inference, end-to-end /predict including SECOM RF, YOLO, meta-classifier, and API overhead; target <120 ms (PASS -44%). Confirmed README.md lines 14/40/257. |
| YOLOv8m visual detection mAP@50 of 93.51% on the open DeepPCB benchmark | FINAL_VALIDATION_REPORT.md lines 325-341: YOLOv8m (medium) trained on 999 DeepPCB image pairs, validated on 501, mAP@50 93.51% (also mAP@50-95 63.50%, precision 89.74%, recall 90.44%). The 93.51% belongs to YOLOv8m, while the inference model is YOLOv11n (lines 632, API_IMPLEMENTATION_SUMMARY.md line 52). |
| Meta-classifier defect (FAIL) recall of 95.91% on the 236-sample test set | FINAL_VALIDATION_REPORT.md lines 214-220, 429, 469, 508: meta-classifier recall 0.9591 on the 236-sample test set (211 of 220 FAIL caught, 9 missed); this is the fused meta-classifier's defect-class recall, not YOLO's. Confirmed README.md lines 21/245. |
| SHAP feature-attribution latency of 15.6 ms per /explain request | FINAL_VALIDATION_REPORT.md line 599: /explain (SHAP explanations) measured at 15.6 ms, 100% success. |
| SHAP consistency validated against Random Forest built-in importance (Pearson > 0.95) | FINAL_VALIDATION_REPORT.md line 823: SHAP feature-importance rankings match the Random Forest built-in importance scores at Pearson correlation > 0.95; the XAI method table (lines 815-819) lists only SHAP, Counterfactual, and Grad-CAM (no LIME, which is not implemented). |

Tech stack
- ML / AI
- XGBoost (meta-classifier), Random Forest (sensor stream), YOLO (visual inspection - YOLOv8m benchmark, YOLOv11n at inference), scikit-learn, imbalanced-learn (SMOTE), Importance-based feature reduction (603 to 164)
- Explainability (XAI)
- SHAP (waterfall attribution), Counterfactual analysis
- Dashboard / Frontend
- Streamlit (4 interactive tabs), Plotly (visualizations)
- API / Backend
- FastAPI, Uvicorn (REST API, 7 endpoints), pandas, numpy, OpenCV
- Data (open / synthetic)
- SECOM (open semiconductor-manufacturing sensor dataset), DeepPCB (open PCB defect image benchmark), Synthetic SECOM-DeepPCB pairing (statistical matching)