SCAttNet: Semantic Segmentation Network with Spatial and Channel Attention Mechanism for High-Resolution Remote Sensing Images

High-resolution remote sensing images (HRRSIs) contain substantial ground object information, such as texture, shape, and spatial location. Semantic segmentation, which is an important task for element extraction, has been widely used in processing mass HRRSIs. However, HRRSIs often exhibit large intraclass variance and small interclass variance due to the diversity and complexity of ground objects, thereby bringing great challenges to a semantic segmentation task. In this paper, we propose a new end-to-end semantic segmentation network, which integrates lightweight spatial and channel attention modules that can refine features adaptively. We compare our method with several classic methods on the ISPRS Vaihingen and Potsdam datasets. Experimental results show that our method can achieve better semantic segmentation results. The source codes are available at https://github.com/lehaifeng/SCAttNet.


I. INTRODUCTION
S EMANTIC segmentation of remote sensing images is a fundamental task that classifies each pixel in an image into a specified category. It plays an important role in many fields such as change detection, element extraction, and military target recognition.
Image semantic segmentation methods can be divided into two categories: traditional methods and deep learning based ones. Traditional methods use the color, texture, shape, and spatial position relationships of an object to extract features and then use clustering, classification, and threshold algorithms to segment an image [1] [2]. However, these methods depend heavily on artificial design features and show some bottlenecks. Recently, deep learning based methods have been regarded as a promising approach to solve image semantic segmentation problems [3][4] [5]. For example, methods based on fully convolutional network (FCN) [4] have achieved stateof-the-art segmentation results on many natural image datasets, such as PASCAL VOC [6] and Cityscapes [7].
However, remote sensing images are different from natural images and often viewed from a high-altitude angle. Thus, the range of imaging is wide, and the background is complex and diverse. Especially in HRRSIs, the difference of ground objects becomes further notable. To segment HRRSIs effectively, many advanced methods have been proposed. For example, weighted focal loss [8] and multi-class loss combined by Dice loss and Binary Cross Entropy loss [9] have been proposed to solve the class imbalance problem in remote sensing images. Multi-modal datas such as digital surface models (DSMs) [10] [11] have been used to improve semantic segmentation performance. In addition, spatial relation module [12] and spatial information inference structure [13] have been designed to model more effective contextual spatial relations. These methods have achieved satisfactory results for remote sensing images segmentation.
Recently, attention mechanisms have been successfully applied to semantic segmentation. These methods can be divided into two categories. One uses attention mechanism to select meaningful features at channel dimension. For example, PAN [14] uses a global attention module as a context prior to select precise features channel-wisely. Attention U-net [15] uses a channel attention module to control the fusion of high-level and low-level features at channel dimension. However, these method do not consider to enhance the feature representation at spatial dimension. Another one is called the self attention mechanism, which calculates the feature representation in each position by weighted sum the features of all other positions [16] [17]. Thus, it can model the longrange context information of semantic segmentation task. For example, DANet [16] uses two self-attention modules to model long-range context information at spatial and channel dimension respectively. However, these methods are complexity in the size of model, thus yield inefficient computation which will be great challenge to process massive remote sensing images. In our work, two lightweight attention modules [18] which contains spatial attention and channel attention are adopted for the semantic segmentation of HRRSIs. The spatial attention module models the spatial features of HRRSIs, and the channel attention module captures what to enhance. Integrating these two attention modules can effectively improve the accuracy of semantic segmentation. The contributions of this study primarily include the following three points: (1) We propose a new semantic segmentation Network with Spatial and Channel Attention (SCAttNet) to improve the semantic segmentation accuracy of HRRSIs.
(2) We visualize the representations learned by spatial and channel attention modules to explain why does our method work.
(3) Experiments on Vaihingen and Potsdam datasets demonstrate competitive results by learning representations for HRRSIs via spatial and channel attention modules, and show arXiv:1912.09121v2 [cs.CV] 7 May 2020

A. Overview of SCAttNet
The proposed semantic segmentation network is shown in Fig. 1. It consists of two parts: a backbone for feature extraction and an attention module. The attention module is composed of a channel attention and a spatial attention in cascade. For an input remote sensing image, we first use the backbone network for feature extraction. Then we feed the extracted feature map into the channel attention module to refine the features in channels. Afterward, we feed the refined channel feature map into the spatial attention module for refinement at spatial axis. Lastly, we can obtain the semantic segmentation results via convolution and SoftMax operations. Specific network details and design ideas are shown in the following sections.

B. Backbone for feature extraction
In this study, we use two representative backbones for feature extraction: SegNet and ResNet50 [19]. On this basis, we proposed two networks: SCAttNet V1 with SegNet as backbone and SCAttNet V2 with ResNet50 as backbone. For SegNet network, it has been widely used as the baseline model of remote sensing images semantic segmentation and achieved sound semantic segmentation results. For example, Audebert et al. [11] based on SegNet network, combined with multimodal data, achieved state-of-the-art semantic segmentation results on the ISPRS Vaihingen dataset. And ResNet50 is also a common backbone for semantic segmentation tasks because it can build a deep-layer model with a wide receptive field. We use eight times downsampling for ResNet50 in our work. Unlike the SegNet and ResNet50 networks, we do not directly use the features of the last layer for semantic inference, instead, we feed the feature map of the last layer into the attention module for feature refinement and then make semantic inference, which is conducive to learning better feature expression.

C. Attention Module
Channel Attention: Given a high-resolution remote sensing image, it will produce a multichannel feature map F ∈ R C×H×W (where C, H, and W denote the number of channels, the height, the width of the feature map, respectively) after passing through several convolutional layers. The information expressed in the feature map of each channel is different. Channel attention aims to use the relationships between each channel of the feature map to learn a 1D weight W c ∈ R C×1×1 , and then multiply it to the corresponding channel. In this manner, it can pay more attention to the meaningful semantic information for the current task. To learn effective weight representation, we first aggregate spatial dimension information through global average pooling and global max pooling to generate two feature descriptors for each channel. Then we feed the two feature descriptors into a shared multilayer perceptron with one hidden layer (where the number of the hidden layer units is C/8) to generate more representative feature vectors. Afterward, we merge the output feature vectors through an element-wise summation operation. Finally, using a sigmoid function, we can obtain the final channel attention map. The flow chart is illustrated in the channel attention module of Fig. 1. The formula for calculating channel attention is shown in Formula 1: Spatial Attention: For the spatial attention, it focuses on where are valuable for current tasks. In HRRSIs, the ground objects are exhibited in various sizes and the distribution is complicated. Therefore, using spatial attention is useful for aggregating spatial information, especially for small ground objects. Spatial attention utilizes the relationships between different spatial positions to learn a 2D spatial weight map W s and then multiplies it to the corresponding spatial position to learn more representative features. To learn the spatial weight relationships effectively, we first generate two feature descriptors for each spatial position through global average pooling and global max pooling operations. Then we concatenate two feature descriptors together and generate a spatial attention map through a 7 × 7 convolution operation. Lastly, we use a sigmoid function to scale the spatial attention map to 0 ∼ 1. The flow chart is illustrated in the spatial attention module of Fig. 1. The spatial attention calculation formula is shown in Formula 2.
where f 7×7 represents a convolution operation with 7 × 7 kernel size.
We can easily compute that the number of parameters of the attention modules are so small that they can be neglected for both our SCAttNet V1 and SCAttNet V2, which have tens of millions of parameters. Specifically, the number of parameters of the channel attention module is C × C/4(C is the number of channels) and the and the number of parameters of the spatial attention module is 98. In addition, we only add the attention module at the end layer of the backbone network; thus, it seldom brings computation complexity to our proposed network.
In this study, we follow the method of Woo [18]to integrate the two attention modules. First, we use channel attention to select significant feature maps in each layer, then use spatial attention to choose considerable neuron's activity in each feature maps, which is conducive to extracting more valuable feature expression.

III. EXPERIMENT
In this section, we evaluate the performance of our network on the ISPRS Vaihingen and ISPRS Potsdam datasets 1 .

A. Datasets and evaluation metrics
The ISPRS Vaihingen dataset contains 33 orthophoto maps and related DSMs. Sixteen of them are labeled. The average size of the images is 2494 × 2064 and the resolution is 9 cm. Each image contains three bands: near infrared, red and green bands. Moreover, it includes six categories: impervious surfaces, buildings, low vegetation, trees, cars and clutter/background. The ISPRS Potsdam dataset contains 38 orthophoto maps and related normalized DSMs. Twenty-four of them are labeled. The size of each image is 6000 × 6000 and the resolution is 5 cm. Each image contains four bands: near infrared, red, green and blue bands. It has the similar categories as the ISPRS Vaihingen dataset.
To evaluate our proposed model, we use three evaluation metrics including mean inter-section over union (MIoU), average F1-score (AF) and overall accuracy (OA) to evaluate semantic segmentation performance.

B. Implementation details
Considering that many remote sensing datasets in practice do not have DSMs, we do not use such datasets in this experiment for wide application value. For the ISPRS Vaihingen dataset, we divide the labeled dataset into two parts, in which (ID 30, 32, 34, 37) are for evaluating the performance of the network, and the remaining 12 images are for training. The number of Vaihingen dataset is small; thus, to prevent overfitting, we first crop the training dataset randomly into a 256 × 256 size and then expand the data through rotation and translation operations, and finally obtain 12,000 patches for training. The Potsdam dataset is also divided into two parts, in which (ID 2 12, 3 12, 4 12, 5 12, 6 12, 7 12) are for testing, and the remaining 18 images are for training. Then, we crop it randomly and obtain 27,000 256 × 256 patches for training.
We trained all the model from the scratch without bells and whistles. The models including FCN-32s, FCN-8s, Unet, SegNet and G-FRNet all use VGG-16 as backbone. As for RefineNet and DeepLabv3+, we adopt the ResNet50 as backbone with 32 times downsampling for RefineNet and eight times downsampling for DeepLabv3+ as the original paper. We also adopt ResNet50 as backbone with eight times downsampling for CBAM. To train the proposed SCAttNet V1, we set the learning rate of SCAttNet V1 on the Vaihingen and Potsdam datasets to 1e-3 and 1e-4, respectively. To train SCAttNet V2, we set the learning rate of SCAttNet V2 on both datasets to 1e-3. The proposed models all adopt Adam as the optimizer and cross-entropy as the loss function. And the training epochs is set to 50. Considering limited computing resources, the batch size is set to 16. To test all the above models, we only use a sliding window without overlap to crop the images and then stitch together. We conduct all our experiments in Tensorflow platform with a NVIDIA 1080Ti GPU. Table I reports the semantic segmentation of the ISPRS Vaihingen dataset. We adopt the practice of [23][24] and do not report the accuracy of the clutter/background class because the Vaihingen dataset has less clutter/background. From the experimental results in Table 1, the MIoU/AF/OA increased by 1.4%/1.25%/0.56% with the channel attention module, compared with original SegNet. This increase shows the effectiveness of the channel attention module to capture meaningful semantic information; With the spatial attention module, the IoU/F1-score for small objects such as cars increased by 3.08%/3.21%. This increase shows that the spatial attention module can aggregate more location information even if the small objects in original images are 32 times downsampling in SegNet. Though the accuracy of impervious surfaces, buildings, and trees classes slightly decreased, we can still increase the MIoU/AF by 2.9%/2.59% compared with original SegNet after inputting the channel-refined features to the spatial attention module. Moreover, in SCAttNet V2, the MIoU/AF/OA increased by 1.21%/0.83%/0.90% compared with ResNet50 which as a baseline model. In addition, we find that in FCN-32s, the car category shows a low accuracy, but the car category in FCN-8s has improved much compared with FCN-32s, which shows the importance of low-level features for segmenting small objects.

C. Results of Vaihingen dataset
To compare the semantic segmentation results, we visualize the semantic segmentation results of ID32. The visualization results are shown in the first row of Fig. 2. We can see that our SCAttNet V1 achieves more coherent results compared with the original SegNet model. In addition, our model infers more accurately in small object areas such as cars in the right middle of the image. We also test the accuracy of the ID32 area. The MIoU/AF/OA of SegNet is 60.57%/74.01%/82.78%, whereas that of our SCAttNet V1 is 64.92%/77.74%/85.49%. On this basis, our network can improve semantic segmentation accuracy by incorporating the attention module effectively.  Table II reports the semantic segmentation results of the IS-PRS Potsdam dataset. From the semantic segmentation results, the proposed SCAttNet V2 model is superior to the comparative models. Moreover, it achieves 1.12%/1.08%/1.03% higher in MIoU/AF/OA metrics compared with ResNet50 which as a baseline model. In SCAttNet V1, The MIoU/AF/OA has increased by 2.08%, 1.74% and 1.35%, respectively compared with SegNet which as a baseline model. Thus, we further confirm the effectiveness of the attention module.

D. Results of Potsdam dataset
The second row of Fig. 2 shows the visualization results of the ID 5 12 area of the ISPRS Potsdam dataset. Compared with the comparative model, our proposed network achieves improved segmentation results in the building area, especially in terms of avoiding background interference. We also test the semantic segmentation performance in this area. The MIoU/AF/OA of the SegNet network is 57.19%/68.87%/83.81%, whereas that of SCAttNet V1 network is 59.50%/71.16%/85.04%. We find that our network achieves higher accuracy in all three metrics compared with the comparative model.

E. Quantitative analysis of improved interpretability
To analyze the enhancement of the attention module to the network, we visualize the feature expression of the SegNet network and our SCAttNet V1 network on the ISPRS Vaihingen dataset. We can simply overlay the heatmap of the network before SoftMax operation with an original image, and the relevant areas can be highlighted for a specific category. The visualization results are shown in Fig. 3. After incorporating the attention module, our network can focus on the areas of target and suppress the influence of other categories better than before. As shown in the first column of Fig.3, after incorporating the attention module, our network only has a strong response in the car category and other areas are cold toned, which means that the relevance in other areas is very low. However, in the original SegNet network, the impervious area also shows a certain response that may cause interference for the car category. In addition, as shown in the building category in the third column of Fig.3 , the impervious surface area is suppressed after incorporating the attention module. Thus, the impervious surface area avoids classifying into Fig. 3. Visualization analysis results of Vaihingen dataset. From left to right: the first two columns represent car categories, the second two columns represent building category, the third two columns represent impervious surfaces category, the fourth two columns represent low vegetation category, the fifth two columns represent tree category. buildings.

IV. CONCLUSION
In this study, we propose a new semantic segmentation network that can adaptively refine features based on the attention module. Experiments on the ISPRS Vaihingen and Potsdam datasets demonstrate the effectiveness of our method. However, some shortcomings remain. The study only uses two common attention modules. Thus, how to design the attention module effectively and capture more discriminative features for semantic inference remains a promising direction for future work.