## 3 Materials and Methods
### Research Process
#### 3.1.4 Model Training Stage  
The research team conducted deep learning training on the labeled dataset based on the YOLOv8 structure, aiming to achieve high-precision automatic identification of multiple types of damage in gray brick walls. The machine learning environment was set as follows: the operating system was Windows 11 (X64), the CUDA version was 11.5, the deep learning framework was PyTorch (1.13.0), and the graphics card and processor were a GeForce RTX 3070 (16 GB) (Santa Clara, CA, USA) card and an AMD Ryzen 9 5900 HX (3.30 GHz) processor (Santa Clara, CA, USA), respectively. The YOLOv8 model uses a modern C2F (cross-stage partial with focus) design, which combines effective feature extraction and a method for merging features at different scales. It can achieve keen perception and precise positioning of fine-grained targets (such as cracks, moss, etc.) while keeping the model lightweight. It is extremely suitable for tasks involving the detection of complex and subtle damage on brick surfaces in traditional buildings. In the specific training strategy, this study set up a two-stage training scheme of gradual unfreezing. The initial stage of training was the Freeze Train stage, which freezes the parameters of the Backbone backbone network and only trains the detection head module, thereby stabilizing the network structure and improving the initial learning efficiency. This stage was from epoch 0 to epoch 50 th of training; the batch size was set to 4, the initial learning rate was 0.01, the stochastic gradient descent (SGD) optimizer was used, and the momentum term 0.937 was combined for optimization and updating. Then, we entered the unfreeze training phase, unlocked the backbone weights, and further trained the entire network to optimize the overall detection performance. The training cycle lasted from the 50 th epoch to the 300 thepoch, and the batch size was adjusted to two to adapt to the video memory resources and ensure training stability. The input image size used in the entire training process was unified to 512 \(\times\) 512 pixels, and the cosine decay learning rate decay strategy (min lr was set to 0.0001) was used to effectively smooth the training process and prevent oscillation or overfitting. The model saves weight parameters every 5 epochs and sets up eight subprocesses for data loading (num workers = 8) to speed up training. The training dataset contains 351 images, and the validation set contains 40. The initial weight of the model was based on the pre-trained model yolov8_x.pth to ensure that the network had a favorable convergence starting point. During the feature extraction and classification process, YOLOv8 identified the basic textures and structures of the original image using the backbone network and then improved the understanding of the image by combining information at different scales with the Neck module (like FPN and PAN structures). Finally, the three sets of detection heads, Head0, Head1, and Head2, each worked with feature maps of different sizes to accurately identify small targets (like microcracks), medium targets (like damaged areas), and large targets (like big patches of moss). The specific parameters of the model are shown in Table 3.