Skip to content

Gunavarthan/PCB-Defect-Classifier

Repository files navigation

PCB Defect Classifier

This project focuses on developing an intelligent system for automated detection and classification of defects in Printed Circuit Boards (PCBs). The system leverages YOLOv8, a state-of-the-art object detection framework, to identify manufacturing defects that could impact PCB functionality and reliability.

About This Project

The manufacturing of PCBs involves complex processes where defects can occur at various stages. Manual inspection is time-consuming and prone to human error. This automated solution addresses these challenges by providing real-time defect detection capabilities.

The system can identify six critical types of PCB defects:

  • Missing hole - Absent drill holes that should be present for component mounting
  • Mouse bite - Small notches or irregular indentations along PCB edges
  • Open circuit - Breaks in conductive traces that interrupt electrical connections
  • Short - Unintended connections between circuits that should remain isolated
  • Spur - Unwanted copper extensions protruding from trace patterns
  • Spurious copper - Excess copper material in areas where it shouldn't exist
Classification Image

Demo

PCBDiffect.mp4

Key Capabilities

This implementation includes several components designed for practical deployment:

Deep Learning Detection: Built on YOLOv8 architecture for accurate real-time object detection and classification

Web Interface: Interactive Streamlit application allowing users to upload images and receive immediate feedback on detected defects

Command-Line Tools: Batch processing capabilities for automated quality control integration

GPU Optimization: CUDA acceleration support for efficient training and inference operations

Data Enhancement: Image augmentation utilities for expanding training datasets

Complete Pipeline: End-to-end workflow from data preparation through model deployment

Directory Structure and Components

PCB-Defect-Classifier/
├── GPU_Check.py              # GPU availability and CUDA validation utility
├── app.py                    # Streamlit web application for interactive detection
├── predict.py                # Command-line inference script for batch processing
├── train.py                  # Complete training pipeline with progress monitoring
├── train_test.py             # Quick training validation (3 epochs for testing)
├── requirements.txt          # Python dependencies specification
├── LICENSE                   # Project license information
├── README.md                 # Project documentation
└── Dataset/
    ├── PCB_DATASET/          # Original dataset with XML annotations
    │   ├── rotate.py         # Image rotation utility for data augmentation
    │   ├── Annotations/      # XML annotation files organized by defect type
    │   │   ├── Missing_hole/
    │   │   ├── Mouse_bite/
    │   │   ├── Open_circuit/
    │   │   ├── Short/
    │   │   ├── Spur/
    │   │   └── Spurious_copper/
    │   ├── images/           # Original PCB images categorized by defect
    │   │   ├── Missing_hole/
    │   │   ├── Mouse_bite/
    │   │   ├── Open_circuit/
    │   │   ├── Short/
    │   │   ├── Spur/
    │   │   └── Spurious_copper/
    │   ├── PCB_USED/         # Base PCB images for augmentation processes
    │   └── rotation/         # Generated rotated images with angle documentation
    └── YOLO_PCB_Dataset/     # YOLO-formatted dataset ready for training
        ├── data.yaml         # Dataset configuration and class definitions
        ├── train/            # Training images and corresponding label files
        ├── valid/            # Validation images and labels
        └── test/             # Test images and labels

Environment Setup and Installation

System Requirements

  • Python 3.8 or higher
  • CUDA-compatible GPU (recommended for training operations)
  • Minimum 8GB RAM, 16GB recommended
  • 10GB free disk space for datasets and model storage

Usage Instructions

Interactive Web Application

The Streamlit interface provides an intuitive way to test the defect detection system:

streamlit run app.py

Navigate to http://localhost:8501 in your browser. The interface allows you to:

  • Upload PCB images in JPG, JPEG, or PNG formats
  • View side-by-side comparison of original and annotated images
  • Download detection results with bounding boxes and confidence scores
  • See detailed defect count and classification information

Command-Line Detection

For automated processing or integration into existing workflows:

python predict.py

The script will prompt for the image path and display results using OpenCV visualization. This method is suitable for:

  • Batch processing of multiple images
  • Integration with manufacturing systems
  • Automated quality control pipelines

Model Training

Development Testing

python train_test.py

Runs a 3-epoch training session to verify system functionality and estimate full training time.

Production Training

python train.py

Executes complete training with the following configuration:

  • Model: YOLOv8s (small variant balancing speed and accuracy)
  • Training duration: 200 epochs
  • Input resolution: 416x416 pixels
  • Batch size: 5 (optimized for typical GPU memory)
  • Dataset: 693 annotated PCB images

The training process includes real-time progress monitoring, loss tracking, and automatic model checkpointing.

Best Model Progress

Image

Dataset Augmentation

To expand the training dataset through rotation:

cd Dataset/PCB_DATASET
python rotate.py

This utility generates rotated variants of existing images with random angles between -10 and +10 degrees, creating additional training samples while maintaining annotation accuracy.

Technical Implementation Details

Dataset Specifications

Source Data: The dataset originates from Roboflow Universe, containing 693 high-quality PCB images with precise annotations for six defect categories.

Data Format: Images are processed in YOLO format with normalized bounding box coordinates. Original resolution varies, with training images standardized to 640x640 pixels.

Data Split: Training (approximately 70%), validation (20%), and testing (10%) to ensure robust model evaluation.

Annoted Data:

Image

Model Architecture and Performance

The YOLOv8s model provides an optimal balance between detection accuracy and inference speed. Key performance metrics include:

  • mAP50-95: Mean Average Precision across IoU thresholds for comprehensive accuracy assessment
  • Box Loss: Localization accuracy optimization for precise defect boundaries
  • Classification Loss: Category prediction accuracy for reliable defect identification
  • Inference Speed: Real-time processing capability for production environments

N0te: this Documendation was generated by AI so for an further queries contact Gunavarthan

About

YOLOv8-based PCB defect classifier model

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages