Skip to content

About

YOLOv8-based AOI system for PCB defect detection — 95.6% mAP50, 6 defect classes, Gradio demo

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

TraceGuard — PCB Defect Detection

🇹🇷 Türkçe sürüm

Status: Phase 1 (model improvement) is complete. Development is ongoing; see the Roadmap below.

TraceGuard is a YOLOv8n-based Automated Optical Inspection (AOI) prototype that detects six PCB manufacturing defects (missing hole, mouse bite, open circuit, short, spur, spurious copper). It is trained on a public Kaggle dataset (693 images) and comes with a Gradio operator interface.

🎯 Final Model Performance

Model: YOLOv8n (transfer learning) · Optimizer: Adam · Input size: 960×960 · Test set: 104 images (never used for training)

Metric Value
mAP50 95.6%
mAP50-95 52.0%
Precision 94.3%
Recall 94.7%
Inference speed ~63.9 ms/image (~15.6 FPS, Tesla T4 GPU)

Per-class results (test set):

Defect type Precision Recall mAP50
Missing Hole 99.6% 100.0% 99.5%
Mouse Bite 92.3% 98.8% 96.5%
Open Circuit 97.1% 92.9% 97.3%
Short 95.8% 96.4% 96.8%
Spur 83.2% 81.3% 84.3%
Spurious Copper 97.8% 98.6% 99.2%

All six classes are above 80% mAP50.

Per-class mAP50

🔍 Example Predictions

Open Circuit and Mouse Bite Missing Hole and Spur Short and Spurious Copper

Confusion matrix (test set):

Confusion Matrix

🖥️ Operator Interface

In the Gradio interface, an operator uploads a PCB image and adjusts the confidence threshold to get instant defect detection. Interface labels are in Turkish.

Gradio interface

🧪 Improvement Process

Starting from a baseline model (YOLOv8n, AdamW, 640px), the following steps were tried in order, measuring results at each step:

  1. Data balancing for Mouse Bite: Increasing YOLO's built-in augmentation parameters was compared against targeted oversampling. Augmentation degraded other classes (especially Spur) and was dropped; oversampling was kept.
  2. Re-tuning the oversampling ratio: The initial ×4 ratio hurt Spur and Spurious Copper; it was reduced to ×2.
  3. Optimizer choice: Adam and AdamW were compared in two separate experiments; Adam came out ahead in both.
  4. Light augmentation: scale=0.4, translate=0.1, degrees=5 (copy_paste deliberately not used).
  5. Hard Positive Mining: Training images where the model struggled (low IoU match or low confidence) were identified programmatically and duplicated. Spurious Copper improved clearly; Spur stayed below the 80% threshold.
  6. Resolution increase (640 → 960): Spur defects cover a very small area of the image, so the bottleneck was resolution rather than data quantity. At 960px all classes passed 80% mAP50. The trade-off is slower inference (≈49.5 ms → ≈63.9 ms).

All experiments, including the discarded ones, are recorded chronologically in TraceGuard.ipynb.

📁 Repository Contents

File Description
TraceGuard.ipynb Experiment notebook: data preparation, all experiments (including discarded ones), final evaluation and Gradio interface. Written in Turkish.
best_v5_final_imgsz960.pt Final model weights (imgsz=960)
best.pt Initial (baseline) model weights, kept for reference
dataset_split.json Canonical train/val/test split (image names)
assets/ README images

🚀 Usage

Inference with the final model:

from ultralytics import YOLO

model = YOLO("best_v5_final_imgsz960.pt")
results = model("pcb_image.jpg", imgsz=960, conf=0.25)
results[0].show()

The dataset is available from the Kaggle PCB Defects Dataset. dataset_split.json can be used to reproduce the same split.

Note: Google Drive paths in the notebook belong to the author's environment. To run it yourself, replace the model path with the weights file from this repository.

⚠️ Notes and Limitations

  • Small test set: The test set has 104 images, i.e. 13–20 images per class (13 for Spur). Per-class results therefore have high variance.
  • Test set was also used during iteration: Method choices were made by looking at results on the same test set (there is no separate final hold-out set), so the reported numbers may be optimistic.
  • Baseline comparison: Baseline results (mAP50 86.1%) were measured on the first data split. The split was later found to be generated inconsistently across environments and was fixed with dataset_split.json. Since the baseline was not retrained on the current split, the two numbers should not be compared directly. Re-evaluation is planned.
  • Inference speed: 960px improved accuracy but reduced speed. Real-time line use would need optimization.
  • Results can vary slightly between runs due to GPU nondeterminism and randomness.

🗺️ Roadmap

Development is ongoing. Next up:

  • Retrain the baseline on the current split for a fair comparison
  • Fine-tuning with synthetic (AI-generated) defect images
  • A simplified English notebook showing only the final pipeline
  • Later: edge deployment (Raspberry Pi 4, ONNX / INT8 quantization)

👤 Author

Emin Ülgüç — Computer Engineering, Manisa Celal Bayar University

About

YOLOv8-based AOI system for PCB defect detection — 95.6% mAP50, 6 defect classes, Gradio demo

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages