This repository implements an advanced deep learning pipeline tailored for high-precision detection and classification of defects in Printed Circuit Boards (PCB). By conducting a Massive Ablation Study on 50+ CNN architectures and integrating a novel Entropy-based Uncertainty Exclusion strategy, the framework achieves a near-perfect production-ready accuracy of 99.80%.
⚠️ Copyright Notice Copyright (c) 2026 Kang Gyu Min. All rights reserved.
The automated pipeline systematically evaluates the top 10 SOTA vision lineages to statistically determine the optimal backbones for the specialized PCB feature space.
| Rank | Architecture | Accuracy | Status |
|---|---|---|---|
| 🏆 | ResNet50_V1 + MobileNet_V1 | 0.9980 | Best Ensemble (Proposed) |
| 1 | ResNet50_V1 | 0.9960 | Elite Backbone |
| 2 | MobileNet_V1 | 0.9955 | High-Efficiency SOTA |
| 3 | MobileNetV2 | 0.9935 | Balanced Model |
| 4 | EffNetB1 | 0.9900 | Lightweight Alternative |
| Defect Type | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| copper / spur | 1.0000 | 1.0000 | 1.0000 | 619 |
| mousebit | 0.9949 | 1.0000 | 0.9975 | 393 |
| open | 1.0000 | 0.9948 | 0.9974 | 388 |
| pin-hole / short | 0.9967 | 0.9967 | 0.9967 | 601 |
| Weighted Avg | 0.9980 | 0.9980 | 0.9980 | 2001 |
To maximize transfer learning efficiency and prevent catastrophic forgetting, every candidate model undergoes a rigorous three-phase training protocol:
- Phase 1: Classifier Foundation (Base Frozen) Backbone weights are strictly locked while training a custom classification head to establish robust, high-level feature mapping.
- Phase 2: Precision Fine-tuning (Partial Unfreeze) The top 50 layers of the backbone are unfrozen to adapt mid-level feature representations to domain-specific PCB patterns.
- Phase 3: Deep Optimization (Large Unfreeze) Up to 75 layers are unfrozen utilizing a
CosineDecayscheduler (initial LR1e-5) to achieve smooth convergence and flawless parameter alignment.
- Input Resolution Optimization: All images are dynamically resized and normalized to
224x224for optimized, high-throughput feature extraction through SOTA CNN backbones. - Uncertainty Filtering: The system calculates the Shannon Entropy of predictive probabilities across models and adaptively adopts the final decision from the network demonstrating the lowest classification uncertainty.
Engineered specifically for stable, extensive overnight training runs on local hardware configurations such as the Apple Silicon M5 (24GB Unified Memory):
- Unified Memory Management: Implemented explicit
K.clear_session()andgc.collect()infrastructure loops between each of the 50+ iterative model evaluations to completely eradicate memory leaks. - Label Smoothing (0.1): Integrated directly into the cross-entropy loss function to significantly improve generalization and absorb industrial-grade image or labeling noise.
Real-time inference samples demonstrating high-precision bounding box localization.
Detailed view of specific defect patterns and clean substrate comparison.
Note
💡 Error Analysis Deep-Dive > Achieved an exceptional 99.8% accuracy using Sugeno Ensembles and Stacking. Intensive error analysis of the 4 misclassified samples revealed highly complex edge-case defects—specifically, mousebits evolving into open circuits and highly irregular shorts. This firmly validates that the model’s Feature Extraction capabilities are fully production-ready, concluding that the remaining 0.2% variance is a Data-centric AI challenge requiring refined labeling standards rather than further architectural tuning.
Final evaluation on the test set using the Entropy-based Ensemble method (Accuracy: 99.80%).
High-dimensional feature separation demonstrating robust model discriminability and distinct class clusters.
📦 pcb_defects_classification
┣ 📂 PCBData # Dataset directory (Resized to 224x224)
┣ 📂 output/ # Prediction Probabilities, Checkpoints & Metrics
┃ ┣ 📂 ensemble/ # Final Entropy-based ensemble results
┃ ┣ 📂 single_model/ # Individual backbone performance reports
┃ ┗ 📂 visualization/ # 3D projections, confusion matrices & detection samples
┣ 📜 train_model.ipynb # Core Pipeline Notebook: 3-Stage Training Execution
┗ 📜 README.md # Project Documentation