CoolFace
Modelpublic

Janani-V/pcb-defect-yolov8s-deeppcb

sourceHugging Facemitupdated 3mo agoView on Hugging Face
1likes51downloads
Model Card

YOLOv8s — DeepPCB Defect Detection

Model Summary

  • —Model: YOLOv8s
  • —Task: PCB defect detection (object detection)
  • —Dataset: DeepPCB (via Roboflow export)
  • —Classes: 6 defect categories
  • —Framework: Ultralytics YOLOv8
  • —Input size: 640 × 640
  • —Training hardware: Google Colab, Tesla T4 GPU
  • —Best validation mAP@0.5: 0.985
  • —Best validation mAP@0.5:0.95: 0.734
  • —Companion module: inspector.py — adds severity, root cause, impact, and recommended action per detection

🔍 Try it live: PCB Defect Detector Space

Model Description

This repository hosts a YOLOv8s object detection model fine-tuned on the DeepPCB PCB defect dataset for automated visual inspection of printed circuit boards. The model detects and localizes six common manufacturing defects from grayscale PCB imagery, making it suitable as a lightweight baseline for automated optical inspection (AOI), defect benchmarking, and industrial vision research.

Alongside the detection weights, this repository includes a companion knowledge-base module (inspector.py) that wraps the raw YOLO output with structured, defect-specific information — explanation, severity, likely root cause, potential impact, and recommended action — for each detected instance. This is a deterministic rules layer bundled with the model, not the neural network itself generating text; the detection weights (best.pt) only output class, bounding box, and confidence, exactly as a standard YOLOv8 model does.

Architecture: YOLOv8s (Ultralytics), single-stage anchor-free object detector Base weights: yolov8s.pt (COCO-pretrained, then fine-tuned) Parameters: ~11.1M GFLOPs: ~28.4

Defect Classes

Class IDNameDescription
0copperExcess/spurious copper residue on the board
1mousebiteSmall irregular notches along conductor edges
2openBreak in a conductor path (broken circuit)
3pin-holeSmall void/hole defect in the copper trace
4shortUnintended connection between two conductors
5spurUnwanted protruding copper extension

Evaluation Results

Dataset Split

SplitImagesUsed For
Train1,050Model fine-tuning
Validation150Metric reporting (below)
Test300Qualitative inference / sample predictions

All metrics below are computed on the validation split (150 images, 1,003 annotated instances). The test split (300 images) was used only for qualitative inference — the sample detections shown further down are drawn from it.

Overall Metrics

MetricValue
Precision0.961
Recall0.963
mAP@0.50.985
mAP@0.5:0.950.734

Per-Class Breakdown

ClassImagesInstancesPrecisionRecallmAP50mAP50-95
copper1181410.9930.9750.9940.849
mousebite1231930.9890.9450.9820.723
open1361950.9550.9870.9830.655
pin-hole1381540.9910.9680.9930.829
short1141510.8900.9340.9700.639
spur1201690.9480.9690.9880.711

Performance Chart

[image]

Inference speed: ~12.0ms preprocess, ~10.1ms inference, ~4.9ms postprocess per image (Tesla T4, batch size 1, 640×640).


Sample Detections

Each pair shows the raw input image (left) and the model's predicted output with bounding boxes and confidence scores (right). Samples are drawn from the test split.

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>

Sample 3

<table> <tr><th>Input</th><th>Prediction</th></tr> <tr> <td><img src="sample3input.jpg" width="300"/></td> <td><img src="sample3predicted.jpg" width="300"/></td> </tr> </table>


Training Configuration

ParameterValue
Base modelyolov8s.pt (COCO-pretrained)
FrameworkUltralytics YOLOv8
DatasetDeepPCB (6 classes), via Roboflow export
Epochs50
Image size640 × 640
Batch size16
OptimizerDefault (SGD, Ultralytics auto-config)
HardwareGoogle Colab, Tesla T4 GPU (16GB)
Train / Val / Test split1,050 / 150 / 300 images

Usage

Option A — Detection only (raw YOLO output)

bash
pip install ultralytics huggingface_hub
python
from huggingface_hub import hf_hub_download
from ultralytics import YOLO

weights_path = hf_hub_download(
    repo_id="Janani-V/pcb-defect-yolov8s-deeppcb",
    filename="best.pt"
)

model = YOLO(weights_path)
results = model.predict("your_pcb_image.jpg", conf=0.25)

results[0].show()          # visualize
print(results[0].boxes)    # raw bounding box data

Batch inference on a folder:

python
results = model.predict(source="path/to/image_folder/", conf=0.25, save=True)

Option B — Detection + structured explanation, severity, root cause, impact, action

python
from huggingface_hub import snapshot_download
import sys

local_dir = snapshot_download(repo_id="Janani-V/pcb-defect-yolov8s-deeppcb")
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 finding in result["findings"]:
    print(finding["class"], "-", finding["severity"])
    print("Explanation:", finding["explanation"])
    print("Root cause:", finding["root_cause"])
    print("Impact:", finding["impact"])
    print("Action:", finding["action"])
    print()

Applications

  • —Automated Optical Inspection (AOI) integration for PCB manufacturing lines
  • —Pre-screening boards before manual QA review, reducing inspector workload
  • —Defect-rate tracking and analytics across production batches
  • —Research baseline for PCB defect detection benchmarking
  • —Educational/demo use for object detection in industrial inspection contexts
  • —Generating structured, actionable inspection reports (via inspector.py) for non-expert reviewers

Limitations

  • —This model was trained on DeepPCB grayscale linear-scan images and has not been validated on RGB PCB images or other imaging modalities.
  • —Performance may degrade under distribution shifts such as different board layouts, camera setups, illumination conditions, or image resolutions.
  • —Localization performance at stricter IoU thresholds is weaker for thin, elongated defects such as open and short, as reflected in their lower mAP@0.5:0.95 scores.
  • —The inspector.py explanations, severities, root causes, impacts, and actions are drawn from a static, hand-curated knowledge base per defect class — they are general guidance, not image-specific diagnosis, and do not account for defect size, position, or board context.
  • —The model should be treated as a research / baseline AOI model, not a production-ready inspection system, unless further validated on real manufacturing data.

Repository Contents

  • —best.pt — best fine-tuned YOLOv8s weights
  • —inspector.py — companion module providing severity, root cause, impact, and recommended action per detected defect
  • —metrics_chart.png — per-class validation performance chart
  • —sample*_input.jpg / sample*_predicted.jpg — example qualitative detections (from test split)
  • —README.md — model documentation and usage instructions

Intended Role in Project

This model is Stage 1 of a two-stage PCB defect detection effort:

  1. 1.Stage 1 (this repo): YOLOv8s fine-tuned on DeepPCB — 6 defect classes, clean grayscale images, used as a baseline and pipeline validation stage.
  2. 2.Stage 2 (in progress): YOLOv8m fine-tuned on DSPCBSD+ — 9 defect classes, larger and more challenging dataset with smaller, imbalanced defect instances.

The two models are intended to be used together or compared, with this repo serving as the simpler, faster baseline.


Author

Fine-tuned and maintained by [Janani-V](https://huggingface.co/Janani-V).


Citation

This model was fine-tuned on the DeepPCB dataset, accessed via a Roboflow-hosted version of the dataset.

Original dataset: Tang, S. et al. — DeepPCB: https://github.com/tangsanli5201/DeepPCB

Dataset access (Roboflow project used for this fine-tuning): janani-v-sdspd/deeppcb-4dhir-failw on Roboflow Universe

Model architecture: Jocher, G., Chaurasia, A., Qiu, J. — Ultralytics YOLOv8: https://github.com/ultralytics/ultralytics