An urban water body extraction method and system based on an attention mechanism

By combining dilated convolution and dual attention mechanisms, the problems of threshold determination and time-consuming feature construction in urban water body extraction are solved, achieving efficient and accurate water body extraction results, especially in better segmenting water body boundaries in high-resolution urban remote sensing images.

CN117475300BActive Publication Date: 2026-11-24WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311316069.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-11
Publication Date
2026-11-24
Estimated Expiration
2043-10-11

AI Technical Summary

Technical Problem

Existing methods for extracting urban water bodies in remote sensing images suffer from problems such as difficulty in determining thresholds, time-consuming construction of complex features, and low accuracy in extracting water features from high-resolution urban images. In particular, they neglect spatial information in low-level features and global feature dependencies.

Method used

A dilated convolution-based backbone network is used to extract multi-scale features, and a dual attention mechanism is combined to extract global features in the spatial and channel domains. The model training is optimized using joint loss functions, including weighted cross-entropy loss and Lovász hinge loss, to improve the accuracy of water body extraction.

Benefits of technology

It significantly improves the accuracy and efficiency of urban water body extraction with limited computational complexity, especially in better segmenting water body boundaries in high-resolution urban remote sensing imagery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117475300B_ABST
    Figure CN117475300B_ABST
Patent Text Reader

Abstract

High-precision extraction of water bodies from urban remote sensing images is of great significance for assisting in the formulation of river and lake management policies and ensuring the sustainable development of urban water resources. However, high-resolution urban remote sensing images contain complex spatial and semantic information, which can lead to discrepancies between water body features extracted based on local information and global information, thus affecting the accuracy of urban water body semantic segmentation. To address this problem, this invention discloses an urban water body extraction method and system based on an attention mechanism. This invention proposes an encoder-decoder neural network based on an attention mechanism. In this network, the backbone network with dilated convolutions can acquire low-level and high-level features of urban remote sensing images at multiple scales. The encoder-decoder structure based on the attention mechanism can extract global features in the spatial domain and channel domain respectively, and then combine the two types of global features to obtain the urban water body semantic segmentation result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent interpretation technology of remote sensing images, and in particular to a method and system for extracting urban water bodies based on an attention mechanism. Background Technology

[0002] Water is the source of life, vital to all known life forms on Earth, and influences climate, biodiversity, and human well-being. Urban water resources, as part of the Earth's water resources, play a crucial role in maintaining urban ecological balance and ensuring healthy urban economic development. However, due to the influence of climate change, human activities, and other factors, the distribution of urban water bodies is extremely uneven. Therefore, obtaining accurate information on the distribution of urban water bodies is of great significance in order to better assist governments in formulating river and lake management policies and ensuring the sustainable development of urban water resources.

[0003] Remote sensing, with its significant advantages of wide coverage, long time series, high efficiency, and saving manpower and resources, plays an increasingly important role in water body extraction. Remote sensing imagery primarily utilizes the spectral differences between water bodies and other land features across different bands for water body extraction. Previous studies have proposed various methods for water body extraction from remote sensing images. Among traditional optical imagery methods, the water index method is commonly used. This involves calculating an index reflecting water body characteristics across multiple bands of the remote sensing image, and then using a threshold to segment the image into water bodies and non-water bodies. Over the years, numerous scholars have proposed various water body indices, such as the Normalized Difference Water Index (NDWI), the Modified NDWI (MNDWI), and the Weighted NDWI (WNDWI). A major challenge of the water index method is determining the threshold; an inappropriate threshold selection can significantly affect the water body extraction results. In addition, due to the highly complex spatial structure of urban remote sensing images, when using water index to extract urban water bodies, roads, buildings, and building shadows are likely to be misclassified as water bodies.

[0004] Classical machine learning methods, such as Support Vector Machines (SVM), Decision Trees (DT), and Random Forests (RF), can also be applied to water body extraction tasks. These algorithms classify remote sensing images by manually setting spectral and texture features, effectively solving the problem of water body misclassification and achieving high accuracy. However, the features in machine learning have a significant impact on the results of water body extraction, thus requiring considerable expertise in manually designing features. Furthermore, constructing feature vectors is time-consuming, resulting in low efficiency for machine learning-based water body extraction. Compared to classical machine learning methods, deep learning methods can directly capture features from the original image through multiple convolutional layers, thus eliminating the complex feature construction process and offering a significant efficiency advantage. Among them, semantic segmentation models based on Convolutional Neural Networks (CNNs) can extract semantic features from images and associate them with category labels. In recent years, numerous scholars have improved upon semantic segmentation models such as Fully Convolutional Networks (FCNs), U-Net, and DeepLab, and applied them to water body extraction tasks, achieving high accuracy. However, these semantic segmentation models can only extract water features with a receptive field of a certain size, or extract multi-scale water features with multiple receptive fields of different sizes. Furthermore, the complex semantics inherent in high-resolution urban remote sensing imagery make it easy for water features extracted based on local information to deviate from global information, thus affecting the accuracy of urban water body semantic segmentation.

[0005] Attention mechanisms, which calculate weight distributions based on global features and apply these weights to features for targeted extraction of global features, have become a major research focus in recent years. Non-local Neural Networks (NNNs) were the first to propose a non-local operator that directly computes relationships between all locations to obtain long-range dependencies. SENet obtained channel-dimensional weights through simple "squeezing" and "activation" operations, demonstrating that dependencies between different channels are equally important for feature extraction. CBAM (Convolutional Block Attention Module) divides the attention process into channel and spatial dimensions and designs two independent, sequential modules to achieve channel-to-space attention extraction of feature maps. DANet (Dual Attention Network) also designs an attention module that considers both channel and spatial dimensions, but uses a parallel approach to obtain attention weights for both dimensions, achieving excellent performance. Convolutional neural networks based on attention mechanisms typically use a backbone network to extract high-level features with significant semantic information, and then apply attention mechanisms to these high-level features. This type of network has relatively few parameters and is more efficient, but it ignores the spatial information contained in low-level features, which can affect the accuracy of water body extraction. Summary of the Invention

[0006] To address the problems existing in the semantic segmentation of urban water bodies, this invention discloses an urban water body extraction method based on an attention mechanism. The main innovation of this method lies in introducing dilated convolution and a dual attention mechanism to solve the multi-scale and multi-feature problem of water body objects. First, multi-scale features are extracted based on dilated convolution, and then the dual attention mechanism is used to enhance the learning of global channel features and spatial features, thereby achieving accurate extraction of urban water bodies.

[0007] This invention addresses the shortcomings of existing urban water body extraction methods by providing an attention-based approach. This method can acquire low-level and high-level features from urban remote sensing images at multiple scales, extracting global features in both the spatial and channel domains, and then combining these two feature sets for water body extraction. Furthermore, considering the importance of Intersection over Union (IoU) for accuracy evaluation in semantic segmentation tasks, and the problem of class imbalance in sample data caused by the extremely uneven distribution of urban water bodies, this invention proposes a joint loss function for urban water body semantic segmentation, achieving higher water body extraction accuracy.

[0008] The technical solution of this invention is a method for extracting urban water bodies based on an attention mechanism, comprising the following steps:

[0009] Step 1: Construct an urban water body extraction model, including an encoder and a decoder. The encoder includes a backbone network with dilated convolutions for extracting low-level and high-level features of the water body at different scales, and a channel attention module for calculating global channel dependencies between high-level features. The decoder includes a spatial attention module, a feature fusion module, and a post-processing module. The spatial attention module is used to calculate global spatial dependencies between low-level features. The feature fusion module is used to fuse the outputs of the channel attention module and the spatial attention module. The post-processing module is used to adjust the scale of the fused feature map to obtain an urban water body extraction result with the same size as the input image.

[0010] Step 2: The urban water body extraction model is trained by combining a weighted cross-entropy loss function and a Lovász hinge, which further improves the accuracy of water body extraction.

[0011] Step 3: Use the trained urban water body extraction model to extract urban water bodies.

[0012] Furthermore, in step 1, ResNet-101 with dilated convolution is used as the backbone network of the model, and the last three residual blocks are improved. The outputs of the first three residual blocks are used as low-level features, and the outputs of all residual blocks are used as high-level features. The specific process for extracting features from the improved residual blocks is as follows:

[0013] Step 111: After passing through a 1×1 convolutional layer, the number of channels in the feature map is reduced;

[0014] Step 112: Apply dilated convolutional layers with 3×3 kernel size and different dilation rates to the three residual blocks respectively to capture feature dependencies at three different scales. The calculation formula for one-dimensional dilated convolution is as follows:

[0015]

[0016] Where x(i) is the output signal, y(i) is the output signal, ω refers to the filter of size K, and r is the dilation rate;

[0017] Step 113: Use a 1×1 convolution to restore the number of channels in the feature map to the original channel size;

[0018] Step 114: Add the processed features from step 113 to the unprocessed features pixel by pixel to output the feature extraction result of the residual block.

[0019] Furthermore, the specific processing flow of the spatial attention module in step 1 is as follows:

[0020] Step 121: For the low-level feature map A with C×H×W output by the backbone network, a 1×1 convolution operation is first performed to obtain feature maps D and E with size (C / 8)×H×W, and they are then transformed to (C / 8)×N, where N represents the number of pixels, N=H×W, and C, H, and W represent the number of channels, height, and width, respectively.

[0021] Step 122: Multiply the transposed D by E, and normalize the product using a softmax layer to obtain an attention feature map S of size N×N, as shown in the formula:

[0022]

[0023] Where i and j each represent a pixel in the feature map; s ji The element in column i and row j of the attention feature map represents the influence of pixel i on pixel j.

[0024] Step 123: Transform F to C×N and multiply it with the transpose of S. Transform the product of size C×N to size C×H×W, then weight the product with parameter α, and add it element-by-element to the original feature map A to obtain the result G of the spatial attention mechanism, with the formula:

[0025]

[0026] The initial value of the weight α is 0, and its subsequent value is dynamically adjusted through model training.

[0027] Furthermore, the specific processing flow of the channel attention module in step 1 is as follows:

[0028] Step 131: For the high-level feature map B output by the backbone network with C×H×W as the number of channels, height, and width, first transform the feature map B to C×N, where C, H, and W represent the number of channels, height, and width, respectively.

[0029] Step 132: Multiply B and its transpose, then normalize the product using a softmax layer to obtain an attention feature map X of size C×C, as shown in the formula:

[0030]

[0031] Where i and j each represent a pixel in the feature map; x ji The element in column i and row j of the attention feature map represents the influence of pixel i on pixel j.

[0032] Step 133: Multiply the transposed X by B, transform the product to C×H×W, apply the residual concept, weight the product with parameter β, and add it element-by-element to the original feature map B to obtain the CAM result I. The formula is:

[0033]

[0034] The initial value of the weight β is 0, and the subsequent value is dynamically adjusted through model training.

[0035] Furthermore, in step 1, before fusion, the output size of the spatial attention mechanism is made the same as that of the low-level features by sequentially setting 1×1 convolution operations and 4x upsampling in the encoder.

[0036] Furthermore, the post-processing module includes 3×3 convolutions to fuse low-level and high-level features, as well as 1×1 convolutions and 4x upsampling to finally obtain urban water body extraction results with the same size as the input image.

[0037] Furthermore, the Lovász hinge loss function in step 2 is calculated as follows;

[0038] The Jaccard index, commonly used in image segmentation, is represented in the following form:

[0039]

[0040] J c Refers to the Jaccard index, where c is the category and y is the index. * For the true value, To use the Jaccard index as a loss function, the predicted value can be transformed as follows:

[0041]

[0042] in For the deformed Jaccard index, the misclassified pixel set M is... c Represented as:

[0043]

[0044] Therefore, formula (7) can be rewritten as:

[0045]

[0046] Where p is the number of pixels in the image. It is discrete and non-differentiable, so it cannot be directly used as a loss function. The Lovász hinge expands the pair through Lovász extension. Smoothing was performed, and the input space was changed from discrete {0,1} p Transform into continuous For a set function Δ: Its Lovász expansion is shown below:

[0047]

[0048] with g i (m)=Δ({π1,…,π i})-Δ({π1,…,π i-1}) (11)

[0049] in Let represent the set function after the Lovász expansion, and π represent the descending order of the elements in m. Although the input form of the function changes after the transformation, its output value remains unchanged and it exhibits convexity. This is relevant to the Jaccard loss for the positive class in binary classification. Its Lovász hinge is shown below:

[0050]

[0051] Where F is the model output. for The Lovász expansion, where m is the hinge loss associated with the prediction result, is expressed as follows:

[0052]

[0053] Where F i (x) represents the i-th element of the model output. This represents the corresponding true value.

[0054] Furthermore, the formula for the weighted cross-entropy loss function in step 2 is as follows:

[0055]

[0056] Where N is the total number of samples, y i For the label of sample i, p i Let w be the probability that sample i is predicted to be positive, and w be the proportion of positive sample pixels in the total number of pixels.

[0057] Furthermore, in step 2, the weighted cross-entropy loss function and the Lovász hinge are combined to obtain the joint loss function Loss suitable for urban water body extraction, as shown in the formula:

[0058] Loss=ω1L1+ω2L2 (15)

[0059] Where L1 and L2 refer to the Lovász hinge loss function and the weighted cross-entropy loss function, respectively, and ω1 and ω2 refer to the corresponding weights. A gradient-based loss method is used to dynamically adjust the weights during training. First, the training speed is defined:

[0060]

[0061]

[0062] Where i = 1, 2 are the indices of the two loss functions, t is the number of training iterations, and L i (t) represents L at time t. i The loss value, L0(t), represents the total loss value at time t; for L at time t... i , Represents the loss ratio, r i (t) represents the inverse value of the relative learning speed; the faster the learning speed, the higher the relative learning speed. With r i The smaller the (t) value;

[0063] To learn the weight ω at time t i (t) requires placing the gradient norms of different tasks under the same metric to obtain their relative magnitudes; and dynamically adjusting the magnitudes of these gradient norms so that different tasks train at similar rates. For the weights W of the last layer of the network model, the following variables are defined:

[0064]

[0065] in For gradient operators, ω i (t)L i (t) represents the weighted L i ,but The weighted L represents the weight W. i The L2 norm of the gradient, and the average value corresponding to the two losses are:

[0066]

[0067] The product of this average value and the inverse value of the learning speed is used as the target value, as shown below:

[0068]

[0069] Where α is a hyperparameter set before training; the greater the difference between the two losses, the greater this value should be. In summary, the calculation... The L1 norm of the difference from the target value can be obtained for ω. i The loss values ​​for (t) are as follows:

[0070]

[0071] During training, ω is first initialized. i (0) = 1, through L grad To achieve the adjustment of ω during each training iteration i(t) is dynamically adjusted, and then the joint loss function in formula (15) is dynamically adjusted.

[0072] This invention also provides an urban water body extraction system based on an attention mechanism, comprising the following modules:

[0073] The model building module is used to construct an urban water body extraction model, including an encoder and a decoder. The encoder includes a backbone network with dilated convolutions to extract low-level and high-level features of water bodies at different scales, as well as a channel attention module to calculate global channel dependencies between high-level features. The decoder includes a spatial attention module, a feature fusion module, and a post-processing module. The spatial attention module is used to calculate global spatial dependencies between low-level features, the feature fusion module is used to fuse the outputs of the channel attention module and the spatial attention module, and the post-processing module is used to adjust the scale of the fused feature map to obtain an urban water body extraction result with the same size as the input image.

[0074] The model training module trains the urban water body extraction model using a joint loss function that combines the weighted cross-entropy loss function and the Lovász hinge, further improving the accuracy of water body extraction.

[0075] The model application module is used to extract urban water bodies using a trained urban water body extraction model.

[0076] Compared with the prior art, the advantages of the present invention are as follows:

[0077] This invention proposes an encoder-decoder neural network based on an attention mechanism. In this network, the backbone network with dilated convolutions can acquire low-level and high-level features of urban remote sensing images at multiple scales. The attention-based encoder-decoder structure can extract global features in the spatial and channel domains respectively, and then combine the two types of global features to obtain the semantic segmentation result of urban water bodies. A joint loss function is also proposed, achieving higher water body extraction accuracy. Experiments demonstrate that, with a limited increase in computational complexity, it significantly improves the accuracy of urban water body extraction. Attached Figure Description

[0078] Figure 1 This is a network model structure diagram of the urban water body extraction method based on the attention mechanism disclosed in this invention.

[0079] Figure 2 This is a schematic diagram of the dilated convolution used in this invention.

[0080] Figure 3 This is a schematic diagram of the residual block with dilated convolution used in this invention.

[0081] Figure 4 This is a schematic diagram of the spatial attention mechanism and channel attention mechanism disclosed in this invention.

[0082] Figure 5 This invention provides a comparison of the effectiveness of the urban water extraction method disclosed in this invention with other commonly used methods. Detailed Implementation

[0083] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and examples.

[0084] like Figure 1 As shown, an attention-based method for extracting urban water bodies includes the following steps:

[0085] S1: Using a backbone network with dilated convolutions, low-level features containing more spatial information and high-level features containing more semantic information of water bodies are extracted at different scales.

[0086] Water bodies exhibit strong spatiotemporal variability, and large-scale water features frequently appear in remote sensing images. Therefore, a large receptive field is required in the backbone network to capture the dependencies of water features. Based on the assumption that neighboring pixels are similar, dilated convolution adds dilation to the kernel of standard convolution, thereby dynamically adjusting the receptive field by increasing the dilation rate without increasing the number of parameters, capturing feature information at different scales, as shown in the attached figure. Figure 2 As shown.

[0087] ResNet is a classic deep convolutional neural network, and its idea of ​​solving overfitting through residual blocks is still applied in many cutting-edge CNNs. ResNet-101 is a commonly used ResNet model, containing 33 similar residual blocks (101 convolutional layers). This invention uses a ResNet-101 model with dilated convolutions as the backbone, primarily improving the last three residual blocks, such as... Figure 3 As shown, the outputs of the first three residual blocks are used as low-level features, and the outputs of all residual blocks are used as high-level features, which are then input into subsequent neural networks for further feature extraction.

[0088] The improved residual block feature extraction process is as follows:

[0089] S11: After a 1×1 convolutional layer, the number of feature map channels is reduced from 256 to 64;

[0090] S12: Apply dilated convolutional layers with 3×3 kernel size and different dilation rates to three residual blocks respectively to capture feature dependencies at three different scales. The calculation formula for one-dimensional dilated convolution is as follows:

[0091]

[0092] Where x(i) is the output signal, y(i) is the output signal, ω refers to the filter of size K, and r is the dilation rate.

[0093] S13: Use 1×1 convolution to restore the number of feature map channels from 64 to 256;

[0094] S14: Add the features processed in S13 to the features before processing pixel by pixel, and output the feature extraction result of the residual block.

[0095] S2: Apply spatial attention mechanism to low-level features to compute global spatial dependencies;

[0096] The low-level features output by the backbone network contain a significant amount of spatial information. Inspired by DANet, this invention introduces a similar spatial attention mechanism into the decoder of the neural network to process the low-level features, thereby obtaining the global feature dependencies in the spatial domain, as shown in the appendix. Figure 4 As shown.

[0097] For the low-level feature map A output by the backbone network, which has C×H×W channels, height, and width, the specific process of feature extraction using the spatial attention mechanism is as follows:

[0098] S21: Perform a 1×1 convolution operation on feature map A to obtain feature maps D and E with size (C / 8)×H×W, and transform them to (C / 8)×N (N=H×W represents the number of pixels, C, H, and W represent the number of channels, height, and width, respectively).

[0099] S22: Multiply the transposed D by E, and normalize the product using a softmax layer to obtain an attention feature map S of size N×N, as shown in the formula:

[0100]

[0101] Where i and j each represent a pixel in the feature map; s ji The element in column i and row j of the attention feature map represents the influence of pixel i on pixel j.

[0102] S23: Transform F to C×N and multiply it by the transpose of S. Transform the product of size C×N to size C×H×W, then weight the product with parameter α, and add it element-by-element to the original feature map A to obtain the result G of the spatial attention mechanism, as shown in the formula:

[0103]

[0104] The initial value of the weight α is 0, and its subsequent value is dynamically adjusted through subsequent model training.

[0105] S3: Apply the channel attention mechanism to high-level features to calculate global channel dependencies;

[0106] The high-level features output by the backbone network contain a significant amount of channel information. Inspired by DANet, we introduce a similar channel attention mechanism into the encoder of the neural network to process high-level features, thereby obtaining the global feature dependencies in the channel domain, as shown in the appendix. Figure 4 As shown.

[0107] For a high-level feature map B with C×H×W output by the backbone network, the specific process of feature extraction using the channel attention mechanism is as follows:

[0108] S31: Transform feature map B to C×N;

[0109] S32: Multiply B and its transpose, then normalize the product using a softmax layer to obtain an attention feature map X of size C×C, as shown in the formula:

[0110]

[0111] Where i and j each represent a pixel in the feature map; x ji The element in column i and row j of the attention feature map represents the influence of pixel i on pixel j.

[0112] S33: Multiply the transposed X by B, transform the product to C×H×W, apply the residual concept, weight the product with parameter β, and add it element-by-element to the original feature map B to obtain the CAM result I. The formula is:

[0113]

[0114] The initial value of the weight β is 0, and its subsequent value is dynamically adjusted through subsequent model training.

[0115] S4: The low-level and high-level features processed by the attention mechanism are fused together, and then urban water bodies are extracted based on global dependencies;

[0116] The specific process is as follows:

[0117] S41: In the encoder, by sequentially setting 1×1 convolution operation and 4x upsampling, the output size (number of channels, width, height) of the spatial attention mechanism is made the same as that of the low-level features;

[0118] S42: In the decoder, the output of the channel attention mechanism is concatenated with the output of the encoder, and then a 3×3 convolution is performed to fuse low-level and high-level features.

[0119] S43: By using 1×1 convolution and 4x upsampling, the urban water body extraction result with the same size as the input image is obtained.

[0120] S5: The accuracy of water extraction is further improved by using a joint loss function that combines the weighted cross-entropy loss function and the Lovász hinge.

[0121] In image segmentation, compared to the commonly used cross-entropy loss function, the IoU score, also known as the Jaccard index, can better evaluate image segmentation performance. The Lovász hinge implemented the use of IoU as a loss function in CNNs and showed good results in the training and testing of semantic segmentation models, but it suffers from training instability. Furthermore, in urban water body semantic segmentation tasks, the ratio of positive to negative samples often differs significantly, but the Lovász hinge does not consider this sample imbalance problem. In contrast, while the weighted cross-entropy loss function does not bring a higher IoU score to the model, its training process is stable, and the weighting method alleviates the problem of positive and negative sample imbalance. Considering IoU, training stability, and the handling of sample imbalance, this invention proposes a joint loss function combining the Lovász hinge and weighted cross-entropy.

[0122] The specific process is as follows:

[0123] S51: Calculate the Lovász hinge. The Jaccard index, commonly used in image segmentation, can be represented as follows:

[0124]

[0125] J c Refers to the Jaccard index, where c is the category and y is the index. * For the true value, This represents the predicted value. To use the Jaccard index as a loss function, it can be transformed as follows:

[0126]

[0127] in The Jaccard index is used for the deformed pixel set M. c Represented as:

[0128]

[0129] Therefore, formula (7) can be rewritten as:

[0130]

[0131] Where p is the number of pixels in the image. It is discrete and non-differentiable, so it cannot be directly used as a loss function. The Lovász hinge expands the pair through Lovász extension. Smoothing was performed, and the input space was changed from discrete {0,1} p Transform into continuous For a set function Δ: Its Lovász expansion is shown below:

[0132]

[0133] with g i (m)=Δ({π1,…,π i})-Δ({π1,…,π i-1}) (11)

[0134] in Let represent the set function after the Lovász expansion, and π represent the descending order of the elements in m. Although the input form of the function changes after the transformation, its output value remains unchanged and it exhibits convexity. If m is a vector of all pixel errors, then... This is considered a weighted sum of these errors. For the Jaccard loss of the positive class in binary classification... Its Lovászhinge is as follows:

[0135]

[0136] Where F is the model output. for The Lovász expansion, where m is the hinge loss associated with the prediction result, is expressed as follows:

[0137]

[0138] Where F i (x) represents the i-th element of the model output. This represents the corresponding true value.

[0139] S52: Calculate the weighted cross-entropy loss function in binary classification, using the following formula:

[0140]

[0141] Where N is the total number of samples, y i For the label of sample i, p i Let w be the probability that sample i is predicted to be positive, and w be the proportion of positive sample pixels in the total number of pixels.

[0142] S53: Combining the two loss functions, a joint loss function Loss suitable for urban water body extraction is proposed, the formula of which is:

[0143] Loss=ω1L1+ω2L2 (15)

[0144] Where L1 and L2 refer to the loss functions described in formulas (12) and (14), respectively, and ω1 and ω2 refer to the corresponding weights. Since different loss functions have different loss descent rates, the model is easily dominated by the loss function with the fastest learning speed, making it difficult to reach the global optimum of the joint loss function. Therefore, this invention uses a gradient loss-based method to achieve dynamic adjustment of weights during training. First, the training speed is defined as:

[0145]

[0146]

[0147] Where i = 1, 2 are the indices of the two loss functions, t is the number of training iterations, and L i (t) represents L at time t. i The loss value, L0(t), represents the total loss value at time t; for L at time t... i , Represents the loss ratio, r i (t) represents the inverse value of the relative learning speed. The faster the learning speed, With r i The smaller the (t) value.

[0148] To learn the weight ω at time t i (t) requires placing the gradient norms of different tasks under the same metric to obtain their relative magnitudes; and dynamically adjusting the magnitudes of these gradient norms so that different tasks train at similar rates. For the weights W of the last layer of the network, the following variables are defined:

[0149]

[0150] in For gradient operators, ω i (t)L i (t) represents the weighted L i ,but The weighted L represents the weight W. i The L2 norm of the gradient, and the average value corresponding to the two losses are:

[0151]

[0152] The product of this average value and the inverse value of the learning speed is used as the target value, as shown below:

[0153]

[0154] Here, α is a hyperparameter set before training; the greater the difference between the two losses, the more this value should be increased. In summary, the calculation... The L1 norm of the difference from the target value can be obtained for ω. i The loss values ​​for (t) are as follows:

[0155]

[0156] During training, ω is first initialized. i (0) = 1. This loss function can then adjust ω during each training iteration. i (t) is dynamically adjusted, and then the joint loss function in formula (15) is dynamically adjusted.

[0157] This invention also provides an urban water body extraction system based on an attention mechanism, comprising the following modules:

[0158] The model building module is used to construct an urban water body extraction model, including an encoder and a decoder. The encoder includes a backbone network with dilated convolutions to extract low-level and high-level features of water bodies at different scales, as well as a channel attention module to calculate global channel dependencies between high-level features. The decoder includes a spatial attention module, a feature fusion module, and a post-processing module. The spatial attention module is used to calculate global spatial dependencies between low-level features, the feature fusion module is used to fuse the outputs of the channel attention module and the spatial attention module, and the post-processing module is used to adjust the scale of the fused feature map to obtain an urban water body extraction result with the same size as the input image.

[0159] The model training module trains the urban water body extraction model using a joint loss function that combines the weighted cross-entropy loss function and the Lovász hinge, further improving the accuracy of water body extraction.

[0160] The model application module is used to extract urban water bodies using a trained urban water body extraction model.

[0161] The specific implementation methods of each module are the same as those of each step, and will not be described in this invention.

[0162] The effectiveness of this invention compared with other commonly used urban water body extraction methods was analyzed using the publicly available remote sensing dataset GID, as shown in the attached figure. Figure 5As shown, U-Net, PSPNet, and CBAM all, to varying degrees, ignore the small river tributaries scattered throughout the urban area in the original image (highlighted by red rectangles). DeepLabv3+ and DANet can identify the small rivers in the example, but due to misclassification caused by buildings and their shadows, the extracted river boundaries appear wider than the actual boundaries. In contrast, this invention extracts this river more comprehensively and accurately, the extracted boundaries are closer to reality, and it better depicts the water body. It is worth noting that the "ground truth" in the figure may not be entirely accurate. For example, in the attached... Figure 5 In (a), several bridges span the stream are located near... Figure 5 This is not reflected in (b). However, it can be seen that the present invention is still able to identify these unmarked non-aquatic bodies to a certain extent, as evidenced by the interception of small rivers in the extraction results, which further illustrates the excellent performance of the present invention in extracting urban water bodies.

[0163] Accuracy was evaluated using three commonly used metrics—precision, recall, and intersection-over-union (IoU)—on the GID dataset, and the results are shown in Table 1. The results show that CBAM and DANet performed relatively poorly in terms of accuracy. This indicates that traditional attention mechanisms neglect the importance of low-level features and are ineffective for urban water intake. On the other hand, DeepLabv3+ performed better among the compared methods due to its ability to extract multi-scale features and combine low- and high-level features. Our invention surpasses all compared methods in terms of accuracy on the GID dataset, achieving 95.52% precision, 95.66% recall, and 91.55% IoU.

[0164] Table 1. Accuracy comparison between the present invention and other commonly used methods.

[0165]

[0166] The specific embodiments described herein are merely illustrative of the spirit of the invention. Those skilled in the art to which this invention pertains may make various modifications or additions to the described specific embodiments or use similar methods to substitute them, without departing from the spirit of the invention or exceeding the scope defined by the appended claims.

Claims

1. A method for extracting urban water bodies based on an attention mechanism, characterized in that, Includes the following steps: Step 1: Construct an urban water body extraction model, including an encoder and a decoder. The encoder includes a backbone network with dilated convolutions for extracting low-level and high-level features of the water body at different scales, and a channel attention module for calculating global channel dependencies between high-level features. The decoder includes a spatial attention module, a feature fusion module, and a post-processing module. The spatial attention module is used to calculate global spatial dependencies between low-level features. The feature fusion module is used to fuse the outputs of the channel attention module and the spatial attention module. The post-processing module is used to adjust the scale of the fused feature map to obtain an urban water body extraction result with the same size as the input image. In step 1, ResNet-101 with dilated convolution is used as the backbone network of the model, and the last three residual blocks are improved. The outputs of the first three residual blocks are used as low-level features, and the outputs of all residual blocks are used as high-level features. The specific process for extracting features from the improved residual blocks is as follows: Step 111, after Convolutional layers are used to reduce the number of channels in the feature map; Step 112, apply convolution kernels of size 1 to each of the three residual blocks. Dilated convolutional layers with different dilation rates capture feature dependencies at three different scales. The calculation formula for one-dimensional dilated convolution is as follows: in For output signal, For output signal, The size is The filter, The expansion rate; Step 113, use Convolution restores the number of channels in the feature map to the original channel size; Step 114: Add the processed features from step 113 to the unprocessed features pixel by pixel, and output the feature extraction result of the residual block. Step 2: The urban water body extraction model is trained by combining a weighted cross-entropy loss function and a Lovász hinge, which further improves the accuracy of water body extraction. Step 3: Use the trained urban water body extraction model to extract urban water bodies.

2. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: The specific processing flow of the spatial attention module in step 1 is as follows: Step 121, for the number of channels, height, and width of the backbone network output are... The low-level feature map A is first processed The convolution operation yields a result of size [size missing]. Feature maps D and E, and deform them to N represents the number of pixels. C, H, and W represent the number of channels, height, and width, respectively. Step 122: Multiply the transposed D by E, and normalize the product using a softmax layer to obtain a product of size . The attention feature map S is given by the formula: in, , Each represents a pixel in a feature map; For attention feature maps List The elements of a row represent pixel pair The influence of pixels; Step 123, deform F to Multiply by the transpose of S, and set the size to... Transform the product to Size, then use parameters The weighted product is then added element-wise to the original feature map A to obtain the result G of the spatial attention mechanism, as shown in the formula: Among them, weight The initial value is 0, and subsequent values ​​are dynamically adjusted through model training.

3. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: The specific processing flow of the channel attention module in step 1 is as follows: Step 131, the number of channels, height, and width output from the backbone network are... The high-level feature map B is first deformed to... C, H, and W represent the number of channels, height, and width, respectively. Step 132: Multiply B and its transpose, then normalize the product using a softmax layer to obtain a product of size . The attention feature map X is given by the formula: in, , Each represents a pixel in a feature map; For attention feature maps List The elements of the row represent the first row. pixel pair The influence of pixels; Step 133: Multiply the transposed X by B, and transform the product to... Then apply the concept of residuals, and then use parameters. The weighted product is then added element-by-element to the original feature map B to obtain the result I of the channel attention mechanism, as shown in the formula: Among them, weight The initial value is 0, and subsequent values ​​are dynamically adjusted through model training.

4. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: In step 1, before fusion, the encoder is first configured sequentially. Convolution operations and 4x upsampling make the output size of the spatial attention mechanism the same as that of the low-level features.

5. The urban water body extraction method based on an attention mechanism according to claim 1, characterized in that: The post-processing module includes Convolution is used to fuse low-level and high-level features, and Convolution and 4x upsampling are used to obtain the final urban water body extraction result with the same size as the input image.

6. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: The Lovász hinge loss function is calculated in step 2 as follows; The Jaccard index, commonly used in image segmentation, is represented in the following form: in Refers to the Jaccard index. As a category, For the true value, To use the Jaccard index as a loss function, the predicted value can be transformed as follows: in For the deformed Jaccard index, the misclassified pixel set Represented as: Therefore, formula (7) can be rewritten as: in The number of pixels in the image. It is discrete and non-differentiable, so it cannot be directly used as a loss function. The Lovász hinge expands the pair through Lovász extension. Smoothing was performed, and the input space was changed from discrete... Transform into continuous For a set function Its Lovász expansion is shown below: in Represents the set function after the Lovász expansion. represent Arranging the elements in descending order changes the input form of the function, but its output value remains unchanged and exhibits convexity. This applies to the Jaccard loss for the positive class in binary classification. Its Lovász hinge is shown below: in For model output, for The expansion of Lovász The hinge loss, which is related to the prediction result, is calculated using the following formula: in The first one representing the model output One element, This represents the corresponding true value.

7. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: The formula for the weighted cross-entropy loss function in step 2 is: in, The total number of samples, For the sample The tag, For the sample The probability of predicting a positive class. This represents the proportion of positive sample pixels in the total number of pixels across all data.

8. The urban water body extraction method based on attention mechanism according to claim 1, characterized in that: In step 2, the weighted cross-entropy loss function and the Lovász hinge are combined to obtain a joint loss function suitable for urban water body extraction. The formula is: in and Lovász hinge loss function and weighted cross-entropy loss function, respectively. and The corresponding weights are used, and a gradient-based loss method is employed to dynamically adjust the weights during training. First, the training speed is defined: in These are the numbers for the two loss functions. To the number of training iterations, represent time The loss value, represent The total loss value at time t; for Moment , Represents the loss ratio, This represents the inverse value of relative learning speed; the faster the learning speed, the higher the relative learning speed. and The smaller the value; In order to learn Time weight It is necessary to place the gradient norms of different tasks under the same metric to obtain their relative magnitudes; And dynamically adjust the size of these gradient norms so that different tasks train at a similar rate, for the weights of the last layer of the network model. Define the following variables: in For gradient operators, For weighted ,but Represents weight corresponding weighting gradient Norm, the average value corresponding to the two types of loss is: The product of this average value and the inverse value of the learning speed is used as the target value, as shown below: in The greater the difference between the two losses, the more this value should be increased; in summary, the calculation... The difference from the target value Norms, which can be used for The loss values ​​are as follows: During training, the initialization process is performed first. ,pass To achieve this during each training iteration Dynamic adjustments are made, and the joint loss function in formula (15) is then dynamically adjusted.

9. An urban water body extraction system based on an attention mechanism, characterized in that, Includes the following modules: The model building module is used to construct an urban water body extraction model, including an encoder and a decoder. The encoder includes a backbone network with dilated convolutions to extract low-level and high-level features of water bodies at different scales, as well as a channel attention module to calculate global channel dependencies between high-level features. The decoder includes a spatial attention module, a feature fusion module, and a post-processing module. The spatial attention module is used to calculate global spatial dependencies between low-level features, the feature fusion module is used to fuse the outputs of the channel attention module and the spatial attention module, and the post-processing module is used to adjust the scale of the fused feature map to obtain an urban water body extraction result with the same size as the input image. In the model building module, ResNet-101 with dilated convolutions is used as the backbone network of the model, and the last three residual blocks are improved. The outputs of the first three residual blocks are used as low-level features, and the outputs of all residual blocks are used as high-level features. The specific process for extracting features from the improved residual blocks is as follows: Step 111, after Convolutional layers are used to reduce the number of channels in the feature map; Step 112, apply convolution kernels of size 1 to each of the three residual blocks. Dilated convolutional layers with different dilation rates capture feature dependencies at three different scales. The calculation formula for one-dimensional dilated convolution is as follows: in For output signal, For output signal, The size is The filter, The expansion rate; Step 113, use Convolution restores the number of channels in the feature map to the original channel size; Step 114: Add the processed features from step 113 to the unprocessed features pixel by pixel, and output the feature extraction result of the residual block. The model training module trains the urban water body extraction model using a joint loss function that combines the weighted cross-entropy loss function and the Lovász hinge, further improving the accuracy of water body extraction. The model application module is used to extract urban water bodies using a trained urban water body extraction model.