# MAS-YOLO: A Lightweight Detection Algorithm for PCB Defect Detection Based on Improved YOLOv12
## 3 Experiment and Analysis
### Introduction to Experimental Environment and Indicators  
In this study, the experimental training environment was setup on a high-performance server equipped with four GeForce RTX 3050 Ti GPUs, running Ubuntu, and the development framework was chosen as PyTorch-GPU (python = 3.10). During the model training phase, meticulous adjustments were made to the hyperparameters to ensure effective learning and convergence to an optimal performance state.  
Specifically, the learning rate was set to 0.01; this relatively high initial learning rate facilitates rapid convergence during the early stages of training and is adjusted in a timely manner based on validation set performance to prevent premature convergence to local optima. Based on preliminary experiments, this study decided to conduct 300 training iterations during the optimal training process. This choice of epoch number was based on a careful balance between ensuring sufficient training for the model to learn the complex patterns in the data and avoiding unnecessary consumption of computational resources. Moreover, to ensure that the model did not overfit the training data, early stopping criteria were considered. Specifically, if the validation loss trend did not change for a certain number of epochs (e.g., 10 epochs), the training process would terminate early. A batch size of 16 was selected, striking a good balance between training stability and GPU memory utilization. For the optimizer, Stochastic Gradient Descent (SGD) was adopted due to its simplicity and effectiveness, and its widespread application in deep learning provides a stable optimization pathway for model training.  
To better align with the actual hardware conditions of industrial inspection and to more accurately assess the model's performance, this study transplanted the trained model to the Jetson Xavier NX embedded platform for application testing. In terms of model performance evaluation, the key metrics focused on in this study include precision, recall, mean average precision (mAP), model parameter count (parameters), computational complexity (GFLOPs), and detection frame rate (FPS).  
Precision is used to measure the risk of the classifier incorrectly classifying negative examples as positive. The calculation formula for precision is as follows:  
\[P=\frac{\text{TP}}{\text{TP}+\text{FP}}. \tag{15}\]  
Recall quantifies the percentage of True Positive instances correctly identified by the model, serving as an indicator of its detection effectiveness. The calculation formula for recall is as follows:  
\[R=\frac{\text{TP}}{\text{TP}+\text{FN}}, \tag{16}\]  
where True Positive (TP) refers to correctly predicted positive cases. False Positive (FP) indicates incorrect negative predictions for actual positive cases, while False Negative (FN) refers to missed positive cases predicted as negative.  
Mean average precision (mAP) offers an integrated evaluation of the model's trade-off between precision and recall across various defect types, making it a crucial metric for assessing overall detection performance:  
\[mAP=\frac{1}{N}\sum_{i=1}^{N}AP_{i} \tag{17}\]  
Model parameters (parameters) reflect the complexity and storage requirements of the model. Computational complexity (GFLOPs) measures the amount of computation re quired during inference, which is closely related to the model's operational efficiency. Detection frame rate (FPS) directly indicates the model's real-time performance in practical applications, which is crucial for meeting the real-time detection demands in industrial production.  
A comprehensive evaluation of these metrics allows for a thorough assessment of the model's performance in PCB defect detection, providing a solid foundation for further optimization and practical implementation.