# Deep Learning-Based Classification of High-Resolution Satellite Images for Mangrove Mapping
## 2 Materials and Methods
### Attention U\({}^{2}\)-Net Model for Mangrove Detection
#### 2.3.3 Configuration of the Attention U\({}^{2}\)-Net  
In order to train and test the attention U\({}^{2}\)-Net model for mangrove detection, we had to prepare a sample dataset from the satellite images. We used LabelMe 4.5 software, which is a tool for image annotation, to label the pixels in satellite images as either mangrove or non-mangrove (background). Similar to the method used in some studies on mangrove classification (e.g., [14]) 2020), labels were created through visual interpretation based on collected reference samples from high-resolution satellite imagery and previous mangrove maps. We removed the images that had less than 1% of mangrove pixels, as they are not suitable for mangrove detection. After this process, we obtained 2237 samples with a size of 320 \(\times\) 320 pixels. The data volume was expanded to three times by further processing these images through horizontal flipping, vertical flipping, and random cropping. We split the dataset into two parts: 70% of the samples were used for model training, and the remaining 30% were used for model testing.  
However, we encountered a problem of sample unbalancing in our dataset. The proportion of mangrove pixels to the total image pixels was only 19%, which means that most of the pixels belonged to the background rather than the mangrove target. This could cause the network to learn more features from the background and ignore the features from the mangrove target, which could affect the accuracy and reliability of mangrove detection. To solve this problem, we used a _loss_ function that considers the contribution of \(F1\)-Score. By considering the \(F1\)-Score in the _loss_ function, we could make the network learn more target features and balance the contribution of mangrove pixels and background pixels. The _loss_ function is expressed as  
\[loss=\alpha\times BCE+(1-\alpha)(1-F1) \tag{5}\]  
\begin{table}
\begin{tabular}{c c c c} \hline \hline  & \multicolumn{2}{c}{**Prediction**} \\ \cline{2-4}  & **Confusion Matrix** & **Positive (Mangrove)** & **Negative (Background)** \\ \hline \multirow{2}{*}{Actual} & Positive (Mangrove) & TP & FN \\ \cline{2-4}  & Negative (Background) & FP & TN \\ \hline \hline \end{tabular}
\end{table}
Table 2: Confusion matrix.  
where \(\alpha\) is the factor that balances \(BCE\) and \(F1\), and its value is set at 0.4. \(BCE\) is a traditional binary classification loss function that represents the difference between the measurement \(x_{i}\) and the classified value \(y_{i}\).  
\[BCE=-\sum_{i=1}^{N}[y_{i}\text{ln}\left(\sigma(x_{i})\right)+(1-y_{i})\text{ ln}(1-\sigma(x_{i}))] \tag{6}\]  
where \(N\) is the number of samples; \(y_{i}\) is the label of sample \(i\), where \(y_{i}\) is 1 if the sample is mangrove and 0 if it is not; and \(\sigma(x_{i})\) represents the probability that sample \(i\) is classified as mangrove.  
In addition, a series of comparative experiments was conducted to determine the optimal model parameter combination by adjusting the values of batch size (\(\text{b}_{\text{n}}\)), learning rate, and epoch number. We set \(\text{b}_{\text{n}}\) to 2, 8, 16, and 32; the learning rate to 0.0001, 0.001, and 0.1\({}^{\text{t}}\)bn/256 [24]; and the number of epochs to 500, 1000, 1500, and 2000.