Rock slice image segmentation method based on ECA-SwinUnet
By constructing the ECA-SwinUnet architecture, which integrates the EMA and CBAM attention mechanisms, the problems of complex background interference and small feature capture in rock thin section image segmentation are solved, achieving high-precision rock thin section image segmentation, which is suitable for oil and gas exploration and geotechnical engineering design.
Patent Information
- Application Number
- CN202511562886.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2026-01-13
AI Technical Summary
Existing technologies struggle to effectively resist interference from complex backgrounds in rock thin section image segmentation, and are also unable to accurately capture minute particle features and clear segmentation boundaries, resulting in insufficient segmentation accuracy. This makes it particularly difficult to meet the high-precision requirements in oil and gas exploration and geotechnical engineering design.
An ECA-SwinUnet architecture integrating EMA and CBAM attention mechanisms is constructed. Multi-scale feature processing enhances the ability to resist background interference in rock thin section images and strengthens the capture of key features. Combined with the window self-attention mechanism of SwinTransformer and a four-level encoding and decoding structure, high-precision segmentation is achieved.
It significantly improves the segmentation accuracy and robustness of rock thin section images, enabling it to better adapt to complex scenarios and provide high-precision data support for rock microstructure analysis, meeting the needs of geological research and practical applications.
Smart Images

Figure CN121329984A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image segmentation, in particular to a rock thin section image segmentation method based on ECA-SwinUnet, which is suitable for rock microstructure analysis in the field of geological exploration, and can especially provide accurate rock thin section image segmentation results for scenes such as oil and gas exploration reservoir evaluation and geotechnical engineering design. BACKGROUND
[0002] In geological research, the particle size analysis of rock thin section images is a core means to explore the microstructure of rocks, and accurate image segmentation can effectively extract target region information such as pores, minerals and cracks, providing a scientific basis for rock property analysis, mineral extraction and geotechnical engineering design. In the field of oil and gas exploration, the analysis of the pore structure of reservoirs directly determines the evaluation results of the reservoirs and the development strategy, so the accuracy of rock thin section image segmentation is of great significance to geological research and application.
[0003] In recent years, deep learning technology has promoted the rapid development of image segmentation, and models such as U-Net based on encoding-decoding structure and SwinTransformer based on Transformer network have significantly improved segmentation accuracy and resolution and enhanced adaptability to complex scenes by automatically learning global and local features. Among them, SwinUnet combines the advantages of SwinTransformer and U-Net and performs well in medical image and remote sensing image segmentation. However, rock thin section images have complex background interference, particle adhesion and sub-pixel level boundary blur, and existing models such as traditional threshold segmentation method have an accuracy of only 72.45% and a mean intersection over union of 70.12%. Even the accuracy of SwinUnet is only 89.32% and the MIoU is 83.14%, which cannot meet the demand for high-precision segmentation.
[0004] Attention mechanism provides a way to improve segmentation performance. EMA enhances the ability to capture global and local information by processing multi-scale features, and CBAM enhances key feature expression by combining channel and spatial attention. However, there is currently no effective fusion of EMA and CBAM applied to SwinUnet to specifically address the pain points of rock thin section image segmentation, and there is an urgent need for a rock thin section image segmentation method that can balance anti-background interference, accurate capture of small particle features and clear segmentation boundaries. SUMMARY
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a rock thin section image segmentation method based on ECA-SwinUnet. By constructing an ECA-SwinUnet architecture that integrates EMA and CBAM attention mechanisms, the method improves the ability to resist complex backgrounds and capture key features of rock thin section images, thereby achieving higher precision segmentation.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: a rock thin section image segmentation method based on ECA-SwinUnet, comprising the following steps:
[0007] S1. Acquire raw images of thin rock sections from underground tight sandstone reservoirs and perform image processing;
[0008] S2. Based on the preprocessed image samples in step S1, the training set and the test set are randomly divided in a ratio of 10:3.
[0009] S3. Construct the ECA-SwinUnet architecture model for rock thin section images, which will be used as a tool for rock thin section image segmentation.
[0010] S4. Construct image segmentation algorithm models that compare SegNet, UNet, SwinUnet, and threshold segmentation.
[0011] S5. The models built based on steps S3 and S4 are trained using the training set, and the trained models are saved.
[0012] S6. Use the trained model to segment the test set, perform model evaluation calculations, obtain the model evaluation index calculation results, analyze and compare the results, and determine the final prediction model.
[0013] In step S1, raw images of thin rock sections from underground tight sandstone reservoirs are acquired and image processing is performed. The process includes:
[0014] S1.1 Acquire the original image using a single-polarized light under a 200x lens and perform noise reduction processing on the image;
[0015] S1.2. Crop the processed image to obtain an image sample with a resolution of 224×224;
[0016] S1.3. Use the Labelme tool to annotate the image samples, generate a JSON format annotation file, and convert it into a PNG format annotation image;
[0017] In step S3, the ECA-SwinUnet architecture model for rock thin section images is constructed, and the process includes:
[0018] S3.1 Based on the U-shaped encoding and decoding structure of SwinUnet, the EMA attention mechanism and CBAM attention mechanism are introduced to form the ECA-SwinUnet architecture with four levels of encoding and decoding;
[0019] S3.2 The implementation process of the EMA attention mechanism is as follows: the input features are grouped by channel, and 1D global pooling is used to process global information and 3×3 convolution is used to capture local spatial information for each group of features. The output results of the two branches are fused by matrix multiplication to generate an attention map and apply it to the original input features to complete multi-scale feature weighting.
[0020] The implementation process of the S3.3 CBAM attention mechanism includes channel attention calculation and spatial attention calculation. Channel attention calculation involves performing global average pooling and global max pooling on the input feature map, inputting the two resulting one-dimensional feature vectors into a shared fully connected layer, summing the outputs of the fully connected layer, and then passing them through a sigmoid activation function to generate channel attention weights. Spatial attention calculation involves performing average pooling and max pooling along the channel dimension on the feature map after channel attention weighting, concatenating the two resulting two-dimensional feature maps, compressing the number of channels to 1 through a 1×1 convolution, and then passing them through a sigmoid activation function to generate spatial attention weights. Finally, the channel attention weights and spatial attention weights are applied to the input feature map in sequence to complete the key feature enhancement.
[0021] S3.4 The architecture includes an encoder, a bottleneck, a decoder, and a skip connection. The encoder adopts a structure based on the Swing Transformer Block, with a window size of 7×7, a head number configuration of [3, 6, 12, 24], and an MLP expansion ratio of 4. The mathematical expression of the ECA-SwinUnet architecture is as follows:
[0022] Encoder feature extraction:
[0023] Among them, I in ∈R H×W×3 (H=W=224) is the input image, F enc For an encoder based on the Swing Transformer Block, θ swin E represents the multi-head self-attention parameter for the window. i The output feature of the encoder at layer i;
[0024] Decoder feature reconstruction:
[0025] Among them, D j For the output features of the decoder at layer j, This indicates a feature concatenation operation. For selecting a gate for dynamic features, θ eca For ECA module parameter set;
[0026] Segmentation result output: P out =σ(Conv 1×1 (D4))
[0027] in, For the Sigmoid activation function, Conv 1×1 For a 1×1 convolution operation, P out This is the final segmentation result;
[0028] In step S5, the models built based on steps S3 and S4 are trained using the training set, and the trained models are saved. This includes the following sub-steps:
[0029] S5.1 Input the training set from step S2 into the ECA-SwinUnet architecture and set the training parameters, where PatchEmbedding uses 4×4 convolutions with a stride of 4 and output channels C=98; EMA uses dilated convolution groups d=(1, 3, 5), subgroups G=8, pooling layers L=3; CBAM uses a channel compression ratio r=8; deformable convolution sampling points 9; and the offset range Δρ∈[-3,3].
[0030] The S5.2 optimizer uses AdamW (β1 = 0.9, β2 = 0.999), weight decay of 0.05, and initial learning rate of 3e-4; the model converges through iterative training to obtain the trained ECA-SwinUnet segmentation model.
[0031] S5.3 Input the training set from step S2 into the ECA-SwinUnet model and the four comparison models SegNet, UNet, SwinUnet, and threshold segmentation. The number of training iterations is the same as that of the ECA-SwinUnet model.
[0032] In step S6, the trained model is used to segment the test set images and perform model evaluation calculations to obtain the model evaluation index calculation results. The results are then analyzed and compared to determine the final prediction model. This step specifically includes the following sub-steps:
[0033] S6.1 Input the test set from step S2 into the trained ECA-SwinUnet segmentation model. The model first performs multi-scale convolution, pooling and normalization operations on the input image through EMA to generate a weighted feature map. Then, CBAM enhances the key features of the weighted feature map from the channel and spatial dimensions. Subsequently, the Swin Transformer module captures long-range dependencies and extracts features. Finally, the decoder is used to gradually restore the spatial resolution of the image. The low-level features from the encoding stage are fused by skip connections to output the segmentation result of the rock thin section image.
[0034] S6.2 Input the test set from step S2 into the trained ECA-SwinUnet model and the four comparison models SegNet, UNet, SwinUnet, and threshold segmentation to obtain the final result;
[0035] S6.3. Accuracy and average intersection-union ratio are used as performance evaluation indicators for the model.
[0036] S6.4. Compare the model evaluation parameter results of the ECA-SwinUnet model with four comparative models, namely SegNet, UNet, SwinUnet, and threshold segmentation, on the test set, and give the final analysis results.
[0037] The advantages of this invention compared to the prior art are mainly reflected in:
[0038] (1) Significantly improved segmentation accuracy: By constructing the ECA-SwinUnet architecture that integrates EMA and CBAM dual attention mechanisms, EMA multi-scale feature processing effectively resists interference from complex background noise, and CBAM channel-spatial attention enhances the capture of key features such as rock particles and pores, solving the problems of small particle feature loss and boundary blurring in traditional models, and providing higher precision data support for rock microstructure analysis.
[0039] (2) Enhanced Feature-Aware Robustness: Leveraging the window self-attention mechanism and four-level encoding / decoding structure of the SwinTransformer, and combining skip connections to fuse high- and low-level features, this approach achieves both long-range dependency capture to adapt to the global structure of rock thin-section images and preservation of local details to handle particle adhesion scenarios. Ablation experiments verify that introducing either the EMA or CBAM modules individually improves model performance, and their synergistic effect further enhances the model's adaptability to complex scenes, avoiding segmentation biases in existing models when there is background interference or weak features.
[0040] (3) Wide applicability of the technology: Based on the PyTorch framework, the model has a clear structure and well-defined parameters, and the training and inference processes are reproducible. The data preprocessing steps are universal, and only a few parameters such as the annotation category and image resolution need to be adjusted to adapt to different types of rock thin section images. At the same time, the model has high training efficiency and can be trained in a conventional GPU hardware environment, which is convenient for deployment and application in practical scenarios such as geological laboratories and oil and gas exploration companies, providing an efficient technical tool for reservoir evaluation and geotechnical engineering design.
[0041] In summary, this invention, through the ECA-SwinUnet attention enhancement architecture, integrates the advantages of dual attention mechanisms and Transformer encoding / decoding to provide a high-precision and robust rock thin-section image segmentation method. This method effectively overcomes the limitations of existing technologies in resisting complex backgrounds and capturing key features, ensuring segmentation accuracy meets the needs of geological research while possessing good versatility and applicability. It provides a new solution for upgrading rock thin-section image analysis technology, and is particularly suitable for scenarios with high requirements for segmentation accuracy and practicality, such as oil and gas exploration and geological research. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the embodiments will be briefly described below:
[0043] Figure 1 This is a flowchart of the experimental design for this invention, clearly showing the complete process of dataset partitioning, model building, training, testing, and evaluation.
[0044] Figure 2 This is a topology diagram of the ECA-SwinUnet architecture of the present invention, showing the location and connection relationship of the encoder, bottleneck, decoder, hop connection, and EMA and CBAM modules;
[0045] Figure 3 The visualization comparison of segmentation results from various models is presented, showing the segmentation results of the original image, threshold segmentation, SegNet, UNet, SwinUnet, and ECA-SwinUnet on the same rock thin section image in sequence, intuitively demonstrating the segmentation advantages of ECA-SwinUnet. Detailed Implementation
[0046] Example 1:
[0047] See Figure 1 The present invention provides a rock thin section image segmentation method based on ECA-SwinUnet, comprising the following steps:
[0048] S1. Acquire raw images of thin rock sections from underground tight sandstone reservoirs and perform image processing;
[0049] S2. Based on the preprocessed image samples in step S1, the training set and the test set are randomly divided in a ratio of 10:3.
[0050] S3. Construct the ECA-SwinUnet architecture model for rock thin section images, which will be used as a tool for rock thin section image segmentation.
[0051] S4. Construct image segmentation algorithm models that compare SegNet, UNet, SwinUnet, and threshold segmentation.
[0052] S5. The models built based on steps S3 and S4 are trained using the training set, and the trained models are saved.
[0053] S6. Use the trained model to segment the test set, perform model evaluation calculations, obtain the model evaluation index calculation results, analyze and compare the results, and determine the final prediction model.
[0054] In this embodiment, step S1 involves preprocessing the rock thin section image data based on both the acquisition source and image processing aspects to ensure data quality and training effectiveness, as detailed below:
[0055] S1.1 Image Acquisition: Using a 200x polarizing microscope (model: Olympus BX53), thin section samples of tight sandstone reservoirs in the Upper Paleozoic Yanchang Formation of the Ordos Basin were imaged under single polarized light. The microscope focal length and light source intensity were adjusted to ensure that the images clearly showed the microstructure of rock particles, pores and other features, and to avoid image quality differences caused by inconsistent imaging parameters. More than 1,300 original images were acquired.
[0056] S1.2 Image Denoising and Cropping: Based on Python's OpenCV library, Gaussian filtering (convolution kernel size 5×5, standard deviation 1.5) was used to denoise the original image, reducing Gaussian noise interference in the image; a sliding window method was used with a window size of 224×224 and a stride of 112 to crop the denoised image, avoiding too many overlapping regions and ensuring sample diversity, ultimately obtaining 1300 image samples with a resolution of 224×224;
[0057] S1.3 Image Annotation and Format Conversion: Launch the Labelme annotation tool and manually annotate the three types of regions in the image: rock particles, pores, and background. After annotation, a JSON file is generated. Use the labelme_json_to_dataset.py script that comes with Labelme to convert the JSON file into a PNG format annotated image, where "rock particles" are annotated with a grayscale value of 255, "pores" with a grayscale value of 128, and "background" with a grayscale value of 0.
[0058] In this embodiment, in step S2, the processed image samples are randomly divided into a training set (1000 images) and a test set (300 images) at a ratio of 10:3 using the train_test_split function in the scikit-leam library of Python. The random_state=42 is set to ensure that the results of each division are consistent, which facilitates experimental reproduction and provides basic data for model training and performance verification.
[0059] In this embodiment, step S3 involves constructing an ECA-SwinUnet architecture model for rock thin section images, which is used as a tool for rock thin section image segmentation. Figure 2 The model structure diagram shows that model construction specifically includes the following sub-steps:
[0060] S3.1 Based on the U-shaped encoding and decoding structure of SwinUnet, the EMA attention mechanism and CBAM attention mechanism are introduced to form the ECA-SwinUnet architecture with four levels of encoding and decoding;
[0061] S3.2 The EMA attention mechanism is implemented as follows: Input features are grouped by channel. For each group of features, 1D global pooling is used to process global information, and 3×3 convolution is used to capture local spatial information. The output results of the two branches are fused by matrix multiplication to generate an attention map, which is then applied to the original input features to complete multi-scale feature weighting. EMA module implementation: Define the EMAModule class. In the forward function, the input features are divided into 8 groups by channel. Each group is 1D global pooled using nn.AdaptiveAvgPool2d1 and 3×3 convolution is performed using a convolutional layer. After sampling the pooling results, they are fused with the convolution results by matrix multiplication to generate an attention map. The attention maps of each group are then concatenated and multiplied with the original input features to complete multi-scale weighting.
[0062] S3.3 The implementation process of the CBAM attention mechanism includes channel attention calculation and spatial attention calculation. Channel attention calculation involves performing global average pooling and global max pooling on the input feature maps, inputting the two resulting one-dimensional feature vectors into a shared fully connected layer, summing the outputs of the fully connected layer, and then passing them through a Sigmoid activation function to generate channel attention weights. Spatial attention calculation involves performing average pooling and max pooling along the channel dimension on the feature maps after channel attention weighting, concatenating the two resulting two-dimensional feature maps, compressing the number of channels to 1 through a 1×1 convolution, and then passing them through a Sigmoid activation function. The live function generates spatial attention weights; finally, the channel attention weights and spatial attention weights are applied sequentially to the input feature map to complete the key feature enhancement; the CBAM module is implemented as follows: the CBAMModule class is defined. The channel attention part pools the input features using nn.AdaptiveAvgPool2d1 and nn.AdaptiveMaxPool2d1, concatenates them, passes them through a shared fully connected layer, and sums the outputs and generates channel weights; the spatial attention part performs average pooling and max pooling along the channel dimension on the channel-weighted features, concatenates them, generates spatial weights, and applies them sequentially to the input features;
[0063] S3.4 Overall Architecture Construction: Based on the open-source SwinUnet code, an EMA module is inserted after the output of each SwinTransformer Block in the encoder, and a CBAM module is inserted before each feature fusion stage in the decoder. The encoder's four layers are downsampled through PatchMerging, and the decoder's four layers are upsampled through PatchExpanding. Skip connections use torch.cat to concatenate the upsampled features of the corresponding layers of the encoder and the decoder. Finally, the segmentation result is output after 1×1 convolution and sigmoid activation.
[0064] The mathematical expression of the ECA-SwinUnet architecture is as follows:
[0065] Encoder feature extraction:
[0066] Among them, I in ∈R H×W×3 (H=W=224) is the input image, F enc For an encoder based on the Swing Transformer Block, θ swin E represents the multi-head self-attention parameter for the window. i The output feature of the encoder at layer i;
[0067] Decoder feature reconstruction:
[0068] Among them, D jFor the output features of the decoder at layer j, This indicates a feature concatenation operation. For selecting a gate for dynamic features, θ eca For ECA module parameter set;
[0069] Segmentation result output: P out =σ(Conv 1×1 (D4))
[0070] Where 6 is the Sigmoid activation function, Conv 1×1 For a 1×1 convolution operation, P out This is the final segmentation result.
[0071] In this embodiment, in step S4, SegNet, UNet, SwinUnet, and threshold segmentation comparison image segmentation algorithm models are constructed based on the PyTorch framework. Specifically, SegNet (using a 13-layer convolution, 3-layer pooling, and 3-layer upsampling structure), UNet (classic U-shaped structure, with 4 layers of downsampling in the encoder and 4 layers of upsampling in the decoder), SwinUnet (original architecture, without EMA and CBAM modules), and threshold segmentation (using the Otsu adaptive thresholding algorithm) are constructed respectively, ensuring that the input and output dimensions of each model are consistent with ECA-SwinUnet.
[0072] In this embodiment, step S5 involves training the models built in steps S3 and S4 using the training set and saving the trained models, including the following sub-steps:
[0073] S5.1 Training Environment Setup: The hardware uses an NVIDIA Tesla V100 GPU (32GB VRAM) and an Intel Xeon Gold 6248 CPU. The software environment is Ubuntu 20.04, CUDA 11.7, and CuDNN 8.5.0.
[0074] S5.2 Training parameter configuration and execution: Set batch size = 16, number of iterations = 100, and use the cross-entropy loss function to calculate the segmentation loss;
[0075] S5.3 The optimizer is AdamW (parameters β1 = 0.9, β2 = 0.999, weight decay 0.05), with an initial learning rate of 3e-4 and dynamic adjustment using a cosine annealing strategy; the training set is divided into a training subset and a validation subset in an 8:2 ratio, and the accuracy and MIoU are calculated on the validation subset after each training epoch, and the model weights with the best performance on the validation set are saved;
[0076] S5.4 Input the training set from step S2 into the ECA-SwinUnet model and the four comparison models SegNet, UNet, SwinUnet, and threshold segmentation. The number of training iterations is the same as that of the ECA-SwinUnet model.
[0077] In this embodiment, step S6 involves using the trained model to segment the test set, performing model evaluation calculations, obtaining the model evaluation index calculation results, analyzing and comparing the results, and determining the final prediction model. This specifically includes the following sub-steps:
[0078] S6.1 Load the optimal weights for each model, convert the test set images into PyTorch tensors and normalize them;
[0079] S6.2 Input the test set from step S2 into the trained ECA-SwinUnet segmentation model. The model first performs multi-scale convolution, pooling and normalization operations on the input image through EMA to generate a weighted feature map. Then, CBAM enhances the key features of the weighted feature map from the channel and spatial dimensions. Subsequently, the Swin Transformer module captures long-range dependencies and extracts features. Finally, the decoder is used to gradually restore the spatial resolution of the image. The low-level features from the encoding stage are fused by skip connections to output the segmentation result of the rock thin section image.
[0080] S6.3. Accuracy and the average intersection-union ratio (AUC) are used as performance evaluation metrics for the model, as shown in the following formulas:
[0081]
[0082] Among them: TP i FP represents the true instance of class i, i.e., the number of pixels correctly predicted as class i; i This represents the number of false positives of class i, i.e., the number of pixels incorrectly predicted as class i.
[0083]
[0084] Among them: TP i Represents the true instance of class i; FP i FN represents a false positive of class i; i This represents a false negative of class i, i.e., the number of pixels that are actually of class i but are incorrectly predicted as other classes;
[0085] S6.4. Compare the model evaluation parameter results of the ECA-SwinUnet model with four comparative models, namely SegNet, UNet, SwinUnet, and threshold segmentation, on the test set, and give the final analysis results, as shown in the table below.
[0086]
[0087] As shown in the table, the ECA-SwinUnet model outperforms other comparative models in both accuracy and MIoU, thus confirming it as the final prediction model. Furthermore, ablation experiments validated the effectiveness of the EMA and CBAM modules: the SwinUnet+EMA model achieved an accuracy of 90.55% and an MIoU of 84.35%, while the SwinUnet+CBAM model achieved an accuracy of 90.51% and an MIoU of 85.47%, both superior to the original SwinUnet, demonstrating that the two modules effectively improve segmentation performance.
[0088] Combination Figure 3 The visualization results from ECA-SwinUnet show that it can not only accurately segment rock particles and pores, but also maintain the clarity of the boundaries and reduce segmentation ambiguity and misjudgment.
Claims
1. A rock thin section image segmentation method based on ECA-SwinUnet, characterized in that, Includes the following steps: S1. Acquire raw images of thin rock sections from underground tight sandstone reservoirs and perform image processing; S2. Based on the preprocessed image samples in step S1, the training set and the test set are randomly divided in a ratio of 10:
3. S3. Construct the ECA-SwinUnet architecture model for rock thin section images, which will be used as a tool for rock thin section image segmentation. S4. Construct image segmentation algorithm models that compare SegNet, UNet, SwinUnet, and threshold segmentation. S5. The models built based on steps S3 and S4 are trained using the training set, and the trained models are saved. S6. Use the trained model to segment the test set, perform model evaluation calculations, obtain the model evaluation index calculation results, analyze and compare the results, and determine the final prediction model.
2. The method according to claim 1, characterized in that, In step S1, raw images of thin rock sections from underground tight sandstone reservoirs are acquired and image processing is performed. The process includes: S1.1 Acquire the original image using a single-polarized light under a 200x lens and perform noise reduction processing on the image; S1.
2. Crop the processed image to obtain an image sample with a resolution of 224×224; S1.
3. Use the Labelme tool to annotate the image samples, generate JSON format annotation files, and convert them into PNG format annotation images.
3. The method according to claim 1, characterized in that, In step S3, the ECA-SwinUnet architecture model for rock thin section images is constructed, and the process includes: S3.1 Based on the U-shaped encoding and decoding structure of SwinUnet, the EMA attention mechanism and CBAM attention mechanism are introduced to form the ECA-SwinUnet architecture with four levels of encoding and decoding; S3.2 The implementation process of the EMA attention mechanism is as follows: the input features are grouped by channel, and 1D global pooling is used to process global information and 3×3 convolution is used to capture local spatial information for each group of features. The output results of the two branches are fused by matrix multiplication to generate an attention map and apply it to the original input features to complete multi-scale feature weighting. The implementation process of the S3.3 CBAM attention mechanism includes channel attention calculation and spatial attention calculation. Channel attention calculation involves performing global average pooling and global max pooling on the input feature map, inputting the two resulting one-dimensional feature vectors into a shared fully connected layer, summing the outputs of the fully connected layer, and then passing them through a sigmoid activation function to generate channel attention weights. Spatial attention calculation involves performing average pooling and max pooling along the channel dimension on the feature map after channel attention weighting, concatenating the two resulting two-dimensional feature maps, compressing the number of channels to 1 through a 1×1 convolution, and then passing them through a sigmoid activation function to generate spatial attention weights. Finally, the channel attention weights and spatial attention weights are applied to the input feature map in sequence to complete the key feature enhancement. S3.4 The architecture includes an encoder, a bottleneck, a decoder, and a skip connection. The encoder adopts a structure based on the Swing Transformer Block, with a window size of 7×7, a head number configuration of [3, 6, 12, 24], and an MLP expansion ratio of 4. The mathematical expression of the ECA-SwinUnet architecture is as follows: Encoder feature extraction: Among them, I in ∈R H×W×3 (H=W=224) is the input image, F enc For an encoder based on the Swing Transformer Block, θ swin E represents the multi-head self-attention parameter for the window. i The output feature of the encoder at layer i; Decoder feature reconstruction: Among them, D j For the output features of the decoder at layer j, This indicates a feature concatenation operation. For selecting a gate for dynamic features, θ eca For ECA module parameter set; Segmentation result output: P out =σ(Conv 1×1 (D4)) Where 6 is the Sigmoid activation function, Conv 1×1 For a 1×1 convolution operation, P out This is the final segmentation result.
4. The method according to claim 1, characterized in that, In step S5, the models built based on steps S3 and S4 are trained using the training set, and the trained models are saved. This includes the following sub-steps: S5.1 Input the training set from step S2 into the ECA-SwinUnet architecture and set the training parameters, where PatchEmbedding uses 4×4 convolutions with a stride of 4 and output channels C=98; EMA uses dilated convolution groups d=(1, 3, 5), subgroups G=8, pooling layers L=3; CBAM uses a channel compression ratio r=8; deformable convolution sampling points 9; and the offset range Δp∈[-3,3]. The S5.2 optimizer uses AdamW (β1 = 0.9, β2 = 0.999), weight decay of 0.05, and initial learning rate of 3e-4; the model converges through iterative training to obtain the trained ECA-SwinUnet segmentation model. S5.3 Input the training set from step S2 into the ECA-SwinUnet model and the four comparison models SegNet, UNet, SwinUnet, and threshold segmentation. The number of training iterations is the same as that of the ECA-SwinUnet model.
5. The method according to claim 1, characterized in that, In step S6, the trained model is used to segment the test set images and perform model evaluation calculations to obtain the model evaluation index calculation results. The results are then analyzed and compared to determine the final prediction model. This step specifically includes the following sub-steps: S6.1 Input the test set from step S2 into the trained ECA-SwinUnet segmentation model. The model first performs multi-scale convolution, pooling and normalization operations on the input image through EMA to generate a weighted feature map. Then, CBAM enhances the key features of the weighted feature map from the channel and spatial dimensions. Subsequently, the Swin Transformer module captures long-range dependencies and extracts features. Finally, the decoder is used to gradually restore the spatial resolution of the image. The low-level features from the encoding stage are fused by skip connections to output the segmentation result of the rock thin section image. S6.2 Input the test set from step S2 into the trained ECA-SwinUnet model and the four comparison models SegNet, UNet, SwinUnet, and threshold segmentation to obtain the final result; S6.
3. Accuracy and average intersection-union ratio are used as performance evaluation indicators for the model. S6.
4. Compare the model evaluation parameter results of the ECA-SwinUnet model with four comparative models, namely SegNet, UNet, SwinUnet, and threshold segmentation, on the test set, and give the final analysis results.
