## 2 Materials and Methods
### Loss Function  
Due to the high-resolution characteristics of remote sensing images, the number of background pixels far exceeds the number of mangrove pixels, leading to a severe sample distribution imbalance problem. To address this challenge, this chapter designs a hybrid loss function \(CL_{\text{loss}}\) to optimize network performance. This loss function combines cross-entropy loss and Lovasz-Softmax loss, which not only effectively alleviates the class imbalance problem but also specifically enhances the optimization of segmentation boundary regions, thereby improving the overall segmentation accuracy of the model. The cross-entropy loss function is used to measure the difference between predicted probabilities and true labels in classification tasks, thereby driving the model to learn correct pixel classification. Its definition is shown in Equation (14):  
\[Loss_{CE}=-\frac{1}{N}\sum_{i=1}^{N}y_{i}*log\hat{y}_{i} \tag{14}\]  
where \(N\) represents the total number of pixels, \(y_{i}\) is the true label of pixel \(i\), \(\hat{y}_{i}\) is the model's predicted probability output for pixel \(i\), and log represents the natural logarithm. The Lovasz-Softmax loss is constructed based on the Jaccard index (IoU) [41]. For category \(c\), the Jaccard index is defined as shown in Equation (15):  
\[J_{c}(y,\widetilde{y})=\frac{|y=c\cap\widetilde{y}=c|}{|y=c\cup\widetilde{y}=c|} \tag{15}\]  
where \(y=c\) represents the set of pixels belonging to Category \(c\) in the true labels, \(\widetilde{y}=c\) represents the set of pixels belonging to Category C in the predicted results, and \(|\cdot|\) represents the cardinality (number of elements) of the set. The Jaccard loss is defined as shown in Equation (16):  
\[\Delta J_{c}(y,\widetilde{y})=1-J_{c}(y,\widetilde{y}) \tag{16}\]  
To more precisely characterize misclassified pixels, the set of misclassified pixels for Class \(c\) can be defined as shown in Equation (17):  
\[M_{c}(y,\widetilde{y})=y=c,\widetilde{y}\
eq c\cup y\
eq c,\widetilde{y}=c \tag{17}\]Based on the set of misclassified pixels, the Jaccard loss can be rewritten as shown in Equation (18):  
\[\Delta J_{c}(y,\widetilde{y})=\frac{|M_{c}|}{|y=c\cup M_{c}|} \tag{18}\]  
Since the Jaccard loss is non-differentiable, it needs to be smoothed for use in deep learning frameworks. Here, the Lovasz extension is introduced, which is a method to extend discrete set functions to continuous domains. For a submodular function \(F\), its Lovasz extension is defined as shown in Equation (19):  
\[\overline{F}(m)=\sum_{p=1}^{P}F(\pi_{1},\ldots,\pi_{p})[\pi_{p}(m)-\pi_{p-1}( m)] \tag{19}\]  
where \(m\) is the error vector, \(P\) is the vector dimension, \(\pi\) is the permutation that sorts the components of \(m\) in descending order, and \(\pi_{0}(m)=0\). The calculation method for the error vector \(m\) is shown in Equation (20):  
\[m_{i}=\left\{ \begin{array}{ll}1-f_{c}(x_{i})&\quad\text{if $y_{i}=c$}\\ f_{c}(x_{i})&\quad\text{otherwise}\end{array} \right. \tag{20}\]  
where \(f_{c}(x_{i})\) is the model's predicted probability that pixel \(i\) belongs to category \(c\). The final Lovasz-Softmax loss is defined as shown in Equation (21):  
\[Loss_{Lovasz}=\frac{1}{|C|}\sum_{c\in C}\overline{\Delta J_{c}}(m(c)) \tag{21}\]  
where \(C\) is the set of categories, which is 2 in this study. Finally, combining the above two loss functions yields the final hybrid loss function, as shown in Equation (22):  
\[Loss_{CL}=\alpha Loss_{CE}+(1-\alpha)Loss_{Lovasz} \tag{22}\]  
where \(\alpha\) is a weight parameter used to balance the contribution of the two loss functions. Through experimental validation, when \(\alpha=0.6\), the model achieves optimal performance. The selection of weights takes into account both the degree of sample imbalance and boundary precision requirements. During the training process, the cross-entropy loss dominates the early optimization process, ensuring basic classification accuracy.