Skip to content

KrP77/defect_detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Injection Mould Plastic Pieces Defect Detection

This project implements an automated defect detection system for injection-molded parts (Type A and Type B pieces) using a ResNet18 architecture. It is designed to be trained on high-performance hardware and deployed on a Raspberry Pi 5 with yolo for real-time edge defect detection.

This project implements a multi-stage automated defect detection pipeline for industrial quality control. Moving beyond simple classification, the system utilizes a cascading YOLOv8 architecture for precise object localization, cropping, and defect segmentation.

The pipeline is designed for high-performance training on GPU-enabled workstations and real-time edge deployment on a Raspberry Pi 5.

🚀 The Pipeline

The system operates through a structured vision pipeline:

  1. Acquisition: Dual-stream image capture via Raspberry Pi 5.
  2. Detection & Cropping: A YOLOv8 detection model identifies the piece and crops the region of interest (ROI) to eliminate background noise.
  3. Classification: Resnet18 model classification to identify specific defects (cracks, short molds, or flash) on Type A and Type B pieces.
  4. Decision: The system evaluates the segmentation mask area to categorize the piece as 'Good' or 'Defective'.

📂 Project Structure

Defect Detection/
├── models/                  # Exported .pth and .pt (YOLOv8) model weights
├── notebooks_and_scripts/
│   ├── model/               # General model utilities and data processing
│   ├── pi_setup/            # Pi camera configuration and dual-streaming logic
│   ├── segmentation/        # Training logic for YOLOv8 segmentation models
│   └── yolo/                # Training logic for YOLOv8 detection/cropping models
├── reports/                 # Project documentation, PPTs, and industrial reports
├── .gitignore
├── README.md
├── requirements.txt         # Dependencies for Python 3.14
└── requirements12.txt       # Dependencies for Python 3.12 (Compatibility Mode)

Getting Started

  1. Clone the Repository
git clone https://github.com/KrP77/defect_detection.git
cd "Defect Detection"
  1. Set Up Virtual Environment On Windows :
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt

python -m venv .venv12
.venv12\Scripts\activate
pip install -r requirements12.txt
  1. Authenticate with Hugging Face:

Because the dataset is large (~50GB), we are using Hugging Face to host our data.

Repository: KrP77-HF/defect_detection/

To download the datasets:

huggingface-cli login

(Paste your Access Token with 'Read' or 'Write' permissions when prompted) Because the dataset is large (~10GB), we are using Hugging Face to host our data.

⚙️ Hardware & Real-Time Inference Pipeline

The system is optimized for the Raspberry Pi 5 using the IMX708 (Camera Module 3). To balance real-time monitoring with high-accuracy detection, the project implements a Dual-Stream Processing Pipeline.

🔄 Dual-Stream Architecture

To avoid lag in the user interface while maintaining high-resolution inspection, the camera handles two simultaneous streams:

  1. Preview Stream (Low Res / High FPS): A lightweight stream used for the live operator dashboard. This ensures the visual feedback is smooth and responsive.
  2. Capture Stream (4K Resolution): High-definition frames are triggered for the actual inspection. This provides the fine detail necessary for the models to identify tiny surface defects.

🧠 Logic Flow

  1. Acquisition: The 4K capture stream feeds a frame into the pipeline.
  2. Detection & Localization (YOLOv8): A YOLO model identifies the location of the plastic piece within the 4K frame.
  3. Dynamic Cropping: The system crops the image to the bounding box of the piece, discarding the background to reduce computational load.
  4. Classification (ResNet): The cropped "Region of Interest" is passed to a ResNet-based classifier to determine the quality status (Pass/Fail).
  5. Visual Feedback: The final classification result is mapped back onto the Low-Res Preview Stream, drawing a real-time colored bounding box (Green for Good, Red for Defective) over the live feed.

🛠️ Deployment Requirements

  • Hardware: Raspberry Pi 5 (8GB recommended), Camera Module 3.
  • Software Stack: * libcamera: For high-level camera control.
    • OpenCV: For frame manipulation and UI overlays.
    • PyTorch / ONNX Runtime: For optimized model inference on the Pi's CPU/GPU.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors