Visual question answering method, storage medium and device based on dynamic routing attention mechanism
The dynamic routing attention mechanism dynamically updates the attention weight in the visual question and answer model, which solves the problems of low training efficiency and poor robustness caused by too many parameters in the existing model, achieves a more compact and robust model, and improves answer accuracy. rate, especially when learning with a small number of samples.
Patent Information
- Application Number
- CN202111525656.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-12-14
AI Technical Summary
The existing visual question and answer model based on the attention mechanism has too many parameters, which leads to increased training time and vanishing gradient problems, affecting the robustness and effect of the model.
Adopting a dynamic routing attention mechanism, by dynamically updating attention weights, using a layer of attention to complete multi-step reasoning, reducing model parameters, and constructing a visual question and answer model based on the dynamic routing attention mechanism, combining convolutional neural networks and bidirectional GRU networks, Perform feature extraction and answer prediction.
It effectively reduces model parameters, avoids the vanishing gradient phenomenon, makes the model more compact and robust, improves training efficiency and answer accuracy, and is especially more robust when learning with a small number of samples.
Smart Images

Figure CN114254618B
Abstract
Description
Technical Field
[0001] The invention relates to a visual question answering method and belongs to the technical field of natural language processing. Background Art
[0002] In view of the successful application of question-answering tasks in the field of natural language processing, many researchers have begun to study the application of question-answering systems in the field of computer vision. In recent years, many researchers have devoted themselves to the study of visual question-answering tasks, and visual question-answering methods have developed rapidly. A variety of visual question-answering models have been proposed, which can be subdivided into joint embedding method models, attention mechanism-based models, combination-based method models, and external knowledge base-based models according to the specific methods they use. In order to obtain the features most relevant to the task, the currently popular visual question-answering methods based on attention mechanisms have introduced multiple layers of attention, and also introduced a large number of parameters, resulting in a sharp increase in the amount of model calculation, which has caused serious damage to the robustness and training effect of the model. Summary of the invention
[0003] The present invention aims to solve the problem that the existing question-answering model that introduces multi-layer attention has too many parameters, resulting in long training time and even gradient disappearance.
[0004] The visual question answering method based on dynamic routing attention mechanism includes the following steps:
[0005] Input the image I and the text question Q into the visual question answering model, and use the visual question answering model to obtain the question answer;
[0006] The visual question answering model includes:
[0007] Feature extraction unit: uses the first neural network to extract features from the image I to obtain visual features, and uses the second neural network to extract features from the text question Q to obtain text question features;
[0008] Dynamic routing attention network unit: Use dynamic routing to update the attention weights in the image using text question features and visual features as reference vectors and feature matrices, and obtain the output vector in the image based on the attention weight distribution;
[0009] Answer prediction unit: The obtained output vector is input into two fully connected layers for feature conversion, and then the answer to the question is predicted through the prediction layer.
[0010] Furthermore, the processing of the visual question answering model includes the following steps:
[0011] S1, using the first neural network to extract features from the image I to obtain visual features F;
[0012] At the same time, the second neural network is used to extract features of the text question Q to obtain the text question feature h;
[0013] S2. Input the acquired visual feature F and text question feature h into the dynamic routing attention mechanism network unit proposed by the present invention for multi-step reasoning. The specific process of dynamic routing attention mechanism reasoning is as follows:
[0014] The text question feature h is used as the reference vector guided in the dynamic routing attention mechanism, and the visual feature F is used as the feature matrix for information query; the visual feature F is composed of k visual feature vectors, and each visual feature vector in the visual feature F is represented as f i , that is, f i ∈F and i∈{1,2,...,k};
[0015] First, use the mapping matrix W f , W h Each visual feature vector f i And the text question feature h is mapped to the same spatial dimension, and f is obtained i p and h p :
[0016] f i p =W f ·f i (1)
[0017] h p =W h ·h (2)
[0018] The output vector s of the dynamic routing attention mechanism is first mapped by the reference vector h p Initialize, and use s0 to represent it:
[0019] s0=h p (3)
[0020] After the tth iteration, the output vector is updated to s t :
[0021]
[0022] Among them, s t-1 Represents the output vector obtained after the last iteration; f i p It is the new visual feature F obtained by mapping the input visual feature matrix F p The i-th visual feature vector in c irepresents the attention weight corresponding to the i-th visual feature vector, which is updated during each iteration; the attention weight c i Constitutes the visual feature matrix F p The attention weight distribution on ;
[0023] Attention weight c i The dynamic routing algorithm uses the softmax function to calculate the update:
[0024]
[0025] Among them, b i is an exponential prior, representing the i-th visual feature vector f i p The exponential prior probability associated with the output vector s;
[0026] Each dynamic routing will be exponential prior b i Update, and then update the b i The attention weight c used for the next iteration i Update of; in each iteration b i By i Add f to the original value i p Update the inner product of the output vector s:
[0027] b i =b i +f i p ·s t (6)
[0028] Among them, s t represents the output vector after the tth iteration;
[0029] The dynamic routing attention mechanism network performs N iterations and obtains the output vector s after N iterations. N It is represented as the joint feature of the visual feature F and the text question feature h as input;
[0030] S3. The joint feature s is input into the answer prediction unit for processing. The joint feature s is first converted through two fully connected layers. The prediction layer uses the loss function to predict the answer using the converted features.
[0031] Furthermore, the second neural network is a bidirectional GRU network; the bidirectional GRU network extracts features of the input text question Q, and uses the hidden layer features of the feedforward and feedback networks in the bidirectional GRU network as the text question feature h.
[0032] Furthermore, the first neural network is a convolutional neural network.
[0033] Furthermore, the sum of the attention weights between the output vector and the visual feature vector is 1.
[0034] Furthermore, during the training process of the visual question answering model, the loss function adopted by the prediction layer is the Softmax cross entropy loss function.
[0035] Alternatively, during the training process of the visual question answering model, the prediction layer is processed as a multi-label classification problem, and the loss function is as follows:
[0036]
[0037] Among them, p l represents the predicted probability of the lth class, y l Indicates whether the lth category is the correct answer, y l =1 means the lth category is among the correct answers.
[0038] A storage medium storing at least one instruction, wherein the at least one instruction is loaded and executed by a processor to implement the visual question answering method based on a dynamic routing attention mechanism.
[0039] A device comprises a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the visual question answering method based on the dynamic routing attention mechanism.
[0040] Beneficial effects:
[0041] In order to solve the problem of too many parameters in the existing model, the present invention proposes a visual question answering method based on a dynamic routing attention mechanism. Through an efficient and robust dynamic routing attention method, a layer of attention is used to complete the multi-step reasoning process, avoiding the gradient vanishing phenomenon in the traditional multi-layer attention layer. At the same time, the model parameters are greatly reduced, making the model more compact and robust. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 The network structure diagram of the visual question answering model based on the dynamic routing attention mechanism.
[0043] Figure 2 A comparison chart of the parameters of different models. DETAILED DESCRIPTION Specific implementation method one:
[0045] This implementation is a visual question answering method based on a dynamic routing attention mechanism. Through an efficient and robust dynamic routing attention method, a layer of attention is used to complete a multi-step reasoning process, which greatly reduces model parameters and solves the problems of training time and gradient disappearance.
[0046] The visual question answering method based on the dynamic routing attention mechanism described in this embodiment is implemented based on the visual question answering model.
[0047] The dynamic routing attention mechanism described in the present invention is a method of adding dynamic routing to the existing attention mechanism, so as to dynamically update the weights according to the routing in the attention mechanism, so it is called the dynamic routing attention mechanism. Then, this embodiment introduces the constructed dynamic routing attention mechanism into the visual question answering task, and builds a visual question answering method based on the dynamic routing attention mechanism by combining the existing convolutional neural network and the bidirectional GRU network. Figure 1 As shown, the network structure of the visual question answering model of the present invention includes:
[0048] Feature extraction unit: Use the pre-trained convolutional neural network to extract features from the input image, and use the bidirectional GRU network to extract problem features.
[0049] Dynamic routing attention network unit: Use dynamic routing to update the attention weights in the image with the problem features as the reference vector, and obtain the key information in the image based on the attention weight distribution.
[0050] Answer prediction unit: The acquired information is input into two fully connected layers for feature conversion, and then the prediction layer predicts the answer to the question.
[0051] The method comprises the following steps:
[0052] In visual question answering, during the training phase, a training sample is a triplet, which can be represented as (I, Q, a), where I represents the input image, Q represents the input text question, and a represents the answer, where both image I and text question Q are input to the model. In the actual question answering process, image I and text question Q are input, and the visual question answering model generates the answer; or candidate answers can be provided in the actual question answering process, and then the final answer is determined from the candidate answers based on the answer generated by the visual question answering model.
[0053] The processing process of the question-answering model network is as follows:
[0054] First, a convolutional neural network is used to extract features from the input image I to generate a feature matrix, namely, visual features, represented as F∈R k×m , k×m is the dimension of the real number space corresponding to the visual features.
[0055] At the same time, the bidirectional GRU network is used to extract features of the input text question Q. The hidden layer features of the feedforward and feedback networks in the bidirectional GRU network are concatenated as text question features, expressed as h∈R n , n is the dimension of the real number space corresponding to the text question features.
[0056] Then, the obtained visual feature F and text question feature h are input into the dynamic routing attention mechanism network unit proposed in the present invention for multi-step reasoning. The specific process of dynamic routing attention mechanism reasoning is as follows:
[0057] The text question feature h is used as the reference vector guided in the dynamic routing attention mechanism, and the visual feature F is used as the feature matrix for information query. The visual feature F is composed of multiple visual feature vectors, the number of visual feature vectors is defined as k, and each visual feature vector in the visual feature F is represented as f i , that is, f i ∈F and i∈{1,2,...,k}. First, use the mapping matrix W f and W h Each visual feature vector f i And the text question feature h is mapped to the same spatial dimension, and f is obtained i p and h p , expressed by the following formula, the mapping matrix W f and W h All of them need to be learned during the model training process.
[0058] f i p =W f ·f i (1)
[0059] h p =W h ·h (2)
[0060] Assume that s is the output vector of the dynamic routing attention mechanism; the output vector s is first mapped by the reference vector h p Initialization is performed, and after initialization, it is represented by s0. The initialization process can be expressed by the following formula:
[0061] s0=h p (3)
[0062] After s0 is initialized, it will be updated multiple times. After the tth iteration, the output vector is updated to s t , which is calculated using the following formula:
[0063]
[0064] Among them, s t-1 Represents the output vector obtained after the last iteration; f i p It is the new visual feature F obtained by mapping the input visual feature matrix F p The i-th visual feature vector in i p ∈F p And i∈{1,2,...,k}; k represents the number of visual feature vectors; c i Represents the attention weight corresponding to the i-th visual feature vector, which is a parameter that the model needs to learn and is updated during each iteration.
[0065] In the formula, c i is the attention weight, which indicates the contribution of the underlying vector, i.e., the visual feature vector, to the output vector. The sum of the attention weights between the output vector and the visual feature vector is 1. These attention weights constitute the visual feature matrix F p The attention weight distribution on .
[0066] Attention weight c i is calculated and updated by the dynamic routing algorithm using the softmax function, c i The update needs to use an intermediate variable b i , b i It is called exponential prior, which is used to represent the given vector, that is, the i-th visual feature vector f i p The exponential prior probability associated with the output vector s. All exponential priors b i are initialized to zero vectors, c i The calculation formula is expressed as follows:
[0067]
[0068] Each dynamic routing will be exponential prior b i Update, and then update the b i The attention weight c used for the next iteration i In each iteration, b i By i Add f to the original value i p The inner product of the output vector s is updated, and the calculation process is expressed as follows:
[0069] b i =b i +f i p ·s t (6)
[0070] Among them, s t Represents the output vector after the tth iteration.
[0071] The dynamic routing attention mechanism network will perform N iterations, where N is a manually preset hyperparameter. The output vector s obtained after N iterations is N It is represented as the joint feature of the visual feature F and the text question feature h as input.
[0072] The joint feature s is then input into the answer prediction unit for processing. The joint feature s is first transformed through two fully connected layers, and the prediction layer uses the transformed features to predict the answer.
[0073] During the training process, different loss functions are used for different data sets in the prediction layer. For example, the questions in the COCO-QA data set correspond to only one correct answer. In this case, the loss function can use Softmax cross entropy. Similar to the VQA1.0 and VQA 2.0 data sets, the questions often correspond to multiple answers, so they need to be processed as multi-label classification problems. The loss function can be expressed as follows:
[0074]
[0075] In the formula, p l represents the predicted probability of the lth class, y l Indicates whether the lth category is the correct answer, y l =1 means the lth category is among the correct answers.
[0076] Part of the code for the above process is as follows:
[0077]
[0078] Specific implementation method 2:
[0080] This embodiment is a storage medium, characterized in that at least one instruction is stored in the storage medium, and the at least one instruction is loaded and executed by a processor to implement the visual question answering method based on the dynamic routing attention mechanism.
[0081] The instructions in this embodiment include but are not limited to the code form in the specific implementation mode one, and may also be other code forms, as long as the visual question answering method based on the dynamic routing attention mechanism can be implemented. Specific implementation method three:
[0083] This embodiment is a device, characterized in that the device includes a processor and a memory, the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the visual question answering method based on the dynamic routing attention mechanism.
[0084] The instructions in this embodiment include but are not limited to the code form in the specific implementation mode one, and may also be other code forms, as long as the visual question answering method based on the dynamic routing attention mechanism can be implemented.
[0085] Example
[0086] The proposed visual question answering model based on dynamic routing attention mechanism is applied to COCO-QA, VQA 1.0 and VQA 2.0 datasets for verification.
[0087] On the COCO-QA dataset, the dynamic routing attention network uses the convolutional feature map before the last fully connected layer of the pre-trained VGG-16 as the input visual feature, with a uniform size of 14*14*512. The dimensions of the feedforward and feedback GRU units are set to 256, so the feature dimension of the output after processing the text question is 512. The attention map dimension of the dynamic routing attention network is set to 512, and the dimensions of the two fully connected layers are also set to 512. There are 434 candidate answers in this dataset.
[0088] In the VQA 1.0 and VQA 2.0 datasets, two visual feature extraction models are used. The first one uses the convolutional feature map before the last pooling layer of the pre-trained ResNet-152 as the visual feature, with a size of 14*14*2048. The second one uses the object detection network Faster R-Cnn to extract features. 36 candidate regions are detected in each image, and the input visual feature dimension is 36*2048. In question feature extraction, the dimension of GRU is 512, the attention map dimension of the dynamic routing attention network is set to 1024, and the dimensions of the two fully connected layers are also set to 2048. On these two datasets, the dimension of the answer prediction layer is set to 3000.
[0089] The dynamic routing attention mechanism-based visual question answering model (DRAN) is compared with the baseline model, the stacked attention network model (SAN), on the above three datasets. Table 1 shows the results on the COCO-QA dataset. The percentage after the task in the table header indicates the proportion of the subtask in the dataset.
[0090] Table 1. Results on the COCO-QA dataset
[0091]
[0092] From the table, we can see that in the four subtasks of Objects, Numbers, Color, and Location, the answer accuracy of the visual question answering model based on the dynamic routing attention mechanism is improved compared with SAN, and the improvement is large in the two tasks of Color and Location, which are increased by 3.7% and 2.1% respectively. To a certain extent, it shows that the dynamic routing attention mechanism is more robust for learning with a small number of samples.
[0093] Tables 2 and 3 show the comparison of the dynamic routing attention mechanism based visual question answering model (DRAN) with the baseline model - the stacked attention network model (SAN), as well as other models that perform well on the VQA 1.0 and VQA 2.0 datasets.
[0094] Table 2. Results on the VQA 1.0 dataset
[0095]
[0096]
[0097] Table 3. Results on the VQA 2.0 dataset
[0098]
[0099] As can be seen from Tables 2 and 3, DRAN performs significantly better than the baseline model SAN, both on VQA 1.0 and VQA2.0, by 4.9% and 4.6% respectively. Compared with the traditional combination model such as DMN, there is a 3.5% improvement on VQA1.0. Compared with knowledge enhancement models such as ASK and VQA-M, DRAN performs relatively well on VQA1.0, with improvements of 4.6% and 0.7% respectively. Compared with the multi-layer attention model such as HiCoAtt, DRAN has a 2.0% improvement on VQA1.0. Compared with bilinear models such as MCB, MFB, and MLB, DRAN's performance phenotype is slightly worse, but it has relatively fewer parameters. Figure 2 The parameter counts of these models are shown in Figure 1, where the unit of parameter count is megabytes. From the figure, we can see that DRAN has relatively few parameters, especially compared to bilinear models such as MCB, MFB, and MLB.
[0100] From Table 3, we can see that when both BUA and DRAN use the Faster R-CNN model for image feature extraction, DRAN shows good performance on both VQA 1.0 and VQA 2.0. The accuracy is 0.1% higher than that of the BUA model.
[0101] The present invention may also have many other embodiments. Without departing from the spirit and essence of the present invention, those skilled in the art may make various corresponding changes and modifications based on the present invention, but these corresponding changes and modifications should all fall within the scope of protection of the claims attached to the present invention.
Claims
1. A visual question answering method based on dynamic routing attention mechanism, characterized in that: Input the image I and the text question Q into the visual question answering model, and use the visual question answering model to obtain the question answer; The visual question answering model includes: Feature extraction unit: uses the first neural network to extract features from the image I to obtain visual features, and uses the second neural network to extract features from the text question Q to obtain text question features; Dynamic routing attention network unit: Use dynamic routing to update the attention weights in the image using text question features and visual features as reference vectors and feature matrices, and obtain the output vector in the image based on the attention weight distribution; Answer prediction unit: The obtained output vector is input into two fully connected layers for feature conversion, and then the answer to the question is predicted through the prediction layer; The processing of the visual question answering model includes the following steps: S1, using the first neural network to extract features from the image I to obtain visual features F; At the same time, the second neural network is used to extract features of the text question Q to obtain the text question feature h; S2. Input the obtained visual features F and text question features h into the dynamic routing attention mechanism network unit for multi-step reasoning. The specific process of dynamic routing attention mechanism reasoning is as follows: The text question feature h is used as the reference vector guided in the dynamic routing attention mechanism, and the visual feature F is used as the feature matrix for information query; the visual feature F is composed of k visual feature vectors, and each visual feature vector in the visual feature F is represented as f i , that is, f i ∈F and i∈{1,2,...,k}; First, use the mapping matrix W f , W h Each visual feature vector f i And the text question feature h is mapped to the same spatial dimension, and f is obtained i p and h p : f i p =W f ·f i (1) h p =W h ·h (2) The output vector s of the dynamic routing attention mechanism is first mapped by the reference vector h p Initialize, and use s0 to represent it: s0=h p (3) After the tth iteration, the output vector is updated to s t : Among them, s t-1 Represents the output vector obtained after the last iteration; f i p It is the new visual feature F obtained by mapping the input visual feature matrix F p The i-th visual feature vector in c i represents the attention weight corresponding to the i-th visual feature vector, which is updated during each iteration; the attention weight c i Constitutes the visual feature matrix F p The attention weight distribution on ; Attention weight c i The dynamic routing algorithm uses the softmax function to calculate the update: Among them, b i is an exponential prior, representing the i-th visual feature vector f i p The exponential prior probability associated with the output vector s; Each dynamic routing will be exponential prior b i Update, and then update the b i The attention weight c used for the next iteration i Update of b i By i Add f to the original value i p Update the inner product of the output vector s: b i =b i +f i p ·s t (6) Among them, s t represents the output vector after the tth iteration; The dynamic routing attention mechanism network performs N iterations and obtains the output vector s after N iterations. N It is represented as the joint feature of the visual feature F and the text question feature h as input; S3. The joint feature s is input into the answer prediction unit for processing. The joint feature s is first converted through two fully connected layers. The prediction layer uses the loss function to predict the answer using the converted features.
2. The visual question answering method based on dynamic routing attention mechanism according to claim 1, characterized in that: The second neural network is a bidirectional GRU network; the bidirectional GRU network extracts features of the input text question Q, and uses the hidden layer features of the feedforward and feedback networks in the bidirectional GRU network as the text question feature h.
3. The visual question answering method based on dynamic routing attention mechanism according to claim 2, characterized in that: The first neural network is a convolutional neural network.
4. The visual question answering method based on dynamic routing attention mechanism according to claim 3, characterized in that: The sum of the attention weights between the output vector and the visual feature vector is 1.
5. The visual question answering method based on dynamic routing attention mechanism according to any one of claims 1 to 4, characterized in that: During the training process of the visual question answering model, the loss function used in the prediction layer is the Softmax cross entropy loss function.
6. The visual question answering method based on dynamic routing attention mechanism according to any one of claims 1 to 4, characterized in that: During the training process of the visual question answering model, the prediction layer is processed as a multi-label classification problem, and the loss function is as follows: Among them, p l represents the predicted probability of the lth class, y l Indicates whether the lth category is the correct answer, y l =1 means the lth category is among the correct answers.
7. A storage medium, characterized in that: The storage medium stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the visual question answering method based on the dynamic routing attention mechanism as described in any one of claims 1 to 6.
8. A visual question answering device based on a dynamic routing attention mechanism, characterized in that: The device includes a processor and a memory, wherein at least one instruction is stored in the memory, and the at least one instruction is loaded and executed by the processor to implement the visual question answering method based on the dynamic routing attention mechanism as described in any one of claims 1 to 6.
