0% found this document useful (0 votes)
26 views

TH-SOF-2046-Automated Optical Inspection of Printed Circuit Boards Using Machine Vision

Uploaded by

inam rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

TH-SOF-2046-Automated Optical Inspection of Printed Circuit Boards Using Machine Vision

Uploaded by

inam rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 114

Automated Optical Inspection of Printed Circuit Boards

Using Machine Vision

Author
Wajih Ahmed Khan
00000318885

Supervisor
Dr. Amir Hamza

DEPARTMENT OF MECHATRONICS ENGINEERING


COLLEGE OF ELECTRICAL & MECHANICAL ENGINEERING
NATIONAL UNIVERSITY OF SCIENCES AND
TECHNOLOGY
ISLAMABAD
AUGUST, 2022
Automated Optical Inspection of Printed Circuit Boards Using
Machine Vision

Author
Wajih Ahmed Khan
00000318885

A thesis submitted in partial fulfilment of the requirements for the degree


of
MS Mechatronics Engineering

Thesis Supervisor:
Dr. Amir Hamza

Thesis Supervisor’s Signature: ____________________________

DEPARTMENT OF MECHATRONICS ENGINEERING


COLLEGE OF ELECTRICAL & MECHANICAL
ENGINEERING
NATIONAL UNIVERSITY OF SCIENCES AND
TECHNOLOGY,
ISLAMABAD
AUGUST, 2022
Declaration

I certify that this research work titled “Automated Optical Inspection of Printed
Circuit Boards Using Machine Vision” is my work. The work has not been presented
elsewhere for assessment. The material that has been used from other sources has been
properly acknowledged/referred to.

Signature of Student
Wajih Ahmed Khan
00000318885

i
Language Correctness Certificate

This thesis has been read by an English expert and is free of typing, syntax, semantic,
grammatical and spelling mistakes. The thesis is also according to the format given by
the university.

Signature of Student
Wajih Ahmed Khan
00000318885

Signature of Supervisor
Dr. Amir Hamza

ii
Copyright Statement

• Copyright in the text of this thesis rests with the student author. Copies (by any
process) either in full, or of extracts, may be made only in accordance with
instructions given by the author and lodged in the Library of NUST College of
E&ME. Details may be obtained by the Librarian. This page must form part of
any such copies made. Further copies (by any process) may not be made
without the permission (in writing) of the author.
• The ownership of any intellectual property rights which may be described in
this thesis is vested in NUST College of E&ME, subject to any prior agreement
to the contrary, and may not be made available for use by third parties without
the written permission of the College of E&ME, which will prescribe the terms
and conditions of any such agreement.
• Further information on the conditions under which disclosures and exploitation
may take place is available from the Library of NUST College of E&ME,
Rawalpindi.

iii
Acknowledgements

I am deeply indebted to my supervisor Dr. Amir Hamza for his kind support and
valuable advice throughout the thesis. His wonderful supervision strategy and constant
encouragement kept me motivated to work on my thesis with sheer dedication.

I am extremely grateful to Dr. Muhammad Usman Akram who managed to spare time
on multiple occasions from his hectic schedule to answer my queries and clear my
ambiguities. His expert opinions on the subject were like a bright light at the end of
the tunnel.

I would also like to extend my sincere thanks to Dr. Umar Shahbaz Khan for providing
constructive feedback and valuable suggestions.

Finally, I would like to thank Allah Almighty for keeping me in the best of health to
be able complete my dissertation.

iv
Dedicated to my exceptional parents and adored sibling whose
tremendous support and cooperation led me to this wonderful
accomplishment

v
Abstract

A printed circuit board (PCB) is an essential part of every electronic equipment.


Because of technical innovation and the rise of the consumer market, the requirement
to make PCBs in large quantities has become a need throughout the years. Small flaws
in a PCB signal path can have a negative impact on an electrical device's operation.
Initially, the PCB inspection quality control procedure was done manually, which was
not only time-consuming but also prone to human errors. Later research focused on
traditional machine vision techniques such as template matching, image subtraction,
and morphological operations. These approaches were efficient and timesaving, but
they were susceptible to noise, orientation, and size. Faults in complicated patterns
were difficult to identify, and only a limited number of defects could be recognized
using traditional machine vision. To address these concerns, we propose a PCB fault
detection system based on the most recent version of you-only-look-once (YOLOv5).
YOLOv5 weights pre-trained on the Common Objects in Context (COCO) dataset
were used to execute transfer learning on the bare PCB defect dataset, which consisted
of 693 pictures with 6 different types of faults. Furthermore, data augmentation was
performed to improve the model's training performance and robustness. The medium
YOLOv5 model produced promising test results with a mean average precision (mAP)
of 96.92 percent, precision of 97.18 percent, and recall of 96.86 percent.

Key Words: Printed circuit board (PCB), Defect detection, YOLOv5, Deep learning,
Transfer learning

vi
Table of Contents

Declaration ................................................................................................................... i

Language Correctness Certificate ............................................................................ ii

Copyright Statement ................................................................................................. iii

Acknowledgements .................................................................................................... iv

Abstract ...................................................................................................................... vi

Table of Contents ..................................................................................................... vii

List of Figures ............................................................................................................. x

List of Tables ........................................................................................................... xiii

Acronyms .................................................................................................................. xv

Chapter 1: Introduction ........................................................................................... 1

1.1 Background and Motivation .......................................................................... 1

1.2 Research Objectives ...................................................................................... 2

1.3 Thesis Structure ............................................................................................. 2

1.3.1 Literature Review ................................................................................... 2

1.3.2 Methodology .......................................................................................... 2

1.3.3 Results and Discussion ........................................................................... 3

1.3.4 Conclusion.............................................................................................. 3

Chapter 2: Literature Review .................................................................................. 4

2.1 Bare PCB Defects .......................................................................................... 5

2.2 Defect Detection in PCBs .............................................................................. 6

2.2.1 Classical Machine Vision Techniques ................................................... 6

2.2.2 Detection using Computer Vision .......................................................... 7

2.3 Object Detection ............................................................................................ 7

2.4 You Only Look Once Object Detection: ....................................................... 8

vii
2.4.1 YOLOv1:................................................................................................ 8

2.4.2 YOLOv2:................................................................................................ 8

2.4.3 YOLOv3:................................................................................................ 8

2.4.4 YOLOv4:................................................................................................ 9

2.4.5 YOLOv5:................................................................................................ 9

2.5 Research Gaps ............................................................................................. 11

Chapter 3: Methodology ......................................................................................... 12

3.1 PCB Dataset................................................................................................. 13

3.2 Dataset Augmentation: ................................................................................ 15

3.2.1 Gaussian Noise ..................................................................................... 16

3.2.2 Brightness and Contrast ....................................................................... 16

3.3 Training PCB Dataset .................................................................................. 17

3.3.1 Google Colaboratory ............................................................................ 17

3.4 YOLOv5 Architecture: ................................................................................ 23

3.5 Performance Metrics: .................................................................................. 24

3.5.1 Precision: .............................................................................................. 24

3.5.2 Recall: .................................................................................................. 24

3.5.3 F1 score: ............................................................................................... 25

3.5.4 Mean Average Precision: ..................................................................... 25

3.6 YOLOv5 Setup: ........................................................................................... 25

3.6.1 Activation Functions: ........................................................................... 25

3.6.2 Optimizer.............................................................................................. 27

3.6.3 Hyperparameters .................................................................................. 27

Chapter 4: Results and Discussion ........................................................................ 28

4.1 Training at 640 Pixels:................................................................................. 28

4.2 Training at 960 pixels: ................................................................................. 29

4.2.1 YOLOV5n: ........................................................................................... 29

viii
4.2.2 YOLOv5s ............................................................................................. 40

4.2.3 YOLOv5m............................................................................................ 50

4.2.4 YOLOv5l.............................................................................................. 61

4.3 Inference Time............................................................................................. 72

4.4 Test Images .................................................................................................. 73

4.4.1 Correct Predictions ............................................................................... 73

4.4.2 Failure Cases ........................................................................................ 76

4.5 Discussion of Results .................................................................................. 78

4.5.1 YOLOv5n ............................................................................................. 78

4.5.2 YOLOv5s ............................................................................................. 79

4.5.3 YOLOv5m............................................................................................ 79

4.5.4 YOLOv5l.............................................................................................. 80

4.5.5 Selecting a Model ................................................................................. 81

Chapter 5: Conclusion ............................................................................................ 82

5.1 Future Work: ............................................................................................... 82

REFERENCES ......................................................................................................... 83

Appendix A ............................................................................................................... 88

Appendix B ............................................................................................................... 92

Completion Certificate............................................................................................. 96

ix
List of Figures

Figure 2.1: Printed Circuit Board Structure ................................................................ 4


Figure 2.2: Types of PCB defects. .............................................................................. 5
Figure 3.1: Block diagram of the methodology. ....................................................... 12
Figure 3.2: PCB defects in dataset ............................................................................ 13
Figure 3.3: PCBs used for dataset. ............................................................................ 14
Figure 3.4: Number of defects per PCB .................................................................... 15
Figure 3.5: (A) Original Image, (B) Image with Gaussian noise .............................. 16
Figure 3.6: (A) Original image, (B) Image with random brightness and contrast. ... 16
Figure 3.7: Change Runtime ..................................................................................... 17
Figure 3.8: Hardware accelerator selector ................................................................ 18
Figure 3.9: GPU specifications ................................................................................. 18
Figure 3.10: Mount Google drive using icon ............................................................ 19
Figure 3.11: Mounting Google drive using code ...................................................... 19
Figure 3.12: Unzip Dataset ....................................................................................... 19
Figure 3.13: Clone YOLOv5 repository ................................................................... 19
Figure 3.14: Change Directory .................................................................................. 19
Figure 3.15: Install YOLOv5 requirements .............................................................. 20
Figure 3.16: Open coco128.yaml file ........................................................................ 20
Figure 3.17: Update coco128.yaml file ..................................................................... 20
Figure 3.18: Open hyperparameter file ..................................................................... 21
Figure 3.19: Hyperparameters of the model .............................................................. 21
Figure 3.20: Training code and configuration ........................................................... 22
Figure 3.21: Performance metrics of training and validation.................................... 22
Figure 3.22: Code to run validation .......................................................................... 22
Figure 3.23:Perform testing....................................................................................... 22
Figure 3.24: Accessing results of experiments. ........................................................ 23
Figure 3.25: Creating zip file of results. ................................................................... 23
Figure 3.26: YOLOv5l Architecture ......................................................................... 24
Figure 3.27: leaky ReLU activation function. ........................................................... 26
Figure 3.28: Sigmoid activation function ................................................................. 27
Figure 4.1: Test results of YOLO models trained at 640-pixels ............................... 28
Figure 4.2: Training and validation results of YOLOv5n ......................................... 30
x
Figure 4.3: Training batch of YOLOv5n. ................................................................. 30
Figure 4.4: F1 curve of validation set ....................................................................... 31
Figure 4.5: Precision curve of validation set ............................................................. 31
Figure 4.6: Recall curve validation set ...................................................................... 32
Figure 4.7: PR curve validation set ........................................................................... 32
Figure 4.8: F1 score of YOLOv5n at 1408 pixels ..................................................... 39
Figure 4.9: Recall curve of YOLOv5n at 1408 pixels .............................................. 39
Figure 4.10: mAP of YOLOv5n at 1408 pixels ........................................................ 40
Figure 4.11: Training and validation loss results ...................................................... 41
Figure 4.12: Training batch of YOLOv5s ................................................................. 41
Figure 4.13: F1 score YOLOv5s at 1408 pixels ....................................................... 48
Figure 4.14: Precision of YOLOv5s at 1408 pixels .................................................. 48
Figure 4.15: Recall curve of YOLOv5s at 1408 pixels ............................................. 49
Figure 4.16: mAP of YOLOv5 at 1408 pixels .......................................................... 49
Figure 4.17: Loss metrics of YOLOv5m .................................................................. 50
Figure 4.18: F1 score of YOLOv5m for validation set. ............................................ 51
Figure 4.19: Precision of YOLOv5m for validation set ............................................ 51
Figure 4.20: Recall curve of YOLOv5m for validation set ...................................... 52
Figure 4.21: mAP of YOLOv5m for validation set .................................................. 52
Figure 4.22: F1 curve of YOLOv5m model ............................................................. 59
Figure 4.23: Precision curve of YOLOv5m at 1408 pixels ...................................... 59
Figure 4.24: Recall curve of YOLOv5m at 1408 pixels ........................................... 60
Figure 4.25: mAP of YOLOv5m at 1408 pixels ....................................................... 60
Figure 4.26: Loss metrics of YOLOv5 ..................................................................... 61
Figure 4.27: F1 curve of validation set YOLOv5l .................................................... 62
Figure 4.28: Precision curve of validation set YOLOv5l ......................................... 62
Figure 4.29: Recall curve of validation set YOLOv5l .............................................. 63
Figure 4.30: mAP of validation set YOLOv5l .......................................................... 63
Figure 4.31: F1 score of YOLOv5l at 1280 pixels ................................................... 70
Figure 4.32: Precision of YOLOv5l at 1280 pixels .................................................. 70
Figure 4.33: Recall of YOLOv5l at 1280 pixels ....................................................... 71
Figure 4.34: mAP of YOLOv5l at 1280 pixels. ........................................................ 71
Figure 4.35: Missing hole correct predictions .......................................................... 74

xi
Figure 4.36: Predictions for mousebite defect. ......................................................... 74
Figure 4.37: Predictions for open circuit defects. ..................................................... 75
Figure 4.38: Correct predictions for short circuit. .................................................... 75
Figure 4.39: misclassification of open circuit ........................................................... 76
Figure 4.40: False negative example ......................................................................... 76
Figure 4.41: Misclassification example .................................................................... 77
Figure 4.42: Dual detection of single object. ............................................................ 77
Figure 4.43: False negative and False positive predictions. ..................................... 78

xii
List of Tables

Table 2.1: Different models of YOLOv5[34] ........................................................... 10


Table 3.1: Number of Defects by Defect Type ......................................................... 15
Table 4.1: Number of Images for Train, Test and Validation ................................... 28
Table 4.2: Highest mAP percentages of different models. ....................................... 29
Table 4.3: Loss metrics of Yolov5n .......................................................................... 29
Table 4.4: Test results of Image size 256 .................................................................. 33
Table 4.5: Test results of image size 384 .................................................................. 33
Table 4.6: Test results image size 512 ...................................................................... 34
Table 4.7: Test results image size 640 ...................................................................... 34
Table 4.8: Test results image size 768 ...................................................................... 35
Table 4.9: Test results image size 896 ...................................................................... 35
Table 4.10: Test results image size 960 .................................................................... 36
Table 4.11: Test results image size 1024 .................................................................. 36
Table 4.12: Test results image size 1152 .................................................................. 37
Table 4.13: Test results image size 1280 .................................................................. 37
Table 4.14: Test results image size 1408 .................................................................. 38
Table 4.15: Test results image size 1536 ................................................................... 38
Table 4.16: Loss metrics of YOLOv5s ..................................................................... 40
Table 4.17: Test results image size 256 .................................................................... 42
Table 4.18: Test results image size 384 .................................................................... 42
Table 4.19: Test results image size 512 .................................................................... 43
Table 4.20: Test results image size 640 .................................................................... 43
Table 4.21: Test results image size 768 .................................................................... 44
Table 4.22: Test results image size 896 .................................................................... 44
Table 4.23: Test results image size 960 .................................................................... 45
Table 4.24: Test results image size 1024 .................................................................. 45
Table 4.25: Test results image size 1152 .................................................................. 46
Table 4.26: Test results image size 1280 .................................................................. 46
Table 4.27: Test results image size 1408 .................................................................. 47
Table 4.28: Test results image size 1536 .................................................................. 47
Table 4.29: Loss metrics of YOLOv5m .................................................................... 50
Table 4.30: Test results image size 256 .................................................................... 53
xiii
Table 4.31: Test results image size 384 .................................................................... 53
Table 4.32: Test results image size 512 .................................................................... 54
Table 4.33: Test results image size 640 .................................................................... 54
Table 4.34: Test results image size 768 .................................................................... 55
Table 4.35: Test results image size 896 .................................................................... 55
Table 4.36: Test results image size 960 .................................................................... 56
Table 4.37: Test results image size 1024 .................................................................. 56
Table 4.38: Test results image size 1152 .................................................................. 57
Table 4.39: Test results image size 1280 .................................................................. 57
Table 4.40: Test results image size 1408 .................................................................. 58
Table 4.41: Test results image size 1536 .................................................................. 58
Table 4.42: Loss metrics of YOLOv5l ...................................................................... 61
Table 4.43: Test results image size 256 .................................................................... 64
Table 4.44: Test results image size 384 .................................................................... 64
Table 4.45: Test results image size 512 .................................................................... 65
Table 4.46: Test results image size 640 .................................................................... 65
Table 4.47: Test results image size 768 .................................................................... 66
Table 4.48: Test results image size 896 .................................................................... 66
Table 4.49: Test results image size 960 .................................................................... 67
Table 4.50: Test results image size 1024 .................................................................. 67
Table 4.51: Test results image size 1152 .................................................................. 68
Table 4.52: Test results image size 1280 .................................................................. 68
Table 4.53: Test results image size 1408 .................................................................. 69
Table 4.54: Test results image size 1536 .................................................................. 69
Table 4.55: Inference time of YOLOv5n .................................................................. 72
Table 4.56: Inference time of YOLOv5s .................................................................. 72
Table 4.57: Inference time of YOLOv5m ................................................................. 73
Table 4.58: Inference time of YOLOv5l ................................................................... 73
Table 4.59: Defects with 1 precision or recall for small model. ............................... 79
Table 4.60: Defects with 1 precision or recall for medium model. ........................... 80
Table 4.61: Defects with 1 precision or recall for large model. ................................ 81

xiv
Acronyms

CAGR Compound Annual Growth Rate


CMOS Complementary Metal-Oxide Semiconductor
COCO Common Objects in Context
CSP Cross Stage Partial
DLP Direct Legend Printing
FLOPs Floating Point Operations per Second
FPS Frames Per Second
FR-1 Fire Retardant-1
GPU Graphical Processing Unit
HSV Hue Saturation Value
IC Integrated Circuit
ICT In-Circuit Test
ILSVRC ImageNet Large Scale Visual Recognition
Challenge
IOU Intersection Over Union
LED Light Emitting Diode
LPI Liquid Photo Imaging
mAP Mean Average Precision
PAN Path Aggregation Network
PCB Printed Circuit Board
RCNN Region-based Convolution Neural Network
SAT Self-Adversarial Training
SGD Stochastic Gradient Descent
SPP Spatial Pyramid Pooling
SSD Single Shot Detector
SURF Speeded Up Robust Features
VGG-16 Visual Geometry Group - 16
YOLOv5 You Only Look Once Version 5

xv
Chapter 1: Introduction
A PCB is a building block for virtually all electronic devices. It is responsible for
housing various components such as resistors, capacitors, transistors, diodes,
integrated circuits (ICs) and many more. PCB is multi-layered and is composed of
different layers of silkscreen, solder mask, copper and a substrate which is usually a
fiberglass as it has high flame retardant [1]. Inspection process of PCBs has been
continually improved by the researchers to meet the demand of modern-day
production.
This research examines the performance of different models of YOLOv5 for detecting
defects present in bare PCBs. The models are trained to detect 6 types of defects that
include missing holes, mouse bites, open circuit, short circuit, spurs and spurious
copper.
The remainder of this chapter is structured as follows. Section 1.1 discusses the
background of this research. Section 1.2 explains the objectives of the research and
section 1.3 gives an overview of the of the subsequent chapters in the document.

1.1 Background and Motivation

PCB manufacturing is a billion-dollar industry. According to a study conducted in [2]


the market has been forecasted to register a compound annual growth rate (CAGR) of
1.53% between 2021-2026. The PCB market was valued at $58 billion in 2020 and is
expected to be around $75 billion by the end of 2026. The rapid growth in this industry
is mainly because of the increase in demand of consumer based electronic products.
PCB manufacturing industries have been working extensively to improve the
production process and one step is ensuring the product meets the quality standards.
Previously, inspection engineers were tasked to find faults in the PCBs. the manual
inspection was carried out using visual inspection through naked eye or with the help
of magnifying glass. Other manual inspection methods involved performing an in-
circuit test (ICT) to determine open circuit, short circuit, and other parameters of the
board. Manual inspection is low cost, but it is time consuming and is prone to human
error as the inspection is highly subjective. Complex patterns are difficult to inspect
1
without errors. Quality standards of industries in this domain are so high that sample
inspection of PCBs is not suitable, and each product needs to be thoroughly
investigated for any anomalies. Manual inspection reduces the production rate making
manual inspection unfavourable. Because of the diversity of defects that occur in the
PCBs and low tolerance levels, simple manual inspection becomes inadequate. To
eradicate the problems faced in manual inspection, a lot of effort has been done in
making this process automated.

1.2 Research Objectives

After extensive literature review of the previous works that have been carried out, the
research objectives of this research have been narrowed down to the ones listed below.
1. Increase mean average precision of the model on the available dataset.
2. Increase precision and recall of YOLOv5 from the benchmark papers.
3. Perform data augmentation to increase the dataset and make the model more
robust.
4. Compute inference time for detection at different image resolutions.
5. Compare the performance of different YOLOv5 models and determine the best
model suitable for PCB defect detection tasks.

1.3 Thesis Structure

The thesis is further categorized into four more chapters that are briefly discussed in
the following sub-sections.

1.3.1 Literature Review

This chapter investigates the previous work that has been carried out in the previous
years on PCB defect detection using classical machine vision techniques and deep
learning methods. Different models of YOLOv5 have been discussed in this chapter.

1.3.2 Methodology

Detailed explanation of data augmentation has been done in this chapter. Configuration
of the model and steps to Training a model on Google Colab has been discussed here.
Model architecture and the performance metrics used for validation are presented.

2
1.3.3 Results and Discussion

This chapter presents the results of different models of Yolov5 trained on the PCB
defect detection datasets. Inference times of each model is investigated using two types
of General Processing Units (GPUs).

1.3.4 Conclusion

The last chapter includes conclusion and mentions future work that can help increase
the model performance in later research.

3
Chapter 2: Literature Review
Prior to printed circuit boards, printed wiring boards were used in which connections
were made through wiring instead of a conducting trace. Printed wiring boards were
more prone to errors and difficult to maintain. Printed circuit board is a platform on
which multiple electronic components can be mounted such as capacitors, resistors,
integrated circuits, amplifiers and many more. PCBs can be of single layer, double
layer or even multi-layered with up to 40 layers [3]. Most common way of categorizing
PCBs is based on number of layers since more layers require more advanced and
sophisticated technology.
The structure of a PCB is composed of multiple layers. The first layer is called the
silkscreen which is used for indicating the placement of electrical components on top
of the PCB. It can be applied manually but more precise and accurate methods are
Liquid Photo Imaging (LPI) [4] and Direct Legend Printing (DLP) [5]. The second
layer is called the solder mask, its main function is to protect the copper from oxidation
and short circuit between the traces and reduce the impact of ambient factors on the
conducting trace. The third layer is a conducting trace made up of copper. Beneath the
copper layer, a dielectric substrate is used. The substrate is divided into four different
categories based on its flame retardant values. The most used substrate in PCB
manufacturing is the FR4 which is a fiberglass epoxy laminate. FR4 uses eight layers
of fiberglass and can withstand temperatures of up to 130°C depending on its thickness.
FR1 and FR2 are not preferred because it is difficult to pass holes through it. FR3 is
not suitable for multi-layered boards. Structure of PCB can be seen in the figure 2.1
below.

Figure 2.1: Printed Circuit Board Structure

4
2.1 Bare PCB Defects

There are multiple types of defects that can occur in a PCB. These defects can be
divided into two blocks. One is the functional defect, and the other is the cosmetic
defect. Functional defects can immediately affect the performance of the PCB whereas,
cosmetic defects may not be an immediate threat to the functionality of the board but
may have an adverse effect on the functionality after some time. The defects include
open circuit, short circuit, mousebite, spur, spurious copper, missing hole, breakout,
pinhole, over etched, under etched, wrong size hole, conductor too close, and excessive
short [6]. Under etch and over etch occur during the process of etching[7]. The
examples of Bare PCB defects are shown in the figure 2.2 below.

Figure 2.2: Types of PCB defects.

5
2.2 Defect Detection in PCBs

Previously, defects in the PCBs were detected manually. The procedure involved a
trained individual performing visual inspection and equipment-based testing. With the
rapid advancement in technology and the production of PCBs, these conventional
methods have become futile as they are prone to error and are high-cost intensive. To
meet the demands of production and quality control, researchers have developed
various techniques using classical machine vision and computer vision. These
techniques will be discussed in the coming sections.

2.2.1 Classical Machine Vision Techniques

Traditional machine vision employs image processing methods. The traditional


methods of machine vision include feature extraction, morphological processes, and
image subtraction. Nayak et al. [8] were able to detect 14 types of defects present in
the PCB. They applied the Hough transform to find the longest lines and aligned the
test and template pictures after preprocessing the 256𝑥256 images to reduce noise.
Later, image subtraction was utilized to determine the difference, and blobs were
utilized to depict the defects. In [9] , To find the flaws, the researchers combined
morphological procedures, picture subtraction, and template matching with the
speeded up robust feature (SURF) [9] extraction technique along with morphological
operations, image subtraction, and template matching to detect the defects. A
dictionary of all the potential components present on the PCB was created using the
SURF descriptors. Features of the test images were compared to the feature descriptors
contained in the dictionary to determine whether a component is missing or not. Can
Ma et al. [10] in their paper used a template matching approach in which the algorithm
was able to classify the PCBs as either qualified or not qualified but was not able to
identify the type of defect present in a PCB. Shui Fang et al. used X-ray imaging to
determine misalignment, offset, and contraction of multi-layered PCB boards [11].
Additionally, study on non-referential systems has been done. The system's capacity
to identify flaws is based on the established design guidelines. The test image does not
need to be compared to a template image when using this technique. Both the amount
of storage needed and the operational speed can be decreased by non-referential
systems.[12].

6
2.2.2 Detection using Computer Vision

Deep learning models for object detection have recently received a lot of attention.
When tackling issues with defect identification, these models have also performed
exceptionally. Peng Wei et al.[13] created a CNN model that has a 95.7 percent
accuracy for classifying 6 different sorts of faults.. their model beat VGG16 [14] and
ResNet50 [15] by 81.2% and 94.8%, respectively. 1818 photos made up the dataset
but number of images by class type were not evenly distributed. In [16], The model
was created to distinguish between genuine and fake PCB faults. Short circuit, spur,
open circuit, and mousebite were categorized as true problems, whereas dust specks
and spots on the PCB were categorized as fake flaws. The collection consisted of 2888
photographs of fake defects and 4655 pictures of real flaws. Pre-trained inception-v3
[17] was utilized to train the dataset, and 91.25% classification accuracy with 93.17%
precision and 88.25% recall was attained. C. Zhang et al. [18] employed a VGG-16
model that was already trained using data from the ImageNet Large Scale Visual
Recognition Challenge (ILSVRC)[19]. To identify six different types of PCB faults,
YOLOv4 with spatial pyramid pooling and a Path Aggregation network was utilized
in[20]. To make the system more robust, several brightness and contrast levels were
introduced at random. The model's overall mAP was 96.88%. In [21], 6 types of PCB
defects were detected using ensemble method with a detection rate of 96.73% but it
had a high false alarm rate of 19.73%. Performance of autoencoder and skip connected
autoencoder was compared in [22].

2.3 Object Detection

Object detection is one of the most challenging tasks in the field of computer vision.
the reason object detection is difficult is because the detection model not only needs to
be accurate but must perform detections with minimum inference time. Object
detectors are further divided into two categories. One is the two-stage detection, and
the other is the one stage detection. Two stage detectors have high recognition and
localization accuracies such as faster RCNN [23]. One stage have high inference
speeds as in YOLO [24] and SSD [25].

7
2.4 You Only Look Once Object Detection:

For PCB defect detection, different models of YOLO algorithm were taken into
consideration. Since 2015 multiple versions of YOLO models have been developed.
In the following sections, different YOLO versions will be discussed.

2.4.1 YOLOv1:

YOLO algorithm was first presented by Joseph Redmond in 2015 [24]. The model was
pretrained on the ImageNet classification dataset. The model was trained on 224𝑥224
images but for detection the image size was doubled to 448x448 image size since
detection requires minute information in the images. Unlike RCNN which is a multi-
stage detector, YOLO dissects single image into a grid cell and each cell is responsible
for predicting the presence of the object inside of it. Multiple bounding boxes are
generated in each cell and based on the score of intersection over union (IOU),
redundant bounding boxes are eliminated and the box with highest IOU is selected for
prediction. Some limitations of this model include that it can predict only two bounding
boxes per cell and can have only one class. The model was also poor when objects
were present in different aspect ratios compared to the data it was trained on.

2.4.2 YOLOv2:

This model was proposed by the original authors in [26]. In this paper, the researchers
propose a new framework for YOLOv2 called the darknet-19, it has nineteen
convolution layers and five max pooling layers. The network was trained on ImageNet
dataset for 160 epochs. Concept of anchor boxes was introduced in this paper, in
YOLOv1 the prediction of bounding boxes was done using the fully connected layers.
YOLOv2 achieved a max mAP of 78.6% on Pascal VOC 2007 dataset whereas,
Yolov1 achieved 76.8% on the abovementioned dataset.

2.4.3 YOLOv3:

YOLOv3 was published by Joseph Redmon and Ali Farhadi in 2018 [27]. Some
updates were made to YOLOv2. For bounding boxes this model uses logistic
regression for prediction, which means that a bounding box is selected if it overlaps
the ground truth box more than the other predicted bounding boxes even if the previous

8
boxes go over the minimum threshold value. For class predictions, logistic classifier is
used instead of a softmax layer. The reason behind not using softmax is that it assumes
that each box has only one class present inside of it which is not true for every example.
The backbone used for training the images was Darknet-53 and it achieved similar
mAP to the other single stage detectors but was roughly 3 times faster than them.

2.4.4 YOLOv4:

In 2020, Alexey et al. [28] introduced a new type of augmentations called the mosaic
and self-adversarial training (SAT). Best possible hyper-parameters were selected for
training using the genetic algorithm. Yolov4 consists of a backbone of CSPDarknet-
53 [29]. The neck part has Spatial Pyramid Pooling (SPP) [30] and Path Aggregation
Network (PAN) [31]. The head is same as Yolov3. The model was tested on MS
COCO dataset. For an image size of 608𝑥608 the mAP of the model reached 65.7%
at 23 frames per second (FPS).

2.4.5 YOLOv5:

Shortly after the release of YOLOv4, Glenn Jocher released YOLOv5 [32] based on
the PyTorch framework [33] in May,2020. One of the main features of Yolov5 was
adaptive anchor boxes. These anchor boxes learn the best possible anchor boxes on the
given dataset during training. Different models of YOLOv5 were trained on COCO
dataset with 80 classes. Each model has different number of parameters and Floating-
Point Operations per second (FLOPs). There are two sets of model categories that were
trained on different image sizes. The following table shows the accuracies of different
models, their inference speed and other performance metrics.

9
Table 2.1: Different models of YOLOv5[34]
Model Size mAP mAP Speed Speed Params FLOPs
(Pixels) 0.5:0.95 0.5 V100 b1 V100 b32 (M) @640
(ms) (ms) (B)
Yolov5n 640 28.0 45.7 6.3 0.6 1.9 4.5
Yolov5s 640 37.4 56.8 6.4 0.9 7.2 16.5
Yolov5m 640 45.4 64.1 8.2 1.7 21.2 49.0
Yolov5l 640 49.0 67.3 10.1 2.7 46.5 109.1
Yolov5x 640 50.7 68.9 12.1 4.8 86.7 205.7
Yolov5n6 1280 36.0 54.4 8.1 2.1 3.2 4.6
Yolov5s6 1280 44.8 63.7 8.2 3.6 12.6 16.8
Yolov5m6 1280 51.3 69.3 11.1 6.8 35.7 50.0
Yolov5l6 1280 53.7 71.3 15.8 10.5 76.8 111.4
Yolov5x6 1280 55.0 72.7 26.2 19.4 140.7 209.8

YOLOv5n, YOLOv5s, YOLOv5m, YOLOv5l, YOLOv5x were trained on image size


of 640 pixels. The other is designed to be trained on image size of 1280 pixels. These
models are referred as YOLOv5n6, YOLOv5s6, YOLOv5m6, YOLOv5l6,
YOLOv5x6. The later models have a greater number of parameters and require more
FLOPs than the ones trained on image size of 640. YOLOv5n is the smallest model
with only 1.9 million parameters and YOLOv5x is the largest model with 86.7 million
parameters.
Each model is composed of three parts, backbone, neck and head. Backbone of
YOLOv5 is of CSP Darknet-53, the neck consists of SPP and CSP-PAN and the head
is of YOLOv3. Data augmentation techniques in YOLOv5 include mosaic training,
copy-paste, mix-up, HSV, scale, shear, flip up and down and other methods.
For best selection of hyperparameters, Evolution is carried out on custom dataset and
with each evolution the best hyperparameters are derived. For best results a minimum
of 300 generations are needed but this makes the process of evolution computationally
expensive and time consuming.

10
2.5 Research Gaps

Some of the conventional machine vision techniques use the reference comparison
method to detect defects, this method is easy to apply but it requires rigorous image
acquisition setup because any change in illumination, rotation and scale can have an
affect over the system’s performance [8]. High false alarm rates were observed in [35].
In the data augmentation phase, researchers have applied random rotations, brightness,
contrast [20], or rotations, gaussian noise and random flips [22] but have not added
random Gaussian noise along with random brightness and contrast to make the dataset
more challenging and the system more robust to noise factors. Comparative study of
different models of YOLOv5 on the PCB dataset provided by [36] has not been carried
out yet. A detailed study of inference times of different models of YOLOv5 for PCB
defect detection has not been addressed in prior research.

11
Chapter 3: Methodology
The process of object detection involves series of steps that are required to achieve
desirable results. Similarly, in this research the relevant tasks and procedures were
carried out to achieve the results.
Figure 3.1 shows the flow diagram of the methodology applied for training defect
detection models. First, the dataset was acquired from the GitHub repository. The
dataset was then split into train, test and validation sets. After segmentation of the
images, dataset augmentation was carried out using OpenCV. For training and testing,
Google colaboratory was used in which YOLOv5 weights were trained and results
were collected for different performance metrics and based on the results, best
performing weight files were saved.

Figure 3.1: Block diagram of the methodology.

12
3.1 PCB Dataset

The researchers that utilized it to carry out fault identification in made a synthetic PCB
dataset accessible on GitHub [36]. A 16-megapixel industrial camera with a CMOS
sensor was used to capture the images. An industrial lens with a variable focal length
of 6–12mm was put to the camera to prevent picture distortion. Two ring LEDs were
employed as the light source to minimize illumination error. Depending on the size of
each PCB, different picture resolutions were achieved.
Using the Adobe Photoshop picture editor, faults were introduced into the photographs
after they had been obtained. The dataset included 693 photos with 6 different types
of flaws. Open circuits, short circuits, missing holes, mouse bites, spurs, and spurious
copper were among the flaws. The defects are shown in the figure 3.2 below.

Figure 3.2: PCB defects in dataset


The dataset was created using a total of 10 PCBs. A variety of PCBs were used, with
the largest PCB measuring 20 mm by 120 mm and the smallest PCB 53 mm by 48 mm.
The PCBs used are shown in the figure 3.2 below.

13
Figure 3.3: PCBs used for dataset.
The distribution of defects per PCB is shown in the figure 3.4 below. Number of
defects per image varied from 1-6 defects per PCB with majority of the PCBs having
5 defects per image.

14
Figure 3.4: Number of defects per PCB
A total of 2,953 defects were present in the original dataset and its distribution by
defect type is presented in the following table 3.1.
Table 3.1: Number of Defects by Defect Type
Sr.no Defect Type Number of images Number of Defects
01 Missing hole 115 497
02 Mousebite 115 492
03 Open Circuit 116 482
04 Short Circuit 116 491
05 Spur 115 488
06 Spurious Copper 116 503
Total 693 2,953

3.2 Dataset Augmentation:

Images from the dataset were taken with the same lighting and camera settings.
Because the dataset lacks additional noise sources and environmental factors, the
model may underperform in real-world circumstances. To widen the model's
application in practical situation, random Gaussian noise, brightness, and contrast were
added to the pictures.

15
3.2.1 Gaussian Noise

Gaussian noise in images occur due to the ineffaceable noise present in the sensor and
other factors that include illumination levels and temperature of the sensor itself. The
strength of the gaussian noise is dependent on the standard deviation (σ) and mean (µ)
[37]. Gaussian noise of different intensity levels was added to the dataset using
OpenCV [38] in python. Sample of image with Gaussian noise is shown in the figure
3.5 below.

Figure 3.5: (A) Original Image, (B) Image with Gaussian noise

3.2.2 Brightness and Contrast

To further increase the robustness of our system for practical applications, random
brightness and contrast were augmented in the dataset. 50 different stages of brightness
and 6 different levels of contrast were added to the images using OpenCV. Examples
our shown in figure 3.6 below.

Figure 3.6: (A) Original image, (B) Image with random brightness and contrast.

16
3.3 Training PCB Dataset

The dataset was split into three categories of train, validation, and test sets. The models
were trained on Google Colaboratory which is a product developed by Google
research. It allows the user to implement Python codes in browser and is extremely
useful for machine learning applications since it gives free access to Graphical
Processing Units (GPUs). The only drawback of using Google Colaboratory is that the
resources provided in the free version are not limited. The access to GPUs may
sometimes be restricted depending on the running time of GPUs or the high
computational demand of the training dataset. Maximum running time for a training
process is 12 hours but it may vary from time to time.

3.3.1 Google Colaboratory

The Colaboratory deletes the uploaded files once the session is ended. For instant
access to the dataset for training different models of YOLOv5, the dataset was
uploaded on Google drive in a zip file. The process of training the model involves
multiple steps that are explained with images below.
The first step is to assign a GPU to the workspace. For this purpose, first go to
“Runtime” and then click on “Change runtime type”. Refer to figure 3.7 to see it
visually.

Figure 3.7: Change Runtime


Select “GPU” as hardware accelerator and “Save” this configuration.

17
Figure 3.8: Hardware accelerator selector
To check the specifications of the GPU assigned to the session, run the code in figure
3.9.

Figure 3.9: GPU specifications


After the GPU is assigned, connect the Google drive to the Google Colab workspace.
There are two ways to mount the Google drive to the colaboratory. One method is to
click the Drive icon in the folder section as shown in figure 3.10 and the other
method is to write the code as shown in the figure 3.11.

18
Figure 3.10: Mount Google drive using icon

Figure 3.11: Mounting Google drive using code


Unzip the dataset from the drive by giving it the path to the zip file as shown in
figure 3.12.

Figure 3.12: Unzip Dataset


Clone YOLOv5 repository from GitHub to the colaboratory as specified in figure
3.13.

Figure 3.13: Clone YOLOv5 repository


Change current directory to YOLOv5 to store results in the YOLOv5 folder.

Figure 3.14: Change Directory


Install requirements from the requirements.txt file.

19
Figure 3.15: Install YOLOv5 requirements
From the files section, go to YOLOv5 directory and open data folder. At the end of
the folder open the coco128.yaml file.

Figure 3.16: Open coco128.yaml file


In the coco128.yaml file set the training path, validation path and test path of the
dataset in lines 12, 13 and 14 respectively. Also set the number of classes and give
the names of classes in the form of a list.

Figure 3.17: Update coco128.yaml file

20
From the YOLOv5 directory, select the “hyps” folder and open the hyp.scratch-
low.yaml file. To update the hyperparameters.

Figure 3.18: Open hyperparameter file


“hyp.scratch-low.yaml” file is used to set the hyperparameters of the model before the
start of training. Hyperparameters. These parameters are essential in determining the
performance of the model.

Figure 3.19: Hyperparameters of the model


Now start the training of the model with the code given in figure 3.20. In this code we
have to set the size of the training image, batch size, number of epochs, specify the
“.yaml” file which has the information about the training data and the weights of the
YOLOv5 model which will be used for transfer learning.

21
Figure 3.20: Training code and configuration
Once the training starts the output window will show the performance metrics of
training and validation set as shown in the figure 3.21.

Figure 3.21: Performance metrics of training and validation


Run the code shown in figure 3.22 to find the values of performance metrics on the
validation set.

Figure 3.22: Code to run validation


To find the performance of the model on the test dataset, use the code in figure 3.23
but add “-- task test ” at the end of the code to access the test dataset from the
coco128.yaml file.

Figure 3.23:Perform testing


To access the results of training, validation, and test, go to “yolov5” → “runs”. Inside
the runs folder different folders will be created after the during the execution of
training, validation, testing and detection. Inside these folders different “exp” folders
will be generated depending on the number of experimentations performed and inside
these folders, results will be stored. Refer to figures 3.24.

22
Figure 3.24: Accessing results of experiments.
Google Colab does not allow multiple files to be downloaded at the same time. To
download all the results collectively, we must create a “.zip” file of the folder we
want to download.

Figure 3.25: Creating zip file of results.

3.4 YOLOv5 Architecture:

Backbone, neck, and head make up the YOLOv5 architecture. Convolutional layers,
CSP bottlenecks, and spatial pyramid pooling make up the backbone. Different scales
are used by Backbone to extract characteristics. The picture is scaled down by 50%
inside the backbone after each convolution layer. and neck creates feature pyramids
that aid the model's detection capabilities at various scales and sizes. The head
component is what performs the detections. There are three distinct scales used for
these detections: 120x120, 60x60, and 30x30. A vector of length 55 is output for each
channel from each detection stage. The number of anchors, number of classes, class
probabilities, and bounding box coordinates make up the output vector. In our
experiment, auto-anchoring produces five anchors per target and the number of classes
are 6. The resulting output vector is [5(5+6)]. Feature maps were created to display the
results of the model's various stages. These feature maps are shown in the appendix A.
YOLOv5 Architecture is shown in figure 3.26.

23
Figure 3.26: YOLOv5l Architecture

3.5 Performance Metrics:

Performance metrics of object detectors are a mean to evaluate the performance of the
model. The metrics selected for this thesis include the following.
1. Precision.
2. Recall.
3. F1 score.
4. Mean average precision.

3.5.1 Precision:

Precision is the percentage of correct predictions made by a model relative to all of its
other predictions.
𝑇𝑃
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 = (3.1)
𝑇𝑃+𝐹𝑃

3.5.2 Recall:

The number of true positives accurately detected by the model out of all true positives
in the dataset is known as recall. The formula to calculate recall is given by

24
𝑇𝑃
𝑅𝑒𝑐𝑎𝑙𝑙 = 𝑇𝑃+𝐹𝑁 (3.2)

3.5.3 F1 score:

The F1 score is the harmonic mean of the model's recall and precision. It is given by
the formula.
2∗(𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛∗𝑅𝑒𝑐𝑎𝑙𝑙)
𝐹1 𝑆𝑐𝑜𝑟𝑒 = (3.3)
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛+𝑅𝑒𝑐𝑎𝑙𝑙

3.5.4 Mean Average Precision:

The IOU of each class is used to determine the mean average precision, which is then
averaged. Two factors determine what an IOU is. The ground truth box is one, while
the predicted box is the other. In our case the threshold value was set at 0.5 for
predictions. The formula for IOU is given in Eq. (3.4)
𝐼𝑛𝑡𝑒𝑟𝑠𝑒𝑐𝑡𝑖𝑜𝑛 𝐴𝑟𝑒𝑎
𝐼𝑂𝑈 = (3.4)
𝑈𝑛𝑖𝑜𝑛 𝐴𝑟𝑒𝑎

3.6 YOLOv5 Setup:

Yolov5 is composed of three main segments.


1. Backbone.
2. Neck.
3. Head.
The purpose of backbone is to extract the relevant features from the input image.
YOLOv5 uses CSPNet as the backbone of the model. The benefit of using CSPNet is
that it provides better processing times when dealing with deep networks. The task of
neck is to generate feature maps at different scales, this helps detects objects of
different sizes. PCB defects are detected at 3 different scales. YOLOv5 uses PANet
for generating feature pyramids. The model head performs the detection and is same
as of YOLOv3.

3.6.1 Activation Functions:

The model uses two activation functions, for the hidden layers it applies leaky ReLU
and for the detection layer it uses sigmoid activation function.

25
3.6.1.1 Leaky ReLU

Leaky ReLU helps avoid dead neurons inside the model as it has a slightly negative
slope. Mathematically, leaky ReLU can be expressed as
𝑥𝑖 , 𝑖𝑓 𝑥𝑖 ≥ 0
𝑓(𝑥) = { (3.5)
𝑎𝑖 𝑥𝑖 , 𝑖𝑓 𝑥𝑖 < 0
In the preceding equation, 𝑥𝑖 is the neuron value while 𝑎𝑖 is the coefficient of slope
and its value is decided before the start of training. Graphically, Leaky ReLU can be
represented as in the figure 3.27 below.

Figure 3.27: leaky ReLU activation function.

3.6.1.2 Sigmoid Activation Function

Sigmoid activation function was used for classification in the detection layer. The input
to the sigmoid function is a real number and the output is a number between zero and
one. This helps in prediction of the probabilities as the value of probability also lies
between zero and one with one being the highest probability and zero being the lowest.
The response of sigmoid activation function is given in figure 3.28

26
Figure 3.28: Sigmoid activation function

3.6.2 Optimizer

The purpose of an optimizer in neural network is to update the weights of the model
based on the gradients and other information. YOLOv5 has two optimization
functions. One is the Stochastic Gradient Descent (SGD), and the other is the Adam
optimizer. Since the PCB dataset was small and SGD generalizes better than Adam on
the default hyperparameters as can be deduced from [39]. Adam optimizer converges
faster but requires fine tuning of hyperparameters. For this reason, SGD was selected
as the optimizer.

3.6.3 Hyperparameters

Before training begins, hyperparameters are set. These parameters establish how the
training process will be carried out. The learning rate was set to 0.1. The SGD
momentum was 0.937. Weight decay with a value of 0.0005 was used for
regularization. Image enhancement settings were also established. The rotation angle
was set at 3.0 degrees. Translation was set to 0.1, image scaling was set to 0.5, image
left-right flip probability was set to 0.5, Mosaic augmentation probability was set to
1.0, and other hyperparameters were set to 1.0.

27
Chapter 4: Results and Discussion
4.1 Training at 640 Pixels:

The dataset was first trained on 640𝑥640 sized images of the PCB. The images were
segmented into three groups of train, test, and validation sets. 80% images were
assigned for training, 10% for validation and 10% for test. Number of images per
category is shown in table 4.1 below.
Table 4.1: Number of Images for Train, Test and Validation
Sr. No Category Number of Images
1 Train 1656
2 Validation 192
3 Test 225
Total 2073

For the YOLOv5 models trained at 640 pixels, the best results for nano, small and
medium models were achieved at 896 image resolution while the best mAP results for
large model was achieved at 768 image resolution. Large model had a mean average
precision of 95.45% which was highest among all models trained at 640 image
resolution.

Test mAP results after 640 image size training


120

100

80
mAP

60

40

20

0
256 384 512 640 768 896 960 1024 1152 1280 1408 1536
Resolutions
Yolov5n Yolov5s Yolov5m Yolov5l

Figure 4.1: Test results of YOLO models trained at 640-pixels

28
Table 4.2: Highest mAP percentages of different models.
Sr.No Model mAP (%)
01 YOLOv5n 92.1
02 YOLOv5s 94.06
03 YOLOv5m 94.92
04 YOLOv5l 95.45

4.2 Training at 960 pixels:

To increase the mean average precision and other performance metrics of the Yolov5
models. The models were trained at 960-pixel images. The drawback of training at
high resolution images are the increased training time and high inference time. Four
models of YOLOv5 were trained using Tesla K80 and Test T4 GPUs on Google Colab.
The results of different models are discussed in the following sections.

4.2.1 YOLOV5n:

The smallest model of the YOLOv5 family was trained for 50 epochs with a batch size
of 8. Low level augmentation was applied using the hyperparameters. The results of
training are given in the table below.
Table 4.3: Loss metrics of Yolov5n
Box Loss Object Loss Class Loss
Train 0.029628 0.018678 0.001596
Validation 0.030403 0.016839 0.001149

29
The results of loss and mAP metrics of training and validation are shown in the
figure 4.2 below.

Figure 4.2: Training and validation results of YOLOv5n


The following figure shows the augmented images of the training batch.

Figure 4.3: Training batch of YOLOv5n.

30
Figure 4.4 shows the F1 curve of the validation set. Highest F1 score was of missing
holes and lowest was for spur defects. For all classes, the maximum score was 0.94 at
0.629 confidence.

Figure 4.4: F1 curve of validation set


In the validation results as shown in figure 4.5, the model was able to get maximum
precision of 1 for missing hole at 0.4 confidence level. Overall, the precision was 1 for
detections at 0.84 confidence level and above.

Figure 4.5: Precision curve of validation set

31
Figure 4.6 shows the recall of the validation set. Spur had the worst recall among the
other defects while missing hole had the highest.

Figure 4.6: Recall curve validation set


Figure 4.7 shows the precision-recall curve of the model. Missing hole defect’s PR
was 0.995 with the second nearest short circuit at 0.962. spur was at the bottom with
0.882

Figure 4.7: PR curve validation set

32
4.2.1.1 Test results

The model was tested and studied under different resolutions. The results are presented
in the following tables.
In the table 4.4 we can see that the model performed poorly and was able to only
achieve mAP of 0.04 which is not suitable for defect detection. Nano model at 256
image resolution could not detect spurious copper as can be seen from the last row of
the table with zero precision and recall for the defect.
Table 4.4: Test results of Image size 256
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95

All 870 0.2773 0.0402 0.0403 0.009144


Missing hole 141 0.1134 0.06383 0.04985 0.01097
Mousebite 126 0.5138 0.02534 0.05663 0.01944
Open circuit 156 0.6455 0.03521 0.03255 0.005283
Short circuit 159 0.2536 0.09434 0.07182 0.01554
Spur 132 0.1375 0.02273 0.03009 0.003504
Spurious copper 156 0 0 0.00087 0.0001302

At 384 image resolution, overall mAP was 0.3996 with mousebite being the best
classified defect with mAP of 0.6012.
Table 4.5: Test results of image size 384
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.5694 0.4068 0.3996 0.1435
Missing hole 141 0.4152 0.3901 0.3436 0.1227
Mousebite 126 0.903 0.4921 0.6012 0.2338
Open circuit 156 0.606 0.391 0.4111 0.1409
Short circuit 159 0.6242 0.4969 0.505 02075
Spur 132 0.5325 0.4015 0.392 0.1231
Spurious copper 156 0.3355 0.2692 0.1451 0.03314

33
At 512 image resolution, the model started to perform well on missing hole defect with
a mAP of 0.9248 but it was having issues in detecting other defects. Overall precision
of the model was good at 0.9227 but this model had a poor recall at this resolution.

Table 4.6: Test results image size 512


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9227 0.7361 0.7637 0.3486
Missing hole 141 0.9346 0.9574 0.9248 0.4651
Mousebite 126 0.9198 0.7222 0.7668 0.4035
Open circuit 156 0.9806 0.647 0.7263 0.3076
Short circuit 159 0.9413 0.7484 0.795 0.3588
Spur 132 0.9069 0.7197 0.7202 0.3016
Spurious copper 156 0.853 0.6218 0.6489 0.2553

At 640 image resolution, the model was able to detect two defects with mAP greater
than 0.90. Precision for all the defects were above 0.90 apart from spurious copper
which had a mAP of 0.8543.

Table 4.7: Test results image size 640


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9322 0.831 0.8682 0.4383
Missing hole 141 0.9578 0.9787 0.9385 0.5264
Mousebite 126 0.9047 0.8016 0.8741 0.4754
Open circuit 156 0.9766 0.8038 0.885 0.4309
Short circuit 159 0.9308 0.9306 0.9248 0.4408
Spur 132 0.9692 0.7147 0.774 0.3752
Spurious copper 156 0.8543 0.7564 0.8126 0.3808

34
At 768 image resolution, the functional defects were being detected with satisfactory
results but improvement was still required in detecting cosmetic defects such as spur
and spurious copper.

Table 4.8: Test results image size 768


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9181 0.8729 0.8969 0.463
Missing hole 141 0.9687 0.9929 0.9772 0.5078
Mousebite 126 0.8315 0.8968 0.9108 0.5229
Open circuit 156 0.9585 0.8881 0.974 0.47
Short circuit 159 0.8914 0.9296 0.8965 0.4505
Spur 132 0.9789 0.7348 0.8021 0.4118
Spurious copper 156 0.8793 0.7949 0.8204 0.4152

mAP milestone of 0.90 was first breached at 896 image resolution for the nano model.
Missing hole defect had a mAP of 0.9743 and recall of 1 which means that no false
negative case occurred on the test set.

Table 4.9: Test results image size 896


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9334 0.8945 0.9059 0.471
Missing hole 141 0.9765 1 0.9743 0.5462
Mousebite 126 0.9285 0.9444 0.9523 0.5004
Open circuit 156 0.9933 0.9454 0.9932 0.5213
Short circuit 159 0.9084 0.9358 0.8952 0.426
Spur 132 0.9447 0.7273 0.7776 0.4097
Spurious copper 156 0.8489 0.8141 0.8425 0.4224

35
The model was trained at 960 resolution and test result show that open circuit had the
best mAP of 0.989 among the classes. Precision of spur was 0.9709 which was higher
than the other defects apart from the open circuit but because of poor recall of spur,
the mAP was bottom in terms of mAP ranking.

Table 4.10: Test results image size 960


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9431 0.9117 0.9299 0.4984
Missing hole 141 0.9693 0.9929 0.9752 0.592
Mousebite 126 0.8752 0.9444 0.952 0.5107
Open circuit 156 0.98 0.9423 0.989 0.5276
Short circuit 159 0.9443 0.9602 0.9465 0.4999
Spur 132 0.9709 0.7652 0.8302 0.4147
Spurious copper 156 0.9188 0.8654 0.8866 0.4457

At 1024-pixel size, missing hole achieved a recall of 1 while open circuit had the
highest mAP of 0.994. mAP of all classes was 0.9295.

Table 4.11: Test results image size 1024


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9468 0.917 0.9295 0.5022
Missing hole 141 0.973 1 0.9807 0.5587
Mousebite 126 0.9048 0.9365 0.9516 0.5372
Open circuit 156 0.9869 0.9648 0.994 0.5245
Short circuit 159 0.963 0.9937 0.9588 0.5047
Spur 132 0.97 0.7358 0.8167 0.4187
Spurious copper 156 0.8831 0.8714 0.8752 0.4692

36
At 1152 image resolution, all defects had a mAP of 0.90 and above but spur lagged
with a mAP of 0.8469.

Table 4.12: Test results image size 1152


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9492 0.9198 0.9429 0.5074
Missing hole 141 0.9696 1 0.9877 0.5815
Mousebite 126 0.89 0.9365 0.9634 0.534
Open circuit 156 0.9871 0.9839 0.9944 0.5297
Short circuit 159 0.9449 0.97 0.9472 0.4968
Spur 132 0.9606 0.75 0.8469 0.4391
Spurious copper 156 0.9432 0.8782 0.9179 0.4631

At 1280 image resolution, spur defect still struggled to reach recall similar to the
other defects.

Table 4.13: Test results image size 1280


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9612 0.9299 0.9377 0.5055
Missing hole 141 0.9723 0.9974 0.9749 0.5931
Mousebite 126 0.9295 0.9683 0.9644 0.5343
Open circuit 156 0.9911 0.9808 0.9947 0.5251
Short circuit 159 0.9331 0.9655 0.9204 0.4908
Spur 132 0.9807 0.77 0.8433 0.4268
Spurious copper 156 0.9589 0.8974 0.9283 0.4631

37
Nano model performed best at 1408 image resolution. a mAP of 0.9464 was achieved
with missing hole and open circuit reaching an individual mAP of greater than 0.99.

Table 4.14: Test results image size 1408


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9535 0.9286 0.9464 0.5216
Missing hole 141 0.9635 0.9929 0.9918 0.6418
Mousebite 126 0.9106 0.9524 0.9506 0.5145
Open circuit 156 0.9808 0.9848 0.9936 0.5295
Short circuit 159 0.9448 0.9688 0.9571 0.5132
Spur 132 0.9807 0.769 0.8503 0.453
Spurious copper 156 0.9407 0.9038 0.9347 0.4777

At 1536 image size, recall of the model was reduced from the recall achieved at 1408
resolution. this resulted in a slightly lower overall mAP of the system with 0.938.

Table 4.15: Test results image size 1536


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.956 0.9147 0.938 0.5144
Missing hole 141 0.9695 0.9929 0.9924 0.6277
Mousebite 126 0.9147 0.9357 0.9446 0.4925
Open circuit 156 0.9804 0.9625 0.9935 0.5098
Short circuit 159 0.944 0.9549 0.9552 0.5308
Spur 132 0.9632 0.7727 0.8243 0.4711
Spurious copper 156 0.9644 0.8695 0.918 0.4547

The best results of YOLOv5n were achieved at 1408 pixels with “Open Circuit” class
having the best mAP of 99.36% while the model did not perform well at detecting
spurs, which had a mAP of 85.03%.

38
The F1-score graph suggests that the performance on spur defects remains below par
even at high confidence values while missing hole and open circuit have scores above
the average line throughout the confidence range.

Figure 4.8: F1 score of YOLOv5n at 1408 pixels


In figure 4.9 of the recall curve, it can be observed that most of the defects are relatively
close to each other, but the model is not performing well on the spur defects resulting
in lower value of the overall recall.

Figure 4.9: Recall curve of YOLOv5n at 1408 pixels

39
From the precision curve shown in figure 4.10, we can see that missing hole and open
circuit had near perfect precision of 0.992 and 0.994 respectively. Spur and spurious
copper had lower precision values from the average curve.

Figure 4.10: mAP of YOLOv5n at 1408 pixels

4.2.2 YOLOv5s

YOLOv5s was trained for 50 epochs with batch size of 8. Low hyperparameter
augmentation was used and 4.99 anchors per target were selected using auto anchoring
method of YOLOv5. Training and validation loss metrics are given in the table below.
Table 4.16: Loss metrics of YOLOv5s
Box Loss Object Loss Class Loss
Train 0.026312 0.016623 0.001216
Validation 0.029405 0.01657 0.001332

40
The loss curves in figure 4.11 are relatively smoother than what was observed in the
nano model. The mean average precision stabilized after 35-40 epochs.

Figure 4.11: Training and validation loss results

Figure 4.12: Training batch of YOLOv5s

41
4.2.2.1 Tests results

In table 4.17, it can be observed that mAP at these resolutions remains low. Small
YOLOv5 model was performing below par.
Table 4.17: Test results image size 256
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.2096 0.07596 0.0532 0.01246
Missing hole 141 0.0195 0.08511 0.0528 0.01617
Mousebite 126 0.5763 0.09524 0.1043 0.02572
Open circuit 156 0.1847 0.05128 0.0266 0.003298
Short circuit 159 0.09087 0.1635 0.0747 0.0157
Spur 132 0.3864 0.06061 0.0582 0.01327
Spurious copper 156 0 0 0.0027 0.0006132

At 384 image resolution, the model had high precision while it had low recall rate.
This implies that detections were accurate but not all defects were detected.
Table 4.18: Test results image size 384
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.7626 0.4969 0.5416 0.1989
Missing hole 141 0.8471 0.4969 0.5588 0.2315
Mousebite 126 0.8754 0.5476 0.6226 0.239
Open circuit 156 0.8358 0.5321 0.5486 0.2002
Short circuit 159 0.8184 0.51 0.5982 0.2446
Spur 132 0.7041 0.5152 0.5251 0.167
Spurious copper 156 0.495 0.359 0.3966 0.1113

42
At 512 image resolution, only missing hole was able to breach the mAP threshold of
0.90.
Table 4.19: Test results image size 512
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9089 0.8239 0.8323 0.4159
Missing hole 141 0.9287 0.9787 0.9368 0.5261
Mousebite 126 0.8679 0.7778 0.798 0.4326
Open circuit 156 0.9524 0.7821 0.8458 0.3986
Short circuit 159 0.8719 0.8616 0.8529 0.4199
Spur 132 0.9713 0.7803 0.7948 0.3768
Spurious copper 156 0.8611 0.7628 0.7639 0.3415

At 640 image resolution, every defect had a mAP of over 0.90 apart from spur and
spurious copper. Spur had the best precision of 0.995 while missing hole had the best
recall of 0.9787.
Table 4.20: Test results image size 640
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.948 0.8514 0.8945 0.4668
Missing hole 141 0.9557 0.9787 0.9366 0.5584
Mousebite 126 0.9375 0.8095 0.9069 0.5218
Open circuit 156 0.9698 0.8224 0.953 0.4569
Short circuit 159 0.9471 0.9497 0.9312 0.4803
Spur 132 0.995 0.7727 0.8127 0.3875
Spurious copper 156 0.8828 0.7756 0.8264 0.3959

43
At 768 image resolution the small model reached a mAP of 0.90 or above. As was the
case in nano model, spur had high precision but poor recall rate.
Table 4.21: Test results image size 768
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9304 0.9041 0.9188 0.4866
Missing hole 141 0.9552 0.9787 0.9388 0.5987
Mousebite 126 0.8663 0.8492 0.9119 0.5162
Open circuit 156 0.9666 0.9285 0.9881 0.4941
Short circuit 159 0.9249 0.9623 0.9381 0.4903
Spur 132 0.9423 0.7955 0.8338 0.3934
Spurious copper 156 0.9268 0.9103 0.9021 0.4392

At 896 image resolution, recall of missing hole was 1. Mousebite had a lowest
precision of 0.8493 and spur had the lowest recall of 0.803.
Table 4.22: Test results image size 896
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9371 0.9244 0.93 0.5233
Missing hole 141 0.9759 1 0.9796 0.6036
Mousebite 126 0.8493 0.9396 0.9174 0.5437
Open circuit 156 0.9799 0.9365 0.9877 05462
Short circuit 159 0.9291 0.956 0.9406 0.5087
Spur 132 0.9665 0.803 0.8592 0.4532
Spurious copper 156 0.9221 0.9111 0.8956 0.4845

44
At 960 image resolution, missing hole again had a recall of 1. All defects had a mAP
of 0.90 and above apart from spur which had a mAP of 0.8636.
Table 4.23: Test results image size 960
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9449 0.9525 0.9436 0.5192
Missing hole 141 0.975 1 0.975 0.5921
Mousebite 126 0.8464 0.9603 0.965 0.5464
Open circuit 156 0.981 0.9944 0.9893 0.5241
Short circuit 159 0.957 0.9874 0.9512 0.5127
Spur 132 0.973 0.82 0.8636 0.4443
Spurious copper 156 0.937 0.9531 0.9177 0.4958

At 1024 image resolution, small model had a higher overall mAP than what was
achieved by nano model at 1408 image size. Spur had a maximum precision of 1 and
missing hole had the highest recall of 1.
Table 4.24: Test results image size 1024
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9517 0.9483 0.9468 0.5266
Missing hole 141 0.9752 1 0.9863 0.6336
Mousebite 126 0.8762 0.9546 0.9559 0.5331
Open circuit 156 0.9835 0.9872 0.9937 0.5381
Short circuit 159 0.9339 0.9623 0.9421 0.4974
Spur 132 1 0.8373 0.8821 0.4478
Spurious copper 156 0.9355 0.9487 0.9208 0.4894

45
At 1152 image size, mAP of every defect was above 0.90. Precision of 1 was achieved
for spur and recall of 1 was achieved for missing hole.
Table 4.25: Test results image size 1152
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9584 0.949 0.9495 0.5306
Missing hole 141 0.9767 1 0.9787 0.6164
Mousebite 126 0.8874 0.9762 0.9394 0.5683
Open circuit 156 0.9943 0.9808 0.9944 0.5583
Short circuit 159 0.9453 0.9786 0.9331 0.5088
Spur 132 1 0.8228 0.9031 0.4432
Spurious copper 156 0.9466 0.9359 0.948 0.4888

In table 4.26, precision of 1 for spur and recall of 1 for missing hole was achieved for
the third consecutive time. overall mAP was at 0.952 while open circuit had the best
individual mAP of 0.9943.
Table 4.26: Test results image size 1280
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9527 0.9422 0.952 0.5344
Missing hole 141 0.9715 1 09842 0.6072
Mousebite 126 0.9071 0.9841 0.9757 0.5763
Open circuit 156 0.9848 0.9872 0.9943 0.562
Short circuit 159 0.9232 0.9623 0.9511 0.5117
Spur 132 1 0.784 0.8887 0.4474
Spurious copper 156 0.9299 0.9359 0.9181 0.5015

46
At 1408 resolution, Open circuit had the best precision, recall and mAP. The small
model performed best at this resolution with overall mAP of 0.9525.
Table 4.27: Test results image size 1408
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9655 0.9517 0.9525 0.5348
Missing hole 141 0.9791 0.9951 0.9787 0.6154
Mousebite 126 0.9376 0.9762 0.9584 0.569
Open circuit 156 0.9962 1 0.995 0.5458
Short circuit 159 0.9328 0.9686 0.9433 0.5167
Spur 132 0.9926 0.8409 0.8954 04702
Spurious copper 156 0.9543 0.9295 0.9444 0.4918

At 1536 resolution, open circuit had the best precision of 0.9829 and missing hole had
the best recall of 0.9947. overall mAP at this resolution was 0.948.
Table 4.28: Test results image size 1536
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9582 0.9442 0.948 0.5288
Missing hole 141 0.9791 0.9947 0.9814 0.6211
Mousebite 126 0.9392 0.9921 0.983 0.5621
Open circuit 156 0.9829 0.9872 0.9869 0.5304
Short circuit 159 0.9391 0.9692 0.949 0.518
Spur 132 0.9752 0.8182 0.8584 0.4683
Spurious copper 156 0.9338 0.9039 0.9294 0.473

In the case of small YOLO model, the best results were obtained at image size of
1408.overall mAP was at 95.25%. Open circuit class had the best mAP of 99.5% and
the mAP of spurs was least among other classes at 89.54%.

47
Figure 4.13 shows the F1 score of the model. Missing hole, short circuit and open
circuit had the F1 scores above the mean line while the other three defects had the
score below the average line.

Figure 4.13: F1 score YOLOv5s at 1408 pixels


The highest precision achieved was for open circuit as can be seen in the figure 4.14
below. Overall, all the classes had the precision of 1 at 0.912 confidence.

Figure 4.14: Precision of YOLOv5s at 1408 pixels

48
Recall curve in figure 4.15 shows that the model had problems with spur and
spurious copper. The model performed better with other four defects.

Figure 4.15: Recall curve of YOLOv5s at 1408 pixels


The PR-curve shows that the small model performed best on open circuit defects with
a mAP of 0.995. In YOLOv5s mAP of all the defects was above 0.9, which was not
the case in YOLOv5n. overall the mAP was recorded at 0.956.

Figure 4.16: mAP of YOLOv5 at 1408 pixels

49
4.2.3 YOLOv5m

YOLOv5m was trained for 50 epochs. 4.99 anchors per target were selected using auto
anchoring.
This model was also trained at low hyperparameter configuration. The results of
training and validation are mentioned in the following table.
Table 4.29: Loss metrics of YOLOv5m
Box Loss Object Loss Class Loss
Train 0.01929 0.013397 0.00065
Validation 0.028498 0.017116 0.000496

The loss curves show fast drop in the loss curves compared to YOLOv5n and
YOLOv5s because of the larger size of the model. The mAP of model stabilized after
25-30 epochs.

Figure 4.17: Loss metrics of YOLOv5m

50
In the validation, the F1 score was 0.96 at 0.356 confidence. Spur and spurious
copper were slightly lower than the average line.

Figure 4.18: F1 score of YOLOv5m for validation set.


In figure 4.19 we can observe that for missing hole the precision was 1 even at 0.1
confidence level while all the classes had 1 precision at 0.905 confidence level.

Figure 4.19: Precision of YOLOv5m for validation set

51
The recall curve shows that spur had the lowest recall among the classes while recall
for missing hole and short circuit was maximum among the classes.

Figure 4.20: Recall curve of YOLOv5m for validation set


mAP of validation set in figure 4.21 shows that the model was able to learn missing
hole, mousebite, open circuit and short circuit efficiently. Spur and spurious copper’s
mAP score was greater than 0.9 but was short of the other defects.

Figure 4.21: mAP of YOLOv5m for validation set

52
4.2.3.1 Test results:

At 256 image resolution, mousebite had the highest precision of 0.6957 and highest
recall of 0.1587.
Table 4.30: Test results image size 256
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.3225 0.1231 0.08759 0.02299
Missing hole 141 0.2529 0.0922 0.0435 0.01115
Mousebite 126 0.6957 0.1587 0.196 0.05001
Open circuit 156 0.4165 0.109 0.121 0.03135
Short circuit 159 0.1125 0.2579 0.1075 0.03343
Spur 132 0.2127 0.07576 0.0358 0.007984
Spurious copper 156 0.2449 0.04487 0.0217 0.004028

At 384 image size, the model started to perform better on all the defects. Precision for
all the defects was good but recall was not up to the mark.
Table 4.31: Test results image size 384
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9238 0.5916 0.6871 0.2961
Missing hole 141 0.9268 0.5385 0.671 0.2905
Mousebite 126 0.9565 0.6111 0.7167 0.3566
Open circuit 156 0.8908 0.5833 0.6604 0.2755
Short circuit 159 0.9672 0.6289 0.7455 0.3064
Spur 132 0.9241 0.6364 0.6818 02964
Spurious copper 156 0.8777 0.5513 0.6472 0.2513

At 512 image resolution, precision for all the defects was greater than 0.90.

53
Table 4.32: Test results image size 512
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9386 0.8661 0.8752 0.456
Missing hole 141 0.9564 0.9787 0.9385 0.5477
Mousebite 126 0.9033 0.8016 0.8554 0.4722
Open circuit 156 0.9498 0.8486 0.8833 0.4496
Short circuit 159 0.919 0.9371 0.9257 0.4421
Spur 132 0.9687 0.7652 0.7853 0.3966
Spurious copper 156 0.9345 0.8654 0.8628 0.428

The model at 640 image resolution had the mAP higher than 0.90 for the first time.
open circuit and short circuit were detected with mAP of 0.9671 and 0.965
respectively.
Table 4.33: Test results image size 640
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9592 0.8767 0.9251 0.4913
Missing hole 141 0.9571 0.9787 0.9385 0.5493
Mousebite 126 0.9633 0.8016 0.916 0.5299
Open circuit 156 0.9635 0.8465 0.9671 0.4923
Short circuit 159 0.9394 0.9744 0.965 0.4983
Spur 132 0.9942 0.7955 0.8709 0.4198
Spurious copper 156 0.9374 0.8634 0.8929 0.458

At 768 resolution, missing hole had a recall of 1 while mAP of open circuit was highest
at 0.9913.

54
Table 4.34: Test results image size 768
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9501 0.929 0.9372 0.5101
Missing hole 141 0.9765 1 0.9752 0.5703
Mousebite 126 0.8971 0.9444 0.9623 0.5661
Open circuit 156 0.9739 0.9564 0.9913 0.5163
Short circuit 159 0.9481 0.9874 0.9577 0.5041
Spur 132 0.9909 0.8267 0.8644 0.4409
Spurious copper 156 0.9143 0.859 0.8726 0.463

At 896 resolution, recall for missing hole and short circuit was 1. Overall mAP of
0.9498 was achieved which was higher than the nano model at 1408 resolution.
Table 4.35: Test results image size 896
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9606 0.9461 0.9498 0.5393
Missing hole 141 0.976 1 0.9779 0.5832
Mousebite 126 0.9028 0.9588 0.955 0.6079
Open circuit 156 0.9858 0.9679 0.9928 0.5712
Short circuit 159 0.9605 1 0.967 0.5146
Spur 132 0.9915 0.8333 0.8674 0.468
Spurious copper 156 0.9466 0.9167 0.9387 0.4912

At 960 image resolution, spur had the highest precision of 0.998 while recall of 1 was
highest for missing hole.

55
Table 4.36: Test results image size 960
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9612 0.9483 0.9475 0.5325
Missing hole 141 0.9758 1 0.9805 0.5805
Mousebite 126 0.9032 0.9662 0.9605 0.5961
Open circuit 156 0.9871 0.9789 0.994 0.5311
Short circuit 159 0.9432 0.9811 0.949 0.5165
Spur 132 0.998 0.8409 0.8751 0.4655
Spurious copper 156 0.9601 0.9268 0.9256 0.5046

At 1024 resolution, precision of open circuit was highest at 0.9995 and recall of
missing hole was highest at 1. The overall mAP of 0.9583 was achieved which was
higher than the small model achieved at 1408 resolution.
Table 4.37: Test results image size 1024
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9667 0.9543 0.9583 0.535
Missing hole 141 0.9763 1 0.9885 0.5934
Mousebite 126 0.9285 0.928 0.9679 0.5846
Open circuit 156 0.9995 0.9936 0.995 0.5421
Short circuit 159 0.9512 0.9816 0.9506 0.5119
Spur 132 0.9832 0.8636 0.8947 0.4655
Spurious copper 156 0.9614 0.9591 0.9529 0.5127

At 1152 resolution, precision was 1 for open circuit and spur while recall was 1 for
missing hole and short circuit.

56
Table 4.38: Test results image size 1152
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9745 0.9667 0.9649 0.5474
Missing hole 141 0.9765 1 0.9888 0.6103
Mousebite 126 0.9284 0.9762 0.9531 0.5892
Open circuit 156 1 0.9846 0.995 0.5751
Short circuit 159 0.9614 1 0.9638 0.5172
Spur 132 1 0.8705 0.9124 0.5024
Spurious copper 156 0.9805 0.9691 0.9762 0.49

At 1280 resolution, recall for missing hole was 1 and highest mAP was for open circuit
with 0.9949.
Table 4.39: Test results image size 1280
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9715 0.9712 0.9655 0.5538
Missing hole 141 0.9776 1 0.9857 0.5913
Mousebite 126 0.9371 0.9841 0.9614 0.6046
Open circuit 156 0.997 0.9872 0.9949 0.5829
Short circuit 159 0.9572 0.9937 0.9572 0.5147
Spur 132 0.9897 0.8939 0.9334 0.5015
Spurious copper 156 0.9702 0.9679 0.9601 0.5279

At 1408 resolution, medium model achieved its maximum mAP of 0.9692. recall for
missing hole was again 1 while maximum precision was for open circuit at 0.9951.

57
Table 4.40: Test results image size 1408
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9718 0.9686 0.9692 0.557
Missing hole 141 0.9791 1 0.9781 0.5978
Mousebite 126 0.9344 0.9841 0.9595 0.5991
Open circuit 156 0.9951 0.9808 0.9949 0.5662
Short circuit 159 0.9552 0.9937 0.972 0.5391
Spur 132 0.9863 0.8788 0.9422 0.5053
Spurious copper 156 0.9806 0.974 0.9686 0.5346

At 1536 resolution, highest precision was for open circuit at 0.9982 while highest recall
was for missing hole at 1. Overall mAP was at 0.9651 which was lower than at 1408
resolution because of poor performance against spur defect.
Table 4.41: Test results image size 1536
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9633 0.971 0.9651 0.5503
Missing hole 141 0.9726 1 0.9833 0.6273
Mousebite 126 0.9082 0.9841 0.9629 0.5945
Open circuit 156 0.9982 0.9872 0.9867 0.5725
Short circuit 159 0.9531 0.9937 0.9568 0.5011
Spur 132 0.9671 0.8898 0.9287 0.4924
Spurious copper 156 0.9806 0.9714 0.9723 0.5143

The medium model of YOLOv5 turned out to be the best performing model in terms
of mean average precision among the other models. A mAP of 96.92% was achieved
at an image size of 1408. Open circuit class had the highest mAP of 99.49% and spur
had the least mAP of 94.22%. the curves of different performance metrics at 1408
pixels are shown in the following figures.

58
Figure 4.22: F1 curve of YOLOv5m model
The precision curve in figure 4.23 shows that precision for mousebite and short circuit
was lower than the other classes. Precision of 1 for all classes was achieved at 0.925
confidence level.

Figure 4.23: Precision curve of YOLOv5m at 1408 pixels

59
From the figure 4.24 we can observe that recall for all the classes was close to each
other, but spur precision was not up to the mark.

Figure 4.24: Recall curve of YOLOv5m at 1408 pixels


Highest overall mAP was achieved by the medium model. The reason for higher mAP
than other models was its ability to detect spur with high mAP. No other model
achieved mAP of 0.942 for spurs. The maximum mAP of 0.995 was achieved for open
circuit defect.

Figure 4.25: mAP of YOLOv5m at 1408 pixels

60
4.2.4 YOLOv5l

YOLOv5l was trained for 30 epochs since it is a large model and high number of
epochs can result in overfitting of the model. The model comprises of 46.5 million
parameters which is 25.3 million more than the YOLOv5m model. Low
hyperparameter configuration was used and 4.99 anchors per target were used. The
loss metrics are mentioned in the following table below.

Table 4.42: Loss metrics of YOLOv5l


Box Loss Object Loss Class Loss
Train 0.02288 0.014496 0.000889
Validation 0.028609 0.016431 0.001155

The model was trained for less epochs than the other models because of its large size.
The large model loss curves were steeper than the previous models. The model reached
validation mAP of 0.9 after just 5 epochs as can be seen in the figure 4.26 below.

Figure 4.26: Loss metrics of YOLOv5


In figure 4.27, the F1 score of large model for validation set was 0.97 at 0.534
confidence level. As in the case of YOLOv5s and YOLOv5n, the model
underperformed for classes spur and spurious copper.

61
Figure 4.27: F1 curve of validation set YOLOv5l
In the precision curve below, precision of spurious copper was below the average.
Precision of all classes was 1 at 0.897 confidence level.

Figure 4.28: Precision curve of validation set YOLOv5l


Recall of spur defects was lower than the other defects. Missing hole and short circuit
had the highest recall.

62
Figure 4.29: Recall curve of validation set YOLOv5l
mAP of validation set reached 0.963 at 0.5 IOU. Missing hole and open circuit had the
joint highest mAP of 0.995.

Figure 4.30: mAP of validation set YOLOv5l

63
4.2.4.1 Test results

For large YOLOv5 model, spurious copper had the best precision and recall at 256
image resolution.
Table 4.43: Test results image size 256
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.2133 0.1432 0.1193 0.03728
Missing hole 141 0.06275 0.1064 0.09151 0.03111
Mousebite 126 0.2978 0.1279 0.1384 0.04758
Open circuit 156 0.3044 0.1655 0.1428 0.05402
Short circuit 159 0.12 0.2579 0.1798 0.04701
Spur 132 0.4406 0.1439 0.1509 0.04096
Spurious copper 156 0.05418 0.05769 0.01267 0.002981

At 384 image size, overall precision reached at 0.9027 but recall remained low for
every defect type.

Table 4.44: Test results image size 384


Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9027 0.6574 0.7291 0.3071
Missing hole 141 0.9272 0.6321 0.7409 0.3577
Mousebite 126 0.9784 0.7183 0.7456 0.3375
Open circuit 156 0.9254 0.6154 0.6735 0.2579
Short circuit 159 0.939 0.6918 0.823 0.3452
Spur 132 0.9175 0.697 0.7363 0.2808
Spurious copper 156 0.7285 0.5897 0.655 0.2634

64
At 512 image resolution, overall mAP reached at 0.9 which was reached by nano model
at 896 resolution, small model at 768 resolution and medium model at 640 resolution.
Table 4.45: Test results image size 512
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9291 0.8729 0.9 0.4623
Missing hole 141 0.9791 0.9991 0.9827 0.5514
Mousebite 126 0.8669 0.8268 0.8979 0.5166
Open circuit 156 0.9169 0.8492 0.905 0.466
Short circuit 159 0.9183 0.956 0.9414 0.4674
Spur 132 0.9715 0.7727 0.8042 0.3837
Spurious copper 156 0.9219 0.8333 0.8686 0.3889

At 640 image resolution, overall precision, recall and mAP reached above 0.9.
Table 4.46: Test results image size 640
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9329 0.9019 0.926 0.5011
Missing hole 141 0.9546 0.9787 0.9366 0.553
Mousebite 126 0.8501 0.8889 0.9398 0.5736
Open circuit 156 0.9573 0.9167 0.9825 0.5208
Short circuit 159 0.9287 0.9748 0.9501 0.4838
Spur 132 0.9766 0.803 0.8447 0.4283
Spurious copper 156 0.9298 0.8491 0.9023 0.4469

65
Large model achieved higher mAP than what was achieved by nano model at 1408
image resolution as can be seen in the table 4.47.
Table 4.47: Test results image size 768
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.959 0.9395 0.9531 0.5167
Missing hole 141 0.9771 1 0.9841 0.5759
Mousebite 126 0.9028 0.9286 0.9648 0.5489
Open circuit 156 0.9815 0.9744 0.9932 0.5554
Short circuit 159 0.9423 0.9811 0.958 0.5154
Spur 132 0.9962 0.8182 0.8562 0.4329
Spurious copper 156 0.9542 0.9346 0.9622 0.4715

Functional defects were detected extremely well by the model at 896 image resolution.
missing hole had a mAP of 0.989, open circuit and short circuit defect both had a mAP
of 0.9948.
Table 4.48: Test results image size 896
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 09578 09557 0.9499 0.5344
Missing hole 141 0.9752 1 0.989 0.5863
Mousebite 126 0.8915 0.978 0.9581 0.6004
Open circuit 156 0.9935 0.9849 0.9948 0.5793
Short circuit 159 0.9476 0.9874 0.9948 0.5188
Spur 132 0.9777 0.8258 0.8388 0.4296
Spurious copper 156 0.9614 0.958 0.964 0.4918

66
At 960 image resolution, recall of missing hole and short circuit was 1. The overall
mAP of 0.9959 was achieved which was higher than what the YOLOv5s model
achieved at 1408 image resolution.
Table 4.49: Test results image size 960
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9589 0.9519 0.9559 0.5379
Missing hole 141 0.9753 1 0.9867 0.5934
Mousebite 126 0.9035 0.9683 0.9544 0.588
Open circuit 156 0.9936 0.9989 0.9949 0.5718
Short circuit 159 0.9604 1 0.9664 0.5263
Spur 132 0.973 0.8182 0.8819 0.4572
Spurious copper 156 0.9475 0.9259 0.9509 0.4904

At previous resolutions, precision of the model was higher than the recall but at 1024
resolution, recall was higher than precision.
Table 4.50: Test results image size 1024
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9587 0.9654 0.959 0.5364
Missing hole 141 0.9742 1 0.9897 0.6114
Mousebite 126 0.9032 0.9762 0.9577 0.5716
Open circuit 156 0.9936 0.9926 0.9949 0.5665
Short circuit 159 0.9469 0.9874 0.9471 0.5141
Spur 132 0.9729 0.8788 0.9047 0.4709
Spurious copper 156 0.9614 0.9577 0.9599 0.4839

67
At 1152 resolution, precision of spur was 1 while recall of missing hole and short
circuit was 1.
Table 4.51: Test results image size 1152
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9679 0.9667 0.962 0.5484
Missing hole 141 0.9755 1 0.9943 0.6287
Mousebite 126 0.923 0.9841 0.9581 0.5782
Open circuit 156 0.9936 0.9995 0.9949 0.5815
Short circuit 159 0.9603 1 0.9588 0.509
Spur 132 1 0.8693 0.913 0.4978
Spurious copper 156 0.9548 0.9474 0.953 0.4952

At 1280 resolution, recall for missing hole and short circuit was 1. The model achieved
overall mAP of 0.9669 which its highest but was lower than medium model by 0.0023.
Table 4.52: Test results image size 1280
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9622 0.9734 0.9669 0.5522
Missing hole 141 0.9752 1 0.985 0.6261
Mousebite 126 0.9047 0.98 0.9623 0.5901
Open circuit 156 0.9852 0.9936 0.9948 0.5878
Short circuit 159 0.9599 1 0.9656 0.5002
Spur 132 0.9897 0.8864 0.9189 0.5056
Spurious copper 156 0.9587 0.9808 0.9748 0.5036

68
At 1408 resolution, mAP of the model came down slightly. This happened because of
poor performance against spur defect.
Table 4.53: Test results image size 1408
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9608 0.9707 0.9565 0.5544
Missing hole 141 0.9757 1 0.9854 0.6179
Mousebite 126 0.9077 0.9762 0.9397 0.5789
Open circuit 156 0.9859 0.9936 0.9949 0.5914
Short circuit 159 0.9606 1 0.9691 0.5171
Spur 132 0.9835 0.9055 0.9089 0.51
Spurious copper 156 0.9515 0.9487 0.9409 0.5109

At 1536 image resolution, short circuit had recall of 1 and highest mAP was of missing
hole at 0.9905.
Table 4.54: Test results image size 1536
Class Labels Precision Recall mAP 0.5 mAP 0.5:0.95
All 870 0.9693 0.9555 0.9623 0.557
Missing hole 141 0.9791 0.9967 0.9905 0.6414
Mousebite 126 0.9209 0.9762 0.9662 0.5832
Open circuit 156 0.9868 0.9744 0.9856 0.6096
Short circuit 159 0.962 1 0.9658 0.4995
Spur 132 0.9936 0.8561 0.9143 0.5059
Spurious copper 156 0.9731 0.9295 0.9514 0.5021

The performance of large model was best observed at image size of 1280. Class wise
trend remained the same for this model as well with highest mAP achieved for open
circuit at 99.48% and lowest mAP of 91.89% achieved for spurs. The curves of F1
score, precision, recall, and mAP at 1280 image size are shown in the following
figures.

69
F1 score of mousebite and spur was low compared to the other defects as can be seen
in the figure 4.31 below.

Figure 4.31: F1 score of YOLOv5l at 1280 pixels


Precision of spur was maximum at 1280 pixels while mousebite had the lowest
precision.

Figure 4.32: Precision of YOLOv5l at 1280 pixels

70
In Figure 4.33 Recall of missing hole and short circuit was 1 which is the highest
possible value. In the previous figure 4.32 spur had the highest precision but in this
case the recall of the spur defect is extremely poor.

Figure 4.33: Recall of YOLOv5l at 1280 pixels


The mAP of open circuit was highest with 0.995. spur had the lowest mAP of 0.922.
large model outperformed medium model with higher or equal mAP in detecting
missing hole, mousebite, open circuit and spurious copper but because of lower mAP
of short circuit and spur the overall mAP was not able to exceed the medium model.

Figure 4.34: mAP of YOLOv5l at 1280 pixels.

71
4.3 Inference Time

Inference time is the amount of time taken by a model to output a prediction. In this
section we will see the inference times of different models on different images sizes.
For detection purposes, the longest side of the image was set to 1408 pixels for nano,
small and medium YOLOv5 models because at this resolution the results were best.
The longer side for large model was set at 1280 pixels. The shorter side of the image
is adjusted accordingly to maintain aspect ratio and yield best predictions. The
following tables (4.55-58) show the inference speeds of different models on PCBs
using Tesla K80 GPU and Tesla T4.
Table 4.55: Inference time of YOLOv5n
PCB Original Processed Inference Inference
Resolution Resolution Time Tesla Time Tesla
K80 (ms) T4 (ms)
01 3034x1586 1408x736 31 12
02 2904x1921 1408x960 37 14
03 2775x2159 1408x1120 41 15
04 3056x2464 1408x1152 43 15
05 2240x2016 1408x1280 47 17
06 2529x2530 1408x1408 50 18

Table 4.56: Inference time of YOLOv5s


PCB Original Processed Inference Inference
Resolution Resolution Time Tesla Time Tesla
K80 (ms) T4 (ms)
01 3034x1586 1408x736 68 24
02 2904x1921 1408x960 87 33
03 2775x2159 1408x1120 98 35
04 3056x2464 1408x1152 100 35
05 2240x2016 1408x1280 100 38
06 2529x2530 1408x1408 102 44

72
Table 4.57: Inference time of YOLOv5m
PCB Original Processed Inference Inference
Resolution Resolution Time Tesla Time Tesla
K80 (ms) T4 (ms)
01 3034x1586 1408x736 121 54
02 2904x1921 1408x960 157 76
03 2775x2159 1408x1120 189 80
04 3056x2464 1408x1152 194 81
05 2240x2016 1408x1280 216 82
06 2529x2530 1408x1408 241 83

Table 4.58: Inference time of YOLOv5l


PCB Original Processed Inference Inference
Resolution Resolution Time Tesla Time Tesla
K80 (ms) T4 (ms)
01 3034x1586 1280x672 188 69
02 3056x2464 1280x864 246 72
03 2904x1921 1280x1024 323 82
04 2775x2159 1280x1056 327 90
05 2240x2016 1280x1152 360 92
06 2529x2530 1280x1280 400 100

4.4 Test Images

Detections were carried out on the test dataset for each model. In this section we will
look at the instances where correct detections were made and the instances where the
model failed to detect a defect or misclassified it.

4.4.1 Correct Predictions

Given below are the few examples of correct predictions made by the YOLOv5
models. Figure 4.35 shows all three correct predictions for missing hole. A total of 3
defects were present in the image.

73
Figure 4.35: Missing hole correct predictions
Figure 4.36 shows the correct predictions made for the 3 mousebite defects present in
the image.

Figure 4.36: Predictions for mousebite defect.

74
In the Figure 4.37, correct predictions were made for the open circuit defect. A total of
5 defects were present and all 5 were easily detected.

Figure 4.37: Predictions for open circuit defects.


The following Figure 4.38 shows the detections of short circuit on a PCB with 6
defects.

Figure 4.38: Correct predictions for short circuit.

75
4.4.2 Failure Cases

This section contains images that were not properly detected by the YOLOv5 models.
The Figure 4.39 shows an example of misclassification where an open circuit defect is
classified as a mousebite.

Figure 4.39: misclassification of open circuit


The image in figure 4.40 is an example of false negative. One spur defect was detected
but the other spur defect was left undetected.

Figure 4.40: False negative example


Figure 4.41 is an example of misclassification where one spur defect was detected as
spur and as well as an open circuit defect. This happened because the spur defect
resembled as an open circuit defect and was detected by another grid cell.

76
Figure 4.41: Misclassification example
In Figure 4.42 model performed double detection of the single object. Single spurious
copper was detected twice but unlike in the previous case in figure 4.41 both detections
were correct for this PCB.

Figure 4.42: Dual detection of single object.


The figure 4.43 below shows false negative and false positive. Missing hole was not
detected while a gap was detected as an open circuit.

77
Figure 4.43: False negative and False positive predictions.

4.5 Discussion of Results

In this section, the pros and cons of the different YOLOv5 models based on the
obtained results will be thoroughly discussed.

4.5.1 YOLOv5n

From the results we can deduce that YOLOv5n performance at small resolutions was
poor. At 512 image size, the model was only able to detect missing hole defect with a
mean average precision of over 90%. The model started to perform better on defects
at 768 image size, but spur and spurious copper were not detected with high recall rate.
At 1024 image resolution the model was able to detect functional defects with
extremely high mAPs. The best results for YOLOv5n were obtained at 1408x1408
pixels with 94.64% mean average precision. The model starts to lose its accuracy at
resolutions above 1408, this is mainly because of the reason that the model was trained
at 960 image size. Even though YOLOv5n is the smallest model with 1.9 million. The
model performed extremely well in detecting missing hole and open circuit defects
with mean average precision of 99.18% and 99.37% respectively. Recall for missing
hole was 1 at image resolutions of 896, 1024 and 1152. The model overall performance
was downgraded because of the spur defects because it had the poor recall of just
78
79.9%. Nano model had issues in detecting small defects. In terms of inference time,
YOLOv5n was the fastest model with detection speed of 18 millisecond for an image
of size 1408x1408 using Tesla T4 GPU.

4.5.2 YOLOv5s

Results of YOLOv5s were slightly better than the results of nano model at low
resolutions. The model had mAP of above 90% for functional defects at image size of
640. For better inference times, image size of 640 can be used for functional defect
detection. YOLOv5s performed well at 1408x1408 image resolution. Even though
spur defect had a maximum precision of 1 at three different image sizes, the overall
result was affected by the poor recall rate of the model. For the spur defect. Best mean
average precision achieved was 95.6%. best precision was achieved at 1280x1280 test
size with 96.74% and best recall was achieved at 1024x1024 images with 95.25%.
there were number of instances where precision of some defects was 1 which means
that no false positives were detected and recall of some defects was 1 which means
that no defects were left undetected. The following table 4.59 shows the defects and
the resolution(s) at which their precision or recall was 1. YOLOv5s is also very fast in
detection since it has inference speeds of 24 milliseconds for and image size of
1408x736 and 44 milliseconds for 1408x1408.

Table 4.59: Defects with 1 precision or recall for small model.


Precision
Defect Type Resolution
Spur 1024, 1152, 1280
Recall
Missing hole 896, 960, 1024, 1152, 1280
Open circuit 1408

4.5.3 YOLOv5m

Medium model was fast at learning features about the defects. At just 640 image size,
the model had a mean average precision of 92.51% with open circuit and short circuit
both having a mAP of over 96%. In case of nano and small models, missing hole was
79
leading the mAP score at low resolution but in medium model open and short circuit
defects were detected with high mAP score. Medium model had the best mean average
precision at 1408 image size with 96.92%. This model achieved the maximum mean
average precision on the PCB dataset. The reason for its success is that the model was
able to detect spur defects with higher mean average precision which was not the case
in other models. In this model there were also some instances where model perfect
score for precision and recall for different defects. These are mentioned in the table
4.60 below. Inference times of medium model were slower than nano and small models
because of its large size but it was not slow enough to have an adverse effect on its
performance. For a small image of size 1408x736, the medium model was detecting
images at 54 milliseconds or approximately 19 FPS.

Table 4.60: Defects with 1 precision or recall for medium model.


Precision
Defect Type Resolution
Spur 1152
Open circuit 1152
Recall
Missing hole 768, 896, 960, 1024, 1152, 1280, 1408,
Short circuit 896,
15361152

4.5.4 YOLOv5l

Large model was the fastest model to reach 90% mAP. At just 512 image resolution,
the model had mAP scores for missing hole, short circuit, and open circuit above 90%.
When tested at 768 image size, the model had a mean average precision of 95.31%
which was higher than the best mAPs of YOLOv5n and YOLOv5s. the mAP was
slightly reduced to 94.99% at 896 image size mainly due to poor performance at
detecting mousebite and spur defect, but the model gained mAP score from 960 image
size till 1280 image size. One trend that was observed at majority of test resolutions
was that precision of mousebite was lowest among other classes while recall for spur
defect was lowest among the classes. Unlike other models, YOLOv5l achieved
maximum mean average precision at 1280 image resolution. Mean average precision
80
was 96.69% which was very close to the medium model. With respect to class the large
model outperformed the medium model in missing hole, mousebite, and spurious
copper but because of the poor result on spurs, the overall mean average precision was
less than that of the medium model. Inference times for the large model were highest
because of the large number of parameters. The large model was taking 69
milliseconds for an image of size 1280x672 and 100 milliseconds for a 1280x1280
image.

Table 4.61: Defects with 1 precision or recall for large model.


Precision

Defect Type Resolution

Spur 1152

Recall

Missing hole 768, 896, 960, 1024, 1152, 1280, 1408

Short circuit 960, 1152, 1280, 1408, 1536

4.5.5 Selecting a Model

Based on the results obtained in the thesis, this section will discuss whether a model is
suitable for a certain task or not.
Mean average precisions of all the models were above 90% on the test dataset but
inference times of nano and small models was very low compared to medium and large
models. If inference time is important than small and nano model are suitable for PCB
defect detection. If accuracy is important than medium and large model offer more
accurate results. Large model has slightly lower mean average precision than medium
model but has high inference time at high resolution images. Small and nano models
are fast but less accurate than the medium model. So, it can be said that the medium
model provides a good balance between accuracy and inference times. Medium and
large models can also be used at low resolutions if the task is to detect functional
defects and not the cosmetic defects. Nano and small models are suitable for use in
mobile applications because of their small storage requirements. Nano model has a
weight file of 11 megabytes and small model with a size of 41 megabytes.

81
Chapter 5: Conclusion
Different models of YOLOv5 were trained on the PCB defect dataset. Nano, small,
medium, and large models were first trained at 640-pixel images. The results of mean
average precision were in the region of 90% or above but the mAP decreased rapidly
when the trained models were tested on higher resolution images. Later, these models
were trained at 960-pixel images for better accuracies. Since the dataset included high
resolution images, training the models at 960 image size yielded better results. The
best results were obtained by the medium model at 1408 pixels with a mAP of 96.92%.
All models found it difficult to correctly detect smaller defects such as spurs and
mousebite but models that were trained at 960 image resolution were more reliable at
detecting smaller defects than the models trained at 640 pixels. The large model had
the similar mAP values to the medium model but had high inference time and was
computationally expensive.

5.1 Future Work:

Even though the mean average precision was improved than the benchmark papers and
the models were made robust with the addition of Gaussian noise and other
augmentations, there is still room for improvement. Following are the ways in which
the system can be made better.
1. Train the dataset on YOLOv5 models designed for training images at 1280
image resolution.
2. Increase the number of images per class.
3. Increase the number of classes to incorporate more defect types.
4. Perform multi-scale training to increase accuracy over a wide range of image
resolutions.
5. Develop a cellphone application using YOLOv5n or YOLOv5s which are
lightweight models.

82
REFERENCES

[1] P. Hadi, M. Xu, C. S. K. Lin, C. W. Hui, and G. McKay, “Waste printed circuit
board recycling techniques and product utilization,” J. Hazard. Mater., vol. 283,
pp. 234–243, 2015, doi: 10.1016/j.jhazmat.2014.09.032.

[2] “Printed Circuit Board Market | 2021 - 26 | Industry Share, Size, Trends -
Mordor Intelligence.” https://www.mordorintelligence.com/industry-
reports/printed-circuit-board-market (accessed Jan. 20, 2022).

[3] J. LaDou, “Printed circuit board industry,” Int. J. Hyg. Environ. Health, vol.
209, no. 3, pp. 211–219, May 2006, doi: 10.1016/J.IJHEH.2006.02.001.

[4] J. Kingsland, “Photo-imageable screen printed soldermasks,” Circuit World,


vol. 13, no. 4, pp. 10–13, Mar. 1987, doi: 10.1108/EB043890/FULL/XML.

[5] K. Clay, I. Gardner, E. Bresler, M. Seal, and S. Speakman, “Direct legend


printing (DLP) on printed circuit boards using piezoelectric inkjet technology,”
Circuit World, vol. 28, no. 2, pp. 24–31, 2002, doi:
10.1108/03056120210412526/FULL/XML.

[6] S. H. Indera Putera and Z. Ibrahim, “Printed circuit board defect detection using
mathematical morphology and MATLAB image processing tools,” ICETC
2010 - 2010 2nd Int. Conf. Educ. Technol. Comput., vol. 5, no. March 2015,
2010, doi: 10.1109/ICETC.2010.5530052.

[7] D. B. Anitha and M. Rao, “A survey on defect detection in bare PCB and
assembled PCB using image processing techniques,” Proc. 2017 Int. Conf.
Wirel. Commun. Signal Process. Networking, WiSPNET 2017, vol. 2018-Janua,
pp. 39–43, 2018, doi: 10.1109/WiSPNET.8299715.

[8] J. Nayak, B. D. Parameshachari, K. M. S. Soyjaudah, Rajashekarappa, R. Banu,


and N. A C, “Identification of PCB Faults using Image Processing,” in 2017
International Conference on Electrical, Electronics, Communication,
Computer, and Optimization Techniques (ICEECCOT), 2017, pp. 1–4, doi:
10.1109/ICEECCOT.2017.8284602.

[9] A. A. I. M. Hassanin, F. E. Abd El-Samie, and G. M. El Banby, “A real-time


approach for automatic defect detection from PCBs based on SURF features

83
and morphological operations,” Multimed. Tools Appl., vol. 78, no. 24, pp.
34437–34457, 2019, doi: 10.1007/s11042-019-08097-9.

[10] C. Ma, J. X. Mao, and J. P. Mao, “Research and develop on PCB defect
intelligent visual inspection robot,” in 2012 Symposium on Photonics and
Optoelectronics, 2012, pp. 1–4, doi: 10.1109/SOPO.2012.6271078.

[11] S.-F. Chuang, W.-T. Chang, C.-C. Lin, and Y.-S. Tarng, “Misalignment
inspection of multilayer PCBs with an automated X-ray machine vision
system,” Int. J. Adv. Manuf. Technol., vol. 51, pp. 995–1008, 2010, doi:
10.1007/s00170-010-2664-9.

[12] S. Kumar, Y. Iwahori, and M. K. Bhuyan, “PCB Defect Classification Using


Logical Combination of Segmented Copper and Non-copper Part,” in
Proceedings of International Conference on Computer Vision and Image
Processing, 2016, vol. 1, pp. 523–532, doi: 10.1007/978-981-10-2104-6_47.

[13] P. Wei, C. Liu, M. Liu, Y. Gao, and H. Liu, “CNN‐based reference comparison
method for classifying bare PCB defects,” J. Eng., vol. 2018, no. 16, pp. 1528–
1533, 2018, doi: 10.1049/joe.2018.8271.

[14] K. Simonyan and A. Zisserman, “Very Deep Convolutional Networks for


Large-Scale Image Recognition,” arXiv. doi: 10.48550/ARXIV.1409.1556.

[15] K. He, X. Zhang, S. Ren, and J. Sun, “Deep Residual Learning for Image
Recognition,” in IEEE Conference on Computer Vision and Pattern
Recognition (CVPR), 2016, pp. 770–778, [Online]. Available: http://image-
net.org/challenges/LSVRC/2015/.

[16] B. Ghosh, M. K. Bhuyan, P. Sasmal, Y. Iwahori, and P. Gadde, “Defect


classification of printed circuit boards based on transfer learning,” in
Proceedings of 2018 IEEE Applied Signal Processing Conference, ASPCON,
2018, pp. 245–248, doi: 10.1109/ASPCON.2018.8748670.

[17] C. Szegedy, V. Vanhoucke, S. Ioffe, J. Shlens, and Z. Wojna, “Rethinking the


Inception Architecture for Computer Vision,” in IEEE Conference on Computer
Vision and Pattern Recognition (CVPR), 2016, pp. 2818–2826.

[18] C. Zhang, W. Shi, X. Li, H. Zhang, and H. Liu, “Improved bare PCB defect
detection approach based on deep feature learning,” J. Eng., vol. 2018, no. 16,
84
pp. 1415–1420, 2018, doi: 10.1049/joe.2018.8275.

[19] O. Russakovsky et al., “ImageNet Large Scale Visual Recognition Challenge,”


Int. J. Comput. Vis., vol. 115, no. 3, pp. 211–252, Dec. 2015, doi:
10.1007/S11263-015-0816-Y/FIGURES/16.

[20] H. Xin, Z. Chen, and B. Wang, “PCB Electronic Component Defect Detection
Method based on Improved YOLOv4 Algorithm,” J. Phys. Conf. Ser., vol.
1827, no. 1, 2021, doi: 10.1088/1742-6596/1827/1/012167.

[21] Y. T. Li, P. Kuo, and J. I. Guo, “Automatic Industry PCB Board DIP Process
Defect Detection with Deep Ensemble Method,” in IEEE International
Symposium on Industrial Electronics, 2020, pp. 453–459, doi:
10.1109/ISIE45063.2020.9152533.

[22] J. Kim, J. Ko, H. Choi, and H. Kim, “Printed circuit board defect detection using
deep learning via a skip-connected convolutional autoencoder,” Sensors, vol.
21, no. 15, 2021, doi: 10.3390/s21154968.

[23] L. Liu et al., “Deep Learning for Generic Object Detection: A Survey,” Int. J.
Comput. Vis., vol. 128, no. 2, pp. 261–318, Feb. 2020, doi: 10.1007/S11263-
019-01247-4/TABLES/2.

[24] J. Redmon, S. Divvala, R. Girshick, and A. Farhadi, “You only look once:
Unified real-time object detection.,” in Proc. IEEE Conf. Comput. Vis. Pattern
Recognit., 2016, pp. 779–788.

[25] L. Wei, D. Anguelov, D. Erhan, C. Szegedy, S. Reed, and C.-Y. Fu, “SSD:
Single shot multibox detector,” in Computer vision ECCV2016 14th European
conference proceedings Part I (eds B. Leibe, J. Matas, N. Sebe, & M. Welling).,
2016, pp. 21–37.

[26] J. Redmon and A. Farhadi, “YOLO9000: Better, Faster, Stronger,” in


Proceedings of the IEEE Conference on Computer Vision and Pattern
Recognition (CVPR), 2017, pp. 7263–7271.

[27] J. Redmon and A. Farhadi, “YOLOv3: An Incremental Improvement,” Apr.


2018, Accessed: Mar. 18, 2022. [Online]. Available:
http://arxiv.org/abs/1804.02767.

[28] A. Bochkovskiy, C.-Y. Wang, and H.-Y. M. Liao, “YOLOv4: Optimal Speed
85
and Accuracy of Object Detection,” Apr. 2020, doi:
10.48550/arxiv.2004.10934.

[29] C.-Y. Wang, H.-Y. M. Liao, Y.-H. Wu, P.-Y. Chen, J.-W. Hsieh, and I.-H. Yeh,
“CSPNet: A New Backbone that can Enhance Learning Capability of CNN,” in
Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern
Recognition (CVPR) Workshops, 2020, pp. 390–391.

[30] K. He, X. Zhang, S. Ren, and J. Sun, “Spatial Pyramid Pooling in Deep
Convolutional Networks for Visual Recognition,” in Lecture Notes in Computer
Science (including subseries Lecture Notes in Artificial Intelligence and Lecture
Notes in Bioinformatics), vol. 8691 LNCS, no. PART 3, Springer Verlag, 2014,
pp. 346–361.

[31] S. Liu, L. Qi, H. Qin, J. Shi, and J. Jia, “Path Aggregation Network for Instance
Segmentation,” in Proceedings of the IEEE Computer Society Conference on
Computer Vision and Pattern Recognition, Mar. 2018, pp. 8759–8768, doi:
10.48550/arxiv.1803.01534.

[32] G. Jocher et al., “ultralytics/yolov5: v6.1 - TensorRT, TensorFlow Edge TPU


and OpenVINO Export and Inference,” Feb. 22, 2022.
https://zenodo.org/record/6222936 (accessed Mar. 21, 2022).

[33] A. Paszke et al., “PyTorch: An imperative style, high-performance deep


learning library,” in Advances in Neural Information Processing Systems, 2019,
vol. 32, no. NeurIPS.

[34] “GitHub - ultralytics/yolov5: YOLOv5 in PyTorch > ONNX > CoreML >
TFLite.” https://github.com/ultralytics/yolov5 (accessed Apr. 07, 2022).

[35] H. Wu, W. Gao, and X. Xu, “Solder Joint Recognition Using Mask R-CNN
Method,” IEEE Trans. Components, Packag. Manuf. Technol., vol. 10, no. 3,
pp. 525–530, 2020, doi: 10.1109/TCPMT.2019.2952393.

[36] W. Huang and P. Wei, “A PCB Dataset for Defects Detection and
Classification,” vol. 14, no. 8, pp. 1–9, 2019, [Online]. Available:
http://arxiv.org/abs/1901.08204.

[37] A. Awad, “Denoising images corrupted with impulse, Gaussian, or a mixture of


impulse and Gaussian noise,” Eng. Sci. Technol. an Int. J., vol. 22, no. 3, pp.
86
746–753, Jun. 2019, doi: 10.1016/J.JESTCH.2019.01.012.

[38] OpenCV, “Open Source Computer Vision Library.” 2015.

[39] D. Choi, C. J. Shallue, Z. Nado, J. Lee, C. J. Maddison, and G. E. Dahl, “On


Empirical Comparisons of Optimizers for Deep Learning,” Oct. 2019, doi:
10.48550/arxiv.1910.05446.

87
Appendix A

Random Gaussian Noise Code


import cv2 as cv
import matplotlib.pyplot as plt
from skimage.util import random_noise
import glob
import numpy as np
from numpy import random
import os
from collections import Counter

file = r'C:\Users\pc\Jupyter_codes\PCBdataset_training\val\Spurious_copper\*.jpg'
glob.glob(file)

images = [cv.imread(image) for image in glob.glob(file)]

print (len(images))

path = r'C:\Users\pc\Jupyter_codes\PCBdataset_training\val\Spurious_copper'

file_names = os.listdir(path)
save_path = r'C:\Users\pc\Jupyter_codes\Gaussian_Noise_vol3\val\Spurious_copper'

i =0
variance= random.randint(1,4, len(images)) /100
c = Counter(variance)

plt.figure()
plt.title('Gaussian Noise Variance for Spurious copper (validation set)')
plt.xlabel('Variance')
plt.ylabel('Number of Images')
plt.bar(c.keys(), c.values(), width= 0.005)
plt.xlim([0,0.04])
plt.show()

for i in range (len(images)):

var1 = variance[i]
img = images[i]
noise_img1= random_noise(img, mode = 'Gaussian', seed=
None, clip=True, mean = 0.0 ,var = var1)
final_image = cv.normalize(noise_img1, None, 0 , 255, c
v.NORM_MINMAX, cv.CV_8UC3)
name =file_names[i]
Final_name = name.replace(".jpg",
88 "_GN.jpg")
cv.imwrite(os.path.join(save_path, Final_name), final_i
mage)

print('Transfer Successful')
for i in range (len(images)):

var1 = variance[i]
img = images[i]
noise_img1= random_noise(img, mode = 'Gaussian', seed= None, clip=True , mean = 0.
0 ,var = var1)
final_image = cv.normalize(noise_img1, None, 0 , 255, cv.NORM_MINMAX, cv.CV_8
UC3)
name =file_names[i]
Final_name = name.replace(".jpg", "_GN.jpg")
cv.imwrite(os.path.join(save_path, Final_name), final_image)

print('Transfer Successful')
print (c.keys())
print(c.values())

Random Brightness and Contrast Code


import cv2 as cv
import matplotlib.pyplot as plt
from skimage.util import random_noise
import glob
import numpy as np
from numpy import random
import os
from collections import Counter

file = r'C:\Users\pc\Jupyter_codes\PCBdataset_training\train\Spurio
us_copper\*.jpg'
glob.glob(file)

images = [cv.imread(image) for image in glob.glob(file)]


print (images)
print (len(images))

path = r'C:\Users\pc\Jupyter_codes\PCBdataset_training\train\Spurio
us_copper'

file_names = os.listdir(path)

save_path = r'D:\MS-19\Thesis\Brightness_Contrast\train\Spurious_co
pper'

alpha= random.randint(10,16, len(images))/10


beta = random.randint(1,51, len(images))

alpha_count = Counter(alpha) 89
beta_count = Counter(beta)

plt.figure()
alpha= random.randint(10,16, len(images))/10
beta = random.randint(1,51, len(images))

alpha_count = Counter(alpha)
beta_count = Counter(beta)

plt.figure()
plt.title('Contrast for Spurious Copper (Train set)')
plt.xlabel('Contrast')
plt.ylabel('Number of Images')
plt.bar(alpha_count.keys(), alpha_count.values(), width= 0.08)
plt.xlim([0.9,1.6])
y_lim_C = alpha_count.values()
plt.yticks(np.arange(0, max(y_lim_C)+1, 2))

plt.figure()
plt.title('Brightness for Spurious Copper (Train set)')
plt.xlabel('Brightness')
plt.ylabel('Number of Images')
plt.bar(beta_count.keys(), beta_count.values(), width= 0.8)
x_lim_B=[1,51]
y_lim_B = beta_count.values()
plt.xticks(np.arange(min(x_lim_B), max(x_lim_B)+1, 2))
plt.yticks(np.arange(min(y_lim_B)-1, max(y_lim_B)+1, 1))
plt.show()

for i in range (len(images)):

alpha_val = alpha[i]
beta_val = beta[i]
img = images[i]
final_image= cv.addWeighted(img, alpha_val, np.zeros(img.sh
ape, img.dtype), 0 , beta_val)
name =file_names[i]
Final_name = name.replace(".jpg", "_BC.jpg")
cv.imwrite(os.path.join(save_path, Final_name), final_image
)

print('Transfer Successful')

90
Google Colaboratory Code
!nvidia-smi
In [ ]:
from google.colab import drive
drive.mount('/content/drive')
In [ ]:
from google.colab import drive
drive.mount('/content/gdrive')
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive
In [ ]:
!unzip /content/drive/MyDrive/YOLOv5_vol3/PCB_Dataset_T
raining_vol3.zip
In [ ]:
!git clone https://github.com/ultralytics/yolov5.git
In [ ]:
%cd yolov5/
In [ ]:
!pip install -r requirements.txt
In [ ]:
!python train.py --img 384 --batch 8 --epochs 2 --data
coco128.yaml --weights yolov5n.pt --cache
In [ ]:
%reload_ext tensorboard
%tensorboard --logdir runs/train
In [ ]:
!python val.py --weights /content/drive/MyDrive/yolov5
_960_weights/yolov5n_960.pt --batch 1 --data coco128.ya
ml --img 256 --iou 0.5 --task test
In [ ]:
!python detect.py --source /content/PCB_Dataset_Trainin
g_vol3/Test --weights /content/drive/MyDrive/yolov5_960
_weights/yolov5n_960.pt --img 256 --save-txt --save-con
f
In [ ]:
!zip -r /content/yolov5l_detection_images.zip /content/
yolov5/runs/detect/exp2/

91
Appendix B

Feature maps of a PCB with 3 open circuit defects have been generated. The maps
show what the filters focus and learn features at different stages of the architecture.
Feature maps of some stages have been presented. Blue feature maps mean that the
filters are not extracting relevant information while bright yellow colour means that
the model is learning features of an image.
Input Image:

Figure B.1: Input image to the network.


Focus Stage:
At stage 0 the model tries to learn every feature about the PCB and take in as much
information as possible.

Figure B.2: Feature maps at focus stage.

92
First Convolution Stage:
At this stage, some filters learn about horizontal trace and some about background.

Figure B.3: Feature maps at first convolution stage.


First C3 x3 Stage:
The model is learning and trying to separate copper traces and background.

Figure B.4: Feature maps at CSP bottleneck.

93
Second Convolution Stage:
Some filters are learning copper traces, some are learning about holes.

Figure B.5: Feature maps at second convolution stage


Fourth Convolution Stage:
At this stage the image is scaled down by a factor of 30. The model starts to learn deep
features and it is hard to explicitly decide what it is trying to learn but we can see the
areas under consideration by the filters.

Figure B.6: Feature maps of fourth convolution stage.

94
Eighth Convolution Stage:

At this stage some filters are concentrating on the open circuit defects marked by three
bright yellow dots.

Figure B.7: Feature maps at eighth convolution stage.

Output Image:

Figure B.8: Output detection image.

95
Completion Certificate

It is certified that the thesis titled “Automated Optical Inspection of Printed circuit
boards using Machine Vision” submitted by CMS ID. 0000031885, NS Wajih
Ahmed Khan of MS-2019, Mechatronics engineering is complete in all respects as
per the requirements of Main Office, NUST (exam branch)

Supervisor: ___________________
Dr. Amir Hamza
Date: ________, August, 2022

96

You might also like