## 3 Materials and Methods
### Research Process
#### 3.1.5 Model Testing Stage  
This study systematically evaluates the performance and verifies the effect of the trained YOLOv8 model and comprehensively analyzes its accuracy, stability, and practicality in tasks for detecting damage to gray bricks. In this stage, not only were standard evaluation indicators for object detection used, but auxiliary analysis methods such as heatmap visualization and damage quantification were also introduced to enhance the interpretability and engineering applicability of building damage detection. In the test phase, 38 independent test set images previously defined were used, and the evaluation indicators included the mean average precision (mAP), F1 score, recall, precision, and log-average miss rate (LAMR). Among them, mAP is the core indicator that measures the detection performance of the model under different categories and IoU thresholds, reflecting its generalization ability in complex damage scenarios. The YOLOv8 model trained in this study achieved high performance in the mAP indicator, indicating that it has excellent recognition in the location and classification of multiple types of detailed damage, such as cracks, missing parts, moss, and stains. The F1 score is used to balance precision and recall and can reflect the comprehensive recognition ability of the model, especially when some categories are unevenly distributed. The improvement in recall indicates that the model has a strong ability to cover all damage, while the accuracy shows that it has high reliability in filtering false positives. The introduction of LAMR measures the model's ability to capture small targets or minor damage in the low recall stage from a robustness perspective. A low LAMR value shows that the model is good at minimizing missed detections,  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Keys** & **Values** & **Keys** & **Values** \\ \hline Input shape & 512, 512 & Unfreeze batch size & 2 \\ \hline Init epoch & 0 & Freeze train & True \\ \hline Freeze epoch & 50 & Init learning rate & 0.01 \\ \hline Unfreeze epoch & 300 & Min learning rate & 0.0001 \\ \hline Freeze batch size & 4 & Optimizer type & \begin{tabular}{c} SGD (Stochastic \\ Gradient Descent) \\ \end{tabular} \\ \hline momentum & 0.937 & \
\begin{tabular}{c} Learning rate \\ decay type \\ \end{tabular} &
\begin{tabular}{c} Cosine annealing \\ \end{tabular} \\ \hline \hline \end{tabular} Source: Author’s statistics.  
\end{table}
Table 3: Model parameters.  
making it ideal for high-precision situations like restoring cultural relics and conducting daily inspections.  
Aside from using numbers to measure things, this study also added two visual tools, heatmap analysis and damage quantity statistics, to make the model results easier to understand and use. In the heatmap part, we created a Grad-CAM mechanism that combines features from multiple layers of convolutional data. In the heatmap module, we constructed a Grad-CAM mechanism based on multi-layer convolutional feature fusion. Through learnable upsampling, feature alignment (DeformConv2d), and dynamic channel fusion modules, a multi-scale semantically enhanced spatial attention map was generated to clearly display the damaged area of the model's attention and its weight distribution. In the visualization results, the model showed high responsiveness on crack edges, missing areas, and biological attachments, verifying its sensitivity to high-risk damage. Additionally, the cropping and statistics modules implemented after the model was deployed enabled automatic classification and quantitative analysis of the detection results. The model can not only locate the damaged type of gray brick but also count and classify all damaged bricks in the image, providing quantifiable data support for subsequent gray brick maintenance evaluation. This capability is supported by transparent border drawing, multi-class legend display, and classification-saving mechanisms, considering both intuitive image presentation and engineering operability.