## 2 Method
### Improvements and Training of the SegFormer Network
#### 2.1.2 Constructing Networks
To mitigate computational complexity, a reduction ratio (RRR) is applied to decrease the length of the sequence: \[\hat{K}=\text{Reshape}\left(\frac{N}{R},C\cdot R\right)(K)\] (2) \[\text{K}=\text{Linear}(C\cdot R,C)\left(\hat{K}\right)\] (3) where \(K\) is the sequence to be reduced, Reshape \(\left(\frac{N}{R},C\cdot R\right)(K)\) refers to reshape \(K\) to the one with a shape of \(\frac{N}{R}\times(C\cdot R)\), and Linear \((C_{in};\ C_{out})(\cdot)\) refers to a linear layer taking a \(C_{in}\)-dimensional tensor as input and generating a \(C_{out}\)-dimensional tensor as output [31]. * Mix-FFN: enhancing transformer layers with positional information. The Mix-FFN structure enhances Transformer layers by integrating positional information. This is accomplished by incorporating a 3 \(\times\) 3 convolutional layer and an MLP layer into the FFN: \[\mathbf{x}_{out}=\text{MLP}(\text{GELU}(\text{Conv}_{3\times 3}(\text{MLP}( \mathbf{x}_{in}))))+\mathbf{x}_{in},\] (4)  
Figure 3: Configuration of SegFormer for mesoscale detecting [31]. Lightweight ALL-MLP decoder: The lightweight ALL-MLP decoder serves as the segmentation decoder in the SegFormer model. Its primary objective is to transform the feature maps extracted by the encoder into pixel-level semantic segmentation predictions. This is accomplished through multi-scale feature fusion and upsampling to produce the final semantic segmentation mask. An essential rationale for SegFormer's use of MLP in the decoder lies in the larger receptive field of Transformers compared to CNNs. The decoding process can be summarized as follows:  
1. Multiple hierarchical features are fed into an MLP layer to standardize the channel dimension;
2. Feature maps are upsampled to 1/4 of the original image size and subsequently concatenated;
3. A single MLP layer aggregates the feature channels;
4. The predicted segmentation mask is outputted with a resolution calculated as follows: \[\frac{H}{4}\times\frac{W}{4}\times N_{cls}\] (5) where \(N_{cls}\) is the number of categories. The decoder is formulated as follows:  
Figure 1:0  
Figure 1:1  
Figure 1:2  
Figure 1:3  
where \(M\) refers to the predicted mask and \(\text{Linear}(C_{in};C_{out})(\cdot)\) refers to a linear layer with \(C_{in}\) and \(C_{out}\) as the input and output vector dimensions, respectively [31]. In this study, enhancements have been made to the decoder of the SegFormer model. The original decoder concatenated features from different scales, overlooking the inherent differences in these features across the scales. Lower-level features typically capture structural and textural characteristics, while higher-level features focus more on semantic representation. In contrast to other methods, the improved algorithm prioritizes the complementarity between these two types of features. Unet and HRNet, as network architectures in deep learning, have been extensively applied in image segmentation tasks, with the goal of labeling each pixel in an image with a specific semantic category for precise image segmentation [32; 33]. These models underscore the significance of multi-scale features for better information capture at different sizes and levels, thereby enhancing segmentation performance. The segmentation results of UNet, HRNet, the original SegFormer, and the modified SegFormer were compared. UNet is a deep learning neural network architecture employed for image segmentation tasks. Its name is derived from its U-shaped network structure. A key feature is the combination of an encoder and a decoder, utilized for pixel-level image segmentation tasks. This facilitates the assignment of each pixel in the input image to a specific semantic category, achieving semantic segmentation at the pixel level. The structure of UNet, encompassing the encoding-decoding structure and the use of skip connections, has served as inspiration for many other network architectures, such as SegNet and PSPNet.