Image description method based on Transform multi-granularity feature fusion

Through the multi-granularity feature fusion method based on Transformer, the problem of lack of detail and flexibility in image description in the existing technology is solved, and a more accurate and detailed image description is generated, which is suitable for multiple application fields.

CN118570598APending Publication Date: 2024-08-30XIAN UNIV OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410723213.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing image description technology mainly focuses on overall visual feature information and ignores local information, resulting in a lack of detailed description in the generated sentences. In addition, RNN has a length dependency problem when generating sentences, resulting in a lack of flexibility and diversity in the generated sentences.

Method used

Using a multi-granularity feature fusion method based on Transformer, the image data is divided into patches of different sizes through a multi-scale feature extraction module and a multi-level fusion module, visual feature vectors are extracted, and visual and text information are fused through the causal attention mechanism to generate Image description.

Benefits of technology

Generating more accurate and detailed image descriptions can more comprehensively capture the local details and global context information of the image, improve the accuracy of image understanding, and is suitable for news, education, medical and other fields.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570598A
    Figure CN118570598A
Patent Text Reader

Abstract

The invention discloses an image description method based on Transform multi-granularity feature fusion, and the method comprises the steps: processing image data, and dividing the data into a training set, a verification set and a test set; constructing a multi-scale feature extraction module MVIT; constructing a multi-feature fusion module HF to perform fusion of visual feature vectors; a text decoder is constructed, the extracted visual feature information and text information are fused through a causal attention mechanism, and final image description content is generated; a complete Transform-based multi-granularity feature fusion image description generation model is built by constructing a multi-scale feature extraction module, a multi-level fusion module and a text decoder, and an image to be described is input into the model to generate image description. Through a multi-granularity feature fusion technology, local details, object relationships and global context information in the image can be captured more comprehensively, so that more accurate and more detailed image description is generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the cross-technical field of computer vision and natural language processing, and relates to an image description method based on Transformer multi-granularity feature fusion. Background Art

[0002] With the rapid development of artificial intelligence technology, image description, as an intersection of computer vision and natural language processing, has become an important research direction. Image description aims to convert image content into accurate text descriptions. The core of this task is to use computer vision technology to extract rich visual feature information from images, and to convert these features into vivid and specific descriptions through natural language processing technology. Image description has great potential for human-computer interaction and can play an important role in many fields such as assisting the visually impaired, smart transportation, and intelligent information dissemination. With the rapid development of the intelligent era, the application prospects of image description are becoming increasingly broad, and its technological progress will bring more convenient and intelligent experience to our lives.

[0003] At present, image description technology is mainly based on deep learning algorithms, especially the combination of convolutional neural networks (CNN) and recurrent neural networks (RNN). CNN extracts low-level visual features and high-level semantic features of images through multiple convolutional layers and pooling layers, while RNN uses these features to generate natural language descriptions related to the image content. Although this method has achieved certain results in the field of image description, there are still some problems. It can be divided into the following aspects. First, the existing algorithms mainly focus on the overall visual feature information after extraction, while ignoring local information, resulting in the lack of detailed description of the generated corresponding sentences; secondly, due to the limitations of RNN itself, there is a problem of length dependency when using RNN as a sentence generator to process sequence data, which makes the generated sentences lack flexibility and diversity. Summary of the invention

[0004] The purpose of the present invention is to provide an image description method based on Transformer multi-granularity feature fusion to overcome the limitations of the traditional CNN-RNN model in image description generation.

[0005] The technical solution adopted by the present invention is an image description method based on Transformer multi-granularity feature fusion, which is specifically implemented according to the following steps:

[0006] Step 1: process the image data and divide the data into training set, validation set and test set;

[0007] Step 2, construct a multi-scale feature extraction module MVIT;

[0008] Step 3, construct a multi-feature fusion module HF to fuse the visual feature vectors;

[0009] Step 4: Build a text decoder to fuse the extracted visual feature information and text information through a causal attention mechanism to generate the final image description content;

[0010] Step 5: By constructing a multi-scale feature extraction module, a multi-level fusion module, and a text decoder, a complete Transformer-based multi-granularity feature fusion image description generation model is built. The image to be described can be input into the model to generate the image description.

[0011] The present invention is also characterized in that:

[0012] Step 1 is as follows:

[0013] Step 1.1, pre-process the collected image data, crop the images to a consistent size, and enhance the image data;

[0014] Step 1.2: Divide the enhanced image data into training set, validation set and test set. The training set is used for model training, the validation set is used for model verification, and the test set is used for model testing to finally evaluate the performance of the model.

[0015] Step 2 is implemented as follows:

[0016] Step 2.1: Cut the input image into two groups of patches of different sizes.

[0017] Step 2.2, extract visual vectors from two groups of patches of different sizes through a multi-layer perceptron;

[0018] Step 2.3: Combine the visual vectors extracted from the two groups of patches to generate the final visual feature vector.

[0019] Step 3 is implemented as follows:

[0020] Step 3.1, the multi-feature fusion module HF includes a multi-layer decoder, and an encoder of the multi-feature fusion module HF is constructed. The structure of each layer of the encoder is similar, and both include a multi-layer self-attention mechanism and a feedforward neural network;

[0021] Step 3.2: The extracted visual feature vector is used as the input of the bottom-level encoder, and after being processed in sequence, it is propagated to the encoder of the higher level;

[0022] In step 3.3, the output of each encoder layer is linearly weighted fused according to the different levels as the final visual feature vector.

[0023] Step 3.2 is as follows:

[0024] Step 3.2.1. First, multiply the input sequence with the corresponding weight matrix to obtain the Query, Key, and Value vectors;

[0025] Step 3.2.2, calculate the similarity score between the Query vector and the Key vector at each position by the dot product method;

[0026] Step 3.2.3, convert the similarity score into attention weight through normalization operation, and use the attention weight to perform weighted summation on the value vector to obtain the output of the self-attention mechanism. The calculation formula is as follows:

[0027]

[0028] In formula (1), Q, K and V are three learnable matrices, namely the query vector matrix, the key vector matrix and the value vector matrix. The input vector X is calculated by multiplying three different arbitrary matrices. The obtained Q, K and V are three different linear transformations of the same input to represent its three different states.

[0029] Step 3.2.4, the output of the self-attention mechanism is processed by the feedforward neural network and then output. The feedforward neural network consists of two linear transformations and an activation function. The first layer of linear transformation: the output vector of the self-attention mechanism is multiplied by a weight matrix W1, and then a bias vector b1 is added to obtain a new vector. The new vector is input into the nonlinear activation function to obtain the output vector of the activation function. The second layer of linear transformation: the output vector of the activation function is multiplied by another weight matrix W2 to obtain the final output vector of the feedforward neural network. The calculation formula of the feedforward neural network is as follows:

[0030] Feedforward neural network output = ReLU((self-attention mechanism output*W1)+b1)*W2(2).

[0031] Step 4 is implemented according to the following steps:

[0032] Step 4.1: The training process optimizes the entire model parameters through the back propagation algorithm and gradient descent. The loss function of the model training adopts the cross entropy loss function, as shown below:

[0033]

[0034] In formula (3), N is the number of training samples, T n is the sequence length of the nth sample, Represents the true label of the nth sample at time step t;

[0035] In step 4.2, the multi-granularity visual feature vector that has undergone multi-scale feature extraction and multi-level feature fusion is used as input and the causal attention mechanism is operated on the text decoding end. Therefore, the decoding end integrates the information of the image and text to generate a text sequence that conforms to the grammatical rules and describes the image content.

[0036] Step 5 is as follows:

[0037] Through steps 3 and 4, the model builds an image description model based on Transformer multi-granularity feature fusion, conducts multiple rounds of training, verifies the training results, uses the test set to evaluate the model performance, and adjusts and optimizes the model according to the evaluation results. The adjustment and optimization include the number of layers of the network structure, the dimension of the hidden layer, and the number of attention heads. Finally, an image description model based on Transformer multi-granularity feature fusion is obtained. The image to be described can be input into the model to generate an image description.

[0038] The beneficial effects of the present invention are:

[0039] The present invention is based on the image description method of Transformer multi-granularity feature fusion. Through the multi-granularity feature fusion technology, it can more comprehensively capture the local details, object relationships and global context information in the image, thereby generating a more accurate and detailed image description, which helps to more accurately convey the image content and improve the accuracy of image understanding; because the image description generated by the present invention is accurate, detailed and easy to understand, it can be widely used in news, education, medical treatment, transportation and other fields. By providing an accurate natural language description for the image, it can help people understand and process image information more quickly, improving work efficiency and convenience. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a flow chart of the image description method based on Transformer multi-granularity feature fusion of the present invention;

[0041] Figure 2 It is a schematic diagram of the structure of the image description model of the Transformer multi-granularity feature fusion of the present invention. DETAILED DESCRIPTION

[0042] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0043] Example 1

[0044] This embodiment provides an image description method based on Transformer multi-granularity feature fusion. Figure 1 As shown, the specific implementation steps are as follows:

[0045] Step 1: process the image data and divide the data into training set, validation set and test set;

[0046] Step 1.1, pre-process the collected image data, crop the images to a consistent size, and perform random rotation and other operations to enhance the image data;

[0047] Step 1.2: Divide the enhanced image data into training set, validation set and test set. The training set of 113,287 images is used for model training, the validation set of 5,000 images is used for model verification, and the test set of 5,000 images is used for model testing. Finally, the performance of the model is evaluated.

[0048] Step 2: construct a multi-scale feature extraction module MVIT to convert the input image information into feature vectors and perform multi-scale extraction;

[0049] Step 2.1: Cut the input image into two groups of patches of different sizes;

[0050] Step 2.2: Use a multi-layer perceptron to extract visual vectors from two groups of patches of different sizes;

[0051] Step 2.3: Combine the visual vectors extracted from the two groups of patches to generate the final visual feature vector.

[0052] Step 3: construct a multi-feature fusion module HF to fuse the visual feature vectors. According to the different weights assigned to the levels, the visual feature vectors are multi-layered and fused to extract information of each granularity of the image.

[0053] Step 4: Build a text decoder to fuse the extracted visual feature information and text information through a causal attention mechanism to generate the final image description content;

[0054] Step 5: By constructing a multi-scale feature extraction module, a multi-level fusion module, and a text decoder, a complete Transformer-based multi-granularity feature fusion image description generation model is built. The image to be described can be input into the model to generate the image description.

[0055] Example 2

[0056] This embodiment provides an image description method based on Transformer multi-granularity feature fusion. Based on Embodiment 1, step 3 is specifically implemented according to the following steps:

[0057] Step 3.1, the multi-feature fusion module HF includes a multi-layer decoder, and an encoder of the multi-feature fusion module HF is constructed. The structure of each layer of the encoder is similar, and both include a multi-layer self-attention mechanism and a feedforward neural network;

[0058] Step 3.2: The extracted visual feature vector is used as the input of the bottom-level encoder, and after being processed in sequence, it is propagated to the encoder of the higher level;

[0059] Step 3.2.1. First, multiply the input sequence with the corresponding weight matrix to obtain the Query, Key, and Value vectors;

[0060] Step 3.2.2, calculate the similarity score between the Query vector and the Key vector at each position by the dot product method;

[0061] Step 3.2.3, convert the similarity score into attention weight through normalization operation, and use the attention weight to perform weighted summation on the value vector to obtain the output of the self-attention mechanism. The calculation formula is as follows:

[0062]

[0063] In formula (1), Q, K and V are three learnable matrices, namely the query vector matrix, the key vector matrix and the value vector matrix, which are calculated by multiplying the input vector X by three different arbitrary matrices respectively. The calculated Q, K and V are three different linear transformations of the same input to represent its three different states.

[0064] Step 3.2.4, the output of the self-attention mechanism is processed by the feedforward neural network and then output. The feedforward neural network consists of two linear transformations and an activation function. The first layer of linear transformation: the output vector of the self-attention mechanism is multiplied by a weight matrix W1, and then a bias vector b1 is added to obtain a new vector. The new vector is input into the nonlinear activation function to obtain the output vector of the activation function. The second layer of linear transformation: the output vector of the activation function is multiplied by another weight matrix W2 to obtain the final output vector of the feedforward neural network. The calculation formula of the feedforward neural network is as follows:

[0065] Feedforward neural network output = ReLU((self-attention mechanism output*W1)+b1)*W2(2).

[0066] In step 3.3, the output of each encoder layer is linearly weighted fused according to the different levels as the final visual feature vector.

[0067] Example 3

[0068] This embodiment provides an image description method based on Transformer multi-granularity feature fusion. Based on Embodiment 1-2, step 4 is specifically implemented according to the following steps:

[0069] Step 4.1: The training process optimizes the entire model parameters through the back propagation algorithm and gradient descent. The loss function of the model training adopts the cross entropy loss function, as shown below:

[0070]

[0071] In formula (3), N is the number of training samples, T n is the sequence length of the nth sample, Represents the true label of the nth sample at time step t;

[0072] In step 4.2, the multi-granularity visual feature vector that has undergone multi-scale feature extraction and multi-level feature fusion is used as input and the causal attention mechanism is operated on the text decoding end. Therefore, the decoding end integrates the information of the image and text to generate a text sequence that conforms to the grammatical rules and describes the image content.

[0073] Example 4

[0074] This embodiment provides an image description method based on Transformer multi-granularity feature fusion. Based on Embodiments 1-3, step 5 is specifically as follows:

[0075] Through step 3 and step 4, the model builds an image description model based on Transformer multi-granularity feature fusion, conducts multiple rounds of training, verifies the training results, uses the test set to evaluate the model performance, and adjusts and optimizes the model according to the evaluation results. The adjustment and optimization include the number of layers of the network structure, the dimension of the hidden layer, and the number of attention heads. Finally, the following is obtained: Figure 2 The image description model based on Transformer multi-granularity feature fusion is shown. The image description can be generated by inputting the image to be described into the model.

[0076] Example verification

[0077] According to the image description method based on Transformer multi-granularity feature fusion of the present invention, image data is processed, and the processed image data includes 113287 training sets, 5000 validation sets and 5000 test sets of image-text pairs.

[0078] The complete model architecture of the multi-granularity feature fusion image description generation method based on Transformer of the present invention is built, and training is performed. The training parameters are set, and the Dropout parameter is set to 0.0005, the epoch is set to 5, the batch_size is set to 32, and the learning_rate is set to 4e-5. The training set and the validation set are input into the neural network for training, and the MViT module is used to extract and encode the multi-level visual features of the image to obtain the visual feature representation of each image. The visual feature representation is input into the HF module, and the context information is extracted through the self-attention mechanism. At the same time, the weight fusion is performed according to the different levels. By using the linear weighting method, we can comprehensively consider the importance of features at different levels and effectively combine them to form the final output feature representation. This fusion process not only retains the fine-grained information of the low level, but also incorporates the coarse-grained information of the high level, thereby improving the richness and accuracy of the features. The model parameters are optimized by minimizing the loss function. When evaluating the model, three evaluation indicators widely used in the field of image description are used: BLEU, CIDEr and SPICE. These indicators are designed to measure the degree of match between the description sentences generated by the model and the manually annotated sentences, so as to comprehensively evaluate the effect of the model. The BLEU indicator evaluates the similarity between the generated text and the reference sentence by calculating the n-gram matching score. As the value of n increases, it can capture longer matching information, thus reflecting the model's ability to generate coherent sentences. The CIDEr indicator evaluates the quality of the generated sentences by calculating the TF-IDF weight of each n-gram. It focuses more on the consistency between the description sentence and the reference sentence, and can reflect the performance of the model in generating description sentences that are highly relevant to the image content. SPICE focuses more on the semantic content of the candidate description rather than simply focusing on the grammatical structure or sentence fluency. By deeply analyzing the constituent elements of the scene graph and their relationships, SPICE can more accurately evaluate the model's ability to capture key information of the image and express scene details. These three indicators comprehensively consider different aspects of semantic and grammatical matching, providing a comprehensive and in-depth evaluation perspective.

[0079] Taking a single neural network Transformer as a comparative example, the image description method based on Transformer multi-granularity feature fusion of the present invention is compared with the single neural network Transformer on the test set. The comparison results are shown in Table 1:

[0080] Table 1 Performance comparison of different models

[0081] method CIDEr(%) BLEU(%) SPICE(%) Transformer 131.1 37.9 22.1 The present invention 137.5 40.4 24.3

[0082] From the above content, it can be seen that the multi-granularity feature fusion image description generation method based on Transformer of the present invention is aimed at the problem that traditional image description algorithms cannot use multi-granularity information. In the visual feature extraction stage, in order to capture image information more comprehensively, the image is innovatively divided into two groups of patches of different sizes. These patches are processed by a multi-layer perceptron, spliced, and then converted into the input of the encoding end through a simple linear layer. During the encoding process, weighted fusion is performed according to the granularity differences contained in the features output by each layer of the visual feature extractor. Finally, the weighted fused image features are passed to the decoding end to generate precise description sentences, which are accurate, detailed and easy to understand.

Claims

1. An image description method based on Transformer multi-granularity feature fusion, characterized in that: Follow the steps below to implement it: Step 1: process the image data and divide the data into training set, validation set and test set; Step 2, construct a multi-scale feature extraction module MVIT; Step 3, construct a multi-feature fusion module HF to fuse the visual feature vectors; Step 4: Build a text decoder to fuse the extracted visual feature information and text information through a causal attention mechanism to generate the final image description content; Step 5: By constructing a multi-scale feature extraction module, a multi-level fusion module, and a text decoder, a complete Transformer-based multi-granularity feature fusion image description generation model is built, and the image to be described is input into the model to generate an image description.

2. The image description method based on Transformer multi-granularity feature fusion according to claim 1 is characterized in that: The step 1 is specifically as follows: Step 1.1, pre-process the collected image data, crop the images to a consistent size, and enhance the image data; Step 1.2: Divide the enhanced image data into training set, validation set and test set. The training set is used for model training, the validation set is used for model verification, and the test set is used for model testing to finally evaluate the performance of the model.

3. The image description method based on Transformer multi-granularity feature fusion according to claim 2 is characterized in that: The step 2 is specifically implemented according to the following steps: Step 2.1: Cut the input image into two groups of patches of different sizes; Step 2.2, extract visual vectors from two groups of patches with different sizes respectively; Step 2.3: Combine the visual feature vectors extracted from the two groups of patches to generate the final visual feature vector.

4. The image description method based on Transformer multi-granularity feature fusion according to claim 3 is characterized in that: The step 3 is specifically implemented according to the following steps: Step 3.1, the multi-feature fusion module HF includes a multi-layer decoder, and an encoder of the multi-feature fusion module HF is constructed. The structure of each layer of the encoder is similar, and both include a multi-layer self-attention mechanism and a feedforward neural network; Step 3.2: The extracted visual feature vector is used as the input of the bottom-level encoder, and after being processed in sequence, it is propagated to the encoder of the higher level; In step 3.3, the output of each encoder layer is linearly weighted fused according to the different levels as the final visual feature vector.

5. The image description method based on Transformer multi-granularity feature fusion according to claim 4 is characterized in that: The step 3.2 is specifically as follows: Step 3.2.

1. First, multiply the input sequence with the corresponding weight matrix to obtain the Query, Key, and Value vectors; Step 3.2.2, calculate the similarity score between the Query vector and the Key vector at each position by the dot product method; Step 3.2.3, convert the similarity score into attention weight through normalization operation, and use the attention weight to perform weighted summation on the value vector to obtain the output of the self-attention mechanism. The calculation formula is as follows: In formula (1), Q, K and V are three learnable matrices, namely the query vector matrix, the key vector matrix and the value vector matrix, which are calculated by multiplying the input vector X by three different arbitrary matrices respectively. The calculated Q, K and V are three different linear transformations of the same input to represent its three different states. Step 3.2.4, the output of the self-attention mechanism is processed by a feedforward neural network and then output. The feedforward neural network consists of two linear transformations and an activation function. The first layer of linear transformation: the output vector of the self-attention mechanism is multiplied by a weight matrix W1, and then a bias vector b1 is added to obtain a new vector. The new vector is input into the nonlinear activation function to obtain the output vector of the activation function. The second layer of linear transformation: the output vector of the activation function is multiplied by another weight matrix W2 to obtain the final output vector of the feedforward neural network. The calculation formula of the feedforward neural network is as follows: Feedforward neural network output = ReLU((self-attention mechanism output*W1)+b1)*W2(2).

6. The image description method based on Transformer multi-granularity feature fusion according to claim 5 is characterized in that: The step 4 is specifically implemented according to the following steps: Step 4.1: The training process optimizes all parameters of the entire model through the back propagation algorithm and gradient descent. The loss function of the model training adopts the cross entropy loss function, as shown below: In formula (3), N is the number of training samples, T n is the sequence length of the nth sample, y t (n) Represents the true label of the nth sample at time step t; In step 4.2, the multi-granularity visual feature vector that has undergone multi-scale feature extraction and multi-level feature fusion is used as input and the causal attention mechanism is operated on the text decoding end. Therefore, the decoding end integrates the information of the image and text to generate a text sequence that conforms to the grammatical rules and describes the image content.

7. The image description method based on Transformer multi-granularity feature fusion according to claim 6 is characterized in that: The step 5 is specifically as follows: Through steps 3 and 4, the model builds an image description model based on Transformer multi-granularity feature fusion, conducts multiple rounds of training, verifies the training results, uses the test set to evaluate the model performance, and adjusts and optimizes the model according to the evaluation results. The adjustment and optimization include the number of layers of the network structure, the dimension of the hidden layer, and the number of attention heads. Finally, an image description model based on Transformer multi-granularity feature fusion is obtained, and the image to be described is input into the model to generate an image description.

Citation Information

Cited By

  • Transform image classification method based on granulation criterion

    CN120599340A