Chapter 4
Chapter 4
CHAPTER 4
4.1 INTRODUCTION
4.2 METHODOLOGY
The difficulty of PCB defect detection lies in the fact that the area of
the minor defect and the defect characteristics are not apparent without enlarging
the picture; that is, it is difficult to be extracted by the classifier, and serious missed
detection exists, which cannot meet the practical requirements of the production
inspection link. To overcome the difficulties posed by small targets and restricted
features, this chapter proposes an attention-inclusive DenseNet121 with a
hyperparameter-tuned GRU network to enhance feature extraction and classify
defects in PCBs. The working architecture of the proposed PCB defect detection
in the system is shown in Figure 4.1. The preprocessing stage utilizes CLAHE for
image contrast enhancement and AMF for noise rejection on the raw PCB dataset
to enhance image quality. The KM-SMOTE is used in the data balancing block to
address the limitations imposed by data class imbalance and data scarcity.
The system introduces the SCDSNT121 in the feature extraction block to capture
the features of the balanced PCB dataset. Finally, the ROGRU is developed to
96
classify the six types of defect classes, where the SCRSO algorithm optimizes the
hyperparameters, including learning rate, epochs, weights, and bias, to reduce the
classification loss. The following sections provide a brief explanation of these
phases. Figure 4.1 shows the Workflow of the proposed ROGRU approach and
Table 4.1 shows the deign and functionality of the proposed pipeline stages.
4.2.1 Preprocessing
Initially, the system collects defect data from the publicly available
Deep PCB database. Then, the preprocessing step takes place, which is essential
for improving the quality of PCB images and ensuring that the deep learning
model effectively learns defect patterns. Preparing and converting original data
into a suitable format for the training methods is part of it. The preprocessing
pipeline consists of two steps designed to standardize the dataset, enhance image
features, and optimize model performance. The first step is to improve contrast to
achieve a clear vision of the image. The next step involves noise filtering to
remove unwanted noise from the PCB image.
98
adjusts the size of the filtering window for each pixelto effectively differentiate
between noise and valid structural patterns on the PCB surface. AMF operates in
two phases: first, it estimates the kernel’s middle value; second, it determines
whether the present pixel value is an impulse (salt and pepper noise). If the pixel
is detected as corrupted, it is replaced with the computed middle value; otherwise,
the original grayscale pixel value is retained. This adaptive mechanism helps
effectively remove noise while preserving critical edge and texture details in the
PCB image. The working process is briefly explained as follows:
computes the top value NFmx , middle value NFmedian , and bottom value NFmi in the
filtering window. If the condition NFmx NFmedian NFmi holds, it indicates that the
window contains a mix of corrupted and uncorrupted pixels, and the algorithm
proceeds to evaluate the central pixel. When the pixel satisfies NFmx NFab Bmi ,
the filtering window is adaptively expanded to improve detection sensitivity.
If not, the pixel is assumed to be corrupted and replaced with the median value of
the surrounding pixels. This iterative process continues until a suitable window
size is found or all impulse noise is removed. Through this adaptive mechanism,
the AMF not only eliminates high-density noise but also preserves fine-grained
defect features, which are critical for accurate PCB defect classification.
minority class. The KM-SMOTE method is employed to balance the dataset and
address this issue. SMOTE is an oversampling method that balances the original
training dataset. The synthetic sample generation is the central concept of the
SMOTE approach, instead of iterating over minority class samples. These samples
are made particularly to replicate the properties of raw data. However, SMOTE
randomly synthesizes minority instances along the line segments connecting
minority samples and their selected nearest neighbors, while ignoring nearby
instances of the majority class. This can lead to the generation of synthetic samples
in regions heavily populated by majority instances, which increases the risk of
misclassification. So, the system first applies the K-means clustering algorithm to
group the minority instances within the dataset. Oversampling is then performed
separately within each cluster. This clustering-based approach mitigates the issue
of SMOTE ignoring nearby majority instances by localizing the oversampling
process. As a result, KM-SMOTE enhances the representation of minority classes,
improving the classifier’s performance and generalization ability. The process
involved in the KM-SMOTE is explained as follows:
Let PBS PB1 , PB2 , PB3 ,......PBN be the set of samples in the
pre-processed PCB defect dataset, where each sample belongs to either the
majority class (non-defective) or the minority class (defective). Then, group only
the minority class samples from PBS to form a new subset PBMin . Then, apply the
K-means clustering algorithm to new subset PBMin to divide the minority class
samples into k clusters C1 , C2 ,.......Ck . For each minority sample PBi PBMin ,
compute the Euclidean distance to each centroid and assign PBi to the nearest
cluster. It is defined as in Equation (4.1).
where, PBi indicates the minority sample and C j denotes the centroid of the cluster
points until convergence. Then, a new minority sample can be created by filtering
clusters with fewer minority classes and choosing clusters with more minority
classes. Next, perform SMOTE oversampling on each filtered cluster. In this
method, interpolation is used between a selected sample from the minority class
PBi and one of its closest neighbours k to produce new synthetic samples PBnew ,
which is calculated using Equation (4.2):
PBnew PBm PBz PBm (4.2)
to capture prominent features, such as textures, edges, and corners, allowing the
network to identify key patterns and providing an output in the form of a feature
map. The convolution layer also has a stride of 2, which essentially means that the
kernel moves 2 pixels at a time, skipping some regions of the input PCB image to
assist in reducing the dimensions, a process known as downsampling. This allows
for lower computational costs and prevents overfitting. The convolution process
is equated as in Equation (4.3),
~
LCEu u . f R u 1 AC (4.3)
u ~
where, LCE refers to the convolutional layer’s output feature maps, u is the u th
-layer neuron status, u and AC represents the weight matrix and bias from
u 1th to R
the u th , and f represents the ReLU activation function, which is
followed directly by the pooling layer. The pooling window padding, stride, and
size are 1, 2, and 3×3, respectively. The model’s capability to extract local features
of the image is impacted by the pooling window size, which estimates the number
of features pooled within each window. By following this layer, there is a four
dense block layer. Regardless of the number of filters, each Dense block has a
fixed feature map dimension. In DenseNet, it helps to minimize the feature map
size and make down-sampling easier. Two convolutions, with 1x1 and 3x3
estimated pieces, are present in each dense block. This is done multiple times in
both dense blocks 1 and 2, 24 and 16 times in dense blocks 3 and 4, respectively.
Then, the input of each layer is forwarded to the next layer. As a result, all feature
maps from earlier layers are sent to the u th layer. The outputs can be written as
shown in Equation (4.4):
DNL FNCu DN0 , DN1, , , , , , , , DNu 1 (4.4)
created in each dense layer 0,1,...., u 1 and FN Cu . shows that the u th layer’s
input of three successive operations, such as BN, ReLU, and Conv. BN is used to
accelerate training and facilitate learning by employing higher learning rates.
105
The transition layer, located between two dense blocks, is essential because it
improves the number of feature maps as they progress through the dense blocks,
which can make them costly and memory-intensive. A batch normalization layer,
a 1 × 1 convolutional, and a 2 × 2 max pooling layer make up each transition layer.
Max pooling is used to detect important characteristics, such as edges, and
efficiently reduce feature dimensionality. After that, the feature maps from the last
dense block are passed to the SCA attention mechanism that focuses on spatial
H W C
and channel dependencies in the PCB image. Let DNL R be the SCA
module’s input, where, H , W , and represent the feature map’s height, width, and
channel count, respectively. The aggregation operation receives the input feature
maps and aggregates them along their channel dimension to generate a channel
descriptor, which provides the global distribution of a spatial feature, which is
calculated using Equation (4.5):
ATSP f R f 11 f R BN f 11 DNL (4.5)
and f
R
. represents the ReLU function. In addition, the aggregation operation
receives the input feature maps and aggregates them in their spatial dimension
H W to generate a channel descriptor, which provides the global distribution of
a channel feature, which is defined as in Equation (4.6):
H W
V m, n
1
ATCH (4.6)
H W
S
m n
where, VS represents the S th channel’s spatial position. Then, the spatial ATSP and
channel features ATCH are fused by element-wise sum and fed into the GAP for
further processing. This pooling operation reduced the feature map’s spatial
dimensions into a single vector, thereby collecting global information. The final
feature vectors are passed to the classifier for further processing.
106
4.2.4 Classification
where, Gt represents the SCDSNT121 -extracted feature vector from the current
region of the PCB, t 1 denotes the output at the previous moment, WC and PR
denote the weight matrices, and BC denotes the bias parameter, respectively.
In addition, s signifies the LReLU function, a type of activation function. It is
applied in neural networks to introduce nonlinearity to the outputs between layers,
and LReLU's simplicity and computational speed make it suitable for training
complex models, such as GRUs. It is defined as in Equation (4.8):
s max 0.01G , G (4.8)
when, G refers to the positive input extracted feature maps, the Leaky ReLU
function returns G in the same way as the ReLU function. On the other hand, this
function returns a tiny negative value corresponding to the input when it G is
negative. Then, the input information Gt and the hidden state t 1 inherited from
the previous node estimate the reset gate IRt , which is used to control the recall
or forgetfulness of the derived information from the previous step. The last time
step’s entire data will be transmitted to the next step if the reset gate yields a high
number; if not, almost all the information will be forgotten and will hardly enter
the next step. It is defined as in Equation (4.9):
IRt s WCIR Gt PRIR t 1 BC IR (4.9)
~
After that, a candidate's hidden state M t is calculated from the reset
gate. This is used to determine the information stored from the past. It is
formulated as in Equation (4.10):
M t tanh WC Gt PR IRt . t 1 BC
~
(4.10)
108
Then, the updated hidden state t is calculated using the update gate
and the candidate hidden state using Equation (4.11):
t 1 IU t . t 1 IU t . M t
~
(4.11)
RSO and to mitigate the issue of premature convergence. Finally, the Cauchy
mutation strategy is employed to improve the exploitation ability and prevent the
algorithm from becoming stuck in local optima. These strategies help
RSO efficiently search the hyperparameter space by maintaining a balance
between exploring new regions and exploiting the most promising solutions,
ultimately leading to the selection of optimal hyperparameter combinations for
improved classifier performance. The process involved in the proposed SCRSO is
explained as follows:
Initially, the optimization process begins by generating the initial
population of hyperparameters using the sine chaotic map, which is known for its
ability to produce non-repetitive, highly random, and stable sequences through the
nonlinear behavior of the sine function. Unlike traditional random or grid-based
methods, the sine chaotic map enhances the diversity of the search space in the
early stages of the optimization process. Its oscillatory and non-periodic
characteristics help avoid premature convergence by ensuring that the initial
population spans a broader and more varied region of the solution space.
It is formulated using Equation (4.13):
SRxc,d1 . sin SRxc, d (4.13)
where, indicates the control parameter, which is between 0, 1/. The sine map
exhibits chaotic behaviour when falls within the range of [0.87, 1]. Then, the
RSO method creates a Fitness Function (FF) to guide the selection of optimal
hyperparameters that produce superior classifier results. This function returns a
positive value to represent the performance quality of each candidate
hyperparameter set. During the tuning process, the minimization of classifier error
rate was supposed to be achieved by formulating FF in Equation (4.14).
FMIC
FF 100 (4.14)
FTN
where, FMIC indicates the count of wrongly classified classes and FTN refers to the
total instance count, respectively. After that, the global exploration phase of
110
RSO employs two leading operators, high walking and belly walking, which
facilitate the hunting phase and help identify areas with a high density of prey.
High walking and belly walking occur in the first and second half of the
exploration phase, respectively. Accordingly, the crocodile positions are updated
as demonstrated in Equation (4.15), allowing the algorithm to explore diverse
regions of the hyperparameter space and improve the chances of discovering
optimal hyperparameter configurations.
, d H x , d EC RFx , d Levy ,
SRbest
c c c
c Tc
c 1 4
SR
, d SRk 1, d N Levy ,
x, d
SRbest
c c c Tc c 2Tc
4 4
(4.15)
c
where, SRbest, d is the d
th
dimension of the fittest hyperparameter at c th iteration,
H xc, d indicates the hunting parameter for the d th dimension of the x th solution,
EC denotes a scalar constant tuned to 0.1, RFxc, d refers to a function whose value
is reduced to narrow the search landscape, SRkc1, d shows the d th dimension of the
where, k 2 and k 3 represents two arbitrary numbers (0,1), ~ is usually 1.5, and
refers to the constant value. During the exploitation phase, the RSO introduces
two discrete states that mirror the hunting behaviour of crocodiles: hunting
coordination and hunting cooperation. These states capitalize on crocodile
111
the best location and the current location, m indicates a small value, and
Cauchy 0, 1 refers to the Cauchy mutation function, respectively. In this, the
Cauchy mutation is added to the RSO is to enhance the search ability to jump out
of local optima. Another purpose is to improve exploitation capabilities in the
context of hunting and prevent the reptile population from becoming trapped in a
local optimum. The Cauchy mutation can produce various random variables that
are consistent with the Cauchy distribution, enhancing the reptile population's
search ability. After the exploitation phase, the proposed SCRSO process
terminates once the end criterion is satisfied. This occurs when the maximum
iteration is reached or the difference between two successive values of the
objective function, based on hyperparameter performance, is less than a
predefined threshold. This termination criterion ensures that the best-performing
hyperparameter configuration is selected without unnecessary computation.
Figure 4.4 illustrates the flowchart of the suggested SCRSO model.
112
(a)
(b)
115
(c)
Figure 4.5 Classified results of the ROGRU model (a) Input sample images,
(b) Preprocessed images, and (c) Final classified images
Figure 4.6 Accuracy Vs. Epoch analysis of the proposed ROGRU model
Figure 4.7 Loss Vs. Epoch analysis of the proposed ROGRU model
between the two and suggesting that the proposed model generalizes well and
avoids overfitting. This is primarily achieved by incorporating KM-SMOTE to
generate new synthetic samples, rather than simply duplicating existing ones,
which helps reduce the risk of overfitting. Most importantly, the SCRSO-based
hyperparameter optimization ensures that the model is trained with the most
suitable configuration, balancing model complexity and generalization.
These components collectively contribute to achieving the best performance.
Table 4.3 Accuracy analysis of the proposed ROGRU and baseline models
Proposed GRU LSTM DNN CNN
Defects
(%) (%) (%) (%) (%)
Missing holes 99.45 96.78 95.98 93.48 92.79
Open circuit 99.37 96.62 95.78 93.33 92.58
Short 99.21 96.45 95.55 93.19 92.36
Spur 98.97 96.18 95.33 93.07 92.37
Spurious copper 98.74 96.03 95.11 92.91 92.05
Mouse bite 98.98 95.98 95.91 92.74 92.75
Average 99.12 96.34 95.61 93.12 92.45
Table 4.3 presents the results of the proposed and baseline models in
terms of the accuracy metric. For the missing holes defect, the existing models
yield accuracies of 96.78%, 95.98%, 93.48%, and 92.79%, which are lower
compared to our model, as our model achieves a high-level outcome of
99.45% accuracy. Similarly, for the remaining defects, such as open circuit, short,
spur, spurious copper, and mouse bite, the proposed model achieves
99.37%, 99.21%, 98.97%, 98.74%, and 98.98% accuracy. Thus, these findings
demonstrate that the suggested model outperforms existing models in terms of
overall efficiency and attains a decent classification result.
118
Figure 4.8 and 4.9 demonstrates the precision and recall evaluation of
the proposed ROGRU method. In this case, the existing DNN and CNN models
exhibit lower performance because they primarily focus on spatial features and
are unable to model temporal dependencies across sequential PCB image patterns.
Temporal information is critical in PCB defect detection, where the structural
continuity or progression of defect patterns across the image plays a key role.
As a result, the DNN and CNN models produce average precision scores of
92.86% and 91.97%, respectively, and recall scores of 92.83% and 91.95%.
119
Furthermore, GRU and LSTM models are more capable of learning temporal
patterns by modeling sequential dependencies, and thus outperform DNN and
CNN. However, they are limited in capturing spatial features, which are crucial
for accurately predicting defects. To address both these challenges, our model
incorporates the SCDSNT121 module, which effectively extracts spatial features
from PCB images, along with the ROGRU model, which captures temporal
dependencies across image regions. This combination results in significantly
improved efficiency, with a precision of 98.74% and a recall of 98.71%. Thus, it
validates the effectiveness of our model in accurately classifying PCB defects.
Table 4.4 F1-score analysis of the proposed ROGRU and baseline models
Defects Proposed GRU LSTM DNN CNN
(%) (%) (%) (%) (%)
Missing holes 99.27 95.88 94.58 93.11 92.15
Open circuit 99.14 95.7 94.36 92.96 92.03
Short 98.69 95.43 94.21 92.78 91.97
Spur 98.57 95.31 94.14 92.56 91.88
Spurious copper 98.36 95.27 93.93 92.39 92.28
Mouse bite 99.49 95.95 94.69 93.24 91.45
Average 98.92 95.59 94.32 92.64 91.96
Table 4.4 shows the proposed and existing methods’ results established
by the F1-score measurement. For example, the baseline methods obtained a
F1-score rate of approximately 91% to 96%, whereas the proposed method
achieved a notably higher score of 99%. Better performance can be attributed to
the hyperparameters being appropriately chosen with the use of SCRSO. On the
other hand, the proposed method outperformed the existing methods, which
included no optimization models for choosing the best parameters.
120
Table 4.5 Average outcomes analysis of the proposed ROGRU and existing
models
MCC NPV FPR FNR FRR
Techniques
(%) (%) (%) (%) (%)
Proposed 0.904 99.23 0.043 0.053 0.053
GRU 0.703 96.47 0.13 0.167 0.168
LSTM 0.540 95.78 0.174 0.286 0.286
DNN 0.462 93.34 0.234 0.364 0.364
CNN 0.616 92.68 0.297 0.211 0.211
To evaluate how well the proposed model performs on unseen data, the
testing results are given in Table 4.6. In this, the proposed model achieves an
accuracy of 98.99%, 99.05% precision, 98.86% recall, and a 99.03% f1-score,
illustrating better performance than the traditional methods when applied to
unseen data, and also, the minimal gap between training and testing results shows
that model generalize well and avoid overfitting due to the integration of
KM-SMOTE-based dataset balancing with better feature learning ability.
4.4 SUMMARY