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.

Stage 1: YOLOv8s Stage 2: YOLOv8m
Model pcb-defect-yolov8s-deeppcb pcb-defect-yolov8m-dspcbsd (this repo)
Dataset DeepPCB DsPCBSD+
Classes 6 9
Train / Val images 1,050 / 150 8,208 / 2,051
Total annotations ~1,003 (val) 4,092 (val)
Image source Grayscale linear-scan CCD RGB copper-surface crops (226Γ—226 native)
Model size YOLOv8s (~11.1M params) YOLOv8m (~25.9M params)
mAP@0.5 0.985 0.839
mAP@0.5:0.95 0.734 0.508
Precision 0.961 0.807
Recall 0.963 0.810
Best-performing class copper (mAP50 0.994) hole_breakout (mAP50 0.984)
Weakest-performing class short (mAP50-95 0.639) conductor_foreign_object (mAP50 0.701)

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_scratch and conductor_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

Class Abbreviation (paper) Description
short SH Unintended connection between conductors
spur SP Sharp protrusion off a conductor edge
spurious_copper SC Unwanted copper residue
open OP Break in a conductor path
mouse_bite MB Small notch/crack at conductor edge
hole_breakout HB Hole center deviates from bounding pad
conductor_scratch CS Scratch on copper wire/surface
conductor_foreign_object CFO Contamination on a conductor
base_material_foreign_object BMFO Contamination on bare substrate

Evaluation Results

Validation set: 2,051 images, 4,092 annotated instances (official 8:2 train/val split).

Overall

Metric Value
Precision 0.807
Recall 0.810
mAP@0.5 0.839
mAP@0.5:0.95 0.508

Per-Class

Class Images Instances Precision Recall mAP50 mAP50-95
short 126 169 0.875 0.882 0.906 0.592
spur 430 929 0.852 0.786 0.850 0.389
spurious_copper 245 285 0.757 0.779 0.822 0.507
open 274 338 0.803 0.855 0.889 0.532
mouse_bite 391 546 0.851 0.773 0.823 0.410
hole_breakout 271 608 0.917 0.977 0.984 0.830
conductor_scratch 279 448 0.696 0.695 0.731 0.456
conductor_foreign_object 309 423 0.693 0.667 0.701 0.408
base_material_foreign_object 305 346 0.817 0.878 0.848 0.449

Performance Chart

metrics chart

Training Curves

training results

Confusion Matrix

confusion matrix


Sample Detections

Sample 1

InputPrediction

Sample 2

InputPrediction

Training Configuration

Parameter Value
Base model yolov8m.pt (COCO-pretrained)
Dataset DsPCBSD+ (9 classes), via Roboflow export
Epochs 50
Image size 640 Γ— 640
Batch size 16
Scheduler Cosine LR
Hardware Google Colab, Tesla T4 GPU

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) and conductor_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.py explanations 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 weights
  • inspector.py β€” companion module with severity/root-cause/impact/action knowledge base
  • metrics_chart.png β€” per-class performance chart
  • results.png β€” training loss/metric curves across all epochs
  • confusion_matrix.png β€” normalized confusion matrix across all 9 classes
  • sample*_input.jpg / sample*_predicted.jpg β€” example detections
  • README.md β€” this file

Author

Fine-tuned and maintained by 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

Downloads last month
160
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using Janani-V/pcb-defect-yolov8m-dspcbsd 1

Evaluation results