Developing robust visual inspection systems in manufacturing, especially for electronics, can be challenging due to the need for high accuracy and limited availability of labeled data. This post walks through how to build a complete pipeline using Python to detect multiple types of defects on printed circuit boards (PCBs), even with a constrained dataset.
The methodology and dataset used in this project are based on the publicly available research by Weibo Wang, Ke Kang, Chen Qian, and Xiaowei Hu, titled “A PCB Dataset for Defects Detection and Classification“. This work provides the basis for the defect categories and imagery used throughout this tutorial.
By the end of this guide, you will understand how to:
- Set up a reliable image acquisition system
- Annotate and augment limited datasets effectively
- Train and deploy a custom object detection model
- Avoid common pitfalls in vision system development
Step 1: System Setup
Two critical components of the inspection setup are:
- Lighting: Uniform and diffuse lighting is essential to avoid reflections and shadows.
- Industrial Camera: A high-resolution, non-distortion lens camera (e.g., 60 MP) is required to detect very small defects accurately.

Depending on the application, setups can be static (manual board placement) or dynamic (with conveyor belts).
Step 2: Data Collection
Data collection must reflect real operating conditions. Key recommendations include:
- Capture hundreds of images with both defective and non-defective samples.
- Include variation in position, orientation, and background.
- Avoid capturing images under artificially ideal conditions.
A typical dataset may start with around 700 images that exhibit diversity across multiple board types and configurations.

Step 3: Defect Annotation
Manual annotation is required to teach the model what constitutes a defect. In this project, six types of defects are identified:
- Missing Hole
- Mouse Bite
- Open Circuit
- Short Circuit
- Spur (Spurious material)
- Spurious Copper
Annotation tools such as makesense.ai can be used to draw bounding boxes around defects. Paid tools like Roboflow also offer annotation capabilities and workflow enhancements.

Step 4: Data Augmentation
To enhance model robustness and simulate data diversity:
- Apply horizontal and vertical flips.
- Use rotations and cropping.
- Simulate noise and lighting variations.
These techniques increase the effective dataset size without the need to capture additional images. For example, augmentation can expand 700 base images into over 10,000 training samples.

Step 5: Model Training
Once annotated and augmented, the data is used to train a custom object detection model. The workflow includes:
- Organizing the data and annotation files in a consistent format.
- Using a Jupyter notebook to run the training process.
- Leveraging GPU acceleration for faster training.
The project uses a YOLO-based model customized and packaged within the AI Vision Academy environment.

Step 6: Inference and Visualization
After training, the model is used in a Python-based application for real-time defect detection. The steps include:
- Loading the image and model.
- Running inference using the trained model.
- Drawing bounding boxes on detected defects.
- Extracting and zooming in on defect regions for better visibility.
This interface is useful for quality control operators who need to verify detection results during production.

Common Pitfalls to Avoid
To improve project success, avoid these common mistakes:
- Inadequate data collection: Poor or insufficient data undermines model performance.
- Low-quality annotations: Imprecise bounding boxes result in inaccurate predictions.
- Unnecessary complexity: Simpler models are easier to debug and often more robust.
- Ignoring hardware constraints: Ensure the solution can run on the target hardware in real time.
Take Your Vision Projects Further
If you are serious about building high-performance computer vision systems like the one demonstrated in this project, everything you need is available, including:
✅ Step-by-step courses on data collection, annotation, and model training
✅ Guidance on deploying real-time inspection tools
✅ Community support, monthly Q&A sessions, and direct mentorship
This is all available in the AI Vision Academy, hosted inside our Skool community.
There, you can connect with like-minded developers, get help on your projects, and receive direct support to bring your ideas into production.
👉 Join the AI Vision Academy Today

Hi there, I’m the founder of Pysource.
I’m a Computer Vision Consultant, developer and Course instructor.
I help Companies and Developers to build efficient computer vision software.