CoolFace
Modelpublic

Janani-V/pcb-defect-yolov8m-dspcbsd

sourceHugging Facemitupdated 2mo agoView on Hugging Face
0likes32downloads
Model Card

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**
Modelpcb-defect-yolov8s-deeppcbpcb-defect-yolov8m-dspcbsd (this repo)
DatasetDeepPCBDsPCBSD+
Classes69
Train / Val images1,050 / 1508,208 / 2,051
Total annotations~1,003 (val)4,092 (val)
Image sourceGrayscale linear-scan CCDRGB copper-surface crops (226×226 native)
Model sizeYOLOv8s (~11.1M params)YOLOv8m (~25.9M params)
mAP@0.50.9850.839
mAP@0.5:0.950.7340.508
Precision0.9610.807
Recall0.9630.810
Best-performing classcopper (mAP50 0.994)hole_breakout (mAP50 0.984)
Weakest-performing classshort (mAP50-95 0.639)conductorforeignobject (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

ClassAbbreviation (paper)Description
shortSHUnintended connection between conductors
spurSPSharp protrusion off a conductor edge
spurious_copperSCUnwanted copper residue
openOPBreak in a conductor path
mouse_biteMBSmall notch/crack at conductor edge
hole_breakoutHBHole center deviates from bounding pad
conductor_scratchCSScratch on copper wire/surface
conductor_foreign_objectCFOContamination on a conductor
base_material_foreign_objectBMFOContamination on bare substrate

Evaluation Results

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

Overall

MetricValue
Precision0.807
Recall0.810
mAP@0.50.839
mAP@0.5:0.950.508

Per-Class

ClassImagesInstancesPrecisionRecallmAP50mAP50-95
short1261690.8750.8820.9060.592
spur4309290.8520.7860.8500.389
spurious_copper2452850.7570.7790.8220.507
open2743380.8030.8550.8890.532
mouse_bite3915460.8510.7730.8230.410
hole_breakout2716080.9170.9770.9840.830
conductor_scratch2794480.6960.6950.7310.456
conductorforeignobject3094230.6930.6670.7010.408
basematerialforeign_object3053460.8170.8780.8480.449

Performance Chart

[image]

Training Curves

[image]

Confusion Matrix

[image]


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

ParameterValue
Base modelyolov8m.pt (COCO-pretrained)
DatasetDsPCBSD+ (9 classes), via Roboflow export
Epochs50
Image size640 × 640
Batch size16
SchedulerCosine LR
HardwareGoogle Colab, Tesla T4 GPU

Usage

python
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](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