English | Türkçe
TraceGuard is an Automated Optical Inspection (AOI) prototype that detects six types of manufacturing defects on printed circuit boards: missing hole, mouse bite, open circuit, short, spur and spurious copper. It is built on YOLOv8n with transfer learning, uses a public dataset of 693 PCB images, and comes with a Gradio interface for an operator.
Both models are evaluated on the same test set: 104 images with 448 labelled defects, never used for training.
| Metric | Baseline | Final | Change |
|---|---|---|---|
| mAP50 | 87.6% | 95.5% | +7.8 pts |
| mAP50-95 | 43.3% | 52.0% | +8.7 pts |
| Precision | 92.8% | 94.3% | +1.5 pts |
| Recall | 83.7% | 94.7% | +10.9 pts |
Changes are computed from unrounded values, so they can differ by 0.1 from the rounded numbers shown.
- Baseline: YOLOv8n, Ultralytics defaults (AdamW chosen automatically), 640 px input, batch 16.
- Final: YOLOv8n, targeted oversampling + hard positive mining, Adam with light augmentation, 960 px input, batch 8 (960 px images need more GPU memory).
- Both start from the same COCO-pretrained weights and train for 50 epochs.
The largest gain is in recall: the final model misses far fewer defects, which is what matters most in quality control.
Per class (test set):
| Defect type | Baseline mAP50 | Final mAP50 | Final precision | Final recall |
|---|---|---|---|---|
| Missing Hole | 97.7% | 100.0% | 99.6% | 100.0% |
| Mouse Bite | 88.7% | 96.0% | 92.3% | 98.8% |
| Open Circuit | 88.9% | 97.1% | 97.1% | 92.9% |
| Short | 96.7% | 96.3% | 95.8% | 96.4% |
| Spur | 67.4% | 84.0% | 83.2% | 81.3% |
| Spurious Copper | 86.3% | 99.6% | 97.8% | 98.6% |
Spur and Spurious Copper, the two classes targeted by hard positive mining, improved the most (+16.6 and +13.3 points). Every class is now above 80% mAP50.
Speed: about 61 ms per image end to end at 960 px (≈16 images per second) on a Colab Tesla T4 GPU.
Starting from the baseline, each step was kept only if it improved the results. The discarded alternatives are documented in the experiment log.
| Step | What | Why |
|---|---|---|
| 1 | Targeted oversampling: Mouse Bite training images ×2 | In the early experiments Mouse Bite was the weakest class. A ×4 ratio hurt Spur and Spurious Copper, so ×2 was kept. Stronger built-in augmentation was tried instead and dropped because it degraded Spur. |
| 2 | Adam + light augmentation (scale=0.4, translate=0.1, degrees=5) |
Adam beat AdamW in two separate comparisons on this dataset. |
| 3 | Hard positive mining for Spur and Spurious Copper | The step-2 model (640 px) is run on the training set. The 96 images where it misses a defect (no same-class prediction with IoU > 0.5 and confidence > 0.4) get 3 extra copies each, bringing the training set to 858 images. |
| 4 | Input size 640 → 960 | Spur defects cover a tiny part of the image, so the bottleneck was resolution rather than the amount of data. The trade-off is slower inference. |
The Gradio demo at the end of the notebook lets an operator upload a PCB image (or pick one of the test examples), set the confidence threshold and see the detected defects with a short summary.
traceguard/
├── notebooks/
│ └── TraceGuard.ipynb # Clean, reproducible pipeline (start here)
├── experiments/
│ └── TraceGuard_experiment_log.ipynb # Full chronological log, including discarded experiments
├── weights/
│ ├── baseline_yolov8n_640.pt # Baseline model
│ ├── intermediate_yolov8n_640.pt # Intermediate model, used for hard positive mining
│ └── final_yolov8n_960.pt # Final model
├── data/
│ └── dataset_split.json # Fixed train / val / test split (485 / 104 / 104 images)
├── assets/ # Figures used in this README
├── requirements.txt
└── LICENSE
The experiment log is kept as a record of the process. Its early baseline numbers were measured
before the split was fixed, so the fair comparison is the one above and in
notebooks/TraceGuard.ipynb.
- Click the Open in Colab badge at the top of this page.
- Select a GPU: Runtime → Change runtime type → T4 GPU.
- Add your Kaggle API token as a Colab secret named
KAGGLE_API_TOKEN(generate one under Kaggle → Settings → API; in Colab, use the key icon in the left sidebar). - Run everything: Runtime → Run all.
By default (RUN_TRAINING = False) the notebook loads the released weights, so it finishes in a
few minutes and ends with the interactive demo. Set RUN_TRAINING = True in the configuration
cell to retrain all models from scratch (about 1.5–2 hours on a T4).
git clone https://github.com/3minulguc/traceguard.git
cd traceguard
pip install ultralyticsfrom ultralytics import YOLO
model = YOLO("weights/final_yolov8n_960.pt")
results = model.predict("your_pcb_image.jpg", imgsz=960, conf=0.25)
results[0].show()The PCB Defects dataset on Kaggle
contains 693 PCB images with 2,953 labelled defects in six classes. It was created at Peking
University from 10 template boards photographed with an industrial camera; the defects were
added digitally (Huang & Wei, 2019). The images are not
included in this repository; the notebook downloads them with the Kaggle API. The split used
for every experiment is stored in data/dataset_split.json, so the results can be reproduced
exactly.
- Same boards in training and test: the 693 images come from only 10 template boards, and the split is by image, not by board, so all 10 boards appear in both the training and the test set. The defects are also synthetic. The results therefore show performance on known board designs; on new designs and on real production defects it is likely lower.
- Small test set: 104 images, i.e. 13–20 images per class (13 for Spur). Per-class results have high variance.
- No separate hold-out set: method choices were made by looking at results on the same test set, so the reported numbers may be slightly optimistic.
- Single training run per model: small differences, such as Short (−0.4 pts), are within normal run-to-run variation.
- Speed: 960 px improves accuracy but slows inference. Real-time use on a production line would need optimization (e.g. ONNX / TensorRT export, INT8 quantization).
Emin Ülgüç — Computer Engineering, Manisa Celal Bayar University
Code and model weights are released under the MIT License. The dataset is not covered by this license; see its Kaggle page for its own terms.





