# Ground-Based Cloud Image Segmentation Method Based on Improved U-Net
## 2 Materials and Methods
### Skip Connection Layer Structure
In the image segmentation task, not only the contextual information but also the spatial information should be paid attention to. A CBAM can combine information on two different features. A CBAM consists of channel attention and spatial attention, and its structure is shown in Figure 3(2). For a traditional CBAM, assuming a tensor \(\mathbf{F}\in\mathbb{R}^{C\times H\times W}\) is given as input, the CBAM will sequentially derive a 1D channel attention feature map \(\mathbf{M}_{\mathbf{c}}\in\mathbb{R}^{C\times 1\times 1}\) and a 2D spatial attention feature map \(\mathbf{M}_{\mathbf{s}}\in\mathbb{R}^{1\times H\times W}\). The whole attention process can be summarized as  
\[ \begin{split}\mathbf{F}^{\prime}&=\mathbf{M}_{ \mathbf{c}}(\mathbf{F})\otimes\mathbf{F}\\ \mathbf{F}^{\prime\prime}&=\mathbf{M}_{\mathbf{s}}( \mathbf{F}^{\prime})\otimes\mathbf{F}^{\prime}\end{split}  \tag{3}\]  
Therefore, the final output feature map \(\mathbf{RF}\in\mathbb{R}^{C\times H\times W}\) can be obtained. A CAM mainly focuses on discovering the key features in images. In a CAM, the importance of each channel is summarized through global average pooling and global max pooling, and then channel attention weights are generated through a shared MLP. Finally, these weights are used to re-weight each channel of the feature map. In short, the channel attention is calculated as follows [27]:  
\[ \begin{split}\mathbf{M}_{\mathbf{c}}(\mathbf{F})& =\sigma\{\text{MLP}[\text{AvgPool}(\mathbf{F})]+\text{MLP}[\text{ MaxPool}(\mathbf{F})]\}\\ &=\sigma\Big{\{}\mathbf{W}_{1}\Big{[}\mathbf{W}_{0}\Big{(} \mathbf{F}_{\text{avg}}^{\text{c}}\Big{)}\Big{]}+\mathbf{W}_{1}[\mathbf{W}_{0} (\mathbf{F}_{\text{max}}^{\text{c}})]\Big{\}}\end{split}  \tag{4}\]  
A SAM differs from a CAM but complements it, focusing more on identifying the key regions of important features. In a SAM, the importance of each location is summarized through global average pooling and global max pooling of the feature map along the channel dimension, and then spatial attention weights are generated through a convolutional layer. Finally, these weights are used to re-weight each position in the feature map. In short, the spatial attention is calculated as follows [27]:  
\[ \begin{split}\mathbf{M}_{\mathbf{s}}(\mathbf{F})& =\sigma\big{\{}f^{7\times 7}[\text{AvgPool}(\mathbf{F});\text{MaxPool}( \mathbf{F})]\big{\}}\\ &=\sigma\Big{[}f^{7\times 7}\Big{(}\mathbf{F}_{\text{avg}}^{ \text{s}}\;;\mathbf{F}_{\text{max}}^{\text{s}}\Big{)}\Big{]}\end{split}  \tag{5}\]  
To focus on the category and location information of clouds and their shadows, this paper replaces the MLP in the CAM with depthwise separable convolutions to focus on the important information and key features in the cloud image. At the same time, the SAM is combined with the multi-head attention mechanism to capture more spatial relationships in the feature map and find the key areas in the key features. As shown in Figure 4, an Im-CSAM consists of an improved CAM and SAM. The Im-CSAM accepts the output \(\mathbf{X}^{2}\) from the previous module DS path. In the improved CAM, the feature map \(\mathbf{X}^{2}\) is down-sampled by the max pooling layer and the average pooling layer respectively, and then enters the depthwise separable module with a two-layer structure. Its output is element-wise added, and the channel attention feature is generated through the sigmod activation function. Finally, it is element-wise multiplied with the input feature \(\mathbf{X}^{2}\) to generate the input features required by the SAM module. Therefore, the improved channel attention is calculated as follows:  
\[\mathbf{M}_{\mathbf{c}}(\mathbf{X}^{2})=\sigma\Big{\{}\text{DSConv}\Big{[} \text{AvgPool}(\mathbf{X}^{2})\Big{]}+\text{DSConv}\Big{[}\text{MaxPool}( \mathbf{X}^{2})\Big{]}\Big{\}} \tag{6}\]  
where DSConv represents the depthwise separable convolution operation.