Pulmonary nodule segmentation algorithm based on TransUNet

By introducing the MaxViT network and multi-axis self-attention mechanism on TransUNet, combined with the DiceBCE loss function, the problem of insufficient segmentation accuracy caused by changes in the shape and size of pulmonary nodules is solved, and more efficient pulmonary nodule segmentation and noise identification are achieved.

CN118628512AActive Publication Date: 2024-09-10BEIJING INST OF TECH TANGSHAN RES INST +1

Patent Information

Application Number
CN202410893732.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-09-10
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

Existing deep learning-based pulmonary nodule segmentation algorithms have insufficient segmentation accuracy and are difficult to effectively identify image noise when pulmonary nodules have different shapes and sizes.

Method used

The pulmonary nodule segmentation algorithm based on TransUNet is adopted, and the MM-TransUNet network is formed by replacing the Transformer layer in the TransUNet network with the MaxViT network. It combines the residual mechanism, CNN and multi-axial self-attention mechanism to improve the skip connection module and use DiceBCE loss function for training and evaluation.

Benefits of technology

It significantly improves the segmentation accuracy of pulmonary nodules, can better extract pulmonary nodule features and distinguish relevant information from noise, and improves the segmentation performance of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118628512A
    Figure CN118628512A
Patent Text Reader

Abstract

The invention relates to the technical field of segmentation algorithms, in particular to a pulmonary nodule segmentation algorithm based on TransUNet, and the algorithm comprises the steps: replacing a Transform layer in a TransUNet network with a MaxViT network, forming an MM-TransUNet network as a segmentation model, and carrying out the segmentation model training through employing the MM-TransUNet network; after each round of training is completed, storing segmentation model parameters of the round, comparing a detection result obtained by the segmentation model with an actual result to calculate loss, and performing parameter adjustment on the segmentation model according to the loss; reading the optimal parameters stored in the training stage, and substituting the optimal parameters into the segmentation model to obtain an optimal pulmonary nodule separation model; the MM-TransUNet network is used as a segmentation model, so that the segmentation precision of the pulmonary nodules can be effectively improved; the MM-TransUNet combines a residual mechanism, a CNN (Convolutional Neural Network) and a multi-axial self-attention mechanism to serve as an encoder module, and plays a role in extracting pulmonary nodule features more completely.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of segmentation algorithms, and in particular to a pulmonary nodule segmentation algorithm based on TransUNet. Background Art

[0002] Studies have shown that lung nodules are closely related to lung cancer and are one of the early symptoms of lung cancer. If lung nodules can be diagnosed and treated as early as possible, it will be of great benefit to reducing the mortality rate of lung cancer. Therefore, realizing a high-precision algorithm for automatic segmentation of lung nodules has valuable clinical value and practical significance. However, due to the random location, different sizes and shapes of lung nodules, the segmentation accuracy of existing lung nodule segmentation algorithms based on deep learning is still not high enough.

[0003] U-Net is one of the most classic models in the field of medical image segmentation. It is called U-Net because of its U-shaped symmetrical structure. The U-Net network is constructed based on CNN. It adopts an encoder-decoder structure, which includes a convolutional layer on the left, a pooling layer, an upsampling layer on the right, and a jump connection design connecting both ends. Compared with other network structures (such as FCN), U-Net does not require direct supervision and loss calculation in high-level feature maps, which helps to improve the segmentation accuracy of the model.

[0004] At present, most lung nodule segmentation models still use the U-Net architecture as the basic structure, that is, using the encoder to extract high-level features of the image, using the decoder to upsample the features extracted by the encoder to obtain the segmentation results, and using jump connections to fuse the different levels of features in the encoder and decoder, and finally realize the automatic segmentation of lung nodules. However, the encoder of U-Net is too simple, resulting in limited feature extraction capabilities and unable to adapt to the random position and size changes of lung nodules in lung nodule images. Moreover, although the jump connection of U-Net can connect high-level features with low-level features, it still omits information at certain levels, resulting in the model being unable to distinguish between relevant information and irrelevant information. Therefore, although U-Net has become a very representative work in the field of medical image segmentation, it still has a lot of room for improvement. Summary of the invention

[0005] The present invention aims to solve the above problems, thereby providing a pulmonary nodule segmentation algorithm based on TransUNet that can accurately segment pulmonary nodules and effectively identify image noise.

[0006] The invention solves the above problem, and the technical solution adopted is:

[0007] A pulmonary nodule segmentation algorithm based on TransUNet, the steps include:

[0008] S1: Acquire a lung CT image dataset, and perform lung parenchyma segmentation, region of interest extraction, and data enhancement operations on the lung CT image dataset;

[0009] S2: Divide the lung CT image dataset after data augmentation into a training set and a test set;

[0010] S3: Build a segmentation model based on the TransUNet network structure and use the training set to train the segmentation model. After each round of training, save the parameters of the segmentation model for this round, compare the detection results obtained by the segmentation model with the actual results to calculate the loss, and adjust the parameters of the segmentation model according to the loss.

[0011] S4: reading the optimal parameters saved in the training phase, and substituting the optimal parameters into the segmentation model to obtain the optimal lung nodule segmentation model;

[0012] S5, using the test set to test the optimal pulmonary nodule segmentation model, and using the evaluation index to evaluate the model accuracy of the optimal pulmonary nodule segmentation model;

[0013] Among them, in step S3, the Transformer layer in the TransUNet network is replaced with the MaxViT network to form an MM-TransUNet network as a segmentation model. The specific process of using the MM-TransUNet network to train the segmentation model is as follows;

[0014] S301: Input the image in the training set into the encoder, first use the residual mechanism with the convolutional neural network to extract shallow features of the input image layer by layer, and extract a shallow feature map;

[0015] S302: The shallow feature map is processed by the MaxViT module to fully perceive the deep context information, further deep feature learning, and extract the deep feature map of the image;

[0016] S303: inputting the shallow feature map and the deep feature map into the decoder, connecting and upsampling the shallow feature map and the deep feature map, performing feature fusion layer by layer, and finally outputting a lung nodule segmentation image;

[0017] S304: Calculate the loss between the lung nodule segmentation image output in step S303 and the actual lung nodule segmentation image through the loss function, adjust the parameters in the MM-TransUNet network, update the MM-TransUNet network model, and return to step S301 for a new round of training until all images in the training set are trained.

[0018] Preferably, in step S1, the specific steps of segmenting the lung parenchyma of the lung CT image dataset are as follows:

[0019] S101: performing binary segmentation on the original CT image using the OTSU algorithm to obtain a binary image;

[0020] S102: filling the cavities of the lung parenchyma using a flood filling method to obtain a filled image; removing noise and small bubbles in the binary image using an opening operation to obtain a denoised image;

[0021] S103: subtracting the denoised image from the filled image to obtain a preliminary lung parenchyma mask image containing a small connected region;

[0022] S104: performing an opening operation to remove small connected regions in the initial-order lung parenchyma mask image to obtain a final-order lung parenchyma mask image;

[0023] S105: performing an AND operation on the final-order lung parenchyma mask image and the original CT image to obtain a lung parenchyma image.

[0024] Preferably, step S1 further comprises:

[0025] S106: extracting a region of interest including a lung nodule from the lung parenchyma image; locating the position of the lung nodule using the lung nodule position information in the data set, and then cropping the lung parenchyma image with the lung nodule as the center point to generate an input image block;

[0026] S107: Expand the image source, randomly flip or rotate the image block, and use the expanded image block and the original image block as the data set of the training set and the test set; flipping is to randomly select an image block to flip horizontally or vertically, and the label image is also flipped accordingly; rotation is to randomly select an image block to rotate 90°, 180° or 270° in a clockwise direction, and the label image is also rotated like the image.

[0027] Preferably, in step S301, at the starting position of the encoder, MM-TransUNet first uses a three-layer ResNet-50 network based on CNN and residual mechanism, and the shallow feature map output by each layer is used as the input of the next layer; each layer of ResNet-50 network directly combines the input features with the output features through skip connections to form a residual block. The core idea of ​​the residual block can be expressed as follows:

[0028] output=F(input)+input

[0029] Where F(*) indicates that the network performs a series of operations on the input;

[0030] Then, the shallow feature map output by the third-layer residual block is divided into blocks and position encoding is added.

[0031] Preferably, in step S302, the shallow feature map after adding the position encoding is processed by the MaxViT module 12 times, and the specific process of each MaxViT module processing is as follows:

[0032] The feature map is input into the MBConv block. After passing through the 1x1 convolution layer and the 3x3 convolution layer, the feature map is input into the channel attention module to strengthen the relevant features in the feature map and weaken the irrelevant features to obtain the enhanced feature map. The enhanced feature map is then convolved point by point with the input feature map to restore the dimension and output the enhanced feature map.

[0033] The enhanced feature map is input into the block attention processing module and split into several complementary overlapping image blocks. Then, the self-attention mechanism is applied to each split image block to achieve interaction in a local range. The image blocks that have completed the local interaction are then input into the feedforward neural network for full connection, so that the output feature map has the same size as the final enhanced feature map.

[0034] The feature map output by the block attention processing module is input into the table attention processing module, the input feature map is aggregated into different local grids in the form of global expansion, the self-attention mechanism is performed on the local space within each grid to achieve global interaction, and finally, all local grids are input into the feedforward neural network for full connection, so that the output feature map has the same size as the final enhanced feature map.

[0035] Preferably, in step S303, the decoder in MM-TransUNet adopts a skip connection structure, and an MSCA attention mechanism is added to the skip connection of each layer;

[0036] The specific decoding steps of the decoder are:

[0037] S3031: extract important features from the shallow feature maps output by each layer of the three-layer ResNet-50 network through a multi-scale cross-axial attention mechanism, i.e., an MSCA attention mechanism. After being processed by the MSCA attention mechanism, the first-layer ResNet-50 network, the second-layer ResNet-50 network, and the third-layer ResNet-50 network respectively output the first-layer important feature map, the second-layer important feature map, and the third-layer important feature map, and the first-layer important feature map, the second-layer important feature map, and the third-layer important feature map are input into the decoder;

[0038] S3032: The decoder integrates the important feature map of the third layer with the deep feature map using a 3x3 convolution layer and uses a Relu function for linear activation, and then upsamples to generate a preliminary segmentation image;

[0039] S3032: The important feature map of the second layer is integrated with the preliminary segmentation image by using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a mid-order segmentation image;

[0040] S3033: The important feature map of the first layer is integrated with the mid-order segmentation image using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a final-order segmentation image;

[0041] S3034: Upsample the final-order segmentation image, and then use the ReLU function for linear activation to obtain a lung nodule segmentation image.

[0042] Preferably, in step S3031, the specific steps of applying the MSCA attention mechanism to process the shallow feature map are: inputting a shallow feature map F with a shape of H×W×C, performing multi-scale convolution operations on the feature map in parallel along the X-axis and the Y-axis respectively; the convolution kernel of the X-axis is set to 1×7, 1×11 and 1×21, and the convolution kernel of the Y-axis is set to 7×1, 11×1 and 21×1; after the multi-scale convolution operation, the convolution output and F of the input feature map F along the X-axis and the Y-axis are obtained. x and F y ; Then calculate F x and F y For the cross attention on the X-axis, first, F x As the key and value matrix, and F y As the query matrix, we get F T ; For the attention on the Y axis, F y As the key and value matrix, and F x As the query matrix, we get F B ; Finally, F B 、F T , F are integrated to obtain the first layer important feature map, the second layer important feature map or the third layer important feature map.

[0043] Preferably, in step S304, when calculating the loss between the detection result and the actual result, the DiceBCE loss function is used for calculation, and the DiceBCE loss function model is:

[0044] L total =(1-α)L BCE +αL Dice

[0045] Among them, α is the weight parameter of the composite loss function, L BCE is the binary cross entropy loss function, L Dice is the Dice loss function;

[0046] L BCE The function expression is as follows,

[0047]

[0048] Among them, G(r,c) is the true value of the pixel at coordinate (r,c), and S(r,c) is the predicted value of the pixel at coordinate (r,c);

[0049] L Dice The function expression is as follows,

[0050]

[0051] Among them, X represents the true value and Y represents the segmentation result.

[0052] Preferably, in step S5, the evaluation indicators include Dice coefficient, MIoU coefficient, Recall coefficient and Precision coefficient for evaluation;

[0053] The Dice coefficient formula is:

[0054]

[0055] The formula for the MioU coefficient is:

[0056]

[0057] The Recall coefficient formula is:

[0058]

[0059] The Precision coefficient is shown below:

[0060]

[0061] Among them, TP is a true positive example, FN is a false negative example, FP is a false positive example, and TN is a true negative example.

[0062] Compared with the prior art, the present invention adopting the above technical solution has the following outstanding features:

[0063] In order to solve the problem of poor segmentation accuracy due to the various shapes and sizes of lung nodules, the application of MM-TransUNet network as a segmentation model can effectively improve the segmentation accuracy of lung nodules. MM-TransUNet combines the residual mechanism, CNN and multi-axis self-attention mechanism as an encoder module to extract lung nodule features more completely. At the same time, the traditional skip connection module is improved by adding a multi-scale cross-axis attention mechanism to the skip connection of each layer, so as to better connect the shallow feature map with the deep feature map. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 is a flowchart of the training and testing of the pulmonary nodule segmentation algorithm based on TransUNet in an embodiment of the present invention;

[0065] Figure 2 is a flowchart of performing lung parenchyma segmentation, region of interest extraction and data enhancement operations on a lung CT image dataset in an embodiment of the present invention;

[0066] Figure 3 is a detailed information list in an XML file in an embodiment of the present invention;

[0067] Figure 4 is an overall network architecture diagram of the MM-TransUNet model in an embodiment of the present invention;

[0068] Figure 5 is a diagram of the encoder architecture in an embodiment of the present invention;

[0069] Figure 6 is a residual block structure diagram in an embodiment of the present invention;

[0070] Figure 7 is a schematic diagram of the MaxViT module processing a feature graph in an embodiment of the present invention;

[0071] Figure 8 is a schematic diagram of a block attention processing module and a table attention processing module processing a feature graph in an embodiment of the present invention;

[0072] Fig. 9 is a diagram of the decoder architecture of the present invention;

[0073] Fig.10 It is an architecture diagram of the MSCA attention mechanism in the present invention when processing feature graphs;

[0074] Fig.11 It is a curve chart showing the changes of various indicators of the MM-TransUNet model during the training phase as the number of training rounds increases;

[0075] Fig.12 This is a comparison chart of the segmentation results of lung nodules for samples 1, 2, 3, and 4 using the MM-TransUNet model and other open source models.

[0076] in, Figure 3 Downsmple is the downsampling operation, and Upsmple is the upsampling operation. DETAILED DESCRIPTION

[0077] The present invention will be further described below in conjunction with embodiments, the purpose of which is only to provide a better understanding of the content of the present invention. Therefore, the examples given do not limit the protection scope of the present invention.

[0078] like Figure 1 , Figure 4 As shown, this embodiment discloses a pulmonary nodule segmentation algorithm based on TransUNet, and the steps include:

[0079] S1: Acquire a lung CT image dataset, and perform lung parenchyma segmentation, region of interest extraction, and data enhancement operations on the lung CT image dataset.

[0080] In this embodiment, the lung CT image dataset adopts the LIDC-IDRI dataset. The LIDC-IDRI dataset contains lung CT data of 1018 research instances. The CT data of each instance is composed of several CT images, and the size of each CT image is 512×512. The pulmonary nodule annotation of each CT image is completed by 4 experienced radiologists. In order to avoid errors caused by forced consensus, the annotation diagnosis work of the database is divided into two stages: first, four doctors independently annotate the pulmonary nodules; then, each doctor will review the annotation results of other doctors.

[0081] The LIDC-IDRI dataset uses XML files to store the contour information, category information, and other feature information of lung nodules. The detailed information in the XML files is as follows: Figure 3 The detailed annotation of lung nodules in the LIDC-IDRI dataset is shown in Table 1.

[0082]

[0083] Table 1 Detailed information on the annotation of lung nodules in the LIDC-IDRI dataset

[0084] Since the pulmonary nodule information in LIDC-IDRI is annotated by physicians, and manual annotation inevitably has a certain degree of subjectivity, in order to ensure the accuracy and reliability of the data used, the experimental work of this embodiment is limited to the use of samples that have been jointly identified and annotated as pulmonary nodules by four doctors, a total of 928 cases; in order to make full use of these samples, each slice in the three-dimensional image containing pulmonary nodules is used as an independent sample, a total of 4946 slices. In order to improve the quality of the input image, thereby improving the processing effect and efficiency of the model on the data, a series of preprocessing operations need to be performed on the data set before applying it to the model; the CT images of the LIDC-IDRI database contain other trunk information in addition to the lung parenchyma, such as lung organs, pulmonary blood vessels, etc.; therefore, in order to avoid the influence of other irrelevant information on the segmentation of pulmonary nodules and improve the accuracy and efficiency of pulmonary nodule segmentation, preprocessing is required first.

[0085] like Figure 2 As shown, the pre-processing operation process is as follows;

[0086] S101: performing binary segmentation on the original CT image using the OTSU algorithm to obtain a binary image.

[0087] S102: Fill the cavity of the lung parenchyma using a flood filling method to obtain a filled image; and use an opening operation to remove noise and small bubbles in the binary image to obtain a denoised image.

[0088] S103: Subtract the denoised image from the filled image to obtain a preliminary lung parenchyma mask image containing a small connected region.

[0089] S104: performing an opening operation to remove small connected regions in the preliminary lung parenchyma mask image to obtain a final lung parenchyma mask image.

[0090] S105: performing an AND operation on the final-order lung parenchyma mask image and the original CT image to obtain a lung parenchyma image.

[0091] S106: The resolution of the lung parenchyma image obtained in step S105 is 512×512 pixels. Considering that the area occupied by lung nodules in the lung region is very small, if the entire image is directly input into the model for processing, the signal-to-noise ratio will be very low, and then the problem of class imbalance will occur, and the accuracy of lung nodule segmentation will be affected; therefore, it is necessary to extract the region of interest containing the lung nodules from the lung parenchyma image; locate the position of the lung nodules by reading the information provided by the XML file in the LIDC-IDRI dataset, and then use the method of taking the lung nodules as the center point to crop the original image to generate an image block with a size of 64×64 pixels; this image block will be used as the input data of the segmentation model for subsequent analysis and processing.

[0092] S107: In order to improve the generalization and robustness of the lung nodule segmentation model and avoid overfitting of the network, it is necessary to enhance and expand the data; perform operations such as flipping and rotating the original data, and use the expanded image and the original image as input data for training and testing the segmentation model; flipping is to randomly select image blocks and flip them horizontally or vertically, and the label image is also flipped accordingly; rotation is to randomly select image blocks and rotate them 90°, 180° or 270° in a clockwise direction, and the label image is also rotated like the image.

[0093] S2: Divide the lung CT image dataset after data augmentation into training set and test set.

[0094] S3: Build a segmentation model based on the TransUNet network structure, and use the training set to train the segmentation model. After each round of training, save the parameters of the segmentation model of this round, compare the detection results obtained by the segmentation model with the actual results to calculate the loss, and adjust the parameters of the segmentation model according to the loss.

[0095] In step S3, the Transformer layer in the TransUNet network is replaced with the MaxViT network to form an MM-TransUNet network as a segmentation model. The specific process of using the MM-TransUNet network to train the segmentation model is as follows;

[0096] S301: Input the image in the training set into the encoder. The encoder architecture is as follows: Figure 5 As shown, the residual mechanism is first used in conjunction with a convolutional neural network (CNN) to extract shallow features of the input image layer by layer to extract a shallow feature map;

[0097] Preferably, in step S301, MM-TransUNet adds a residual mechanism to the convolutional neural network and places it in the first three layers of the encoder, thereby improving the learning ability of the model and accelerating the convergence speed of the model, and avoiding the gradient explosion or gradient disappearance. At the starting position of the encoder, a three-layer ResNet-50 network based on CNN and residual mechanism is first used, and the shallow feature map output by each layer is used as the input of the next layer. The residual block structure of the ResNet-50 network is as follows: Figure 6 As shown in the figure, the ResNet-50 network is one of the variants of the ResNet network. Compared with the traditional CNN network, ResNet adds a residual mechanism, which enables the model to better solve the problems of gradient disappearance and gradient explosion of the neural network, and provides feasibility for the development of neural networks to be higher and wider.

[0098] The core idea of ​​ResNet is to combine the input features directly with the output features through skip connections to form residual blocks; by setting up skip connections, the network can learn residual information instead of relying entirely on information transmitted layer by layer; at the same time, the residual mechanism can better realize gradient transmission, making the network more stable and faster during the training phase; by setting up a residual learning mechanism, the learning and expression capabilities of the network can be improved, the problems of gradient vanishing and gradient exploding can be solved, and the convergence speed of the network can be accelerated.

[0099] The core idea of ​​the residual block can be expressed as a formula,

[0100] output=F(input)+input

[0101] Where F(*) represents a series of operations performed by the network on the input; the residual mechanism enables the model to better solve the problems of gradient disappearance and gradient explosion.

[0102] Then, the shallow feature map output by the third-layer residual block is divided into blocks and position encoding is added.

[0103] S302: The shallow feature map is processed by the MaxViT module (MaxViT Block) to fully perceive the deep context information, further deep feature learning, and extract the deep feature map of the image.

[0104] MaxViT is a hierarchical Transformer architecture that cleverly combines the attention mechanism with convolution operations and introduces an independent multi-axis attention module; the multi-axis attention module consists of two parts: one is the local attention mechanism that focuses on local features, and the other is the expanded global attention mechanism that can capture global contextual information; this design gives the MaxViT model the ability to handle perception tasks with linear complexity; by setting local attention and global attention, MaxViT realizes the form of local and global interaction, so it performs well in image segmentation and object detection.

[0105] Furthermore, in step S302, the shallow feature map after adding the position encoding is processed by the MaxViT module 12 times, such as Figure 7 As shown in the figure, the MaxViT module is composed of a serial structure, which has good flexibility and simplicity. The modules can be easily disassembled or combined, and have better scalability. The specific process of each MaxViT module processing is as follows:

[0106] S3021: The feature map is input into the MBConv module, which is a mobile flippable convolution block that combines attention and residual structures. The feature map is convolved by a 1x1 convolution layer, and the input feature map that has been processed by convolution will be processed by a depth-wise separable convolution (3x3 convolution layer). The channel attention module (SE) is input to strengthen the relevant features and weaken the irrelevant features in the feature map to obtain an enhanced feature map, and then the enhanced feature map is convolved point by point with the input feature map to restore the dimension, and the enhanced feature map is output.

[0107] S3022: Figure 7 , Figure 8 As shown, the enhanced feature map is input into the block attention processing module (BlockAttention), and the block attention processing module (BlockAttention) divides the input feature map into complementary overlapping image blocks. The splitting operation can be expressed as;

[0108]

[0109] After splitting the input image into several complementary overlapping image blocks, the self-attention mechanism (Block-SA) is applied to each split image block P×P to achieve interaction in a local range. Then the image blocks that complete the local interaction are input into the feedforward neural network (FNN) for full connection, so that the output feature map has the same size as the final enhanced feature map.

[0110] S3023: Input the feature map output by the block attention processing module into the table attention processing module (GridAttention). The table attention processing module aggregates the input image into different local grids in the form of global expansion. The specific operation can be expressed as:

[0111]

[0112] The input feature map is aggregated into different local grids in the form of global expansion. ) The local space within the local area performs a self-attention mechanism (Grid-SA) to achieve global interaction. Finally, all local grids are input into the feed-forward neural network for full connection, so that the output feature map has the same size as the final enhanced feature map.

[0113] S303: inputting the shallow feature map and the deep feature map into the decoder, connecting and upsampling the shallow feature map and the deep feature map, performing feature fusion layer by layer, and finally outputting a lung nodule segmentation image;

[0114] Preferably, in step S303, the decoder in MM-TransUNet adopts a skip connection structure, and an MSCA attention mechanism is added to the skip connection of each layer;

[0115] like Fig. 9 , the specific decoding steps of the decoder are:

[0116] S3031: The shallow feature maps output by each layer of the three-layer ResNet-50 network are first extracted through the multi-scale cross-axial attention mechanism, namely the MSCA attention mechanism. The MSCA attention mechanism is a method of embedding multi-scale features into axial attention, and it combines horizontal axial attention and vertical axial attention to better segment lesions or organs of various sizes and shapes.

[0117] After being processed by the MSCA attention mechanism, the first-layer ResNet-50 network, the second-layer ResNet-50 network, and the third-layer ResNet-50 network output the first-layer important feature map, the second-layer important feature map, and the third-layer important feature map respectively, and the first-layer important feature map, the second-layer important feature map, and the third-layer important feature map are input into the decoder.

[0118] like Fig.10In step S3031, the specific steps of applying the MSCA attention mechanism to process the shallow feature map are as follows: input the shallow feature map F with a shape of H×W×C, perform multi-scale convolution operations on the feature map in parallel along the X-axis and Y-axis respectively; the convolution kernel of the X-axis is set to 1×7, 1×11 and 1×21, and the convolution kernel of the Y-axis is set to 7×1, 11×1 and 21×1; after the multi-scale convolution operation, the convolution output and F of the input feature map F along the X-axis and Y-axis are obtained. x and F y ;

[0119]

[0120]

[0121] Then calculate F x and F y For the cross attention on the X-axis, first, F x As the key and value matrix, and F y As the query matrix, we get F T ;

[0122] F T =MHCA y (F y ,F x ,F x )

[0123] Among them, MHCA y (*,*,*) indicates multi-head cross attention along the X-axis.

[0124] For the attention on the Y axis, F y As the key and value matrix, and F x As the query matrix, we get F B ;

[0125] F B =MHCA x (F x ,F y ,F y )

[0126] Among them, MHCA x (*,*,*) indicates multi-head cross attention along the Y-axis.

[0127] Finally, F B 、F T , F are integrated to obtain the first layer important feature map, the second layer important feature map or the third layer important feature map. The integration process formula is:

[0128] F out =Conv1×1 (F T )+Conv 1×1 (F B )+F

[0129] By adding the MSCA attention mechanism to the feature maps in the skip connection, the neural network's perception of specific channels and spatial dimensions can be enhanced to more effectively extract richer and more useful features, thereby enhancing the functionality of the skip connection.

[0130] S3032: The decoder integrates the important feature map of the third layer with the deep feature map using a 3x3 convolution layer and uses a Relu function for linear activation, and then upsamples to generate a preliminary segmentation image;

[0131] S3032: The important feature map of the second layer is integrated with the preliminary segmentation image by using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a mid-order segmentation image;

[0132] S3033: The important feature map of the first layer is integrated with the mid-order segmentation image using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a final-order segmentation image;

[0133] S3034: Upsample the final-order segmentation image, and then use the ReLU function for linear activation to obtain a lung nodule segmentation image.

[0134] S304: Calculate the loss between the lung nodule segmentation image output in step S303 and the actual lung nodule segmentation image through the loss function, adjust the parameters in the MM-TransUNet network, update the MM-TransUNet network model, and return to step S301 for a new round of training until all images in the training set are trained.

[0135] Furthermore, considering that the binary cross entropy loss function is the most common loss function in binary semantic segmentation, using it alone will lead to insufficient model learning feature capability and insufficient segmentation accuracy. The Dice loss function is not conducive to model training. When the target area contained in the image is small, even if only a very small number of pixels are predicted to be biased, it may cause significant fluctuations in the loss function value, which will not only affect the stability of the model during training, but may also have a negative impact on the convergence performance of the model.

[0136] In order to make full use of the characteristics of the binary cross entropy loss function and the Dice loss function, this embodiment combines them to form a new loss function DiceBCE; the DiceBCE loss function linearly combines the Dice loss function and the BCE loss function, so that it has the characteristics of relatively stable back propagation and the ability to pay more attention to the lung nodule area; using the DiceBCE loss function to guide the model to learn can enable the model to improve the accuracy of lung nodule segmentation while accelerating the convergence speed.

[0137] The DiceBCE loss function model is:

[0138] L total =(1-α)L BCE +αL Dice

[0139] Among them, α is the weight parameter of the composite loss function. Different values ​​of the weight parameter will affect the segmentation model's focus on different learning contents, thereby affecting the segmentation accuracy of lung nodules; L BCE is the binary cross entropy loss function, L Dice is the Dice loss function;

[0140] L BCE The function expression is as follows,

[0141]

[0142] Among them, G(r,c) is the true value of the pixel at coordinate (r,c), and S(r,c) is the predicted value of the pixel at coordinate (r,c);

[0143] L Dice The function expression is as follows,

[0144]

[0145] Among them, X represents the true value and Y represents the segmentation result.

[0146] S4: reading the optimal parameters saved in the training phase, and substituting the optimal parameters into the segmentation model to obtain the optimal lung nodule segmentation model;

[0147] S5, the optimal pulmonary nodule segmentation model is tested using the test set, and the model accuracy of the optimal pulmonary nodule segmentation model is evaluated using evaluation indicators.

[0148] In the field of medical image segmentation, in order to evaluate and compare the segmentation effects of different models, researchers usually use a series of evaluation indicators; the design of these indicators closely fits the specific needs and goals of the segmentation task and can fully reflect the segmentation ability of the model; lung nodule segmentation is a pixel-level image analysis task, and its goal is to accurately classify each pixel; for the lung nodule segmentation task, this embodiment uses the following four evaluation indicators to evaluate the model accuracy.

[0149] (1) Dice coefficient: This index is used to evaluate the degree of overlap between the model prediction output and the true label. Its value range is [0, 1]. The closer the value is to 1, the higher the degree of overlap between the model segmentation result and the true label. The Dice coefficient formula is:

[0150]

[0151] (2) MIoU coefficient, which is the ratio of the intersection area to the union area. Its value range is [0,1]. The closer the value is to 1, the better the segmentation effect. The formula of MioU coefficient is:

[0152]

[0153] (3) Recall coefficient, which indicates the proportion of lung nodules correctly detected by the model to all real lung nodules; the formula of Recall coefficient is:

[0154]

[0155] (4) Precision coefficient, which indicates the proportion of pixels predicted by the model to be lung nodules whose true values ​​are also lung nodules. The Precision coefficient is expressed as follows:

[0156]

[0157] Among them, TP is a true positive example, FN is a false negative example, FP is a false positive example, and TN is a true negative example.

[0158] When conducting the experiment specifically, this embodiment uses RMSprop as the optimization algorithm of the model, which is an algorithm that adaptively adjusts the learning rate to minimize the loss function and optimize the parameters of the model; the initial learning rate is set to 0.001, and the experimental details are set as shown in Table 2.

[0159]

[0160] Table 2 Experimental details settings

[0161] As shown in Table 2, the initial learning rate is set to 0.001. Training with a larger initial learning rate is to accelerate the convergence of the network. ExponentialLR is used to create a learning rate scheduler, and the learning rate decay rate gamma is set to 0.9, so that at the end of each epoch, the learning rate will be updated according to the set decay rate. The learning rate is gradually reduced during the training process to better optimize the model. Through the setting of exponential decay, the learning rate gradually decreases in the later stage of training, which is conducive to more fine-tuning the parameters of the model.

[0162] Furthermore, in order to eliminate the possible impact of differences in experimental environments on the experimental results and ensure the reliability of the experiments, this chapter adopted a unified experimental environment setting for all experiments; the detailed hardware configuration of the experimental environment can be seen in Table 3.

[0163]

[0164] Table 3 Hardware parameters

[0165] The experiments in this chapter use the Pytorch framework to implement the proposed model. The source code of the Pytorch framework is intuitive and easy to understand, and the design is simple and efficient. Therefore, Pytorch is selected as the framework for building the model; the specific software parameters of the experiment are shown in Table 4.

[0166]

[0167]

[0168] Table 4 Software parameters

[0169] In order to verify the effectiveness of the MM-TransUNet model in the task of pulmonary nodule segmentation and prove that it can cope with the poor segmentation accuracy caused by the different shapes and scales of pulmonary nodules, this section uses MM-TransUNet to perform segmentation experiments on pulmonary nodule images in the LIDC-IDRI dataset; Fig.11 The figure shows the changes of various indicators of MM-TransUNet during the training stage. It can be seen that the loss in the training stage gradually decreases with the increase of training rounds, and finally converges to a smaller value; while the Dice and IoU indicators representing the segmentation accuracy gradually increase with the increase of rounds, and finally tend to a constant value; MM-TransUNet will save the parameters of the round with the highest segmentation accuracy and load them in the test stage; in the test stage, the Dice coefficient of MM-TransUNet reached 85.82%, proving that it can complete the lung nodule segmentation task well.

[0170] Furthermore, in order to prove that the MaxViT module and the MSCA attention mechanism module in MM-TransUNet have a positive impact on the accuracy of lung nodule segmentation, this embodiment sets up corresponding ablation experiments to complete the effectiveness test of each module; the test results are shown in Table 5.

[0171]

[0172]

[0173] Table 5 MM-TransUNet ablation experiment results

[0174] Table 5 shows the lung nodule segmentation accuracy after adding different modules at different positions of the TransUNet model based on the TransUNet model. These indicators are evaluated on the LIDC-IDRI dataset. Compared with the baseline method 1, the baseline method 1 is the TransUNet model. When MaxViT, MSCA-1, MSCA-2, and MSCA-3 are gradually integrated into the baseline method, the indicators are improved to varying degrees. Among them, MSCA-1, MSCA-2, and MSCA-3 refer to adding MSCA modules to the first, second, and third layer skip connections, respectively. MaxViT means replacing the ViT block in the baseline method with the MaxViT block. As can be seen from Table 5, after using the MaxViT module, the indicators of method 2 are improved to varying degrees compared with the baseline method. By comparing Method 1, Method 3, Method 4 and Method 5, it can be seen that after adding the MSCA module to the skip connection in the baseline method, various indicators have been greatly improved, and the magnitude of these improvements has increased roughly with the increase in the number of MSCA modules; when MSCA-1, MSCA-2, and MSCA-3 are integrated into the baseline method, various indicators have basically achieved the greatest improvement; due to the simple design of the skip connection of the baseline method, although it can fuse the low-level features and high-level features in the encoder and decoder, it also introduces some redundant information. By adding the MSCA module to the skip connection, the model's perception ability on specific channels and spatial dimensions can be enhanced to more effectively extract richer and more useful features.

[0175] After integrating MSCA, MSCA-1, MSCA-2 and MSCA-3 into the benchmark method, the improvement of various indicators reached the maximum, with the Dice coefficient increased by 2.17% and MIoU increased by 1.71%. Overall, in practical applications, MaxViT has good scalability and can also extract features well when processing high-resolution images, so that the neural network can further learn deep features and fully perceive deep contextual information; and the skip connection improved by the MSCA attention mechanism, after extracting richer and more effective features from the feature map, passes it to the decoder, so as to better realize the fusion of lower-level features in the encoder with higher-level features in the corresponding decoder, and finally achieve the improvement of various segmentation indicators.

[0176] In order to determine the optimal value of the α weight in the DiceBCELoss hybrid function designed in this chapter, the experiment set different α values, trained and evaluated MM-TransUNet, and selected the best performing value as the weight parameter α in the loss function by observing the performance of MM-TransUNet on the test set. The impact of different α values ​​on the model segmentation accuracy is shown in Table 6.

[0177]

[0178] Table 6 Effect of different α values ​​on accuracy

[0179] It can be seen from Table 6 that the value of α will have some influence on the segmentation accuracy of the model; when the value of α is 0.5, the Dice coefficient can reach the optimal value of 85.82%, and the Dice coefficient is one of the most important indicators for measuring the segmentation accuracy of the model. It indicates the degree of overlap between the model's prediction and the true value. Therefore, this embodiment selects 0.5 as the value of α.

[0180] In order to further verify the effectiveness of MM-TransUNet in the task of pulmonary nodule segmentation, we also conducted a multi-model comparative experiment based on the LIDC-IDRI dataset. The selected comparative models include U-Net, U-Net++, U-Net3+, Res-UNet, TransUNet, RISU-Net, and REMU-Net. The final results of the comparative experiment are shown in Table 7. Compared with the existing excellent open source models and the improved models proposed by other scholars, MM-TransUNet achieved the best results in the Dice coefficient, which is the most important indicator for measuring the segmentation accuracy of the model. It represents the degree of overlap between the model output and the true label. At the same time, MM-TransUNet also achieved the best values ​​in the MIoU index and Precision index, which proves the effectiveness of MM-TransUNet in improving the accuracy of pulmonary nodule segmentation, and also effectively proves the gain brought by combining Transformer with CNN to the model.

[0181]

[0182] Table 7 Comparative experimental results

[0183] Fig.12 The segmentation results of lung nodules by different open source models are intuitively displayed. In order to better demonstrate the various situations encountered in the segmentation of lung nodules, four lung nodule CT image samples of different shapes and sizes are selected here, so as to better restore the lung nodule segmentation tasks under different situations, making the comparative experiment representative.

[0184] Sample 1 is an irregularly shaped, medium-sized lung nodule, which is not only concave but also has a convex strip at the bottom. The segmentation results show that MM-TransUNet can learn its features in detail and restore its concave and convex shape better, while other models are lacking in this regard. For example, U-Net does not segment the convex structure at the bottom, and the remaining models that restore the convex structure are also far from the gold standard in terms of degree.

[0185] Sample 2 selects small-sized lung nodules. The segmentation of small-sized lung nodules is particularly susceptible to noise. For example, the U-Net3+ model mistakenly identifies other noises as lung nodules, while the U-Net model identifies lung nodules as noise, resulting in segmentation results that are too small. The MM-TransUNet model can appropriately distinguish lung nodules from similar noises, and the segmentation results are neither too large nor too small.

[0186] Sample 3 is a large-sized lung nodule with irregular shape and concave in the middle. It can be seen from the segmentation results that the selected model can basically capture the trend of concave lung nodules, but the degree of restoration varies. The U-Net model has excessive concave, resulting in distortion, while the segmentation result of the TransUNet model has less obvious concave. The segmentation result of MM-TransUNet has achieved better restoration in terms of the degree of concave.

[0187] Sample 4 selects a lung nodule with an irregular shape and large size, and there is noise on its surface. The segmentation results show that due to the presence of surface noise, other models identify the convex lung nodule below as noise and fail to segment it, which is a serious distortion. However, MM-TransUNet can still generate good segmentation results under the interference of noise. Although it cannot fully restore every detail of the lung nodule, it can distinguish between lung nodules and noise very well.

[0188] In summary, judging from the visualized segmentation results, MM-TransUNet can produce higher segmentation accuracy when facing different forms of lung nodules. Compared with other excellent models, its segmentation results are closer to the gold standard.

[0189] The above description is only a preferred feasible embodiment of the present invention, and does not limit the scope of rights of the present invention. All equivalent changes made using the contents of the present specification and its drawings are included in the scope of rights of the present invention.

Claims

1. A pulmonary nodule segmentation algorithm based on TransUNet, comprising the following steps: S1: Acquire a lung CT image dataset, and perform lung parenchyma segmentation, region of interest extraction, and data enhancement operations on the lung CT image dataset; S2: Divide the lung CT image dataset after data augmentation into a training set and a test set; S3: Build a segmentation model based on the TransUNet network structure and use the training set to train the segmentation model. After each round of training, save the parameters of the segmentation model for this round, compare the detection results obtained by the segmentation model with the actual results to calculate the loss, and adjust the parameters of the segmentation model according to the loss. S4: reading the optimal parameters saved in the training phase, and substituting the optimal parameters into the segmentation model to obtain the optimal lung nodule segmentation model; S5, using the test set to test the optimal pulmonary nodule segmentation model, and using the evaluation index to evaluate the model accuracy of the optimal pulmonary nodule segmentation model; It is characterized in that, in step S3, the Transformer layer in the TransUNet network is replaced with the MaxViT network to form an MM-TransUNet network as a segmentation model, and the specific process of using the MM-TransUNet network to train the segmentation model is as follows; S301: Input the image in the training set into the encoder, first use the residual mechanism with the convolutional neural network to extract shallow features of the input image layer by layer, and extract a shallow feature map; S302: The shallow feature map is processed by the MaxViT module to fully perceive the deep context information, further deep feature learning, and extract the deep feature map of the image; S303: inputting the shallow feature map and the deep feature map into the decoder, connecting and upsampling the shallow feature map and the deep feature map, performing feature fusion layer by layer, and finally outputting a lung nodule segmentation image; S304: Calculate the loss between the lung nodule segmentation image output in step S303 and the actual lung nodule segmentation image through the loss function, adjust the parameters in the MM-TransUNet network, update the MM-TransUNet network model, and return to step S301 for a new round of training until all images in the training set are trained.

2. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 1, characterized in that: In step S1, the specific steps of segmenting the lung parenchyma of the lung CT image dataset are as follows: S101: performing binary segmentation on the original CT image using the OTSU algorithm to obtain a binary image; S102: Fill the cavity of the lung parenchyma using a flood filling method to obtain a filled image; Use the opening operation to remove the noise and small bubbles in the binary image to obtain the denoised image; S103: subtracting the denoised image from the filled image to obtain a preliminary lung parenchyma mask image containing a small connected region; S104: performing an opening operation to remove small connected regions in the initial-order lung parenchyma mask image to obtain a final-order lung parenchyma mask image; S105: performing an AND operation on the final-order lung parenchyma mask image and the original CT image to obtain a lung parenchyma image.

3. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 2, characterized in that: Step S1 also includes, S106: extracting a region of interest including a lung nodule from the lung parenchyma image; locating the position of the lung nodule using the lung nodule position information in the data set, and then cropping the lung parenchyma image with the lung nodule as the center point to generate an input image block; S107: Expand the image source, randomly flip or rotate the image block, and use the expanded image block and the original image block as the data set of the training set and the test set; flipping is to randomly select an image block to flip horizontally or vertically, and the label image is also flipped accordingly; rotation is to randomly select an image block to rotate 90°, 180° or 270° in a clockwise direction, and the label image is also rotated like the image.

4. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 1, characterized in that: In step S301, at the start position of the encoder, MM-TransUNet first uses a three-layer ResNet-50 network based on CNN and residual mechanism. The shallow feature map output by each layer is used as the input of the next layer; each layer of ResNet-50 network directly combines the input features with the output features through skip connections to form a residual block. The core idea of ​​the residual block can be expressed as follows: output=F(input)+input Where F(*) indicates that the network performs a series of operations on the input; Then, the shallow feature map output by the third-layer residual block is divided into blocks and position encoding is added.

5. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 4, characterized in that: In step S302, the shallow feature map after adding the position encoding is processed by the MaxViT module 12 times. The specific process of each MaxViT module processing is as follows: The feature map is input into the MBConv block. After passing through the 1x1 convolution layer and the 3x3 convolution layer, the feature map is input into the channel attention module to strengthen the relevant features in the feature map and weaken the irrelevant features to obtain the enhanced feature map. The enhanced feature map is then convolved point by point with the input feature map to restore the dimension and output the enhanced feature map. The enhanced feature map is input into the block attention processing module and split into several complementary overlapping image blocks. Then, the self-attention mechanism is applied to each split image block to achieve interaction in a local range. The image blocks that have completed the local interaction are then input into the feedforward neural network for full connection, so that the output feature map has the same size as the final enhanced feature map. The feature map output by the block attention processing module is input into the table attention processing module, the input feature map is aggregated into different local grids in the form of global expansion, the self-attention mechanism is performed on the local space within each grid to achieve global interaction, and finally, all local grids are input into the feedforward neural network for full connection, so that the output feature map has the same size as the final enhanced feature map.

6. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 5, characterized in that: In step S303, the decoder in MM-TransUNet adopts a skip connection structure, and an MSCA attention mechanism is added to the skip connection of each layer; The specific decoding steps of the decoder are: S3031: extract important features from the shallow feature maps output by each layer of the three-layer ResNet-50 network through a multi-scale cross-axial attention mechanism, i.e., an MSCA attention mechanism. After being processed by the MSCA attention mechanism, the shallow feature maps output by the first layer ResNet-50 network, the second layer ResNet-50 network, and the third layer ResNet-50 network are correspondingly processed into the first layer important feature map, the second layer important feature map, and the third layer important feature map. The first layer important feature map, the second layer important feature map, and the third layer important feature map are input into the decoder; S3032: The decoder integrates the important feature map of the third layer with the deep feature map using a 3x3 convolution layer and uses a Relu function for linear activation, and then upsamples to generate a preliminary segmentation image; S3032: The important feature map of the second layer is integrated with the preliminary segmentation image by using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a mid-order segmentation image; S3033: The important feature map of the first layer is integrated with the mid-order segmentation image using a 3x3 convolution layer and a Relu function is used for linear activation, and then up-sampled to generate a final-order segmentation image; S3034: Upsample the final-order segmentation image, and then use the ReLU function for linear activation to obtain a lung nodule segmentation image.

7. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 6, characterized in that: In step S3031, the specific steps of applying the MSCA attention mechanism to process the shallow feature map are as follows: input a shallow feature map F with a shape of H×W×C, perform multi-scale convolution operations on the feature map in parallel along the X-axis and the Y-axis respectively; the convolution kernel of the X-axis is set to 1×7, 1×11 and 1×21, and the convolution kernel of the Y-axis is set to 7×1, 11×1 and 21×1; after the multi-scale convolution operation, the convolution output and F of the input feature map F along the X-axis and the Y-axis are obtained. x and F y ; Then calculate F x and F y For the cross attention on the X-axis, first, F x As the key and value matrix, and F y As the query matrix, we get F T ; For the attention on the Y axis, F y As the key and value matrix, and F x As the query matrix, we get F B ; Finally, F B 、F T , F are integrated to obtain the first layer important feature map, the second layer important feature map or the third layer important feature map.

8. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 6, characterized in that: In step S304, when calculating the loss of the detection result and the actual result, the DiceBCE loss function is used for calculation. The DiceBCE loss function model is: L total =(1-α)L BCE +αL Dice Among them, α is the weight parameter of the composite loss function, L BCE is the binary cross entropy loss function, L Dice is the Dice loss function; L BCE The function expression is as follows, Among them, G(r,c) is the true value of the pixel at coordinate (r,c), and S(r,c) is the predicted value of the pixel at coordinate (r,c); L Dice The function expression is as follows, Among them, X represents the true value and Y represents the segmentation result.

9. The TransUNet-based pulmonary nodule segmentation algorithm according to claim 1, characterized in that: In step S5, the evaluation indicators include Dice coefficient, MIoU coefficient, Recall coefficient and Precision coefficient for evaluation; The Dice coefficient formula is: The formula for the MioU coefficient is: The Recall coefficient formula is: The Precision coefficient is shown below: Among them, TP is a true positive example, FN is a false negative example, FP is a false positive example, and TN is a true negative example.

Citation Information

Patent Citations

  • Multi-center child X-ray chest radiography image lung segmentation method based on TransUNet model

    CN114708255A

  • Multi-type pulmonary nodule accurate segmentation method and model based on hybrid Transform

    CN115731387A

  • Method for establishing model for searching images by images, method, system, equipment and medium for searching images by images

    CN116187439A

  • Lung CT image segmentation method based on Transform and convolutional neural network

    CN116739985A

  • Pulmonary nodule segmentation method based on DMC-UNet

    CN116824147A

Cited By

  • Double-attention mechanism medical image segmentation method based on improved TransUnet network

    CN119205705A

  • Pneumonia segmentation method based on multi-connection axial graph convolutional network

    CN120298422A

  • Semantic segmentation network and semantic segmentation method

    CN120635453A

  • LSTM and GAN combination-based pulmonary nodule growth prediction method

    CN120727289A

  • Lung nodule growth prediction method based on combination of lstm and gan

    CN120727289B