A medical visual question answering method, device, equipment and storage medium
By introducing an attention-based image block selector and contextual information fusion into the medical multi-modal large language model, the problem of the model being difficult to capture the visual and textual relationship under complex visual and text input is solved, and the accuracy of responses is improved. sex.
Patent Information
- Application Number
- CN202410919350.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-10
AI Technical Summary
When faced with complex visual and text inputs, existing medical multimodal large language models are difficult to capture the complex relationship between vision and text, which limits the model's expression ability and response accuracy.
Adopt a medical visual question answering method to improve the model's understanding of key image areas and contextual details through visual encoders, text encoders and multi-level feature alignment modules, including attention-based image patch selectors and contextual information fusion ability to generate more accurate responses.
It improves the model's ability to pay attention to key areas of the image and understand contextual details, significantly improving the accuracy of responses.
Smart Images

Figure CN118467707B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a medical visual question answering method, device, equipment and storage medium. Background Art
[0002] The existing medical multimodal large language model is mainly the LLaVA model, which connects the CLIP visual encoder and the LLaMA text decoder through a simple linear layer to achieve multimodal pre-training. The training process of LLaVA includes two stages. The first stage is to perform feature alignment pre-training on a 595k image description dataset, and only train the linear layer parameters; the second stage is to fine-tune on 158k high-quality instruction data, freeze the visual encoder, and train the linear layer and large language model.
[0003] Therefore, existing multimodal large language models often align visual features and text features through simple linear layers, such as LLaVA. However, in medical scenarios, faced with complex visual and text inputs, simple linear layers are difficult to capture the complex relationship between vision and text, which in turn limits the expressive power of the model.
[0004] Therefore, there is an urgent need for a medical visual question answering method that can improve the model's attention to key areas of the image and the model's ability to understand contextual details, thereby improving the accuracy of the answer. Summary of the invention
[0005] The main purpose of the present invention is to provide a medical visual question answering method, device, equipment and storage medium, aiming to solve the technical problem that in medical scenarios, when faced with complex visual and text inputs, it is difficult to capture the complex relationship between vision and text, thereby limiting the expressive ability of the model.
[0006] To achieve the above object, the present invention provides a medical visual question answering method, which comprises the following steps:
[0007] Acquire a target image and a user instruction input by a user, and determine whether the target image and the user instruction meet the medical visual question answering requirements;
[0008] When the target image meets the medical visual question answering requirements, the target image and the user instruction are input into a target medical multimodal large language model to generate a corresponding target answer, wherein the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, and the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device;
[0009] The targeted reply is returned to the user.
[0010] Optionally, the step of inputting the target image and the user instruction into a target medical multimodal large language model to generate a corresponding target response includes:
[0011] Inputting the target image into the visual encoder to obtain visual features;
[0012] Inputting the visual features and the user instructions into the text encoder to generate a text query vector;
[0013] Inputting the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features;
[0014] The image key area features, the context fusion features and the text query vector are input into the large language model-based text decoder to generate a corresponding target reply.
[0015] Optionally, the step of inputting the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features includes:
[0016] Inputting the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information;
[0017] The key area features of the image and the contextual image information are fused and represented by the contextual information fuser to obtain contextual fusion features. The contextual information fuser is composed of a multi-layer stacked Transformer decoder module, and each of the Transformer decoder modules includes a causal self-attention layer, a cross attention layer and a feedforward neural network layer.
[0018] Optionally, the step of inputting the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information comprises:
[0019] Based on the visual features and the text query vector, calculating an attention weight matrix by a preset matrix multiplication;
[0020] For the attention weight matrix, predicting the cross-modal feature distribution through a preset lightweight module, wherein the preset lightweight module is a lightweight module including a plurality of multi-layer perceptrons;
[0021] By sampling the cross-modal feature distribution, the key area features of the image and the contextual image information are obtained based on the sampling results;
[0022] Wherein, the preset matrix multiplication is:
[0023] ;
[0024] In the formula, Represents visual features, represents the transpose of the visual features, represents the text query vector, and is a learnable parameter, represents the attention weight matrix, K represents the number of text query vectors, , represents the number of blocks of the target image, and H and W represent the height and width of the target image respectively.
[0025] Optionally, the step of sampling the cross-modal feature distribution and selecting and obtaining the image key area features and context image information based on the sampling result includes:
[0026] The cross-modal feature distribution is processed using the Gumbel-Softmax technique to obtain a processed cross-modal feature distribution;
[0027] Sampling the processed cross-modal feature distribution to obtain a binary decision mask;
[0028] Selecting and obtaining key image region features and context image information based on the binary decision mask;
[0029] Among them, the Gumbel-Softmax technique is:
[0030] ;
[0031] In the formula, represents the cross-modal feature distribution, represents the cross-modal feature distribution after processing, is a sample of independent and identically distributed random variables randomly sampled from a Gumbel (0,1) distribution, It is the temperature parameter used to control the smoothness of the softmax function, and exp represents the natural exponential function.
[0032] Optionally, the cross attention layer uses the context image information as a query, and uses the image key area features updated by the causal self-attention layer as keys and values to perform context information fusion based on feature space similarity to obtain context information fusion features;
[0033] The information fusion of the cross attention layer is expressed as:
[0034] ;
[0035] In the formula, , , is the learnable parameter matrix, is the key area feature of the image, P is the number of key area features of the image, C represents the number of embedding channels, is the key area feature of the image after the causal self-attention layer updates, It is the context information fusion feature.
[0036] Optionally, the large language model-based text decoder includes a visual projection layer, a semantic projection layer and a large language model;
[0037] Accordingly, the step of inputting the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target answer includes:
[0038] The key area features of the image and the context fusion features are combined to obtain target visual features;
[0039] Based on the input dimension of the large language model, linearly mapping the target visual features through the visual projection layer to obtain visual information;
[0040] Based on the input dimension of the large language model, linearly mapping the text query vector through the semantic projection layer to obtain semantic information;
[0041] The visual information and the semantic information are concatenated and input into the large language model to generate a corresponding target response.
[0042] In addition, to achieve the above-mentioned purpose, the present invention also proposes a medical visual question-answering device, the device comprising:
[0043] A data acquisition module, used to acquire a target image and a user instruction input by a user, and determine whether the target image and the user instruction meet the requirements of medical visual question answering;
[0044] A reply generation module, used for inputting the target image and the user instruction into a target medical multimodal large language model to generate a corresponding target reply when the target image meets the medical visual question answering requirements, wherein the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, and the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device;
[0045] A reply returning module is used to return the target reply to the user.
[0046] In addition, to achieve the above-mentioned purpose, the present invention also proposes a medical visual question and answer device, which includes: a memory, a processor, and a medical visual question and answer program stored in the memory and executable on the processor, wherein the medical visual question and answer program is configured to implement the steps of the medical visual question and answer method described above.
[0047] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a medical visual question and answer program is stored. When the medical visual question and answer program is executed by a processor, the steps of the medical visual question and answer method described above are implemented.
[0048] The present invention obtains a target image and a user instruction input by a user, and determines whether the target image and the user instruction meet the requirements of medical visual question answering; when the target image meets the requirements of medical visual question answering, the target image and the user instruction are input into a target medical multimodal large language model to generate a corresponding target reply, wherein the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module, and a text decoder based on a large language model, wherein the multi-level feature alignment module includes an image block selector based on attention and a context information fusion device; and the target reply is returned to the user. Since the target medical multimodal large language model of the present invention includes a visual encoder, a text encoder, a multi-level feature alignment module, and a text decoder based on a large language model, wherein the multi-level feature alignment module includes an image block selector based on attention and a context information fusion device, compared with the prior art, the present invention improves the model's attention to key areas of the image and the model's ability to understand context details, thereby improving the accuracy of the reply. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 It is a flowchart of the first embodiment of the medical visual question answering method of the present invention;
[0050] Figure 2 It is a flowchart of the second embodiment of the medical visual question answering method of the present invention;
[0051] Figure 3 Schematic diagram of the structure of the context information fusion device in the medical visual question answering method of the present invention;
[0052] Figure 4 It is a flowchart of the third embodiment of the medical visual question answering method of the present invention;
[0053] Figure 5 Schematic diagram of the overall structure of the target medical multimodal large language model in the medical visual question answering method of the present invention;
[0054] Figure 6is a structural block diagram of the first embodiment of the medical visual question-answering device of the present invention;
[0055] Figure 7 It is a structural diagram of a medical visual question-answering device in a hardware operating environment involved in an embodiment of the present invention.
[0056] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0057] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0058] The embodiment of the present invention provides a medical visual question answering method, referring to Figure 1 , Figure 1 4 is a flow chart of the first embodiment of the medical visual question answering method of the present invention.
[0059] In this embodiment, the medical visual question answering method includes steps S10 to S30:
[0060] Step S10: Acquire the target image and the user instruction input by the user, and determine whether the target image and the user instruction meet the requirements of medical visual question answering.
[0061] It should be noted that the execution subject of this embodiment can be a computer server device with data processing, network communication and program running functions, such as a server, a tablet computer, a personal computer, etc., or an electronic device capable of realizing the above functions, a medical visual question-answering device, etc. The following takes the medical visual question-answering device as an example to illustrate this embodiment and the following embodiments.
[0062] It is understandable that the above-mentioned determination of whether the target image and the user instruction meet the medical visual question answering requirements may be to determine whether the target image is a medical image and whether the user instruction is text content related to the medical image.
[0063] Step S20: When the target image meets the requirements of medical visual question answering, the target image and the user instruction are input into a target medical multimodal large language model to generate a corresponding target answer. The target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model. The multi-level feature alignment module includes an attention-based image block selector and a context information fuser.
[0064] It should be noted that the step of inputting the target image and the user instruction into the target medical multimodal large language model to generate a corresponding target response includes:
[0065] Step S201: input the target image into the visual encoder to obtain visual features.
[0066] It should be explained that the above-mentioned visual encoder can be a Vision Transformer (ViT) model, which is used to extract visual features of the target image. Compared with the traditional convolutional neural network (CNN), ViT has better long-distance information capture capabilities, can learn the global dependencies between features through the self-attention mechanism, and has better scalability and generalization capabilities.
[0067] In the specific implementation, this embodiment selects the visual basic pre-training model CLIP containing billions of parameters. For a given target image , where H and W represent the height and width of the target image respectively. This example uses the pre-trained CLIP to obtain the visual feature X:
[0068]
[0069] in, , , C represents the number of embedding channels, and p represents the number of blocks of the target image.
[0070] Step S202: input the visual features and the user instructions into the text encoder to generate a text query vector.
[0071] It should be noted that the above-mentioned text encoder is a multimodal text encoder, which can be a Q-Former model or a Bert model. This embodiment uses the Q-Former model as a multimodal text encoder for illustration. Q-Former is specially designed to process multimodal instructions. It introduces the visual perception part based on Transformer, and can integrate the features of the image into the text representation. Q-Former can learn the text representation that is most relevant to vision through multi-stage multi-task pre-training, and achieve good performance in downstream tasks. For a given user instruction T and visual feature X, this embodiment generates a text query vector through the text encoder. :
[0072] ;
[0073] In the formula, , K represents the number of text query vectors, and D represents the dimension of the text query vector. Through this multimodal text encoder, it can be ensured that the query vector contains more textual representations related to visual cues.
[0074] Step S203: inputting the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features.
[0075] It should be noted that the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device.
[0076] It should be understood that in the medical multimodal large language model, the most critical step is to find the main targets in the image, which represent the organs or parts that need to be focused on in the medical image.
[0077] It should be explained that the above-mentioned attention-based image block selector can evaluate the importance of each image block in the visual feature through cross-modal attention weights, and select the most important part to represent the entire image.
[0078] It should be noted that in the medical multimodal large language model, context information is as important as the key image area, and they represent the image details that need to be paid attention to in the multimodal question answering task. Therefore, this embodiment uses a context information fuser to fuse the image key area features selected in the target image and the unselected context image information, instead of directly discarding the context information, to obtain context fusion features.
[0079] Step S204: Input the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target response.
[0080] It should be noted that the above-mentioned text decoder based on the large language model includes a visual projection layer, a semantic projection layer and a large language model.
[0081] Step S30: Return the target reply to the user.
[0082] This embodiment obtains the target image and user instructions input by the user, and determines whether the target image and the user instructions meet the requirements of medical visual question answering; when the target image meets the requirements of medical visual question answering, the target image and the user instructions are input into the target medical multimodal large language model to generate a corresponding target reply, the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device; the target reply is returned to the user. Since the target medical multimodal large language model of this embodiment includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device, compared with the prior art, this embodiment improves the model's attention to key areas of the image and the model's ability to understand context details, thereby improving the accuracy of the reply.
[0083] refer to Figure 2 , Figure 2 4 is a flow chart of the second embodiment of the medical visual question answering method of the present invention.
[0084] Based on the first embodiment, in this embodiment, step S203 includes steps S2031-S2032:
[0085] Step S2031: input the visual features and the text query vector into the attention-based image block selector to obtain image key area features and contextual image information.
[0086] It should be noted that the goal of the attention-based image block selector in this embodiment is to evaluate the importance of each image block in the visual features through cross-modal attention weights, and select the most important part to represent the entire image.
[0087] In a specific implementation, the attention weight matrix can be calculated based on the visual features and the text query vector through a preset matrix multiplication; the cross-modal feature distribution of the attention weight matrix is predicted through a preset lightweight module, and the preset lightweight module is a lightweight module including several multi-layer perceptrons; by sampling the cross-modal feature distribution, the key area features of the image and the contextual image information are selected based on the sampling results.
[0088] It needs to be explained that the above preset matrix multiplication is:
[0089] ;
[0090] In the formula, Represents visual features, represents the transpose of the visual features, represents the text query vector, and is a learnable parameter, represents the attention weight matrix, K represents the number of text query vectors, , represents the number of blocks of the target image, and H and W represent the height and width of the target image respectively.
[0091] It should be noted that the above attention weight matrix can be expressed as follows by predicting the cross-modal feature distribution through a preset lightweight module: , where MLP stands for Multi-Layer Perceptron.
[0092] By distributing Sampling, we can get a binary decision mask In order to relax the sampling and make it differentiable, the present invention distributes the cross-modal features Adopt Gumbel-Softmax technique.
[0093] In a specific implementation, the step of sampling the cross-modal feature distribution and selecting the image key area features and contextual image information based on the sampling results includes: processing the cross-modal feature distribution using the Gumbel-Softmax technique to obtain a processed cross-modal feature distribution; sampling the processed cross-modal feature distribution to obtain a binary decision mask; and selecting the image key area features and contextual image information based on the binary decision mask.
[0094] It needs to be explained that the Gumbel-Softmax technique is:
[0095] ;
[0096] In the formula, represents the cross-modal feature distribution, represents the cross-modal feature distribution after processing, is a sample of independent and identically distributed random variables randomly sampled from a Gumbel (0,1) distribution, It is the temperature parameter used to control the smoothness of the softmax function, and exp represents the natural exponential function.
[0097] It should be noted that the Gumbel (0,1) distribution can be obtained by using the inverse transform sampling, that is, taking And calculate . The higher the value, the smoother the output of the softmax function will be, and the more diverse the results will be. On the contrary, the output will be steeper, and the model will tend to select image blocks with higher scores. After that, the binary decision mask M can be obtained from Through this binary decision mask, the key area features of the selected image can be obtained and unselected context image information , where P is the number of image blocks of key area features in the image.
[0098] Step S2032: The key area features of the image and the contextual image information are fused and represented by the contextual information fuser to obtain contextual fusion features. The contextual information fuser is composed of a multi-layer stacked Transformer decoder module, and each of the Transformer decoder modules includes a causal self-attention layer, a cross-attention layer and a feedforward neural network layer.
[0099] The schematic diagram of the above context information fusion device can be referred to Figure 3 , Figure 3 FIG. 1 is a schematic diagram of the structure of the context information fusion device in the medical visual question answering method of the present invention. The Transformer decoder module consists of a stacked layer of Transformer decoder modules. Each Transformer decoder module includes a causal self-attention layer, a cross attention layer, and a feedforward neural network layer. In the specific implementation, the selected image is divided into blocks (image key area features ) is input into the causal self-attention layer to obtain the updated image key area features, and then the context image is divided into blocks (context image information ) is used as the query, and the updated image key area features are used as keys and values to perform context information fusion based on feature space similarity to obtain context information fusion features (in the figure, Q, K, and V represent learnable parameter matrices). The context information fusion features are then input into the feedforward neural network layer. Finally, after the L-layer context information fuser, the final context fusion features can be obtained. .
[0100] It should be noted that the cross-attention layer uses the context image information as a query, and uses the image key area features updated by the causal self-attention layer as keys and values to perform context information fusion based on feature space similarity to obtain context information fusion features.
[0101] The information fusion of the cross attention layer is expressed as:
[0102] ;
[0103] In the formula, , , is the learnable parameter matrix, is the key area feature of the image, P is the number of key area features of the image, C represents the number of embedding channels, is the key area feature of the image after the causal self-attention layer updates, It is the context information fusion feature.
[0104] In this embodiment, the visual features and the text query vector are input into the attention-based image block selector to obtain image key area features and context image information; the image key area features and the context image information are fused and represented by the context information fusion device to obtain context fusion features. The context information fusion device is composed of a multi-layer stacked Transformer decoder module, each of which includes a causal self-attention layer, a cross-attention layer and a feedforward neural network layer. Compared with the prior art, this embodiment can dynamically obtain the image key area features and context fusion features in each image through the attention-based image block selector and the context information fusion device, which effectively improves the model's attention to the key areas of the image and the model's ability to understand the context details.
[0105] refer to Figure 4 , Figure 4 4 is a flow chart of the third embodiment of the medical visual question answering method of the present invention.
[0106] Based on the above embodiments, in this embodiment, step S204 includes steps S2041 to S2044:
[0107] Step S2041: splicing the image key area features and the context fusion features to obtain target visual features.
[0108] It should be understood that by combining the image key area features and the context fusion features, a complete visual feature, namely the target visual feature, can be obtained. , the splicing operation can be expressed as:
[0109]
[0110] in, , C represents the number of embedding channels.
[0111] Step S2042: Based on the input dimension of the large language model, the target visual features are linearly mapped through the visual projection layer to obtain visual information.
[0112] Step S2043: Based on the input dimension of the large language model, the text query vector is linearly mapped through the semantic projection layer to obtain semantic information.
[0113] It should be noted that since the medical multimodal large language model needs to generate professional and complex text responses based on the input target image and user instructions, the text decoder needs to have strong text understanding and text generation capabilities. and text query vector Mapped to the dimensions of the pre-trained large language model:
[0114] ;
[0115] ;
[0116] Among them, and are all learnable parameters, visual information , semantic information , is the input dimension of the large language model.
[0117] Step S2044: splicing the visual information and the semantic information and inputting them into the large language model to generate a corresponding target response.
[0118] It is understandable that after the linear mapping of the visual projection layer and the semantic projection layer, both the visual information and the semantic information are converted into the language space. These visual information and semantic information can be used in the subsequent large language model to generate the corresponding target response:
[0119] ;
[0120] in, Represents pre-trained large language models, such as LLaMA-2, ChatGLM, Baichuan, and LLaMA. With the powerful text generation capabilities of these large language models, it can effectively ensure that the target responses generated by the model are rich in sufficient semantic information and improve model performance.
[0121] For example, refer to Figure 5 , Figure 5The overall structure diagram of the target medical multimodal large language model in the medical visual question answering method of the present invention is shown in FIG. In the figure, the target image (medical image) is input into the image encoder (visual encoder) to obtain the visual feature X, and the user instruction (write a comprehensive medical report according to the attached figure) is input into the text encoder to obtain the text query vector , visual features X and text query vector Input to the attention-based image block selector in the multi-level feature alignment module to obtain the selected image blocks (image key area features ) and unselected context image blocks (context image information ), the key area features of the image and contextual image information Input to the context information fusion in the multi-level feature alignment module to obtain context fusion features ,Will and Input to the visual projection layer to obtain visual information , the text query vector Input to the semantic projection layer to obtain semantic information , and then the visual tokens corresponding to the visual information and the semantic tokens corresponding to the semantic information are input into the LLM decoder (large language model) to generate the corresponding target response (the heart contour is slightly enlarged, mainly the left ventricle, the aorta remains curved, the pulmonary blood vessels are not congested, there is some mild atelectasis at the lung base, but there are no focal fusion lesions).
[0122] It should be noted that LoRA, the full name of Low-Rank Adaptation, is a lightweight fine-tuning technology for large language models (such as the GPT series). It allows the model to adapt to new tasks or data by adding low-rank matrices while keeping the original pre-trained weights unchanged. It has the advantages of high computational efficiency, small memory usage and easy migration.
[0123] This embodiment concatenates the key area features of the image and the context fusion features to obtain target visual features; based on the input dimension of the large language model, the target visual features are linearly mapped through the visual projection layer to obtain visual information; based on the input dimension of the large language model, the text query vector is linearly mapped through the semantic projection layer to obtain semantic information; the visual information and the semantic information are concatenated and input into the large language model to generate the corresponding target response. Compared with the prior art, this embodiment can effectively ensure that the target response generated by the model is rich in sufficient semantic information and improve the model performance.
[0124] In addition, an embodiment of the present invention further provides a storage medium, on which a medical visual question answering program is stored. When the medical visual question answering program is executed by a processor, the steps of the medical visual question answering method described above are implemented.
[0125] Reference Figure 6 , Figure 6 This is a structural block diagram of the first embodiment of the medical visual question-answering device of the present invention.
[0126] like Figure 6 As shown, the medical visual question-answering device proposed in the embodiment of the present invention includes: a data acquisition module 601, a reply generation module 602 and a reply return module 603.
[0127] The data acquisition module 601 is used to acquire the target image and user instructions input by the user, and determine whether the target image and the user instructions meet the requirements of medical visual question answering.
[0128] The answer generation module 602 is used to input the target image and the user instruction into the target medical multimodal large language model to generate a corresponding target answer when the target image meets the medical visual question and answer requirements. The target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model. The multi-level feature alignment module includes an attention-based image block selector and a context information fuser.
[0129] The reply returning module 603 is used to return the target reply to the user.
[0130] The reply generation module 602 is also used to input the target image into the visual encoder to obtain visual features; input the visual features and the user instructions into the text encoder to generate a text query vector; input the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features; input the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target reply.
[0131] The embodiment of the present device obtains the target image and user instruction input by the user, and determines whether the target image and the user instruction meet the requirements of medical visual question answering; when the target image meets the requirements of medical visual question answering, the target image and the user instruction are input into the target medical multimodal large language model to generate a corresponding target reply, the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device; and the target reply is returned to the user. Since the target medical multimodal large language model of the present device embodiment includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device, compared with the prior art, the embodiment of the present device improves the model's attention to key areas of the image and the model's ability to understand context details, thereby improving the accuracy of the reply.
[0132] Based on the above-mentioned first embodiment of the medical visual question-answering device of the present invention, a second embodiment of the medical visual question-answering device of the present invention is proposed.
[0133] In this embodiment, the reply generation module 602 is also used to input the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information; the image key area features and the context image information are fused and represented by the context information fuser to obtain context fusion features, and the context information fuser is composed of multiple layers of stacked Transformer decoder modules, each of which includes a causal self-attention layer, a cross attention layer and a feedforward neural network layer.
[0134] The reply generation module 602 is also used to calculate the attention weight matrix based on the visual features and the text query vector through a preset matrix multiplication; predict the cross-modal feature distribution of the attention weight matrix through a preset lightweight module, and the preset lightweight module is a lightweight module including several multi-layer perceptrons; and obtain the image key area features and contextual image information by sampling the cross-modal feature distribution based on the sampling results.
[0135] The response generation module 602 is also used to process the cross-modal feature distribution using the Gumbel-Softmax technique to obtain a processed cross-modal feature distribution; sample the processed cross-modal feature distribution to obtain a binary decision mask; and select image key area features and contextual image information based on the binary decision mask.
[0136] Other embodiments or specific implementations of the medical visual question-and-answer device of the present invention may refer to the above-mentioned method embodiments, which will not be described in detail here.
[0137] The present application provides a medical visual question-answering device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the medical visual question-answering method in the above-mentioned embodiment one.
[0138] Reference below Figure 7 , which shows a schematic diagram of the structure of a medical visual question-answering device suitable for implementing an embodiment of the present application. The medical visual question-answering device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The medical visual question-answering device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0139] like Figure 7As shown, the medical visual question-answering device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the medical visual question-answering device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the medical visual question-answering device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a medical visual question-answering device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0140] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0141] The medical visual question-answering device provided by the present application adopts the medical visual question-answering method in the above-mentioned embodiment, which can solve the technical problem that in medical scenarios, when faced with complex visual and text inputs, it is difficult to capture the complex relationship between vision and text, thereby limiting the expressive ability of the model. Compared with the prior art, the beneficial effects of the medical visual question-answering device provided by the present application are the same as the beneficial effects of the medical visual question-answering method provided by the above-mentioned embodiment, and the other technical features in the medical visual question-answering device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0142] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0143] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0144] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0145] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0147] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A medical visual question answering method, characterized in that: The method comprises: Acquire a target image and a user instruction input by a user, and determine whether the target image and the user instruction meet the medical visual question answering requirements; When the target image meets the medical visual question-answering requirements, the target image and the user instruction are input into a target medical multimodal large language model to generate a corresponding target answer, wherein the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, and the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device; returning the target reply to the user; The step of inputting the target image and the user instruction into the target medical multimodal large language model to generate a corresponding target response includes: Inputting the target image into the visual encoder to obtain visual features; Inputting the visual features and the user instructions into the text encoder to generate a text query vector; Inputting the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features; Inputting the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target answer; The step of inputting the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features includes: Inputting the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information; The key area features of the image and the context image information are fused and represented by the context information fuser to obtain context fusion features, wherein the context information fuser is composed of a multi-layer stacked Transformer decoder module, each of which includes a causal self-attention layer, a cross attention layer and a feedforward neural network layer; The step of inputting the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information comprises: Based on the visual features and the text query vector, calculating an attention weight matrix by a preset matrix multiplication; For the attention weight matrix, predicting the cross-modal feature distribution through a preset lightweight module, wherein the preset lightweight module is a lightweight module including a plurality of multi-layer perceptrons; By sampling the cross-modal feature distribution, the key area features of the image and the contextual image information are obtained based on the sampling results; Wherein, the preset matrix multiplication is: ; In the formula, Represents visual features, represents the transpose of the visual features, represents the text query vector, and is a learnable parameter, represents the attention weight matrix, K represents the number of text query vectors, , represents the number of blocks of the target image, and H and W represent the height and width of the target image respectively.
2. The medical visual question answering method according to claim 1, characterized in that: The step of sampling the cross-modal feature distribution and selecting and obtaining the key area features of the image and the context image information based on the sampling result includes: The cross-modal feature distribution is processed using the Gumbel-Softmax technique to obtain a processed cross-modal feature distribution; Sampling the processed cross-modal feature distribution to obtain a binary decision mask; Selecting and obtaining key image region features and context image information based on the binary decision mask; Among them, the Gumbel-Softmax technique is: ; In the formula, represents the cross-modal feature distribution, represents the cross-modal feature distribution after processing, is a sample of independent and identically distributed random variables randomly sampled from a Gumbel (0,1) distribution, It is the temperature parameter used to control the smoothness of the softmax function, and exp represents the natural exponential function.
3. The medical visual question answering method according to claim 1, characterized in that: The cross attention layer uses the context image information as a query, and uses the image key area features updated by the causal self-attention layer as keys and values to perform context information fusion based on feature space similarity to obtain context information fusion features; The information fusion of the cross attention layer is expressed as: ; In the formula, , , is the learnable parameter matrix, is the key area feature of the image, P is the number of key area features of the image, C represents the number of embedding channels, is the key area feature of the image after the causal self-attention layer updates, is the context information fusion feature, is the context image information.
4. The medical visual question answering method according to claim 1, characterized in that: The text decoder based on the large language model includes a visual projection layer, a semantic projection layer and a large language model; Accordingly, the step of inputting the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target answer includes: Splicing the image key area features and the context fusion features to obtain target visual features; Based on the input dimension of the large language model, linearly mapping the target visual features through the visual projection layer to obtain visual information; Based on the input dimension of the large language model, linearly mapping the text query vector through the semantic projection layer to obtain semantic information; The visual information and the semantic information are concatenated and input into the large language model to generate a corresponding target response.
5. A medical visual question-answering device, characterized in that: The device comprises: A data acquisition module, used to acquire a target image and a user instruction input by a user, and determine whether the target image and the user instruction meet the requirements of medical visual question answering; A reply generation module, used for inputting the target image and the user instruction into a target medical multimodal large language model to generate a corresponding target reply when the target image meets the medical visual question answering requirements, wherein the target medical multimodal large language model includes a visual encoder, a text encoder, a multi-level feature alignment module and a text decoder based on a large language model, and the multi-level feature alignment module includes an attention-based image block selector and a context information fusion device; A reply returning module, used for returning the target reply to the user; The reply generation module is further used to input the target image into the visual encoder to obtain visual features; input the visual features and the user instructions into the text encoder to generate a text query vector; input the visual features and the text query vector into the multi-level feature alignment module to obtain image key area features and context fusion features; input the image key area features, the context fusion features and the text query vector into the text decoder based on the large language model to generate a corresponding target reply; The reply generation module is further used to input the visual features and the text query vector into the attention-based image block selector to obtain image key area features and context image information; fuse the image key area features and the context image information through the context information fusion device to obtain context fusion features, and the context information fusion device is composed of multiple layers of stacked Transformer decoder modules, each of which includes a causal self-attention layer, a cross attention layer and a feedforward neural network layer; The reply generation module is further used to calculate an attention weight matrix based on the visual features and the text query vector by a preset matrix multiplication; predict the cross-modal feature distribution of the attention weight matrix by a preset lightweight module, wherein the preset lightweight module is a lightweight module including a plurality of multi-layer perceptrons; and obtain image key area features and contextual image information by sampling the cross-modal feature distribution based on the sampling results; Wherein, the preset matrix multiplication is: ; In the formula, Represents visual features, represents the transpose of the visual features, represents the text query vector, and is a learnable parameter, represents the attention weight matrix, K represents the number of text query vectors, , represents the number of blocks of the target image, and H and W represent the height and width of the target image respectively.
6. A medical visual question-answering device, characterized in that: The device comprises: a memory, a processor, and a medical visual question answering program stored in the memory and executable on the processor, wherein the medical visual question answering program is configured to implement the steps of the medical visual question answering method according to any one of claims 1 to 4.
7. A storage medium, characterized in that: The storage medium stores a medical visual question answering program, and when the medical visual question answering program is executed by the processor, the steps of the medical visual question answering method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Visual question and answer oriented method of context awareness based on multi-modal interaction
CN114970517A
