## 3 Materials and Methods
### YOLOv8 Model Structure  
In this study, to realize the automatic recognition and accurate classification of the damage to the gray brick wall in Macau, this study used the YOLOv8 model as the core detection structure, and based on keeping its original structure unchanged, combined the characteristics of the building surface damage to scientifically configure and fully train its application process. As a representative model with both speed and accuracy in the current object detection field, YOLOv8 has excellent multi-scale perception capabilities and a lightweight network structure and is particularly suitable for the detection of targets with complex textures and tiny cracks, such as gray brick surfaces. The overall structure of the YOLOv8 model consists of three parts: the backbone network (Backbone), the feature fusion network (Neck), and the detection head (Head) (Figure 2). The backbone network adopts an advanced CSP (cross-stage partial) structure, which enhances the gradient flow and feature extraction capabilities while maintaining the model's operational efficiency and can effectively capture subtle damage features in gray brick walls, such as cracks and broken corners. The model gathers important details at different levels by using various convolution and downsampling techniques, which correspond to different sizes of the areas it looks at, helping with later detection at multiple scales. As shown in Figure 2, the YOLOv8 structure uses a backbone network based on CSPDarknet53. This part extracts feature maps of different spatial scales through a multi-level feature pyramid (P1 to P5), starting from the input 512 \(\times\) 512 \(\times\) 3 color image, and gradually reduces the spatial resolution and increases the number of feature channels. Specifically, P1 (256 \(\times\) 256 \(\times\) 80) to P5 (16 \(\times\) 16 \(\times\) 640) gradually extract gray brick surface feature information from low to high layers through convolution and downsampling operations. The Neck part, as a feature fusion module, uses the C2f structure, which replaces the CSPlayer in YOLOv5 in YOLOv8. The C2f module contains the input convolution (Conv(c1, 2 \(\times\) c)) that divides the input channel into two parts and then achieves dense residual fusion through multiple Bottleneck stacking. Finally, the output channel is integrated by convolution (Conv((2 + n) \(\times\) c, c2)) to improve the perception and expression capabilities of multi-layer features. The C2f layer in Neck outputs feature size annotations such as 64 \(\times\) 64 \(\times\) 320, 32 \(\times\) 32 \(\times\) 640, and 16 \(\times\) 16 \(\times\) 640. Combined with the standard convolution layer (Conv), batch normalization (BN), and SiLU activation function, the context perception of the feature map is effectively enhanced. The up- and downsampling modules (Upsample) and the feature concatenation operation (Concat) further realize the alignment and fusion of features of different scales to improve the robustness of multi-scale features and the overall performance of the model. Figure 2: YOLOv8 model structure. C2f: CSP-based large residual structure for feature extraction and channel fusion; cv2, cv3: multi-scale detection heads, used for bounding box position regression and classification prediction, respectively; Conv: standard convolutional layer with batch normalization and SiLU activation for feature extraction and downsampling. (Image source: drawn by the authors). In the detection head (Head) part, YOLOv8 adopts a decoupled detection head design to separate the objectness, classification, and bounding box regression tasks in the detection task. Specifically, the localization branch (cv2 module) consists of three layers of convolution (Conv3 \(\times\) 3\(\rightarrow\)Conv3 \(\times\) 3\(\rightarrow\)Conv1 \(\times\) 1) to output the bounding box offset (the channel is 4 \(\times\) reg_max), while the classification branch (cv3 module) adopts a similar structure, and the final output channel is num_classes, which is used for target classification.