This repository contains the code and resources for a PCB defect detection project. The project uses YOLO and other comparative models to detect and classify PCB defects, along with improvements to the dataset for achieving better results.
The following PCB defects are identified by the models:
- Mouse Bite
- Spur
- Missing Hole
- Short
- Open Circuit
- Spurious Copper
The goal of this project is to develop an efficient and accurate system for detecting defects in PCBs (Printed Circuit Boards). The project includes:
- Implementation of YOLO (You Only Look Once) for real-time object detection.
- Comparative analysis of other deep learning models.
- Dataset augmentation and preprocessing for improved performance.
The dataset used in this project has been carefully curated and improved to achieve better detection results. It includes labeled images of PCBs with the following defect categories:
Defect Name | Label ID |
---|---|
Mouse Bite | 0 |
Spur | 1 |
Missing Hole | 2 |
Short | 3 |
Open Circuit | 4 |
Spurious Copper | 5 |
- Data augmentation techniques such as rotation, flipping, and scaling.
- Cleaning mislabeled or noisy data.
- Adding more diverse samples to handle edge cases.
-
Install the YOLOv8 repository from Ultralytics:
pip install ultralytics
-
Customize the YOLOv8 model head to match the number of classes (6 for PCB defects):
from ultralytics import YOLO # Load YOLOv8 model model = YOLO('yolov8s.yaml') # Use YOLOv8 small model as base # Modify the model head for 6 classes (PCB defect classes) model.model.head = model.model.head.__class__( ch=model.model.head.in_channels, # Input channels from backbone nc=6 # Number of classes in your dataset ) # Train the model model.train(data='pcb_dataset.yaml', epochs=50, imgsz=640, project='pcb_defect_detection', name='yolov8_custom')
To train the model on your dataset:
python train.py model=yolov8s.yaml data=pcb_dataset.yaml epochs=50 imgsz=640
Update your pcb_dataset.yaml
file:
# pcb_dataset.yaml
train: path/to/train/images
val: path/to/val/images
nc: 6
names: ["mouse_bite", "spur", "missing_hole", "short", "open_circuit", "spurious_copper"]
After training, evaluate the performance:
python val.py model=pcb_defect_detection/yolov8_custom/weights/best.pt data=pcb_dataset.yaml
Performance comparisons have been conducted to evaluate precision, recall, and F1-score.
The following table summarizes the performance metrics for the best-performing models:
Model | Precision | Recall | F1-Score |
---|---|---|---|
YOLOv8 | 0.94 | 0.92 | 0.93 |
YOLOv5 | 0.92 | 0.90 | 0.91 |
Faster R-CNN | 0.88 | 0.85 | 0.86 |
EfficientNet | 0.85 | 0.83 | 0.84 |
-
Clone this repository:
git clone https://github.com/Dr-irshad/PCBGuard-AI-Powered-PCB-Defect-Detection-and-Analysis.git cd pcb-defect-detection
-
Install the required dependencies:
pip install -r requirements.txt
To train the YOLO model on your dataset:
python train.py --data config.yaml --weights yolov5s.pt --epochs 50
To train YOLOv8:
python train.py model=yolov8s.yaml data=pcb_dataset.yaml epochs=50 imgsz=640
To perform inference on test images:
python detect.py --weights best.pt --source test_images/
To evaluate the model:
python evaluate.py --weights best.pt --data config.yaml
- Further enhancement of dataset quality and diversity.
- Implementation of additional state-of-the-art models.
- Deployment of the best-performing model in an industrial setting.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m 'Add feature'
). - Push to the branch (
git push origin feature-name
). - Create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to open an issue for questions, suggestions, or any assistance.