Semantic segmentation method based on Transform model

By using the Transformer model and the cross-attention module in the semantic segmentation task, the deficiencies of the FCN model in learning long-range dependency information are solved, the clarity of the segmented area and the accuracy of edge detection are improved, and better semantic segmentation results are achieved. .

CN118608787APending Publication Date: 2024-09-06NANJING TECH UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410780285.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

Existing models based on fully convolutional networks (FCN) are difficult to effectively learn long-range dependency information in semantic segmentation tasks, resulting in blurred segmentation areas, inaccurate target edges, and slow image feature fitting.

Method used

The Transformer model is used as the encoder, combined with the cross-attention module, for sequence-sequence learning, replacing the encoder part of the traditional FCN, and a feature cross-attention module is added to the model to fuse spatial and temporal features, and the attention mechanism is used to learn space and time. feature.

Benefits of technology

It improves the performance and generalization ability of the semantic segmentation model, can better capture features in spatiotemporal sequence data, and enhances the accuracy of segmentation results and the accuracy of edge detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118608787A
    Figure CN118608787A
Patent Text Reader

Abstract

The invention provides a semantic segmentation method based on a Transform model, and the method comprises the steps: data preparation: carrying out image serialization to convert an input image X into feature embedding; feature extraction is carried out, data are input into a first layer Transform, and each Transform layer is composed of multiple attention, layer normalization and an MLP layer; feature decoding: taking the extracted feature sequence as input, enabling the extracted feature sequence to pass through a cross-attention decoder structure, and obtaining a learned feature vector after the extracted feature sequence and the extracted feature sequence pass through a cross-attention decoder by using a cross-attention module; and generating a segmentation result, and sending a new feature vector output by a cross attention module serving as a decoder into a segmentation layer for prediction to obtain a final segmentation result. Compared with most existing semantic segmentation models based on an FCN model, feature extraction work of a semantic segmentation task is carried out through a Transform encoder, and learning of the model on remote dependency information can be enhanced to a great extent; and the cross attention module is used as a decoder, so that the model can extract global context information in a more efficient and high-quality manner, and the accuracy and segmentation quality of the semantic segmentation model are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer vision, and in particular to a method for semantic segmentation based on contrastive learning. Background Art

[0002] In recent years, the rapid development of deep learning has brought new hope to many difficult-to-advance computer vision tasks. Compared with traditional methods, deep learning can learn appropriate feature representations for current problems. The application of deep learning has greatly improved the accuracy of tasks in the field of computer vision. However, compared with other visual analysis tasks, semantic segmentation is more challenging. Traditional semantic segmentation methods mostly use probabilistic graphical model conditional random fields to classify pixels. This traditional method based on manual feature extraction cannot meet the image processing requirements of complex scenes. In recent years, researchers have improved the image classification model based on deep learning and applied it to the field of semantic segmentation, greatly improving the segmentation accuracy.

[0003] In the field of computer vision, semantic segmentation is the task of classifying images into different object or background categories at the pixel level. Existing semantic segmentation models have been dominated by models based on fully convolutional networks (FCNs). The standard FCN model has an encoder-decoder architecture: the encoder is used for feature representation learning, while the decoder is used to classify the feature representation at the pixel level. This design is very popular, but it also brings a big limitation, namely learning long-range dependency information, which is crucial for semantic segmentation tasks. The limited receptive field has become a big challenge in the semantic segmentation problem. Summary of the invention

[0004] Purpose of the invention: To overcome the problems of existing FCN-based models in learning long-range dependency information, and based on recent studies showing that combining with attention mechanism is an effective strategy for learning long-range context information, the present invention proposes a method for semantic segmentation based on Transformer model.

[0005] The present invention uses the Transformer model commonly used in the field of natural language processing as an encoder to extract global semantic information, replacing the encoding part of the traditional FCN, and provides a new perspective for the semantic segmentation problem from the perspective of sequence-sequence learning. The method includes the following steps:

[0006] (1) Perform image serialization and segmentation processing to obtain the input of the Transformer layer;

[0007] (2) Using Transformer-based visual encoder to learn feature representation;

[0008] (3) A cross-attention module is used as the decoder part of the model. The feature sequence obtained by the visual encoder part is processed by dimension and the initialization query sequence q is used as the K, V, and Q inputs of the cross-attention module respectively. After the two pass through the decoder of the cross-attention, the learned feature vector can be obtained;

[0009] (4) Finally, the features are sent to the segmentation layer to obtain the final segmentation result.

[0010] The present invention addresses the problems of blurred segmented areas, inaccurate edge segmentation of image targets, slow image feature fitting, and inability to effectively utilize attention information. It is proposed to add a feature cross-attention module to the model. The cross-attention network consists of two branches and a feature cross-attention module. By using the cross-attention mechanism to fuse spatial and temporal features, the correlation between different positions in the spatiotemporal features can be learned by calculating the attention weights, which can better capture the features in the spatiotemporal series data and improve the model performance and generalization ability. Specifically, the following steps are included:

[0011] (1) Process the time series feature key-value pair sequence after Transformer into two sequences;

[0012] (2) Initialize a vector as a query. The query interacts with the previously generated features. After the two pass through the cross-attention decoder, a learned feature vector can be obtained. The first query q0 is randomly initialized at the beginning of training;

[0013] (3) After the cross-attention decoder, the learned feature vector can be obtained. This part of the vector multiplied by the feature map is the predicted segmentation image result. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0015] Figure 1 It is the overall model diagram of the present invention;

[0016] Figure 2 It is a structural diagram of a video encoder based on Transformer of the present invention;

[0017] Figure 3 This is a structural diagram of the decoder of the cross-attention module of the present invention. DETAILED DESCRIPTION

[0018] The specific implementation of the present invention is given below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of the present invention.

[0019] For details, see Figure 1 , a method for semantic segmentation based on a Transformer model, comprising the steps of:

[0020] S1: Data preparation, image serialization is performed to convert the input image X into feature embedding. The production steps are as follows:

[0021] S11: Sequence the H×W×3 image into 256 The grid of . So the input sequence length of Transformer is Tiling the grid into a sequence;

[0022] S12: Each vectorized grid p is further mapped to the latent 3D embedding space by using the linear projection function f. This results in a 1D patch embedding sequence for the image X.

[0023] S13: Encoding patch spatial information, we learn a specific embedding p for each position i i and compare it with e i Add together to form the final sequence input E = {e1+p1, e2+p2, ..., e L +p L}. In this way, spatial information is preserved;

[0024] S2: Feature extraction, input data to the first layer Transformer. Each Transformer layer consists of multi-head attention, layer normalization, and MLP layer. The output result is Input E obtained in the previous step into 24 series-connected Transformers, so that the receptive field of each Transformer is the entire image. The steps include:

[0025] S21: Given a one-dimensional embedding sequence E as input, a Transformer-based encoder is used to learn feature representations;

[0026] S22: Transformer encoder consists of L e It consists of a multi-layer self-attention and a multi-layer perceptron. In each layer, the input of the self-attention is a triple of (query, key, value), starting from the input Z l-1 The calculations show that:

[0027] query=Zl-1 W Q , key = Z l-1 W K ,value=Z l-1 W V

[0028] Where W Q , W K , W V ∈R C×d are the learnable parameters of the three linear projection layers, and d is the dimension of (query, key, value);

[0029] S23: Calculation using self-attention mechanism:

[0030]

[0031] S24: Multi-head self-attention is an extension of m independent self-attention operations, projecting them and concatenating the outputs; the output of the multi-head self-attention is then converted to an MLP with residual skip as the output:

[0032] MSA(Z l-1 )=[SA1(Z l-1 );SA2(Z l-1 );...;SA m (Z l-1 )]W0

[0033] Z l =MSA(Z l-1 )+MLP(MSA(Z l-1 ))

[0034] S25: A set of (q, k, v) represents an attention mechanism operation. These multiple matrices are concatenated and then multiplied by a parameter matrix W. O , the final output can be obtained, and the result is obtained after residual network and layer normalization.

[0035] S3: Feature decoding, taking the extracted feature sequence as input, through a cross-attention decoder structure, by using the cross-attention module, a learned new feature vector is obtained. Using the features extracted by the Transformer encoder and the randomly initialized query q, the query interacts with the previously generated features, and the two can obtain a learned feature vector after passing through the cross-attention decoder. The first query q0 is randomly initialized at the beginning of training;

[0036] S4: Generate segmentation results, and send the new feature vector output by the cross-attention module acting as the decoder to the segmentation layer to predict the final segmentation result.

Claims

1. A semantic segmentation method based on a Transformer model, characterized in that: Includes steps: S1: Data preparation, image serialization to convert input images into feature embeddings; S2: Feature extraction, input data to the first layer of Transformer. Each Transformer layer consists of multi-head attention, layer normalization, and MLP layer, and finally outputs a feature sequence; S3: Feature decoding, taking the extracted feature sequence as input, passing through a cross-attention decoder structure, and obtaining a learned new feature vector by using the cross-attention module; S4: Generate segmentation results, and send the new feature vector output by the cross-attention module acting as the decoder to the segmentation layer to predict the final segmentation result.

2. The method for semantic segmentation based on the Transformer model according to claim 1, characterized in that: In step S1, image serialization is performed to convert the input image into feature embedding. The calculation method includes the following steps: S11: Sequence the H×W×3 image into 256 The grid of . So the input sequence length of Transformer is Tiling the grid into a sequence; S12: Each vectorized grid is further mapped to a latent 3D embedding space by using a linear projection function. This results in a 1D patch embedding sequence of the image. S13: Encoding patch spatial information, we learn a specific embedding p for each position i i and compare it with e i Add together to form the final sequence input E.

3. The method for semantic segmentation based on the Transformer model according to claim 1, characterized in that: In step S2, the Transformer encoder is used to extract image features and output the generated feature sequence. Each Transformer layer consists of multi-head attention, layer normalization, and MLP layer, including the following steps: S21: Given a one-dimensional embedding sequence E as input, a Transformer-based encoder is used to learn feature representations; S22: Transformer encoder consists of L e It consists of a multi-layer self-attention and a multi-layer perceptron. In each layer, the input of the self-attention is a triple of (query, key, value), starting from the input Z l-1 The calculation results in: query=Z l-1 W Q ,key=Z l-1 W K ,value=Z l-1 W V Where W Q , W K , W v The learnable parameters of the three linear projection layers, d is the dimension of (query, key, value); S23: Calculation using self-attention mechanism: S24: Multi-head self-attention is an extension of m independent self-attention operations, projecting them and concatenating the outputs; the output of the multi-head self-attention is then converted to an MLP with residual skip as the output: MSA(Z l-1 )=[SA1(Z l-1 );SA2(Z l-1 );…;ARE m (WITH l-1 )]IN O Z l =MSA(Z l-1 )+MLP(MSA(Z l-1 )) S25: Each group (q, k, v) represents an attention mechanism operation. These multiple matrices are concatenated and multiplied by a parameter matrix W. O , the final output can be obtained, and the result is obtained after residual network and layer normalization.

4. The method for semantic segmentation based on the Transformer model according to claim 1, characterized in that: In step S3, the extracted feature sequence is used as input, and passes through a cross-attention decoder structure. By using the cross-attention module, a learned new feature vector is obtained to complete the feature decoding work.

5. The method for semantic segmentation based on the Transformer model according to claim 1, characterized in that: In step S4, the new feature vector output by the cross-attention module acting as a decoder is sent to the segmentation layer. This part of the vector is multiplied by the feature map to obtain the final segmentation result, completing the generation task.

Citation Information

Cited By

  • Semi-supervised cardiac image segmentation method based on Mamba-Transform double structure and contrast learning

    CN120147330A