## 2 Materials and Methods
### Methods
#### 2.2.4 Combination Loss Function Based on Focal and Dice Loss  
Cross-entropy loss is a common loss function in deep learning. However, cross-entropy is a global loss function that only considers pixel-level loss, so when cross-entropy loss is used in our post-earthquake building damage dataset, it will lead to the model weights being biased in favor of categories with a high number of sample categories, whereas in the post-earthquake dataset, the number of samples in the generally largely intact category is much larger than in the other categories. As a result, it can easily lead to larger errors when extracting damaged houses in the models. Unlike cross-entropy loss, since Dice loss emphasizes the overlap between predicted results and true labels [27], focal loss focuses more on the strategy of hard-to-predict samples by adjusting the sample weights [28]. Therefore, both Dice loss and focal loss enable the model to concentrate more significantly on samples from a limited number of classes, thereby mitigating the issue of model weights disproportionately favoring intact classes to some extent. To address the imbalance where the number of damaged houses in the post-earthquake building damage dataset is significantly lower than that of undamaged houses, a combined loss function comprising Dice loss and focal loss, alongside a cross-entropy loss function, is proposed. This combined loss function is utilized to optimize the model during the training process. The Dice coefficient is a metric utilized to quantify the degree of overlap between predicted and ground truth regions in semantic segmentation tasks. It serves as an evaluation measure, assessing model performance by comparing the similarity between predicted results and actual labels. The Dice coefficient ranges between 0 and 1, where a value of  
Figure 4: MFAF module structure. 1 indicates a perfect overlap, meaning the predicted region is identical to the real region, while a value of 0 implies no overlap, indicating that the prediction has no relevance. The Dice coefficient offers several advantages over other metrics. Firstly, it exhibits regional correlation, meaning the loss of a given pixel is not solely dependent on its predicted value but also on the values of neighboring pixels. This characteristic enables the Dice coefficient to provide a balanced assessment of the data, particularly in scenarios where there is class imbalance. Secondly, since larger Dice coefficients indicate better performance, this metric remains unaffected by data imbalance. In neural network training, the goal is often to minimize the loss function to optimize the model. However, as larger Dice coefficients are desirable, it is possible to utilize the complementary value of the Dice coefficient (1 minus the Dice coefficient) as the formulation for the Dice loss function, as depicted in Equation (2). This approach aims to prioritize an enhancement in the Dice coefficient during training, thereby improving the model's performance in semantic segmentation tasks. Furthermore, Equation (3) presents the focal loss, which serves as an additional component to the balanced cross-entropy loss function to adjust the weights of samples that are easy or challenging to classify. The focal loss introduces an adjustable focusing parameter, \(\gamma\), to decrease the weight of easily separable samples and emphasize the importance of difficult-to-categorize samples. By utilizing a \(\gamma\) value greater than 1, the focal loss reduces the weight assigned to conveniently separable samples, directing the model's attention towards more challenging instances. Conversely, an \(\gamma\) value less than 1 increases the weight of easily separable samples, ensuring a balanced consideration of all categories. This mechanism directs the model to focus more on samples that are challenging to classify, thereby enhancing the classification accuracy of minority categories.