Janani-V/pcb-defect-yolov8m-dspcbsd
YOLOv8m — DsPCBSD+ Defect Detection
Model Summary
- Model: YOLOv8m
- Task: PCB defect detection (object detection)
- Dataset: DsPCBSD+ (via Roboflow export)
- Classes: 9 defect categories
- Framework: Ultralytics YOLOv8
- Input size: 640 × 640
- Training hardware: Google Colab, Tesla T4 GPU
- Validation mAP@0.5: 0.839
- Validation mAP@0.5:0.95: 0.508
- Companion module:
inspector.py— adds severity, root cause, impact, and recommended action per detection
🔍 Part of a two-stage project: see also Janani-V/pcb-defect-yolov8s-deeppcb — a simpler 6-class baseline on DeepPCB.
Model Comparison — Stage 1 vs Stage 2
Note: These two models were trained on different datasets (DeepPCB vs. DsPCBSD+) with different class counts and difficulty levels, so this is not a strictly apples-to-apples benchmark — it's meant to help you choose the right model for your use case.
Why the difference in scores?
DsPCBSD+ is a meaningfully harder benchmark than DeepPCB:
- More classes (9 vs. 6) increases inter-class confusion risk
- Class imbalance is more pronounced (spur: 929 instances vs. short: 169, a ~5.5x gap)
- Higher intra-class variability — especially for
conductor_scratchandconductor_foreign_object, which vary widely in size, shape, and appearance - DeepPCB's defects are more visually distinct and the dataset itself is smaller and cleaner by design
A lower mAP on DsPCBSD+ does not mean this model is "worse" — it reflects a genuinely harder detection problem with more real-world defect diversity.
Which model should you use?
- Use the YOLOv8s / DeepPCB model if your defects match DeepPCB's 6 categories (open, short, mousebite, spur, copper, pin-hole) and you're working with grayscale linear-scan imagery — it's faster and more accurate for that specific defect set.
- Use the YOLOv8m / DsPCBSD+ model (this repo) if you need broader defect coverage, including hole breakout, conductor scratches, and foreign object contamination — categories DeepPCB doesn't cover at all.
Model Description
This repository hosts a YOLOv8m object detection model fine-tuned on DsPCBSD+, a large-scale (10,259 image, 20,276 annotation) PCB surface defect dataset covering 9 defect categories across conductors, holes, and base material. This is a substantially harder detection task than DeepPCB — defects are smaller, more varied in shape/scale, and the class distribution is imbalanced.
Alongside the detection weights, this repository includes inspector.py, a companion knowledge-base module providing explanation, severity, root cause, impact, and recommended action per detected defect. This is a deterministic rules layer, not the model itself generating text — best.pt outputs class, bounding box, and confidence only.
Architecture: YOLOv8m (Ultralytics), single-stage anchor-free object detector Base weights: yolov8m.pt (COCO-pretrained, then fine-tuned)
Defect Classes
Evaluation Results
Validation set: 2,051 images, 4,092 annotated instances (official 8:2 train/val split).
Overall
Per-Class
Performance Chart
Training Curves
Confusion Matrix
Sample Detections
Sample 1 <table> <tr><th>Input</th><th>Prediction</th></tr> <tr><td><img src="sample1input.jpg" width="300"/></td><td><img src="sample1predicted.jpg" width="300"/></td></tr> </table>
Sample 2 <table> <tr><th>Input</th><th>Prediction</th></tr> <tr><td><img src="sample2input.jpg" width="300"/></td><td><img src="sample2predicted.jpg" width="300"/></td></tr> </table>
Training Configuration
Usage
from huggingface_hub import snapshot_download
import sys
local_dir = snapshot_download(repo_id="Janani-V/pcb-defect-yolov8m-dspcbsd")
sys.path.append(local_dir)
from inspector import PCBDefectInspector
inspector = PCBDefectInspector(weights_path=f"{local_dir}/best.pt")
result = inspector.inspect("your_pcb_image.jpg")
print(result["summary"])
for f in result["findings"]:
print(f["class"], "-", f["severity"], "-", f["action"])Limitations
conductor_foreign_object(mAP50 0.701) andconductor_scratch(mAP50 0.731) are the weakest classes — these defects have high intra-class variability in size, shape, and color, making them inherently harder to detect consistently.- Trained on 226×226-native PCB crop images; performance on full, un-cropped board images has not been separately validated.
- Class distribution is imbalanced (spur: 929 instances vs. short: 169); rare-class performance may vary more across different data splits.
- The
inspector.pyexplanations are drawn from a static, hand-curated knowledge base — general guidance, not image-specific diagnosis. - Research/baseline model — not validated for production deployment without further testing on real manufacturing data.
Repository Contents
best.pt— fine-tuned YOLOv8m weightsinspector.py— companion module with severity/root-cause/impact/action knowledge basemetrics_chart.png— per-class performance chartresults.png— training loss/metric curves across all epochsconfusion_matrix.png— normalized confusion matrix across all 9 classessample*_input.jpg/sample*_predicted.jpg— example detectionsREADME.md— this file
Author
Fine-tuned and maintained by [Janani-V](https://huggingface.co/Janani-V).
Citation
Original dataset: Lv, S. et al. "A dataset for deep learning based detection of printed circuit board surface defect." Scientific Data 11, 811 (2024). https://doi.org/10.1038/s41597-024-03656-8
Dataset access: janani-v-sdspd/dspcbsd-plus on Roboflow Universe
Model architecture: Jocher, G. et al. — Ultralytics YOLOv8: https://github.com/ultralytics/ultralytics
