A comprehensive machine learning system for automatically detecting and classifying defects in printed circuit boards (PCBs) using convolutional neural networks.
This project addresses the critical need for automated quality control in PCB manufacturing by developing a robust defect classification system. The solution achieves 84.44% accuracy in identifying six common PCB defect types and is deployed as an intuitive web application for practical use in industrial settings.
- Final Validation Accuracy: 84.44%
- Dataset Size: 180 carefully annotated PCB images
- Best Class Performance: 96.7% recall on Class 2 defects
- Average Prediction Confidence: 87.5%
- Macro F1-Score: 0.843
| Defect Type | Precision | Recall | F1-Score |
|---|---|---|---|
| Missing Hole | 82.6% | 63.3% | 71.7% |
| Mouse Bite | 86.2% | 83.3% | 84.7% |
| Open Circuit | 90.6% | 96.7% | 93.5% |
| Short | 81.8% | 90.0% | 85.7% |
| Spur | 71.4% | 83.3% | 76.9% |
| Spurious Copper | 96.4% | 90.0% | 93.1% |
The system employs a carefully optimized convolutional neural network architecture:
Input Layer (128×128×3 RGB images)
↓
Conv2D (32 filters, 3×3) + Batch Normalization + ReLU Activation
↓
MaxPooling2D (2×2)
↓
Conv2D (64 filters, 3×3) + Batch Normalization + ReLU Activation
↓
MaxPooling2D (2×2)
↓
Conv2D (64 filters, 3×3) + Batch Normalization + ReLU Activation
↓
Flatten Layer
↓
Dense Layer (128 units) + Batch Normalization + ReLU Activation
↓
Dropout Layer (50% rate)
↓
Output Layer (6 units, Softmax Activation)
- Optimization: Adam optimizer with categorical crossentropy loss
- Regularization: Strategic use of batch normalization and dropout to prevent overfitting
- Data Augmentation: Comprehensive augmentation including random rotations (±15°), horizontal/vertical flipping, zoom variations (±5%), and brightness adjustments (±10%)
- Early Stopping: Automatic training termination with 8-epoch patience to maintain optimal performance
- Learning Rate Scheduling: Dynamic learning rate reduction when validation performance plateaus
- YOLO Annotation Conversion: Transformed bounding box annotations into cropped defect-focused images
- Image Standardization: Resized all images to 128×128 pixels for consistent processing
- Class Balancing: Ensured equal representation across all six defect categories
- Dataset Splitting: Implemented 80/20 training/validation split with stratification
- Python 3.8+
- TensorFlow 2.x
- Flask
- OpenCV
- PIL
Download the pre-trained model: https://drive.google.com/file/d/1FbpueBcYs9UbIWvPBGKraoZpYqaah8fQ/view?usp=sharing
- Click the link above
- Click the "Download" button in Google Drive
- Save the file to your computer
- Go to Google Drive
- Upload the downloaded
pcb_defect_model_84percent.h5file to your main Drive folder (not in any subfolder)
- Go to Google Colab
- Create a new notebook
- Copy and paste the entire code from code/app_colab.py into a cell
- Run the cell
- Output should provide a URL
- Click on the link and it will redirect you to the user interface