Image segmentation method and device, electronic equipment and storage medium

By dividing the image into multiple training blocks and introducing the local self-attention and downsampling modules of edge detection operators in the model, the problem of uneven information distribution in image segmentation is solved, the segmentation accuracy and performance are improved, and the Resource consumption.

CN118691818APending Publication Date: 2024-09-24CHINA TELECOM CORP LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410841278.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

When existing image segmentation technology processes images with uneven information distribution, it is easy to ignore small targets and edge information, leading to the loss of key information. Moreover, the application of high-resolution algorithms and attention mechanisms increases computing resources and model complexity, limiting the Image segmentation effect.

Method used

An image segmentation method is proposed. By dividing the original image into multiple training image blocks, a training image data set is constructed, and a local self-attention module and a downsampling module based on edge detection operators are introduced into the image segmentation prediction model, using Gradient intensity probability is used for feature analysis and data volume reduction to achieve efficient analysis and accurate segmentation of image features.

Benefits of technology

It improves the accuracy of image segmentation, reduces model complexity and computing resource consumption, significantly improves the retention of small targets and edge information, and improves image segmentation performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118691818A
    Figure CN118691818A
Patent Text Reader

Abstract

The invention discloses an image segmentation method and apparatus, an electronic device and a storage medium. The method comprises the steps of obtaining an original image; processing the original image to obtain a training image data set; inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; a target local self-attention module of the original image segmentation prediction model is constructed based on a first gradient intensity probability calculated by an edge detection operator, and a target down-sampling module of the original image segmentation prediction model is constructed based on a second gradient intensity probability calculated by the edge detection operator; inputting a prediction image block of a to-be-predicted image into the target image segmentation prediction model for prediction, and outputting an image segmentation prediction result; and segmenting the to-be-predicted image according to the image segmentation prediction result to obtain a target segmented image. The image segmentation accuracy can be improved, the model complexity can be reduced, the consumption of computing resources can be reduced, and the method can be widely applied to the technical field of image processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image segmentation method, device, electronic device and storage medium. Background Art

[0002] In related technologies, there are many challenges when using image segmentation technology to process images with uneven information distribution. Traditional methods often ignore small targets and edge information due to the average distribution of computing resources, resulting in the loss of key information. Although high-resolution algorithms and methods that introduce attention mechanisms can improve segmentation effects, they also increase the consumption of computing memory and resources, and increase the complexity of the model. Although some emerging models can be optimized for segmented areas, they still show obvious limitations when dealing with complex boundaries, which limits the image segmentation effect.

[0003] In summary, the technical problems existing in the relevant technologies need to be improved. Summary of the invention

[0004] The embodiments of the present application aim to solve at least one of the technical problems in the related art to a certain extent. To this end, the main purpose of the embodiments of the present application is to propose an image segmentation method, device, electronic device and storage medium, which can improve the accuracy of image segmentation, reduce model complexity and reduce the consumption of computing resources.

[0005] To achieve the above object, an embodiment of the present application provides an image segmentation method, which comprises the following steps:

[0006] Get the original image;

[0007] Segmenting the original image to obtain a number of training image blocks, and constructing a training image data set based on the training image blocks;

[0008] Input the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator;

[0009] Inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting the image segmentation prediction result;

[0010] The image to be predicted is segmented according to the image segmentation prediction result to obtain a target segmented image.

[0011] In some embodiments, the step of inputting the training image dataset into an original image segmentation prediction model for training to obtain a target image segmentation prediction model includes:

[0012] Acquire the training image dataset as a current training image dataset, and construct a label image dataset corresponding to the current training image dataset as a current label image dataset;

[0013] Input any training image block in the current training image data set into the original image segmentation prediction model to obtain a first segmentation prediction result, and use the first segmentation prediction result as the current segmentation prediction result, and use the original image segmentation prediction model as the current image segmentation prediction model;

[0014] Calculate the loss difference between the current segmentation prediction result and the current label image data set based on the target loss function to obtain a first loss difference result, and use the first loss difference result as the current loss difference result;

[0015] If the difference loss value in the current loss difference result is greater than the target difference threshold, returning to execute the step of acquiring the training image dataset as the current training image dataset, and constructing a label image dataset corresponding to the current training image dataset as the current label image dataset, until the difference loss value in the current loss difference result is less than or equal to the target difference threshold;

[0016] When the difference loss value in the current loss difference result is less than or equal to the target difference threshold, the current image segmentation prediction model corresponding to the current loss difference result is used as the target image segmentation prediction model.

[0017] In some embodiments, the step of inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction and outputting the image segmentation prediction result comprises:

[0018] Acquire the image to be predicted;

[0019] Segmenting the image to be predicted to obtain a plurality of predicted image blocks;

[0020] Constructing a prediction image data set according to the plurality of prediction image blocks;

[0021] The predicted image data set is input into the target image segmentation prediction model for prediction, and the image segmentation prediction result is output.

[0022] In some embodiments, the step of inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction and outputting the image segmentation prediction result comprises:

[0023] Inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model, and performing a first feature extraction process on any of the predicted image blocks through a first feature processing module of the target image segmentation prediction model to obtain a first feature map;

[0024] Inputting the first feature map into a feature focusing module of the target image segmentation prediction model, and performing feature focusing processing on the first feature map by the feature focusing module to obtain a second feature map;

[0025] The second feature map is input into the second feature processing module of the target image segmentation prediction model, and the second feature processing module performs second feature extraction processing on the second feature map to obtain a third feature map, and the third feature map is used as the image segmentation prediction result.

[0026] In some embodiments, the first feature processing module includes a first convolution module and a first target downsampling module, and the plurality of predicted image blocks corresponding to the image to be predicted are input into the target image segmentation prediction model, and the first feature extraction processing is performed on any of the predicted image blocks by the first feature processing module of the target image segmentation prediction model to obtain a first feature map, including:

[0027] Inputting the plurality of predicted image blocks corresponding to the image to be predicted into the first feature processing module of the target image segmentation prediction model;

[0028] Performing a first convolution process on any of the predicted image blocks through the first convolution module in the first feature processing module to obtain a first convolution feature map;

[0029] The first convolution feature map is input into the first target downsampling module, and the first target downsampling module performs a first downsampling process on the first convolution feature map to obtain the second feature map.

[0030] In some embodiments, the feature focusing module includes a target local self-attention module and a second target downsampling module, and the feature focusing module inputs the first feature map into the target image segmentation prediction model, performs feature focusing processing on the first feature map through the feature focusing module to obtain a second feature map, including:

[0031] Inputting the first feature map into a feature focusing module of the target image segmentation prediction model;

[0032] Calculating a first gradient intensity probability of the first feature map by using an edge detection operator through the feature focusing module, and constructing a first gradient intensity probability distribution map according to the first gradient intensity probability;

[0033] Introducing the first gradient intensity probability distribution map as first prior knowledge into the target local self-attention module, so that the target local self-attention module calculates the first feature map using a self-attention formula to obtain a candidate feature map containing target edge information;

[0034] Calculating a second gradient intensity probability of the candidate feature map by using the edge detection operator through the feature focusing module, and constructing a second gradient intensity probability distribution map according to the second gradient intensity probability;

[0035] The second gradient intensity probability distribution map is introduced into the second target downsampling module as second prior knowledge, so that the second target downsampling module downsamples the candidate feature map using a downsampling formula to obtain the second feature map.

[0036] In some embodiments, the second feature processing module includes a second convolution module and an upsampling module, the second feature map is input to the second feature processing module of the target image segmentation prediction model, the second feature processing module performs a second feature extraction process on the second feature map to obtain a third feature map, and the third feature map is used as the image segmentation prediction result, including:

[0037] Inputting the second feature map into a second feature processing module of the target image segmentation prediction model;

[0038] Performing a second convolution process on the second feature map by the second convolution module in the second feature processing module to obtain a second convolution feature map;

[0039] The second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module to obtain the third feature map, and the third feature map is used as the image segmentation prediction result.

[0040] To achieve the above objective, another aspect of the present application provides an image segmentation device, the device comprising the following modules:

[0041] An original image acquisition module, used for acquiring the original image;

[0042] A training data set acquisition module is used to segment the original image to obtain a plurality of training image blocks, and construct a training image data set based on the plurality of training image blocks;

[0043] A model training module, used for inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator;

[0044] A model prediction module, used for inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting an image segmentation prediction result;

[0045] The image segmentation module is used to perform segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image.

[0046] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above-mentioned method when executing the computer program.

[0047] To achieve the above objective, another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described above is implemented.

[0048] The embodiments of the present application include at least the following beneficial effects: The present application provides an image segmentation method, device, electronic device and storage medium, which obtains an original image; performs segmentation processing on the original image to obtain a number of training image blocks, and constructs a training image data set based on the number of training image blocks; inputs the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator; inputs a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputs an image segmentation prediction result; performs segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image. The embodiment of the present application can divide the original image into multiple training image blocks, so that the original image can be divided into smaller image blocks that are easier to process and analyze, and the local features in the original image can be extracted more effectively, which can reduce the computational complexity and improve the efficiency of the training model. The embodiment of the present application integrates the gradient intensity probability distribution of the image into the local self-attention module, so as to realize efficient analysis and precise segmentation of image features. The downsampling module introduces a guidance mechanism based on the gradient intensity probability, which can effectively retain the edge information of the target object while reducing the amount of feature map data and reducing the computing requirements. The local self-attention module and the downsampling module respectively introduce the gradient intensity probability calculated based on the edge detection operator, so that the segmentation performance of the model can be improved while the consumption of computing resources and memory can be significantly reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 is a flowchart of the steps of an image segmentation method provided in an embodiment of the present application;

[0050] Figure 2 yes Figure 1 Flow chart of step S103 in FIG.

[0051] Figure 3 yes Figure 1 Flow chart of step S104 in FIG.

[0052] Figure 4 yes Figure 3 Flow chart of step S301 in FIG.

[0053] Figure 5 yes Figure 3 Flow chart of step S302 in FIG.

[0054] Figure 6 yes Figure 3 Flow chart of step S303 in FIG.

[0055] Figure 7 It is a schematic diagram of an image segmentation model training structure provided in an embodiment of the present application;

[0056] Figure 8 It is a schematic diagram of an image segmentation reasoning architecture provided in an embodiment of the present application;

[0057] Fig. 9 Schematic diagram of a local self-attention module based on edge detection provided in an embodiment of the present application;

[0058] Fig.10 is a structural schematic diagram of an image segmentation device provided in an embodiment of the present application;

[0059] Fig.11 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are only examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the attached claims.

[0061] It is understood that the terms "first", "second", etc. used in this application can be used to describe various concepts in this article, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another concept. For example, without departing from the scope of the embodiment of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determination".

[0062] The terms "at least one", "multiple", "each", "any", etc. used in this application, at least one includes one, two or more, multiple includes two or more, each refers to each of the corresponding multiple, and any refers to any one of the multiple.

[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0064] As an example, the distribution of image content information in the real world is often uneven. For example, in outdoor street scene images, the road surface occupies most of the image content, while small target objects such as pedestrians and lamp poles, although they account for a small proportion, are key information elements in the image segmentation process. However, when processing such images, traditional neural network segmentation methods often ignore the importance of small target objects and edge information due to the average distribution of computing resources, resulting in the loss of important information during the downsampling process. Although some algorithms enhance the segmentation effect by increasing the resolution of the input image, this undoubtedly increases the consumption of computing memory and resources. Although some network models can automatically pay attention to the image segmentation area, the global attention mechanism they rely on is still affected by quadratic complexity when processing high-resolution images, and it is difficult to cope with large-scale data. Although the subsequent clustering-based sparse attention model attempted to reduce the amount of calculation, it did not significantly improve the segmentation effect, but instead increased the complexity of the model. To address these issues, a model in the related technology proposes a method based on local attention adaptive downsampling. This method reduces computational complexity by utilizing local attention and combines it with a clustering downsampling strategy so that computing resources can be dynamically allocated according to the importance of different targets in the image. However, this method still faces challenges when processing natural images, especially when segmenting small target objects and irregular target object boundaries. Its attention is often concentrated in the center of the target and gradually weakens from the center to the edge, resulting in poor segmentation of edges and small target objects.

[0065] In view of this, an image segmentation method, device, electronic device and storage medium are provided in an embodiment of the present application. The scheme obtains an original image; segments the original image to obtain a number of training image blocks, and constructs a training image data set based on the number of training image blocks; inputs the training image data set into an original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein a target local self-attention module of the original image segmentation prediction model is constructed based on a first gradient intensity probability calculated by an edge detection operator, and a target downsampling module of the original image segmentation prediction model is constructed based on a second gradient intensity probability calculated by an edge detection operator; inputs a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputs an image segmentation prediction result; segments the image to be predicted according to the image segmentation prediction result to obtain a target segmented image. The embodiment of the present application can divide the original image into multiple training image blocks, so that the original image can be divided into smaller image blocks that are easier to process and analyze, and the local features in the original image can be extracted more effectively, which can reduce the computational complexity and improve the efficiency of the training model. The embodiment of the present application integrates the gradient intensity probability distribution of the image into the local self-attention module, so as to realize efficient analysis and precise segmentation of image features. The downsampling module introduces a guidance mechanism based on the gradient intensity probability, which can effectively retain the edge information of the target object while reducing the amount of feature map data and reducing the computing requirements. The local self-attention module and the downsampling module respectively introduce the gradient intensity probability calculated based on the edge detection operator, so that the segmentation performance of the model can be improved while the consumption of computing resources and memory can be significantly reduced.

[0066] The image segmentation method provided in the embodiment of the present application relates to the field of image processing technology. The image segmentation method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server, and can also be software running in a terminal or a server. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, and a car terminal, etc., but is not limited to this; the server side can be configured as an independent physical server, or it can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured to provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network, content distribution network) and big data and artificial intelligence platforms and other basic cloud computing services. The cloud server, the server can also be a node server in the blockchain network; the software can be an application that implements the image segmentation method, etc., but is not limited to the above forms.

[0067] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs (personal computers), minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0068] See also Figure 1 , Figure 1 is an optional step flow chart of an image segmentation method provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S105.

[0069] Step S101, obtaining an original image;

[0070] Among them, the original image is the data basis for subsequent model segmentation training. The original image is the initial image data captured directly from the image source (such as camera, scanner, network, etc.) without any processing or modification. The original image may contain various types of information, including but not limited to: color, brightness, texture, shape, etc., which is of great significance for subsequent image processing and analysis.

[0071] In step S101 shown in the embodiment of the present application, the original image is obtained to provide a data basis for subsequent image segmentation.

[0072] Step S102, segmenting the original image to obtain a number of training image blocks, and constructing a training image data set based on the training image blocks;

[0073] The training image block refers to a small image area cut or divided from the original image before model training for model training. The image block divided from the image can also be called a patch block, that is, a patch block can be randomly selected from the original image as the model input image. It should be noted that the size and number of the training image blocks can be determined according to the specific image segmentation task and model requirements, and the embodiments of the present application do not limit this.

[0074] The training image data set is a data set composed of several training image blocks.

[0075] When a patch is randomly selected on the original image, the corresponding patch also needs to be selected on the image label as the training label. The training label represents the correct output of each patch. During the model training process, the model will try to learn how to map the input patch to these training labels. During the model training process, prediction results will be generated. These prediction results need to be compared with the actual training labels to evaluate the performance of the model.

[0076] Step S102 shown in the embodiment of the present application can divide the original image into smaller image blocks that are easier to process and analyze by segmenting the original image into multiple training image blocks, thereby more effectively extracting local features in the original image, reducing computational complexity and improving the efficiency of the training model. The constructed training image data set provides rich samples for subsequent model training.

[0077] Step S103, inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator;

[0078] Among them, the original image segmentation prediction model is a model that has not been trained and optimized. It is an initial model for image segmentation tasks. The model has certain basic structures and functions before training, but its parameters and performance need to be optimized through training data sets.

[0079] Among them, the architecture of the original image segmentation prediction model includes an image input module, a first feature processing module, a feature focusing module, a second feature processing module and a prediction map output module. Specifically, first, a patch block randomly selected from the original image is used as a model input image and input into the original image segmentation prediction model through the image input module. Secondly, the first feature processing module includes a first convolution module and a first target downsampling module, wherein, when the model input image reaches the first feature processing module, the first feature processing module is used to perform two convolution operations and downsampling processes on the model input image, that is, a convolution operation and a downsampling process are performed first, and then a convolution operation and a downsampling process are performed on the feature map obtained after the first processing, wherein the convolution operation is a 3×3 convolution, and the RELU() function is introduced when performing the 3×3 convolution operation, aiming to perform a 3×3 convolution while also having nonlinearity. Transformation operation increases the nonlinear ability of the model, accelerates model training, improves model sparsity and reduces model parameters. In addition, a convolution feature map is generated in each of the two convolution operations. In the two downsampling processes of the first feature processing module, the edge detection operator is first used to calculate the gradient intensity probability of the convolution feature map obtained each time, and then a gradient intensity probability distribution map is constructed according to the gradient intensity probability. Finally, the gradient intensity probability distribution map is introduced into the first target downsampling module as prior knowledge, so that the first target downsampling module uses the downsampling formula to downsample the convolution feature map. Furthermore, after the first feature processing module is completed, it reaches the feature focusing module, which includes a target local self-attention module and a second target downsampling module. The feature focusing module uses an edge detection operator to calculate the first gradient intensity probability of the feature map obtained after processing by the first feature processing module, and constructs a first gradient intensity probability distribution map based on the first gradient intensity probability. The first gradient intensity probability distribution map is introduced into the target local self-attention module as the first prior knowledge, so that the target local self-attention module uses the self-attention formula to calculate the feature map obtained after processing by the first feature processing module to obtain a candidate feature map containing target edge information. Then, the feature focusing module uses the edge detection operator to calculate the second gradient intensity probability of the candidate feature map processed by the target local self-attention module, and constructs a second gradient intensity probability distribution map based on the second gradient intensity probability. The second gradient intensity probability distribution map is introduced into the second target downsampling module as the second prior knowledge, so that the second target downsampling module uses the downsampling formula to downsample the candidate feature map, wherein the operation performed by the feature focusing module needs to be repeated three times.Furthermore, the second feature processing module includes a second convolution module and an upsampling module. When the feature focusing module completes processing and reaches the second feature processing module, the second convolution module in the second feature processing module performs a second convolution processing on the feature map obtained by the feature focusing module (the convolution processing of this step is the same as the processing method of the first convolution module) to obtain a second convolution feature map, and then the second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module, and the feature map after the upsampling processing is used as the image segmentation prediction result, and the image segmentation prediction result is output by the prediction map output module.

[0080] Among them, the edge detection operator is an algorithm or operator used for edge detection in image processing. Edge detection is an important step in image processing, which aims to identify the edges in the image, that is, the places where the grayscale or color in the image changes dramatically. These edges usually correspond to the boundaries of objects, scenes or image regions.

[0081] Among them, the target image segmentation prediction model is an optimized model obtained by inputting the training image dataset into the original image segmentation prediction model for training. The training process aims to enable the model to more accurately identify and segment targets in the image by adjusting the parameters and weights of the model. Since the target local self-attention module and the target downsampling module in the original model are both constructed based on the gradient intensity probability calculated by the edge detection operator, the trained target image segmentation prediction model can better focus on small targets and edge information when processing images with uneven information distribution, thereby improving the accuracy and robustness of segmentation.

[0082] In the specific implementation, the algorithm steps of the local self-attention module based on the edge detection operator are as follows:

[0083] First, a square grid is defined on the local area of ​​the 2D (Two Dimensions) grid (feature map). For each point P on the grid ij , calculate the point P ij Centered on P i-1j , P i+1j , P ij-1 , P ij+1 , P i-1j-1 , P i+1j+1 , P i+1j-1 , P i-1j+1 For the gradients in these eight directions, the embodiment of the present application calculates the gradients by using the convolution kernel of the Sobel operator, and the convolution kernel of the Sobel operator is:

[0084]

[0085] Among them, P ijIt is represented as a pixel point on the feature map, i is represented as the horizontal coordinate of the feature map, j is represented as the horizontal coordinate of the feature map, G i It is represented by convolution with the pixels on the grid along the i-axis direction to obtain the approximate horizontal brightness difference, G j It is represented by convolution with the pixels on the grid along the j-axis to obtain an approximate vertical brightness difference.

[0086] In order to reduce the amount of calculation, the present embodiment uses the L1 norm to calculate P ij The gradient of P is calculated using the L1 norm ij The calculation formula of the gradient is:

[0087] |P ij |=|G i *P ij |+|G j *P ij |

[0088] For all the marked points P in the grid, according to |P ij |Sort the marker points P in ascending order, get the maximum value in the sequence, take the maximum value as the baseline, and calculate the probability distribution map of the gradient strength of all marker points P in the grid. The calculation formula of the probability distribution map of the gradient strength is:

[0089]

[0090] Among them, r(P ij ) is expressed as a probability distribution diagram of the gradient strength, P ij It is represented as a pixel point on the feature map, i is represented as the horizontal coordinate of the feature map, and j is represented as the horizontal coordinate of the feature map.

[0091] For each grid area, local attention needs to be calculated. Let the input image of the grid area be X, that is, the feature map of the feature focus module of the input model is called X. X is linearly transformed using two 1×1 convolutions to reduce the number of channels of the input image X, thereby reducing the amount of calculation, and Q and K are obtained. Q is the query vector and K is the key vector. In Transformer (a neural network model based on the self-attention mechanism), Q and K are multiplied to generate a similarity matrix. Based on Q, a linear transformation can generate a feature map Q. Based on K, a linear transformation can generate a feature map K. Both Q and K are used for the subsequent attention calculation. The calculation expressions of Q and K are:

[0092] Q = conv1(conv1(X))

[0093] K = conv1(conv1(X))

[0094] In order to make the network automatically focus on the region of interest based on the gradient information, for the gradient intensity probability distribution map r(P ij ) Use 1×1 convolution to perform a linear transformation to obtain V (value vector). The calculation expression of V is:

[0095] V = conv1(r(P ij ))

[0096] According to the self-attention formula, the input image X can be calculated to get the output image A. The calculation formula of self-attention is:

[0097] A=softmax(QK T +V)

[0098] =softmax(conv1(conv1(X))×conv1(conv1(X)) T +conv1(r(P ij )))

[0099] Where T represents the matrix transpose operation, X∈R H×W×C , C>C1, where H represents the height of the feature map, W represents the width of the feature map, and C represents the number of channels of the feature map.

[0100] After the above calculation process, a local self-attention module based on edge operator can be obtained.

[0101] In the image segmentation prediction model, the features of the feature focusing module for the input model Figure X The embodiment of the present application uses a 9×9 grid slider to obtain the gradient strength probability distribution map R of the grid, and uses the feature map and the gradient strength probability distribution map R as the input of the local attention module after two linear transformations, namely Q and K. Compared with the general attention module input, the image segmentation prediction model of the embodiment of the present application introduces the gradient strength of the feature map as prior knowledge into the attention model, and introduces attention to the obvious points of pixel transformation in the feature map while capturing the internal correlation of the data or features. Most of the parts of the image where the pixel information has obvious transformations are the edges of the target objects, which can enable the image segmentation prediction model to actively pay attention to the edges of the target objects instead of aimlessly performing self-learning.

[0102] Specifically, the image segmentation prediction model of the embodiment of the present application is directly designed to embed gradient information into the attention model, which is used as the V value to guide the local attention model to focus on the edge area, making full use of the edge information, which is more conducive to the segmentation of small target objects and general target objects; at the same time, the image segmentation prediction model of the embodiment of the present application does not directly perform matrix multiplication on the entire feature map, but selects a 9×9 grid each time for local attention transformation, which reduces the pressure on computing resources, makes full use of edge information and reduces the consumption of computing resources.

[0103] In practical applications, it can be seen from natural images that the boundary between the large background image and the target object image is very obvious, so this part of information can be fully utilized to retain the image boundary information during the network downsampling process, remove large blocks of background information, and adaptively retain the key point information of the target object. In order to better prevent the loss of image information during the downsampling process, the embodiment of the present application proposes an adaptive downsampling method using gradient information, which is specifically designed as follows:

[0104] According to the above method of calculating the probability distribution map of the gradient strength based on the edge detection operator, the probability distribution map r1(0) of the gradient strength of the input feature map M is calculated. ij ), wherein the input feature map M may be a feature map obtained by convolution operation in the first feature processing module of the image segmentation prediction model, or may be an output image A obtained by calculating the input image X by the self-attention formula in the above-mentioned feature focusing module. Both the feature map obtained by convolution operation in the first feature processing module and the output image A calculated by the self-attention formula in the feature focusing module need to be downsampled, and thus both can be used as the feature map M. Downsampling is performed on the input feature map M using 2×2 sliders, the sliders do not overlap, and the feature map is not filled, wherein the downsampling calculation formula is:

[0105] pooling(O ij )=Max{P ij × i (P ij ),P i+1j ×r1(P i+1j ),P ij+1 ×r1(P ij+1 ),P i+1j+1 ×r1(P i+1j+1 )}

[0106] Among them, r1(P ij ) is represented as the probability distribution diagram of the gradient strength of the feature map M, P ij Represented as a pixel point on the feature map M, i represents the horizontal coordinate of the feature map M, j represents the horizontal coordinate of the feature map M, M∈R H×W×C, 1 <i<H-1,1<j<W-1。

[0107] In the image segmentation prediction model, for the feature map output in the previous stage (the feature map obtained by the convolution operation in the first feature processing module and the output image A calculated by the self-attention formula in the feature focusing module), it is necessary to calculate its gradient probability distribution map R, use a 2×2 slider for downsampling, and in the grid slider, combine the gradient probability with the slider pixel point to take the maximum value; by combining the maximum value downsampling with the gradient probability distribution map, the edge information of the target object in the feature map can be retained, and for the part of the object where the internal feature information is consistent and accounts for a large proportion, only 25% of the information is retained. This not only effectively eliminates redundant and repeated feature information, but also greatly improves the importance and utilization of feature map information.

[0108] The image segmentation prediction model of the embodiment of the present application proposes to use the gradient probability distribution map of the feature map as prior information to guide the model to actively retain the edge information of small target objects or general target objects during the downsampling process. For the part with consistent internal feature information and a large proportion of the object, 1 / 4 of the data information is selected each time for retention. When the network depth gradually deepens, the pixel information about the edge areas of small target objects and general target objects in the high-level feature map can be retained, and the redundant data information of the feature map can also be reduced, reducing the calculation pressure.

[0109] It can be understood that the first gradient strength probability mentioned in the above content is the probability calculated by the local self-attention module based on the edge detection operator, and the second gradient strength probability is the probability calculated by the downsampling module based on the edge detection operator. The calculation methods of the two are the same, but the input variables and output contents are different.

[0110] In some embodiments, see Figure 2 , Figure 2 yes Figure 1 The flowchart of step S103 in FIG. Figure 2 As shown, the method in step S103 may include but is not limited to steps S201 to S205:

[0111] Step S201, acquiring the training image dataset as a current training image dataset, and constructing a label image dataset corresponding to the current training image dataset as a current label image dataset;

[0112] For labeled image datasets, when a patch is randomly selected on the original image, the corresponding patch also needs to be selected on the image label as the training label. The training label represents the correct output of each patch. During the model training process, the model will try to learn how to map the input patch to these training labels. During the model training process, prediction results will be generated. These prediction results need to be compared with the actual training labels in order to evaluate the performance of the model.

[0113] Step S202, inputting any training image block in the current training image data set into the original image segmentation prediction model to obtain a first segmentation prediction result, and using the first segmentation prediction result as the current segmentation prediction result, and using the original image segmentation prediction model as the current image segmentation prediction model;

[0114] Step S203, calculating the loss difference between the current segmentation prediction result and the current label image data set based on the target loss function, obtaining a first loss difference result, and using the first loss difference result as the current loss difference result;

[0115] In order to solve the problem of unbalanced distribution of target objects in natural images, the embodiment of the present application selects Focal Loss as the loss function. The Focal Loss loss function is an improved loss function based on the cross entropy loss. It introduces a term that dynamically adjusts the weights of difficult and easy samples to solve the problem of imbalance between positive and negative samples during training, especially reducing the weights of easy-to-classify samples, so that the model pays more attention to difficult-to-classify samples during training. The loss function plays a vital role in the model training process. It is used to quantify the difference between the model prediction results and the true labels, thereby guiding the update and optimization of the model parameters. The calculation expression of the total loss function is:

[0116]

[0117] Among them, p represents the model's prediction result for the pixel point, α represents the balance factor to balance the unevenness of positive and negative samples, y represents the label result, and r represents the weight factor / hyperparameter.

[0118] Step S204, if the difference loss value in the current loss difference result is greater than the target difference threshold, return to execute the step of acquiring the training image dataset as the current training image dataset, and constructing a label image dataset corresponding to the current training image dataset as the current label image dataset, until the difference loss value in the current loss difference result is less than or equal to the target difference threshold;

[0119] The target difference threshold is a preset limit value used to evaluate whether the performance of the model during training has reached the expected standard. The threshold can be set based on the specific task of the model, the characteristics of the data set, and the training goal.

[0120] In the specific implementation, when the loss difference value (which can be understood as the difference between the predicted value and the true value, calculated by the Focal Loss loss function) generated by the model during the training process is greater than the target difference threshold, it means that the performance of the model has not yet reached the expected standard. In order to improve the performance of the model, the algorithm will start again from the starting point of the training dataset, that is, execute the step of "obtaining the training image dataset as the current training image dataset, and constructing the label image dataset corresponding to the current training image dataset as the current label image dataset" again, and continue to train the model. This process may be repeated many times until the loss difference value of the model on the validation set or test set is less than or equal to the target difference threshold.

[0121] Step S205: when the difference loss value in the current loss difference result is less than or equal to the target difference threshold, the current image segmentation prediction model corresponding to the current loss difference result is used as the target image segmentation prediction model.

[0122] Steps S201 to S205 shown in the embodiment of the present application effectively improve the performance of the image segmentation prediction model by adopting the Focal Loss function and the iterative training model, and enable the model to better handle unbalanced data and reduce the risk of overfitting.

[0123] In step S103 shown in the embodiment of the present application, a target image segmentation prediction model is obtained by inputting a training image data set into the original image segmentation prediction model for training. Based on the training process, the model can learn the mapping relationship from the image to the segmentation result. Furthermore, the embodiment of the present application incorporates a target local self-attention module and a target downsampling module. Both modules are constructed based on the gradient intensity probability of the feature map calculated by the edge detection operator, respectively. The gradient intensity probability distribution of the image is integrated into the local self-attention model, which realizes efficient analysis and accurate segmentation of image features, that is, the model can more accurately locate and capture when processing image data. By making full use of the edge information in the image, the segmentation prediction model can more accurately determine the category to which each pixel belongs, thereby achieving more refined and accurate pixel-level classification, and ultimately improving the performance of the entire image segmentation; and, a guidance mechanism based on gradient strength probability is introduced in the downsampling module, which can efficiently retain the edge information of the target object while reducing the amount of feature map data and reducing computing requirements. By introducing the gradient strength probability calculated based on the edge detection operator in the local self-attention module and the downsampling module respectively, it can significantly reduce the consumption of computing resources and memory while improving the segmentation performance of the model.

[0124] Moreover, by adopting the loss function and iterative model, the performance of the image segmentation prediction model is effectively improved, and the model can better handle unbalanced data and reduce the risk of overfitting.

[0125] Step S104, inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting an image segmentation prediction result;

[0126] Among them, the image to be predicted is an image that has not been processed by the image segmentation prediction model and needs to be segmented to identify different areas or objects therein. It is different from the above-mentioned training image, but it is also necessary to divide the image to be predicted into multiple predicted image blocks, and input the predicted image blocks into the target image segmentation prediction model for prediction, and output the image segmentation prediction result.

[0127] In some embodiments, step S104 may include: obtaining an image to be predicted; performing segmentation processing on the image to be predicted to obtain a number of predicted image blocks; constructing a predicted image data set based on the number of predicted image blocks; inputting the predicted image data set into a target image segmentation prediction model for prediction, and outputting an image segmentation prediction result.

[0128] In some embodiments, see Figure 3 , Figure 3 yes Figure 1 The flowchart of step S104 in FIG. Figure 3As shown, the method in step S104 may include but is not limited to steps S301 to S303:

[0129] Step S301, inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model, performing a first feature extraction process on any of the predicted image blocks through a first feature processing module of the target image segmentation prediction model, and obtaining a first feature map;

[0130] Step S302, inputting the first feature map into a feature focusing module of the target image segmentation prediction model, and performing feature focusing processing on the first feature map by the feature focusing module to obtain a second feature map;

[0131] Step S303: input the second feature map into the second feature processing module of the target image segmentation prediction model, perform second feature extraction processing on the second feature map through the second feature processing module to obtain a third feature map, and use the third feature map as the image segmentation prediction result.

[0132] Steps S301-S303 shown in the embodiment of the present application can effectively segment the image to be predicted by combining the first feature processing module, the feature focusing module and the second feature processing module. The first feature processing module provides preliminary feature extraction, while the feature focusing module can focus on key features and improve the model's attention to important information. Finally, the second feature processing module further extracts features to generate more refined segmentation results. That is, the target image segmentation prediction model provided in the embodiment of the present application can segment images more accurately and finely, especially when processing images with complex structures and textures, by focusing on key features through the feature focusing module, the accuracy and robustness of the segmentation results can be improved.

[0133] In some specific embodiments, see Figure 4 , Figure 4 yes Figure 3 The flowchart of step S301 in FIG. Figure 4 As shown, the method in step S301 may include but is not limited to steps S401 to S403:

[0134] Step S401, inputting a plurality of predicted image blocks corresponding to the image to be predicted into the first feature processing module of the target image segmentation prediction model;

[0135] Step S402, performing a first convolution process on any of the predicted image blocks through the first convolution module in the first feature processing module to obtain a first convolution feature map;

[0136] Step S403: input the first convolution feature map to the first target downsampling module, and perform a first downsampling process on the first convolution feature map through the first target downsampling module to obtain the second feature map.

[0137] In a specific implementation, the first feature processing module includes a first convolution module and a first target downsampling module, wherein, when the predicted image block reaches the first feature processing module, the first feature processing module is used to perform two convolution operations and downsampling processes on the predicted image block, that is, a convolution operation and a downsampling process are performed first, and then a convolution operation and a downsampling process are performed on the feature map obtained after the first convolution and the first downsampling process, wherein the convolution operation is a 3×3 convolution, and the RELU() function is introduced when performing the 3×3 convolution operation, aiming to perform a 3×3 convolution while also having nonlinearity. Transformation operation increases the nonlinear ability of the model, accelerates model training, improves model sparsity and reduces model parameters. In addition, a convolution feature map is generated in each of the two convolution operations. In the two downsampling processes of the first feature processing module, the edge detection operator is first used to calculate the gradient intensity probability of the convolution feature map obtained each time, and then a gradient intensity probability distribution map is constructed according to the gradient intensity probability. Finally, the gradient intensity probability distribution map is introduced into the first target downsampling module as prior knowledge, so that the first target downsampling module uses the downsampling formula to downsample the convolution feature map to obtain the second feature map.

[0138] In the image segmentation prediction model, for the feature map obtained by the convolution operation in the first feature processing module, it is necessary to calculate its gradient probability distribution map R, use a 2×2 slider for downsampling, and in the grid slider, combine the gradient probability with the slider pixel point to take the maximum value; by combining the maximum value downsampling with the gradient probability distribution map, the edge information of the target object in the feature map can be retained, and for the part with consistent and relatively large internal feature information of the object, only 25% of the information is retained, which not only effectively eliminates redundant and repeated feature information, but also greatly improves the importance and utilization of feature map information.

[0139] In the steps S401-S403 shown in the embodiment of the present application, during the downsampling process, the feature channel of the feature map remains unchanged, and the maximum value of the product of the gradient intensity probability of each pooled area and the feature map (i.e., the gradient intensity probability map of the corresponding position multiplied by the pixel value of the feature map) is calculated as the pooling result, so that the model can focus on and retain the edge features of the target object in the feature map during downsampling, and only retain 25% of the information for the part with consistent and large internal feature information of the object, which not only effectively eliminates redundant and repeated feature information, but also greatly improves the utilization rate of important information in the feature map. By introducing a guidance mechanism based on edge operators in the downsampling module, the edge information of the target object can be efficiently retained while reducing the amount of feature map data and reducing the computing requirements during downsampling.

[0140] In some specific embodiments, see Figure 5 , Figure 5 yes Figure 3 The flowchart of step S302 in FIG. Figure 5 As shown, the method in step S302 may include but is not limited to steps S501 to S505:

[0141] Step S501, inputting the first feature map into a feature focusing module of the target image segmentation prediction model;

[0142] Step S502, calculating a first gradient intensity probability of the first feature map by using an edge detection operator through the feature focusing module, and constructing a first gradient intensity probability distribution map according to the first gradient intensity probability;

[0143] Step S503, introducing the first gradient intensity probability distribution map as first prior knowledge into the target local self-attention module, so that the target local self-attention module calculates the first feature map using a self-attention formula to obtain a candidate feature map containing target edge information;

[0144] Steps S504-S503 shown in the embodiment of the present application first calculate the probability distribution map of the gradient intensity of the image, and then transform it through a linear model as the input of the local self-attention module, guiding the attention module to focus on the edge area of ​​the image while self-learning the long-distance dependencies of the feature map sequence, so as to increase the model's preference for pixels with obvious pixel changes in the feature map, extract more edge feature information of the target object, and accurately segment the target object. Through a local self-attention module based on an edge operator, the probability distribution of the gradient intensity of the image is integrated into the local self-attention model, achieving efficient analysis and accurate segmentation of image features.

[0145] Step S504, calculating a second gradient intensity probability of the candidate feature map by using the edge detection operator through the feature focusing module, and constructing a second gradient intensity probability distribution map according to the second gradient intensity probability;

[0146] Step S505: introduce the second gradient intensity probability distribution map as second prior knowledge into the second target downsampling module, so that the second target downsampling module uses a downsampling formula to downsample the candidate feature map to obtain the second feature map.

[0147] In the steps S504-S505 shown in the embodiment of the present application, the downsampling process here is the same as the downsampling method in the first feature processing module, and the input variables are different from the output content. Specifically, the feature channel of the feature map remains unchanged, and the maximum value of the product of the gradient intensity probability of each pooling area and the feature map is calculated as the pooling result, so that the model can focus on and retain the edge features of the target object in the feature map during downsampling, and only retain 25% of the information for the part with consistent and relatively large internal feature information of the object, which not only effectively eliminates redundant and repeated feature information, but also greatly improves the utilization rate of important information in the feature map. By introducing a guidance mechanism based on edge operators in the downsampling module, the edge information of the target object can be efficiently retained while reducing the amount of feature map data and reducing the computing requirements during downsampling.

[0148] In a specific implementation, the feature focusing module includes a target local self-attention module and a second target downsampling module. When the first feature processing module is completed and reaches the feature focusing module, the feature focusing module uses an edge detection operator to calculate the first gradient intensity probability of the first feature map obtained after processing by the first feature processing module, and constructs a first gradient intensity probability distribution map based on the first gradient intensity probability. The first gradient intensity probability distribution map is introduced into the target local self-attention module as the first prior knowledge, so that the target local self-attention module uses the self-attention formula to calculate the first feature map to obtain a candidate feature map containing target edge information. Then, the feature focusing module uses the edge detection operator to calculate the second gradient intensity probability of the candidate feature map processed by the target local self-attention module, and constructs a second gradient intensity probability distribution map based on the second gradient intensity probability. The second gradient intensity probability distribution map is introduced into the second target downsampling module as the second prior knowledge, so that the second target downsampling module uses the downsampling formula to downsample the candidate feature map to obtain the second feature map. The operation performed by the feature focusing module needs to be repeated three times.

[0149] In some specific embodiments, see Figure 6 , Figure 6 yes Figure 3 The flowchart of step S303 in FIG. Figure 6 As shown, the method in step S303 may include but is not limited to steps S601 to S603:

[0150] Step S601, inputting the second feature map into a second feature processing module of the target image segmentation prediction model;

[0151] Step S602, performing a second convolution process on the second feature map by the second convolution module in the second feature processing module to obtain a second convolution feature map;

[0152] Step S603: input the second convolution feature map to the upsampling module, perform upsampling processing on the second convolution feature map through the upsampling module to obtain the third feature map, and use the third feature map as the image segmentation prediction result.

[0153] In a specific implementation, the second feature processing module includes a second convolution module and an upsampling module. When the feature focusing module completes processing and reaches the second feature processing module, the second convolution module in the second feature processing module performs a second convolution processing on the second feature map obtained by the feature focusing module (the convolution processing of this step is the same as the processing method of the first convolution module) to obtain a second convolution feature map, and then the second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module, and the feature map after the upsampling processing is used as the image segmentation prediction result, and the image segmentation prediction result is output by the prediction map output module.

[0154] Specifically, the model prediction process can be as follows: first, a patch block randomly selected from the original image is used as a model input image and input into the original image segmentation prediction model through the image input module. Secondly, the first feature processing module includes a first convolution module and a first target downsampling module, wherein when the model input image reaches the first feature processing module, the first feature processing module is used to perform two convolution operations and downsampling processes on the model input image, that is, first perform a convolution operation and a downsampling process, and then perform a convolution operation and a downsampling process on the feature map obtained after the first processing, wherein the convolution operation is a 3×3 convolution, and the RELU() function is introduced when performing the 3×3 convolution operation, aiming to perform a 3×3 convolution while also having nonlinearity. Transformation operation increases the nonlinear ability of the model, accelerates model training, improves model sparsity and reduces model parameters. In addition, a convolution feature map is generated in each of the two convolution operations. In the two downsampling processes of the first feature processing module, the edge detection operator is first used to calculate the gradient intensity probability of the convolution feature map obtained each time, and then a gradient intensity probability distribution map is constructed according to the gradient intensity probability. Finally, the gradient intensity probability distribution map is introduced into the first target downsampling module as prior knowledge, so that the first target downsampling module uses the downsampling formula to downsample the convolution feature map. Furthermore, after the first feature processing module is completed, it reaches the feature focusing module, which includes a target local self-attention module and a second target downsampling module. The feature focusing module uses an edge detection operator to calculate the first gradient intensity probability of the feature map obtained after processing by the first feature processing module, and constructs a first gradient intensity probability distribution map based on the first gradient intensity probability. The first gradient intensity probability distribution map is introduced into the target local self-attention module as the first prior knowledge, so that the target local self-attention module uses the self-attention formula to calculate the feature map obtained after processing by the first feature processing module to obtain a candidate feature map containing target edge information. Then, the feature focusing module uses the edge detection operator to calculate the second gradient intensity probability of the candidate feature map processed by the target local self-attention module, and constructs a second gradient intensity probability distribution map based on the second gradient intensity probability. The second gradient intensity probability distribution map is introduced into the second target downsampling module as the second prior knowledge, so that the second target downsampling module uses the downsampling formula to downsample the candidate feature map, wherein the operation performed by the feature focusing module needs to be repeated three times.Furthermore, the second feature processing module includes a second convolution module and an upsampling module. When the feature focusing module completes processing and reaches the second feature processing module, the second convolution module in the second feature processing module performs a second convolution processing on the feature map obtained by the feature focusing module (the convolution processing of this step is the same as the processing method of the first convolution module) to obtain a second convolution feature map, and then the second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module, and the feature map after the upsampling processing is used as the image segmentation prediction result, and the image segmentation prediction result is output by the prediction map output module.

[0155] In step S104 shown in the embodiment of the present application, by using the trained target image segmentation prediction model to predict the new image to be predicted, the image segmentation result can be obtained quickly and accurately. In addition, by introducing the gradient intensity probability calculated based on the edge detection operator in the local self-attention module and the downsampling module of the target image segmentation prediction model, in the process of model segmentation prediction, efficient analysis and accurate segmentation of image features can be achieved, and the edge information of the target object can be efficiently retained, so that while improving the model segmentation performance, the consumption of computing resources and memory can be significantly reduced.

[0156] Step S105 , performing segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image.

[0157] The target segmented image refers to the final result image that identifies and segments different regions or objects from the image to be predicted after being processed by the image segmentation prediction model.

[0158] In step S105 shown in the embodiment of the present application, by applying the image segmentation prediction result, the original image to be predicted can be accurately segmented to obtain a target segmented image.

[0159] Steps S101 to S106 shown in the embodiment of the present application are as follows: obtaining an original image; segmenting the original image to obtain a number of training image blocks, and constructing a training image data set based on the number of training image blocks; inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein a target local self-attention module of the original image segmentation prediction model is constructed based on a first gradient intensity probability calculated by an edge detection operator, and a target downsampling module of the original image segmentation prediction model is constructed based on a second gradient intensity probability calculated by an edge detection operator; inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting an image segmentation prediction result; segmenting the image to be predicted according to the image segmentation prediction result to obtain a target segmented image. The embodiment of the present application can divide the original image into multiple training image blocks, so that the original image can be divided into smaller image blocks that are easier to process and analyze, and the local features in the original image can be extracted more effectively, which can reduce the computational complexity and improve the efficiency of the training model. The embodiment of the present application integrates the gradient intensity probability distribution of the image into the local self-attention module, so as to realize efficient analysis and precise segmentation of image features. The downsampling module introduces a guidance mechanism based on the gradient intensity probability, which can effectively retain the edge information of the target object while reducing the amount of feature map data and reducing the computing requirements. The local self-attention module and the downsampling module respectively introduce the gradient intensity probability calculated based on the edge detection operator, so that the segmentation performance of the model can be improved while the consumption of computing resources and memory can be significantly reduced.

[0160] In order to explain the principle of the technical solution of the present invention in detail, the overall process of the present invention is described below in combination with some specific embodiments. It is easy to understand that the following is an explanation of the technical principle of the present invention and cannot be regarded as a limitation of the present invention.

[0161] See also Figure 7 , Figure 7 is a schematic diagram of an image segmentation model training structure provided in an embodiment of the present application; Figure 7 As shown, the architecture of the original image segmentation prediction model includes an image input module, a first feature processing module ( Figure 7 The part represented by letter A in the figure), feature focusing module ( Figure 7 The part represented by the letter B in the figure), the second feature processing module ( Figure 7 The part represented by the letter C in the figure) and the prediction map output module, wherein the first feature processing module includes a first convolution module ( Figure 7 Conv3×3+ReLu()) in part A and the first target downsampling module ( Figure 7The processing process of the first feature processing module is repeated twice; the feature focusing module includes a target local self-attention module ( Figure 7 The local self-attention module based on edge detection operator in part B) and the second target downsampling module ( Figure 7 The adaptive downsampling module in part B of FIG. 1 ), wherein the processing process of the feature focusing module is repeated three times; the second feature processing module includes a second convolution module ( Figure 7 Conv3×3+ReLu()) and upsampling module ( Figure 7 The upsampling module in part C of the figure), wherein the processing process of the second feature processing module is repeated five times.

[0162] Specifically, first, a patch block randomly selected from the original image is used as a model input image and input into the original image segmentation prediction model through an image input module. Secondly, when the model input image reaches the first feature processing module, the first feature processing module is used to perform two convolution operations and downsampling processes on the model input image, that is, the model input image is firstly subjected to a convolution operation and a downsampling process, and then the feature map obtained after the first processing is subjected to a convolution operation and a downsampling process, wherein the convolution operation is a 3×3 convolution, and the RELU() function is introduced when performing the 3×3 convolution operation, aiming to perform a nonlinear transformation operation while performing the 3×3 convolution, thereby increasing the nonlinear ability of the model, accelerating model training, improving model sparsity and reducing model parameters. In addition, a convolution feature map is generated in each of the two convolution operations, and in the two downsampling processes of the first feature processing module, the edge detection operator is first used to calculate the gradient intensity probability of the convolution feature map obtained each time, and then a gradient intensity probability distribution map is constructed according to the gradient intensity probability, and finally the gradient intensity probability distribution map is introduced as a priori knowledge into the first target downsampling module, so that the first target downsampling module uses the downsampling formula to perform downsampling processing on the convolution feature map. Furthermore, when the feature focusing module is reached after the first feature processing module is processed, the first gradient intensity probability of the feature map obtained after the first feature processing module is processed is calculated by the feature focusing module using the edge detection operator, and a first gradient intensity probability distribution map is constructed according to the first gradient intensity probability, and the first gradient intensity probability distribution map is introduced into the target local self-attention module as the first prior knowledge, so that the target local self-attention module uses the self-attention formula to calculate the feature map obtained after the first feature processing module is processed, and obtains a candidate feature map containing target edge information, then, the second gradient intensity probability of the candidate feature map processed by the target local self-attention module is calculated by the feature focusing module using the edge detection operator, and a second gradient intensity probability distribution map is constructed according to the second gradient intensity probability, and the second gradient intensity probability distribution map is introduced into the second target downsampling module as the second prior knowledge, so that the second target downsampling module uses the downsampling formula to downsample the candidate feature map,

[0163] Among them, the operation performed by the feature focusing module needs to be repeated three times. Furthermore, the second feature processing module includes a second convolution module and an upsampling module. When the feature focusing module completes the processing and reaches the second feature processing module, the second convolution module in the second feature processing module performs a second convolution processing on the feature map obtained by the feature focusing module (the convolution processing of this step is the same as the processing method of the first convolution module) to obtain a second convolution feature map, and then the second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module. The processing process of the second feature processing module is repeated five times, and the feature map after the final upsampling processing is used as the image segmentation prediction result, and the image segmentation prediction result is output by the prediction map output module.

[0164] See also Figure 8 , Figure 8 is a schematic diagram of an image segmentation reasoning architecture provided in an embodiment of the present application; Figure 8 As shown, first, a patch block of a training image is obtained as current training image data, and label image data corresponding to the current training image data is constructed as current label image data; then, the current training image data is input into the original image segmentation prediction model to obtain a first segmentation prediction result, and the first segmentation prediction result is used as the current segmentation prediction result, and the original image segmentation prediction model is used as the current image segmentation prediction model; then, the loss difference between the current segmentation prediction result and the current label image data is calculated based on the target loss function to obtain a first loss difference result, and the first loss difference result is used as the current loss difference result; if the difference loss value in the current loss difference result is greater than the target difference threshold, then return to execute the step of obtaining a patch block of the training image as the current training image data, and constructing label image data corresponding to the current training image data as the current label image data, until the difference loss value in the current loss difference result is less than or equal to the target difference threshold; when the difference loss value in the current loss difference result is less than or equal to the target difference threshold, the current image segmentation prediction model corresponding to the current loss difference result is used as the target image segmentation prediction model. Finally, the target image segmentation prediction model with the best training results obtained through continuous training is written into the hardware kernel or called in the software module. The front-end camera then acquires the image and calls this model for prediction. Finally, the predicted segmentation result is transmitted to the hardware kernel or software module to guide the hardware or software to perform corresponding operations.

[0165] Among them, randomly selecting patches from the original image (i.e. dividing the image into multiple small blocks) as the model input image is because the pixel resolution of natural images is relatively large, and directly inputting the original image will take up a lot of computing resources. Randomly selecting patches will perform convolution operations on patches at different positions of the original image. The model can learn various local features of the original image and then understand the entire image, thereby reducing the complexity of the model and improving training efficiency. When randomly selecting patches on the original image, the corresponding patches are selected on the image label as training labels.

[0166] By adopting the loss function and iterative training model, the performance of the image segmentation prediction model is effectively improved, and the model can better handle unbalanced data and reduce the risk of overfitting.

[0167] See also Fig. 9 , Fig. 9 is a schematic diagram of a local self-attention module based on edge detection provided in an embodiment of the present application; Fig. 9 As shown, the sequence number 100 represents the input feature Figure X , serial number 001 indicates that the Figure X A square grid is defined on the local area on the grid. The number 200 represents a 9×9 grid slider, and the number 300 represents the calculation feature. Figure X The obtained gradient intensity probability distribution map R, serial number 400 represents the feature map Q obtained after linear transformation, serial number 500 represents the feature map K obtained after linear transformation, serial number 600 represents the similarity feature map obtained by multiplying the feature map Q and the feature map K, serial number 700 represents the output of the 9×9 grid slider, serial number 800 represents the feature map of the predicted output, and serial number 002 represents the feature map corresponding to the predicted output Figure X The local area on a square grid is defined on the location area.

[0168] for Fig. 9 The algorithm of the local self-attention module based on the edge detection operator in , the overall calculation steps are as follows:

[0169] First, a square grid is defined on the local area of ​​the 2D grid (feature map). For each point P on the grid ij , calculate the point P ij Centered on P i-1j , P i+1j , P ij-1 , P ij+1 , P i-1j-1 , P i+1j+1 , P i+1j-1 , P i-1j+1The gradients in these eight directions are calculated by using the convolution kernel of the Sobel operator in this embodiment. In order to reduce the amount of calculation, the L1 norm is used in this embodiment to calculate O ij gradient.

[0170] For all the marked points O in the grid, according to |P ij |Sort the marked points P in ascending order, obtain the maximum value in the sequence, take the maximum value as the baseline, and calculate the probability distribution map of the gradient strength of all marked points P in the grid through the calculation formula of the probability distribution map of the gradient strength.

[0171] For each grid area, local attention needs to be calculated. Let the input image of the grid area be X, that is, the feature map of the feature focusing module of the input model is called X. X is linearly transformed using two 1×1 convolutions to reduce the number of channels of the input image X, thereby reducing the amount of calculation, and Q and K are obtained. Q is the query vector and K is the key vector. In Transformer (a neural network model based on the self-attention mechanism), Q and K are multiplied to generate a similarity matrix. Based on Q, a linear transformation can generate a feature map Q. Based on K, a linear transformation can generate a feature map K. Both Q and K are used for subsequent attention calculations.

[0172] In order to make the network automatically focus on the region of interest based on the gradient information, for the gradient intensity probability distribution map r(P ij ) Use 1×1 convolution to perform a linear transformation and obtain V (Value, value vector).

[0173] Using Q (query vector), K (key vector), V (value vector) and the probability distribution graph r (P ij ), the output image A can be obtained by calculating the input image X according to the self-attention formula.

[0174] After the above calculation process, a local self-attention module based on edge operator can be obtained.

[0175] In the image segmentation prediction model, the features of the feature focusing module for the input model Figure XThe embodiment of the present application uses a 9×9 grid slider to obtain the gradient strength probability distribution map R of the grid, and uses the feature map and the gradient strength probability distribution map R as the input of the local attention module after two linear transformations, namely Q and K. Compared with the general attention module input, the image segmentation prediction model of the embodiment of the present application introduces the gradient strength of the feature map as prior knowledge into the attention model, and introduces attention to the obvious points of pixel transformation in the feature map while capturing the internal correlation of the data or features. Most of the parts of the image where the pixel information has obvious transformations are the edges of the target objects, which can enable the image segmentation prediction model to actively pay attention to the edges of the target objects instead of aimlessly performing self-learning.

[0176] Specifically, the image segmentation prediction model of the embodiment of the present application is directly designed to embed gradient information into the attention model, which is used as the V value to guide the local attention model to focus on the edge area, making full use of the edge information, which is more conducive to the segmentation of small target objects and general target objects; at the same time, the image segmentation prediction model of the embodiment of the present application does not directly perform matrix multiplication on the entire feature map, but selects a 9×9 grid each time for local attention transformation, which reduces the pressure on computing resources, makes full use of edge information and reduces the consumption of computing resources.

[0177] It should be pointed out that this embodiment only briefly illustrates the general process of the image segmentation method. The detailed description of each step can refer to the relevant content in the aforementioned embodiment and will not be repeated here. It can be understood that the present invention is not limited to this.

[0178] The embodiment of the present application obtains an original image; segments the original image to obtain a number of training image blocks, and constructs a training image data set based on the number of training image blocks; inputs the training image data set into an original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein a target local self-attention module of the original image segmentation prediction model is constructed based on a first gradient intensity probability calculated by an edge detection operator, and a target downsampling module of the original image segmentation prediction model is constructed based on a second gradient intensity probability calculated by an edge detection operator; inputs a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputs an image segmentation prediction result; segments the image to be predicted according to the image segmentation prediction result to obtain a target segmented image. The embodiment of the present application can divide the original image into multiple training image blocks, so that the original image can be divided into smaller image blocks that are easier to process and analyze, and the local features in the original image can be extracted more effectively, which can reduce the computational complexity and improve the efficiency of the training model. The embodiment of the present application integrates the gradient intensity probability distribution of the image into the local self-attention module, so as to realize efficient analysis and precise segmentation of image features. The downsampling module introduces a guidance mechanism based on the gradient intensity probability, which can effectively retain the edge information of the target object while reducing the amount of feature map data and reducing the computing requirements. The local self-attention module and the downsampling module respectively introduce the gradient intensity probability calculated based on the edge detection operator, so that the segmentation performance of the model can be improved while the consumption of computing resources and memory can be significantly reduced.

[0179] Among them, in order to more effectively utilize edge information and reasonably allocate computing resources, the specific effects of the following two innovative points proposed in the embodiment of the present application are:

[0180] 1. Local self-attention module based on edge detection operator: The probability distribution of image gradient intensity is integrated into the local self-attention model to achieve efficient analysis and accurate segmentation of image features. First, the probability distribution map of image gradient intensity is obtained by calculation, and then it is transformed by a linear model as the input of the local self-attention module, guiding the attention module to focus on the edge area of ​​the image while self-learning the long-distance dependencies of the feature map sequence, so as to increase the model's preference for pixels with obvious changes in the feature map, extract more edge feature information of the target object, and accurately segment the target object.

[0181] 2. Downsampling module guided by edge detection operator: A guidance mechanism based on gradient intensity probability is introduced in the downsampling module. This mechanism can effectively retain the edge information of the target object while reducing the amount of feature map data and computing requirements. In this process, the feature channel of the feature map remains unchanged, and the maximum value of the product of the gradient intensity probability and the feature map in each pooling area is calculated as the pooling result. The model is targeted to focus on and retain the edge features of the target object in the feature map during downsampling, and only retains 25% of the information for the part with consistent and relatively large internal feature information of the object. This not only effectively eliminates redundant and repeated feature information, but also greatly improves the importance and utilization of feature map information.

[0182] By combining the local self-attention module based on the edge detection operator and the downsampling module guided by the edge detection operator, the consumption of computing resources and memory can be significantly reduced while improving the model performance.

[0183] In addition, when applying the algorithm, first obtain the training data set of the pre-application scenario, send it to the original image segmentation prediction model for training, and then apply the optimized target image segmentation prediction model to the scene to be identified, such as security monitoring, autonomous driving, character background replacement, and robotics. The specific steps are as follows:

[0184] (1) Obtaining a training data set for a pre-application scenario, and transmitting the training data set to an original image segmentation prediction model for training;

[0185] (2) Obtaining the optimal training model during the training process as the target image segmentation prediction model;

[0186] (3) Writing the target image segmentation prediction model into the hardware kernel or calling the target image segmentation prediction model in the software module;

[0187] (4) The front-end camera acquires the image and calls the target image segmentation prediction model for prediction;

[0188] (5) The predicted segmentation results are transmitted to the hardware kernel or software module to guide the hardware or software to perform corresponding operations.

[0189] See also Fig.10 , Fig.10 is a structural diagram of an image segmentation device provided in an embodiment of the present application. The embodiment of the present application also provides an image segmentation device 1000, which can implement the above-mentioned image segmentation method. The device 1000 includes the following modules:

[0190] The original image acquisition module 1001 is used to acquire the original image;

[0191] The training data set acquisition module 1002 is used to segment the original image to obtain a plurality of training image blocks, and construct a training image data set according to the plurality of training image blocks;

[0192] A model training module 1003 is used to input the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator;

[0193] The model prediction module 1004 is used to input a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and output an image segmentation prediction result;

[0194] The image segmentation module 1005 is used to perform segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image.

[0195] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0196] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above image segmentation method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0197] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0198] See also Fig.11 , Fig.11 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0199] The processor 1101 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0200] The memory 1102 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1102 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1102, and the processor 1101 calls and executes the image segmentation method of the embodiment of the present application;

[0201] Input / output interface 1103, used to implement information input and output;

[0202] The communication interface 1104 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);

[0203] A bus 1105 that transmits information between various components of the device (e.g., the processor 1101, the memory 1102, the input / output interface 1103, and the communication interface 1104);

[0204] The processor 1101 , the memory 1102 , the input / output interface 1103 and the communication interface 1104 are connected to each other in communication within the device via the bus 1105 .

[0205] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned image segmentation method is implemented.

[0206] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiments, the functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0207] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0208] The image segmentation method, image segmentation device, electronic device and storage medium provided by the embodiments of the present application are as follows: acquiring an original image; performing segmentation processing on the original image to obtain a plurality of training image blocks, and constructing a training image data set based on the plurality of training image blocks; inputting the training image data set into an original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein a target local self-attention module of the original image segmentation prediction model is constructed based on a first gradient intensity probability calculated by an edge detection operator, and a target downsampling module of the original image segmentation prediction model is constructed based on a second gradient intensity probability calculated by an edge detection operator; inputting a plurality of predicted image blocks corresponding to an image to be predicted into a target image segmentation prediction model for prediction, and outputting an image segmentation prediction result; performing segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image. The embodiment of the present application can divide the original image into multiple training image blocks, so that the original image can be divided into smaller image blocks that are easier to process and analyze, and the local features in the original image can be extracted more effectively, which can reduce the computational complexity and improve the efficiency of the training model. The embodiment of the present application integrates the gradient intensity probability distribution of the image into the local self-attention module, so as to realize efficient analysis and precise segmentation of image features. The downsampling module introduces a guidance mechanism based on the gradient intensity probability, which can effectively retain the edge information of the target object while reducing the amount of feature map data and reducing the computing requirements. The local self-attention module and the downsampling module respectively introduce the gradient intensity probability calculated based on the edge detection operator, so that the segmentation performance of the model can be improved while the consumption of computing resources and memory can be significantly reduced.

[0209] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0210] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0211] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0212] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0213] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0214] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0215] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0216] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0217] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0218] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0219] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. An image segmentation method, characterized in that: The method comprises the following steps: Get the original image; Segmenting the original image to obtain a number of training image blocks, and constructing a training image data set based on the training image blocks; Input the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator; Inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting the image segmentation prediction result; The image to be predicted is segmented according to the image segmentation prediction result to obtain a target segmented image.

2. The method according to claim 1, characterized in that: The step of inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model comprises: Acquire the training image dataset as a current training image dataset, and construct a label image dataset corresponding to the current training image dataset as a current label image dataset; Input any training image block in the current training image data set into the original image segmentation prediction model to obtain a first segmentation prediction result, and use the first segmentation prediction result as the current segmentation prediction result, and use the original image segmentation prediction model as the current image segmentation prediction model; Calculate the loss difference between the current segmentation prediction result and the current label image data set based on the target loss function to obtain a first loss difference result, and use the first loss difference result as the current loss difference result; If the difference loss value in the current loss difference result is greater than the target difference threshold, returning to execute the step of acquiring the training image dataset as the current training image dataset, and constructing a label image dataset corresponding to the current training image dataset as the current label image dataset, until the difference loss value in the current loss difference result is less than or equal to the target difference threshold; When the difference loss value in the current loss difference result is less than or equal to the target difference threshold, the current image segmentation prediction model corresponding to the current loss difference result is used as the target image segmentation prediction model.

3. The method according to claim 1, characterized in that The step of inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction and outputting the image segmentation prediction result comprises: Acquire the image to be predicted; Segmenting the image to be predicted to obtain a plurality of predicted image blocks; Constructing a prediction image data set according to the plurality of prediction image blocks; The predicted image data set is input into the target image segmentation prediction model for prediction, and the image segmentation prediction result is output.

4. The method according to claim 1, characterized in that: The step of inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction and outputting the image segmentation prediction result comprises: Inputting a plurality of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model, and performing a first feature extraction process on any of the predicted image blocks through a first feature processing module of the target image segmentation prediction model to obtain a first feature map; Inputting the first feature map into a feature focusing module of the target image segmentation prediction model, and performing feature focusing processing on the first feature map by the feature focusing module to obtain a second feature map; The second feature map is input into the second feature processing module of the target image segmentation prediction model, and the second feature processing module performs second feature extraction processing on the second feature map to obtain a third feature map, and the third feature map is used as the image segmentation prediction result.

5. The method according to claim 4, characterized in that The first feature processing module includes a first convolution module and a first target downsampling module, and the plurality of predicted image blocks corresponding to the image to be predicted are input into the target image segmentation prediction model, and the first feature extraction processing is performed on any of the predicted image blocks by the first feature processing module of the target image segmentation prediction model to obtain a first feature map, including: Inputting the plurality of predicted image blocks corresponding to the image to be predicted into the first feature processing module of the target image segmentation prediction model; Performing a first convolution process on any of the predicted image blocks through the first convolution module in the first feature processing module to obtain a first convolution feature map; The first convolution feature map is input into the first target downsampling module, and the first target downsampling module performs a first downsampling process on the first convolution feature map to obtain the second feature map.

6. The method according to claim 4, characterized in that The feature focusing module includes a target local self-attention module and a second target downsampling module, the feature focusing module inputs the first feature map to the target image segmentation prediction model, performs feature focusing processing on the first feature map by the feature focusing module, and obtains a second feature map, including: Inputting the first feature map into a feature focusing module of the target image segmentation prediction model; Calculating a first gradient intensity probability of the first feature map by using an edge detection operator through the feature focusing module, and constructing a first gradient intensity probability distribution map according to the first gradient intensity probability; Introducing the first gradient intensity probability distribution map as first prior knowledge into the target local self-attention module, so that the target local self-attention module calculates the first feature map using a self-attention formula to obtain a candidate feature map containing target edge information; Calculating a second gradient intensity probability of the candidate feature map by using the edge detection operator through the feature focusing module, and constructing a second gradient intensity probability distribution map according to the second gradient intensity probability; The second gradient intensity probability distribution map is introduced into the second target downsampling module as second prior knowledge, so that the second target downsampling module downsamples the candidate feature map using a downsampling formula to obtain the second feature map.

7. The method according to claim 4, characterized in that The second feature processing module includes a second convolution module and an upsampling module, the second feature map is input to the second feature processing module of the target image segmentation prediction model, the second feature processing module performs a second feature extraction process on the second feature map to obtain a third feature map, and the third feature map is used as the image segmentation prediction result, including: Inputting the second feature map into a second feature processing module of the target image segmentation prediction model; Performing a second convolution process on the second feature map by the second convolution module in the second feature processing module to obtain a second convolution feature map; The second convolution feature map is input into the upsampling module, and the second convolution feature map is upsampled by the upsampling module to obtain the third feature map, and the third feature map is used as the image segmentation prediction result.

8. An image segmentation device, characterized in that: The device comprises the following modules: An original image acquisition module, used for acquiring the original image; A training data set acquisition module is used to segment the original image to obtain a plurality of training image blocks, and construct a training image data set based on the plurality of training image blocks; A model training module, used for inputting the training image data set into the original image segmentation prediction model for training to obtain a target image segmentation prediction model; wherein the target local self-attention module of the original image segmentation prediction model is constructed based on the first gradient intensity probability calculated by the edge detection operator, and the target downsampling module of the original image segmentation prediction model is constructed based on the second gradient intensity probability calculated by the edge detection operator; A model prediction module, used for inputting a number of predicted image blocks corresponding to the image to be predicted into the target image segmentation prediction model for prediction, and outputting an image segmentation prediction result; The image segmentation module is used to perform segmentation processing on the image to be predicted according to the image segmentation prediction result to obtain a target segmented image.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Passport information acquisition method and system based on image detection and identification

    CN119723602A

  • Image recognition method, electronic equipment, storage medium, program product and chip

    CN121330465A

  • Image recognition method, electronic device, storage medium, program product, and chip

    CN121330465B