Paint surface image segmentation system and method based on dual attention mechanism and U-net network
By using the Efficientnet-B0 encoder and modulation coefficient FocalLoss loss function in the U-net network, combined with the serial dual-channel CBAM module, the paint surface image segmentation system is improved and solves the problems of low segmentation accuracy and poor real-time performance in the existing technology. problem, achieving higher segmentation accuracy and performance.
Patent Information
- Application Number
- CN202111413562.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-25
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-11-25
AI Technical Summary
Existing technologies in the field of paint surface image segmentation have problems such as low segmentation accuracy, low segmentation precision, and poor real-time performance. This is mainly due to the U-net network's insufficiency in feature extraction and loss function design, and its inability to effectively handle the complexity of paint surface information.
The Efficientnet-B0 encoder is used to extract paint surface image features, and the FocalLoss loss function of the modulation coefficient and the serial dual-channel CBAM module are introduced in the feature fusion stage to improve the U-net network to improve segmentation accuracy and real-time performance.
Through the combination of features extracted by the Efficientnet-B0 encoder and the FocalLoss loss function, the network's attention to the paint surface area is strengthened, the segmentation accuracy and real-time performance are improved, and the mis-segmentation and real-time performance of the traditional U-net network in paint surface segmentation are solved. Low accuracy problem.
Smart Images

Figure CN113989271B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of steel plate paint surface image processing, and relates to a paint surface image segmentation system and method based on a dual attention mechanism and a U-net network. Background Art
[0002] In the industrial field, in order to protect metals or other base materials, the surface is generally painted to achieve the effects of rust prevention, oxidation prevention and corrosion prevention. When the paint layer partially falls off or the surface needs to be repainted for other reasons, the original paint layer needs to be completely cleaned. There are many traditional paint cleaning methods, mainly manual combined with mechanical grinding, chemical cleaning and other methods. These traditional paint cleaning methods are not only energy-intensive, highly polluting, and easy to damage metal materials, but also often cause certain physical harm to workers. The ideal way to solve these problems is to use a visual automatic guided vehicle equipped with laser paint removal instead of traditional paint cleaning methods.
[0003] The segmentation accuracy of paint images is the premise and guarantee of the working efficiency and effect of the visual automatic paint removal vehicle. In practical applications, the contrast between the paint image and the background (metal materials, ground, etc.) is not high, the noise in the image acquisition process, the light and shadow changes in the environment, etc. will affect the segmentation accuracy of the paint image. Although the current deep learning and neural network algorithms are very mature, many neural network models can solve the problems of image recognition and image segmentation, and the performance is good, but there are few methods applied in the field of paint image segmentation. In addition, there is no public paint dataset, which increases the difficulty of paint image segmentation.
[0004] The U-net neural network model is often used in the field of medical image segmentation, thanks to its lightweight structure, excellent segmentation performance, and strong tolerance to input images. These features are more consistent with paint images, but directly applying the U-net model to the field of paint image segmentation will have disadvantages such as mis-segmentation, low segmentation accuracy, and poor real-time performance.
[0005] The most similar technical solution to the present invention is an EfficientNet sensitive image detection method and system based on the attention mechanism disclosed in patent number CN112396571A. The technical solution disclosed in CN112396571A directly adopts the EfficientNet network structure and embeds the attention mechanism for application, while the native U-net neural network is directly used for paint image segmentation, which has the defects of low segmentation accuracy, low segmentation precision, and long segmentation time. The main reason for these problems is that the paint information has a lot of feature information, and U-net abandons the fully connected layer for the lightweight of the network, and the original encoder of U-net is not detailed enough for feature extraction, and the native U-net loss function uses the commonly used cross entropy loss function, and the degree of attention to the feature area is not enough. The above characteristics of U-net cause the extraction of paint feature information to be incomplete. Summary of the invention
[0006] Purpose of the invention: In view of the above-mentioned problems of the prior art, the purpose of the present invention is to improve the segmentation precision, accuracy and real-time performance of the paint image by using the Efficientnet-B0 encoder to extract the original paint image features, using the FocalLoss loss function that introduces the modulation coefficient, and embedding the serial dual-channel CBAM module in the feature fusion stage.
[0007] Technical solution: To achieve the above-mentioned invention object, the present invention specifically adopts the following technical solution:
[0008] The invention provides a paint surface image segmentation system based on a dual attention mechanism and a U-net network, comprising: a preprocessing module, used for preprocessing the collected original paint surface images to obtain an image training set; a U-net network improvement module, used for improving the U-net network by using an Efficientnet-B0 encoder to extract the original paint surface image features, using a FocalLoss loss function that introduces a modulation coefficient, and embedding a serial dual-channel CBAM module in a feature fusion stage to obtain an improved U-net network; a U-net segmentation model training module, used for training the image training set as input data of the improved U-net network to obtain a trained U-net segmentation model; and an image segmentation module, used for inputting the paint surface image to be segmented as test data into the trained U-net segmentation model to obtain a segmented result.
[0009] Furthermore, in the preprocessing module, the specific method of preprocessing is: according to the length and width of the original paint image, the original paint image and the label image corresponding to the original paint image are expanded into square images; specifically: when the length and width of the original paint image are different, the width and length of the original paint image are made the same by adding a gray edge, thereby obtaining the edge-filled paint image and the corresponding label image; the edge-filled paint image is subjected to Gaussian filtering denoising to obtain the denoised paint image; the denoised paint image and the edge-filled label image are subjected to data enhancement; specifically: the denoised paint image and the edge-filled label image are corresponded to form a data set N1, the paint image and the label image in N1 are horizontally flipped to obtain a data set N2, and data sets N3, N4 and N5 are obtained by three rotations with angle values of 90°, 180° and 270° respectively, and finally the data set composed of N1, N2, N3, N4 and N5 is used as the image training set.
[0010] Furthermore, in the U-net network improvement module:
[0011] The specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is:
[0012] The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks are processed respectively. The feature map extracted by the 5th MBConv block is input into the upsampling part for feature fusion through the spatial attention module, and the feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction; each mobile inverted bottleneck module includes: four 1×1 convolution layers, one 3×3 depth-separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depth-separable convolution structure, and a channel attention mechanism is added after the 3×3 depth-separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer;
[0013] The specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is:
[0014] A spatial attention module is added in the feature fusion link to increase the weight of the improved U-net network on the painted area, while reducing the weight of the non-painted area; a channel attention module is embedded after the output of the convolutional layer in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion.
[0015] Furthermore, the feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network;
[0016] In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate a feature map Q; the feature map Q is spliced with the output feature map O of the convolution layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is:
[0017]
[0018]
[0019]
[0020] Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function;
[0021] In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. The global feature M is convolved with a one-dimensional convolution of size k to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is:
[0022]
[0023] Where C is the number of channels, |A odd It represents the odd number closest to A;
[0024] The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The calculation of the channel attention module is:
[0025]
[0026]
[0027]
[0028]
[0029] G=r[N+P]
[0030] in, represents the convolution operation, and r represents the ReLu activation function.
[0031] Furthermore, in the U-net segmentation model training module, the specific training process is as follows: use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; use adaptive matrix estimation as the optimizer and FocalLoss as the loss function to set the training parameters of the improved U-net network: the initial learning rate is 0.001, and the exponential decay rate β is calculated for the first-order moment estimation. 1 = 0.9, the exponential decay rate for the second-order moment estimation is β 1 =0.999, the number of training rounds is 100, and the number of training samples in each round is 8; the image training set obtained by preprocessing is rearranged randomly, and then input into the improved U-net network for training until a trained U-net segmentation model is obtained.
[0032] In addition, the present invention provides a paint image segmentation method based on a dual attention mechanism and a U-net network, comprising: step 1, preprocessing the collected original paint image to obtain an image training set; step 2, improving the U-net network by using an Efficientnet-B0 encoder to extract the original paint image features, using a FocalLoss loss function that introduces a modulation coefficient, and embedding a serial dual-channel CBAM module in the feature fusion stage to obtain an improved U-net network; step 3, using the image training set as input data of the improved U-net network for training to obtain a trained U-net segmentation model; step 4, inputting the paint image to be segmented as test data into the trained U-net segmentation model to obtain a segmented result.
[0033] Further, in step 1, the specific method of preprocessing is: according to the length and width of the original paint image, the original paint image and the label image corresponding to the image are expanded into a square image; specifically: when the length and width of the original paint image are different, the width and length of the original paint image are made the same by adding a gray edge, thereby obtaining an edge-filled paint image and a corresponding label image; the edge-filled paint image is subjected to Gaussian filtering denoising to obtain a denoised paint image; the denoised paint image and the edge-filled label image are subjected to data enhancement; specifically: the denoised paint image and the edge-filled label image are corresponded to form a data set N1, the paint image and the label image in N1 are horizontally flipped to obtain a data set N2, and data sets N3, N4 and N5 are obtained by three rotations with angle values of 90°, 180° and 270° respectively, and finally the data set composed of N1, N2, N3, N4 and N5 is used as an image training set.
[0034] Furthermore, in step 2:
[0035] The specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is:
[0036] The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks are processed respectively. The feature map extracted by the 5th MBConv block is input into the upsampling part for feature fusion through the spatial attention module, and the feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction; each mobile inverted bottleneck module includes: four 1×1 convolution layers, one 3×3 depth-separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depth-separable convolution structure, and a channel attention mechanism is added after the 3×3 depth-separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer;
[0037] The specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is:
[0038] A spatial attention module is added in the feature fusion link to increase the weight of the improved U-net network on the painted area, while reducing the weight of the non-painted area; a channel attention module is embedded after the output of the convolutional layer in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion.
[0039] Furthermore, the feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network;
[0040] In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate a feature map Q; the feature map Q is spliced with the output feature map O of the convolution layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is:
[0041]
[0042]
[0043]
[0044] Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function;
[0045] In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. The global feature M is convolved with a one-dimensional convolution of size k to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is:
[0046]
[0047] Where C is the number of channels, |A| odd It represents the odd number closest to A;
[0048] The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The calculation of the channel attention module is:
[0049]
[0050]
[0051]
[0052]
[0053] G=r[N+P]
[0054] in, represents the convolution operation, and r represents the ReLu activation function.
[0055] Furthermore, in step 3, the specific training process is as follows: use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; use adaptive matrix estimation as the optimizer and FocalLoss as the loss function to set the training parameters of the improved U-net network: the initial learning rate is 0.001, and the exponential decay rate β is calculated for the first-order moment estimation. 1 = 0.9, the exponential decay rate for the second-order moment estimation is β 1 =0.999, the number of training rounds is 100, and the number of training samples in each round is 8; the image training set obtained by preprocessing is rearranged randomly, and then input into the improved U-net network for training until a trained U-net segmentation model is obtained.
[0056] Beneficial effects: According to the paint surface image segmentation system and method based on the dual attention mechanism and U-net network provided by the present invention, compared with the existing segmentation method, the present invention uses the Efficientnet-B0 encoder to extract the original paint surface image features, uses the FocalLoss loss function that introduces the modulation coefficient, and embeds the serial dual-channel CBAM module in the feature fusion stage to improve the U-net network, taking advantage of the Efficientnet series network, reducing the training parameters of the model and improving the real-time performance of the segmentation model; taking advantage of the serial dual-channel attention mechanism, strengthening the network's attention weight to the paint surface area, improving the accuracy and precision of the network, and solving the problems of inaccurate feature extraction, mis-segmentation, low segmentation accuracy, and poor real-time performance of a single U-net network when performing paint surface segmentation. Experimental results show that the method proposed by the present invention, compared with the traditional U-net network, has a good balance between the requirements of segmentation accuracy and real-time performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a flow chart of the present invention.
[0058] Figure 2 is the image training set after preprocessing.
[0059] Figure 3 This is the structure diagram of the Efficientnet-B0 encoder.
[0060] Figure 4 It is a structural diagram of the serial dual-channel attention mechanism.
[0061] Figure 5 It is the structure diagram of the U-net segmentation model.
[0062] Figure 6 These are the images segmented by different network models. DETAILED DESCRIPTION
[0063] The specific implementation of the present invention is described in detail below in conjunction with the embodiments and drawings.
[0064] Embodiment 1
[0065] This embodiment discloses a paint surface image segmentation system based on a dual attention mechanism and a U-net network. Figure 1 As shown. The paint image segmentation system based on the dual attention mechanism and the U-net network includes: a preprocessing module, which is used to preprocess the collected original paint images to obtain an image training set; a U-net network improvement module, which is used to improve the U-net network by using the Efficientnet-B0 encoder to extract the original paint image features, using the FocalLoss loss function that introduces the modulation coefficient, and embedding the serial dual-channel CBAM module in the feature fusion stage to obtain an improved U-net network; a U-net segmentation model training module, which is used to train the image training set as input data of the improved U-net network to obtain a trained U-net segmentation model; an image segmentation module, which is used to input the paint image to be segmented as test data into the trained U-net segmentation model to obtain the segmented result.
[0066] Furthermore, in the preprocessing module, the specific method of preprocessing is: according to the length and width of the original paint surface image, the original paint surface image and the label image corresponding to the original paint surface image are expanded into a square image; specifically: when the length and width of the original paint surface image are different, the width and length of the original paint surface image are made the same by adding a gray edge, so as to obtain the edge-filled paint surface image and the label image corresponding to it; the edge-filled paint surface image is subjected to Gaussian filtering denoising to obtain the denoised paint surface image, wherein the Gaussian kernel is 1, a Gaussian template matrix of size 3×3; the denoised paint image and the edge-filled label image are used for data enhancement; specifically: the denoised paint image and the edge-filled label image are matched to form a data set N1, the paint image and the label image in N1 are horizontally flipped to obtain a data set N2, and the data sets N3, N4 and N5 are obtained by three rotations with angle values of 90°, 180° and 270° respectively. Finally, the data set composed of N1, N2, N3, N4 and N5 is used as the image training set. The image training set is as follows Figure 2 shown.
[0067] Furthermore, in the U-net network improvement module:
[0068] Figure 3 This is the structure diagram of the Efficientnet-B0 encoder, such as Figure 3 As shown in the figure, the specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is:
[0069] The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks are processed respectively. The feature map extracted by the 5th MBConv block is input into the upsampling part for feature fusion through the spatial attention module, and the feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction; each mobile inverted bottleneck module includes: four 1×1 convolution layers, one 3×3 depth-separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depth-separable convolution structure, and a channel attention mechanism is added after the 3×3 depth-separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer;
[0070] The specific method of improving the U-net network using the FocalLoss loss function that introduces the modulation coefficient is:
[0071] The cross entropy loss function is
[0072]
[0073] Where p represents the probability of y=1, -log(p) is the loss value when y=1;
[0074] make
[0075]
[0076] Then the cross entropy loss function formula is simplified to CE(p,y)=CE(p t )=-log(p t );
[0077] In order to enable the cross entropy loss function to control the weights of easy-to-classify and difficult-to-classify samples, a modulation coefficient (1-p t ) γ ,γ≥0, the FocalLoss loss function is
[0078] Focal Loss = -(1-p t ) γ log(p t )
[0079] Figure 4 It is a serial dual-channel attention mechanism structure diagram, such as Figure 4 As shown in Figure 1, the specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is:
[0080] A spatial attention module is added in the feature fusion link to increase the weight of the improved U-net network on the painted area, while reducing the weight of the non-painted area; a channel attention module is embedded after the output of the convolutional layer in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion, thereby improving the training efficiency and real-time performance of the improved U-net network.
[0081] Furthermore, the feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network; the specific process is as follows:
[0082] Perform 1×1 convolution on the feature map whose feature map size × feature map size × number of channels is 38×38×48, and increase the feature map dimension to 38×38×128; For the feature map whose feature map size × feature map size × number of channels is 19×19×136, first perform 1×1 convolution to reduce the feature map dimension to 19×19×28, and then upsample it to 38×38×128; Concatenate and normalize the above two 38×38×128 feature maps to obtain a fused feature map of 38×38×384, and use the 38×38×384 feature map as the feature fusion feature map of the improved U-net network; Perform 1×1 convolution on the feature map of 19×19×136, increase the feature map dimension to 19×19×384, and use the 19×19×384 feature map as the downsampled feature map of the improved U-net network;
[0083] In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate a feature map Q; the feature map Q is spliced with the output feature map O of the convolution layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is:
[0084]
[0085]
[0086]
[0087] Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function;
[0088] In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. The global feature M is convolved with a one-dimensional convolution of size k to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is:
[0089]
[0090] Where C is the number of channels, |A| odd It represents the odd number closest to A;
[0091] The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The output feature map G has clearer paint semantic information, fewer redundant channels, and a larger receptive field. The calculation of the channel attention module is:
[0092]
[0093]
[0094]
[0095]
[0096] G=r[N+P]
[0097] in, represents the convolution operation, and r represents the ReLu activation function.
[0098] Furthermore, in the U-net segmentation model training module, the specific training process is as follows: use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; use adaptive matrix estimation as the optimizer and FocalLoss as the loss function to set the training parameters of the improved U-net network: the initial learning rate is 0.001, and the exponential decay rate β is calculated for the first-order moment estimation. 1 = 0.9, the exponential decay rate for the second-order moment estimation is β 1 =0.999, the number of training rounds is 100, and the number of training samples in each round is 8; the image training set obtained by preprocessing is rearranged randomly, and then input into the improved U-net network for training until a trained U-net segmentation model is obtained, such as Figure 5 shown.
[0099] Finally, the trained U-net segmentation model is used as a prediction model for paint image segmentation. The output size is 520×520, which is consistent with the label size. Therefore, after 100 rounds of training using FocalLoss as the loss function, the loss value is stable and reaches the minimum, and the tested training model can be segmented.
[0100] Figure 6 are images segmented by different network models, such as Figure 6 As shown in the figure, the improved U-net model effectively solves the problems of mis-segmentation and low segmentation accuracy of the traditional U-net model. The effectiveness and real-time performance of the present invention are verified by the following experiments:
[0101] 1. Experimental conditions
[0102] This experiment was conducted in the environment shown in Table 1.
[0103] Table 1 Experimental environment settings
[0104] project model operating system Windows 10 Development Language Python 3.7 Deep Learning Frameworks Pytorch 1.8 CPU Intel Xeon Sliver 4110@2.10GHz GPU NVIDIA GeForce RTX 2080Ti
[0105] 2. Experimental content
[0106] The same verification data was segmented using the U-net model, Res-Unet model, DeepLabV3, DeepLabV3+ model and the improved U-net model in this paper. The processed paint surface image was input into the trained segmentation model. The image size was 520×520×3. The experimental results are shown in Table 2.
[0107] Table 2 Segmentation accuracy and performance of different models
[0108]
[0109]
[0110] It can be seen from Table 2 that the improved algorithm of the present invention can reach 98% and 90.1% in terms of accuracy, which has obvious advantages over the traditional U-net model and Res-Unet model, and is almost comparable to the most advanced DeepLabV3 and DeepLabV3+ models. In addition, in terms of model performance, especially the segmentation time, the improved algorithm of the present invention is only 0.1039s, which is greatly improved compared with the DeepLabV3 and DeepLabV3+ models.
[0111] Embodiment 2
[0112] This embodiment provides a paint surface image segmentation method based on a dual attention mechanism and a U-net network. Figure 1As shown. The paint image segmentation method based on the dual attention mechanism and the U-net network includes: step 1, preprocessing the collected original paint image to obtain an image training set; step 2, using the Efficientnet-B0 encoder to extract the original paint image features, using the FocalLoss loss function that introduces the modulation coefficient, and embedding the serial dual-channel CBAM module in the feature fusion stage to improve the U-net network to obtain an improved U-net network; step 3, using the image training set as input data of the improved U-net network to train and obtain a trained U-net segmentation model; step 4, inputting the paint image to be segmented as test data into the trained U-net segmentation model to obtain the segmented result.
[0113] Further, in step 1, the specific method of preprocessing is: according to the length and width of the original paint image, the original paint image and the label image corresponding to the image are expanded into a square image; specifically: when the length and width of the original paint image are different, the width and length of the original paint image are made the same by adding a gray edge, thereby obtaining the edge-filled paint image and the corresponding label image; Gaussian filtering and denoising are performed on the edge-filled paint image to obtain a denoised paint image, wherein the Gaussian kernel is a Gaussian template matrix with a standard deviation of 1 and a size of 3×3; data enhancement is performed on the denoised paint image and the edge-filled label image; specifically: the denoised paint image and the edge-filled label image are corresponded to form a data set N1, the paint image and the label image in N1 are horizontally flipped to obtain a data set N2, and the data sets N3, N4 and N5 are obtained by three rotations with angle values of 90°, 180° and 270° respectively, and finally the data set composed of N1, N2, N3, N4 and N5 is used as an image training set. The image training set is as follows: Figure 2 shown.
[0114] Furthermore, in step 2:
[0115] Figure 3 This is the structure diagram of the Efficientnet-B0 encoder, such as Figure 3 As shown in the figure, the specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is:
[0116] The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks are processed respectively. The feature map extracted by the 5th MBConv block is input into the upsampling part for feature fusion through the spatial attention module, and the feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction; each mobile inverted bottleneck module includes: four 1×1 convolution layers, one 3×3 depth-separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depth-separable convolution structure, and a channel attention mechanism is added after the 3×3 depth-separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer;
[0117] The specific method of improving the U-net network using the FocalLoss loss function that introduces the modulation coefficient is:
[0118] The cross entropy loss function is
[0119]
[0120] Where p represents the probability of y=1, -log(p) is the loss value when y=1;
[0121] make
[0122]
[0123] Then the cross entropy loss function formula is simplified to CE(p,y)=CE(p t )=-log(p t );
[0124] In order to enable the cross entropy loss function to control the weights of easy-to-classify and difficult-to-classify samples, a modulation coefficient (1-p t ) γ ,γ≥0, the FocalLoss loss function is
[0125] Focal Loss = -(1-p t ) γ log(p t )
[0126] Figure 4 It is a serial dual-channel attention mechanism structure diagram, such as Figure 4 As shown in Figure 1, the specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is:
[0127] A spatial attention module is added in the feature fusion link to increase the weight of the improved U-net network on the painted area, while reducing the weight of the non-painted area; a channel attention module is embedded after the output of the convolutional layer in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion, thereby improving the training efficiency and real-time performance of the improved U-net network.
[0128] Furthermore, the feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network; the specific process is as follows:
[0129] Perform 1×1 convolution on the feature map whose feature map size × feature map size × number of channels is 38×38×48, and increase the feature map dimension to 38×38×128; For the feature map whose feature map size × feature map size × number of channels is 19×19×136, first perform 1×1 convolution to reduce the feature map dimension to 19×19×28, and then upsample it to 38×38×128; Concatenate and normalize the above two 38×38×128 feature maps to obtain a fused feature map of 38×38×384, and use the 38×38×384 feature map as the feature fusion feature map of the improved U-net network; Perform 1×1 convolution on the feature map of 19×19×136, increase the feature map dimension to 19×19×384, and use the 19×19×384 feature map as the downsampled feature map of the improved U-net network;
[0130] In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate a feature map Q; the feature map Q is spliced with the output feature map O of the convolution layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is:
[0131]
[0132]
[0133]
[0134] Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function;
[0135] In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. The global feature M is convolved with a one-dimensional convolution of size k to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is:
[0136]
[0137] Where C is the number of channels, |A| odd It represents the odd number closest to A;
[0138] The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The output feature map G has clearer paint semantic information, fewer redundant channels, and a larger receptive field. The calculation of the channel attention module is:
[0139]
[0140]
[0141]
[0142]
[0143] G=r[N+P]
[0144] in, represents the convolution operation, and r represents the ReLu activation function.
[0145] Furthermore, in step 3, the specific training process is as follows: use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; use adaptive matrix estimation as the optimizer and FocalLoss as the loss function to set the training parameters of the improved U-net network: the initial learning rate is 0.001, and the exponential decay rate β is calculated for the first-order moment estimation. 1 = 0.9, the exponential decay rate for the second-order moment estimation is β 1=0.999, the number of training rounds is 100, and the number of training samples in each round is 8; the image training set obtained by preprocessing is rearranged randomly, and then input into the improved U-net network for training until a trained U-net segmentation model is obtained, such as Figure 5 shown.
[0146] Finally, the trained U-net segmentation model is used as a prediction model for paint image segmentation. The output size is 520×520, which is consistent with the label size. Therefore, after 100 rounds of training using FocalLoss as the loss function, the loss value is stable and reaches the minimum, and the tested training model can be segmented.
[0147] Figure 6 are images segmented by different network models, such as Figure 6 As shown in the figure, the improved U-net model effectively solves the problems of mis-segmentation and low segmentation accuracy of the traditional U-net model. The effectiveness and real-time performance of the present invention are verified by the following experiments:
[0148] 1. Experimental conditions
[0149] This experiment was conducted in the environment shown in Table 1.
[0150] Table 1 Experimental environment settings
[0151]
[0152]
[0153] 2. Experimental content
[0154] The same verification data was segmented using the U-net model, Res-Unet model, DeepLabV3, DeepLabV3+ model and the improved U-net model in this paper. The processed paint surface image was input into the trained segmentation model. The image size was 520×520×3. The experimental results are shown in Table 2.
[0155] Table 2 Segmentation accuracy and performance of different models
[0156] Model mPA PA Split time / s Training time / h Improved U-net 98.0 90.1 0.1039 1.5 Unet 95.9 87.6 0.0895 1.3 Res-Unet 96.8 87.9 0.1084 1.45 DeepLabV3 97.9 89.5 1.2895 6.3 DeepLabV3+ 98.2 90.8 1.0568 6.5
[0157] It can be seen from Table 2 that the improved algorithm of the present invention can reach 98% and 90.1% in terms of accuracy, which has obvious advantages over the traditional U-net model and Res-Unet model, and is almost comparable to the most advanced DeepLabV3 and DeepLabV3+ models. In addition, in terms of model performance, especially the segmentation time, the improved algorithm of the present invention is only 0.1039s, which is greatly improved compared with the DeepLabV3 and DeepLabV3+ models.
[0158] There are many methods and approaches to implement the technical solution of the present invention, and the above are only preferred embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be regarded as the protection scope of the present invention. All components not specified in this embodiment can be implemented by existing technologies.
Claims
1. A paint image segmentation system based on dual attention mechanism and U-net network, characterized in that: include: A preprocessing module is used to preprocess the collected original paint surface images to obtain an image training set; The U-net network improvement module is used to improve the U-net network by extracting the original paint surface image features using the Efficientnet-B0 encoder, using the FocalLoss loss function that introduces the modulation coefficient, and embedding the serial dual-channel CBAM module in the feature fusion stage to obtain an improved U-net network; in the U-net network improvement module: The specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is: The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks respectively. The feature map extracted by the 5th MBConv block passes through the spatial attention module and is input to the upsampling part for feature fusion. The feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction. Each mobile inverted bottleneck module includes: four 1×1 convolutional layers, one 3×3 depthwise separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depthwise separable convolution structure, and a channel attention mechanism is added after the 3×3 depthwise separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer. The specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is: A spatial attention module is added to the feature fusion stage to increase the weight of the improved U-net network on the painted area and reduce the weight of the non-painted area; A channel attention module is embedded after the output of the convolutional layer in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion; A U-net segmentation model training module is used to train the image training set as input data of the improved U-net network to obtain a trained U-net segmentation model; The image segmentation module is used to input the paint surface image to be segmented as test data into the trained U-net segmentation model to obtain the segmented result.
2. The paint surface image segmentation system based on dual attention mechanism and U-net network according to claim 1, characterized in that: In the preprocessing module, the specific method of the preprocessing is: According to the length and width of the original paint surface image, the original paint surface image and the label image corresponding to the original paint surface image are expanded into square images; specifically: when the length and width of the original paint surface image are different, the width and length of the original paint surface image are made the same by adding a gray edge, so as to obtain the paint surface image with edge filling and the label image corresponding to the original paint surface image; Performing Gaussian filtering and noise reduction processing on the edge-filled paint surface image to obtain a noise-reduced paint surface image; Performing data enhancement on the denoised paint surface image and the edge-filled label image; Specifically: the denoised paint image and the edge-filled label image are matched to form a data set N1, the paint image and label image in N1 are horizontally flipped to obtain a data set N2, and three rotations with angle values of 90°, 180° and 270° are performed to obtain data sets N3, N4 and N5. Finally, the data set composed of N1, N2, N3, N4 and N5 is used as the image training set.
3. The paint surface image segmentation system based on dual attention mechanism and U-net network according to claim 2, characterized in that: The feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network; In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate the feature map Q; The feature map Q is concatenated with the output feature map O of the convolutional layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is: Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function; In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. Use a one-dimensional convolution of size k to convolve the global feature M to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is Where C is the number of channels, |A odd It represents the odd number closest to A; The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The calculation of the channel attention module is: G=r[N+P] in, represents the convolution operation, and r represents the ReLu activation function.
4. The paint surface image segmentation system based on dual attention mechanism and U-net network according to claim 3, characterized in that: In the U-net segmentation model training module, the specific training process is as follows: Use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; Using adaptive matrix estimation as the optimizer and FocalLoss as the loss function, the training parameters of the improved U-net network are set: the initial learning rate is 0.001, the exponential decay rate β1=0.9 when calculating the first-order moment estimation, the exponential decay rate β1=0.999 when calculating the second-order moment estimation, the number of training rounds is 100, and the number of training samples in each round is 8; The image training set obtained by preprocessing is rearranged randomly and then input into the improved U-net network for training until a trained U-net segmentation model is obtained.
5. A paint image segmentation method based on a dual attention mechanism and a U-net network, comprising: Step 1, preprocessing the collected original paint surface images to obtain an image training set; Step 2, the U-net network is improved by using the Efficientnet-B0 encoder to extract the original paint surface image features, using the FocalLoss loss function that introduces the modulation coefficient, and embedding the serial dual-channel CBAM module in the feature fusion stage to obtain an improved U-net network; in step 2: The specific method of using the Efficientnet-B0 encoder to extract the original paint image features to improve the U-net network is: The EfficientNet-B0 encoder contains 16 mobile inverted bottleneck modules, which extract the feature maps after the 5th and 7th MBConv blocks respectively. The feature map extracted by the 5th MBConv block passes through the spatial attention module and is input to the upsampling part for feature fusion. The feature map extracted by the 7th MBConv block is used for downsampling for deeper feature extraction. Each mobile inverted bottleneck module includes: four 1×1 convolutional layers, one 3×3 depthwise separable convolution and one feature fusion operation. 1×1 convolution is used to increase the dimension before the 3×3 depthwise separable convolution structure, and a channel attention mechanism is added after the 3×3 depthwise separable convolution structure. Finally, a residual edge is added after the 1×1 convolution is used to reduce the dimension. Batch normalization layer and Swish activation layer are added after each convolution layer. The specific method of embedding the serial dual-channel CBAM module to improve the U-net network in the feature fusion stage is: A spatial attention module is added to the feature fusion stage to increase the weight of the improved U-net network on the painted area and reduce the weight of the non-painted area; A channel attention module is embedded after the convolutional layer output in the feature enhancement part of the original U-net network to reduce the number of redundant channels after feature fusion; Step 3, using the image training set as input data of the improved U-net network to train and obtain a trained U-net segmentation model; Step 4: Input the paint surface image to be segmented as test data into the trained U-net segmentation model to obtain the segmented result.
6. The paint surface image segmentation method based on dual attention mechanism and U-net network according to claim 5, characterized in that: In step 1, the specific method of the pretreatment is: According to the length and width of the original paint surface image, the original paint surface image and the label image corresponding to the image are expanded into a square image; specifically: when the length and width of the original paint surface image are different, the width and length of the original paint surface image are made the same by adding a gray edge, so as to obtain the paint surface image with edge filling and the label image corresponding to the image; Performing Gaussian filtering and noise reduction processing on the edge-filled paint surface image to obtain a noise-reduced paint surface image; Performing data enhancement on the denoised paint surface image and the edge-filled label image; Specifically: the denoised paint image and the edge-filled label image are matched to form a data set N1, the paint image and label image in N1 are horizontally flipped to obtain a data set N2, and three rotations with angle values of 90°, 180° and 270° are performed to obtain data sets N3, N4 and N5. Finally, the data set composed of N1, N2, N3, N4 and N5 is used as the image training set.
7. The paint surface image segmentation method based on dual attention mechanism and U-net network according to claim 6, characterized in that: The feature map extracted by the 5th MBConv block is used as the feature fusion feature map of the improved U-net network, and the feature map extracted by the 7th MBConv block is used as the down-sampling feature map of the improved U-net network; In the spatial attention module, the feature map F extracted from the 5th MBConv block of the EfficientNet-B0 encoder is subjected to average pooling and maximum pooling operations in the channel dimension to generate two single-channel feature maps: average feature map And the maximum feature map The mean feature map And the maximum feature map After a convolution operation, the channels are stacked to generate a weight map R, and then the feature map F is weighted by the weight map R to generate the feature map Q; The feature map Q is concatenated with the output feature map O of the convolutional layer in the feature enhancement part of the improved U-net to obtain the feature map P after preliminary feature fusion. In the feature map P, the area related to the paint surface is given a higher weight, and the weight of the remaining areas is reduced. The calculation of the spatial attention module is: Among them, M s (F) is the output feature map information of the spatial attention module. represents the convolution operation, and r represents the ReLu activation function; In the channel attention module, the feature map P is averaged and max-pooled once, and then channel concatenation is performed to generate a 1×1×C global feature M, where C represents the number of channels. Use a one-dimensional convolution of size k to convolve the global feature M to generate an attention weight map N. The calculation formula for the convolution kernel size k of the one-dimensional convolution is Where C is the number of channels, |A odd It represents the odd number closest to A; The attention weight map N is multiplied by the feature map P channel by channel to obtain the output feature map G with weighted attention. The calculation of the channel attention module is: G=r[N+P] in, represents the convolution operation, and r represents the ReLu activation function.
8. The paint surface image segmentation method based on dual attention mechanism and U-net network according to claim 7, characterized in that: In step 3, the specific training process is as follows: Use the trained weight file in the Efficientnet-B0 network to initialize the parameters of the Efficientnet-B0 network; Using adaptive matrix estimation as the optimizer and FocalLoss as the loss function, the training parameters of the improved U-net network are set: the initial learning rate is 0.001, the exponential decay rate β1=0.9 when calculating the first-order moment estimation, the exponential decay rate β1=0.999 when calculating the second-order moment estimation, the number of training rounds is 100, and the number of training samples in each round is 8; The image training set obtained by preprocessing is rearranged randomly and then input into the improved U-net network for training until a trained U-net segmentation model is obtained.
Citation Information
Cited By
Methods for deep artificial neural networks for signal error correction
US20230360733A1
