# A Lightweight and High-Accuracy Model for Pavement Crack Segmentation
## 3 Methods
### Dynamic Combined Loss Function  
Cross-entropy is a commonly used loss function for classification tasks. In semantic segmentation, the cross-entropy loss function focuses on pixel-wise classification, aiming to increase the confidence of output pixels in their true categories. The cross-entropy loss function can be defined as follows:  
\[CELoss(y,\hat{y})=-\sum_{i=1}^{c}y_{i}\log\hat{y}_{i} \tag{2}\]  
where \(c\) represents the total number of classes, \(y\) represents the true probability distribution, and \(\hat{y}\) represents the predicted probability distribution from the model across all \(c\) classes, respectively. Although the cross-entropy loss function is widely used, it assigns equal weight to all pixels, overlooking the importance of boundary regions. This limitation reduces its ability to focus effectively on the edges of target regions, leading to blurry boundary details in crack segmentation [34; 35]. The Dice coefficient is used to evaluate the overlap between the predicted results and the ground truth labels. Let the predicted binary mask be \(A\) and the actual binary mask be \(B\), the Dice coefficient is calculated as follows:  
\[Dice(A,B)=\frac{|A|+|B|}{2\times|A\cap B|} \tag{3}\]  
_DiceLoss_ is based on the Dice coefficient, and its calculation formula is as follows:  
\[DiceLoss=1-Dice(A,B) \tag{4}\]  
_DiceLoss_, based on overlap, can better focus on easily misclassified edge regions. Additionally, it effectively handles class imbalance issues, making it particularly suitable for pavement cracks, which are often minority classes with intricate edge details. However, using _DiceLoss_ as the sole loss function in the early stages of network training can lead to instability in model training. Introducing _DiceLoss_ when the network has achieved a certain level of discriminative ability can guide the model to more stably focus on the edge regions. Figure 4: Carafe Up-sampling Module. _FocalLoss_ is based on an improved version of the cross-entropy loss function. It dynamically adjusts the contribution of samples to the loss function based on the disparity between predicted probabilities and true probabilities, allowing the network to focus on learning from harder-to-classify samples. This enhances the network capacity to recognize difficult pixels (primarily in boundary regions), leading to more precise segmentation of the target area. The calculation formula for _FocalLoss_ is as follows:  
\[FocalLoss(y,\hat{y})=-\sum_{i}^{c}\alpha_{i}(1-\hat{y_{i}})^{\gamma}y\log\hat{y }_{i} \tag{5}\]  
where \(\alpha_{i}\) is the weighting factor for class \(i\), \(\gamma\) is the adjustment factor, and the meanings of the other symbols remain the same. Given the characteristics of cross-entropy loss, Dice loss, and Focal loss, appropriately assigning weights to these three loss functions for joint optimization often results in better segmentation performance. Cross-entropy loss is suitable for improving overall accuracy, Dice loss focuses on addressing class imbalance, and Focal loss emphasizes hard-to-classify samples, especially in boundary regions. However, fixed weight assignments limit the model's flexibility at different training stages and make it difficult to find optimal parameters, which may lead to instability during training or suboptimal segmentation results. To overcome this issue, this paper proposes a dynamic weight adjustment method based on a nonlinear function. As the training progresses, the model's focus changes at different stages. Specifically, as the number of training epochs increases, we dynamically allocate different weights to the three loss functions to ensure that, in the early stages of training, the model focuses on improving overall accuracy, while in the later stages, it pays more attention to segmenting crack edge details.