Image-text retrieval method and device in remote sensing field based on prompt learning
By using multi-layer text prompts and learnable prompts in image-text retrieval in the field of remote sensing, the image-text encoder is optimized to solve the problems of high computing power consumption and low flexibility in the existing technology, and achieve efficient and fast Image-text retrieval and flexible model training.
Patent Information
- Application Number
- CN202410829745.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-09-24
AI Technical Summary
Existing image-text retrieval methods in the field of remote sensing consume a lot of computing power and time, have poor flexibility, and cannot effectively cope with new data set requirements.
A prompt-based learning method is adopted to optimize the image-text encoder through multi-layer text prompts and learnable prompts. Only the parameters of the prompt learning module and adapter module are updated to reduce the amount of calculation and training time and improve flexibility.
It reduces computing power consumption and time in image-text retrieval in the field of remote sensing, improves retrieval efficiency, and enhances the flexibility of the model to adapt to the needs of different data sets.
Smart Images

Figure CN118690034A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of remote sensing image technology, and in particular to an image-text retrieval method and device in the remote sensing field based on prompt learning. Background Art
[0002] Cross-modal image-text retrieval is an important task in multimodal information processing, which aims to retrieve relevant text based on the query image and retrieve matching images based on the query text. With the development of sensors and Internet technology, multi-modal data is growing rapidly, and the application scope of cross-modal image-text retrieval is becoming more and more extensive. For example, image-text retrieval technology in general (natural) fields accurately searches for relevant images based on a descriptive text. When it comes to professional fields (such as remote sensing image retrieval), image-text retrieval technology in specific fields can more deeply understand the semantic information in professional fields by matching images with relevant texts, and realize the retrieval of target images.
[0003] At present, for image-text retrieval in the remote sensing field, remote sensing image-text data is usually used to fully fine-tune the Contrastive Language-Image Pre-Training (CLIP) model of contrastive learning, and then the optimized model obtained by training is used to implement remote sensing image-text retrieval. However, due to the large size of the CLIP encoder, the full fine-tuning method requires updating all parameters, which generates a huge amount of calculation, consumes more computing power and time, and when a new data set needs to be trained, the full fine-tuning method requires changing all parameters of the model, which has poor flexibility. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide an image-text retrieval method and device in the remote sensing field based on prompt learning, so as to solve the problem that image-text retrieval in the remote sensing field requires more computing power and time and has poor flexibility.
[0005] To solve the above technical problems, the embodiments of the present invention provide the following technical solutions:
[0006] A first aspect of the present invention provides an image-text retrieval method in the remote sensing field based on prompt learning, the method comprising:
[0007] Preset processing is performed on the image modality data and the text modality data respectively, and an input image and an input text are obtained correspondingly;
[0008] Input the input text and multi-layer text prompts into the text encoder, and output the text feature vector;
[0009] Determine the image feature vector based on the input image, the text prompts of each layer, the prompt learning module and the image encoder. The prompt learning module includes a Transformer module and a fully connected layer.
[0010] The learnable hint, text feature vector and image feature vector are input into the adapter module respectively, and the final text feature vector and the final image feature vector are outputted accordingly;
[0011] According to the final text feature vector and the final image feature vector, the image-text contrast loss and the symmetry loss are calculated, and back-propagation optimization is performed based on the contrast loss and the symmetry loss to obtain an optimized retrieval model;
[0012] The test data set is input into the optimized retrieval model and a similarity matrix is output to determine the matching results between the image and the text in the test data set according to the similarity matrix.
[0013] The second aspect of the present application provides an image-text retrieval device in the remote sensing field based on prompt learning, the device comprising:
[0014] A processing module, used to perform preset processing on the image modality data and the text modality data respectively, and obtain an input image and an input text correspondingly;
[0015] A first input module, for inputting input text and multi-layer text prompts into a text encoder, and outputting a text feature vector;
[0016] A first determination module is used to determine an image feature vector according to an input image, text prompts of each layer, a prompt learning module and an image encoder, wherein the prompt learning module includes a Transformer module and a fully connected layer;
[0017] A second input module is used to input the learnable prompt, the text feature vector and the image feature vector into the adapter module respectively, and output the final text feature vector and the final image feature vector accordingly;
[0018] A calculation module, used to calculate the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector, and perform back propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model;
[0019] The second determination module is used to input the test data set into the optimized retrieval model and output a similarity matrix to determine the matching results between the image and the text in the test data set according to the similarity matrix.
[0020] Compared with the prior art, the image-text retrieval method and device in the remote sensing field based on prompt learning provided by the present invention inputs input text and multi-layer text prompts into a text encoder, and outputs a text feature vector; determines an image feature vector according to an input image, text prompts at each layer, a prompt learning module and an image encoder; inputs a learnable prompt, a text feature vector and an image feature vector into an adapter module respectively, and outputs a final text feature vector and a final image feature vector accordingly; calculates image-text contrast loss and symmetry loss according to the final text feature vector and the final image feature vector, and performs back propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model; inputs a test data set into the optimized retrieval model, and outputs a similarity matrix, so as to determine the matching result between the image and the text in the test data set according to the similarity matrix. In this way, multi-layer text prompts are used as input of the text encoder, the image feature vector is determined through each layer of text prompts, and the learnable prompts are used as input of the adapter module. Multi-layer text prompts and learnable prompts are used to retrieve image-text in the remote sensing field, so that the computational amount of the retrieval is smaller, and thus the retrieval consumes less computing power and time. In the process of obtaining the optimized retrieval model, only the parameters of the prompt learning module and the adapter module are trained, so that the parameters are less, and thus the retrieval flexibility is better. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] By reading the detailed description below with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0022] Figure 1 Schematic diagram of the process of image-text retrieval method in remote sensing based on prompt learning Figure 1 ;
[0023] Figure 2 Schematic diagram of the process of image-text retrieval method in remote sensing based on prompt learning Figure 2 ;
[0024] Figure 3 The overall framework of image-text retrieval in the remote sensing field based on prompt learning is schematically shown;
[0025] Figure 4 The structure diagram of an image-text retrieval device in the remote sensing field based on prompt learning is schematically shown. DETAILED DESCRIPTION
[0026] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.
[0027] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in the present invention should have the common meanings understood by those skilled in the art to which the present invention belongs.
[0028] The method in the embodiment of the present invention is described in detail below.
[0029] Figure 1 The flowchart of the image-text retrieval method for remote sensing based on prompt learning in an embodiment of the present invention is schematically shown. Figure 1 As shown, the method may include:
[0030] S101 . Perform preset processing on image modality data and text modality data respectively, and obtain input images and input texts accordingly.
[0031] Before performing preset processing on the image modality data and the text modality data respectively to obtain the input image and the input text correspondingly, the method further includes:
[0032] Acquire multimodal data, where the multimodal data includes image modality data and text modality data.
[0033] Preset processing includes chunking, encoding, or input tokenizer.
[0034] S102, inputting the input text and the multi-layer text prompt into a text encoder, and outputting a text feature vector.
[0035] The text encoder is in the CLIP model and is a text encoder based on a multi-layer Transformer.
[0036] Specifically, the input text and the multi-layer text prompts are input into a text encoder based on a multi-layer Transformer to perform text encoding calculations and output a text feature vector.
[0037] S103, determining an image feature vector according to the input image, the text prompts of each layer, the prompt learning module and the image encoder.
[0038] Among them, the prompt learning module includes a Transformer module and a fully connected layer, and the text prompts of each layer are used as the input of the prompt learning module.
[0039] The image encoder is in the CLIP model, which is an image encoder based on a multi-layer Transformer. The text encoder and the image encoder constitute the CLIP model.
[0040] Specifically, image encoding calculation is performed according to the input image, the text prompts of each layer, the prompt learning module and the image encoder to determine the image feature vector.
[0041] S104, inputting the learnable hint, the text feature vector and the image feature vector into the adapter module respectively, and outputting the final text feature vector and the final image feature vector accordingly.
[0042] The adapter module includes a Transformer module and takes a learnable cue as input.
[0043] S105. Calculate the image-text contrast loss and the symmetry loss based on the final text feature vector and the final image feature vector, and perform back-propagation optimization based on the contrast loss and the symmetry loss to obtain an optimized retrieval model.
[0044] S106: Input the test data set into the optimized retrieval model and output a similarity matrix to determine the matching results between the images and texts in the test data set according to the similarity matrix.
[0045] Specifically, the test data set is input into the optimized retrieval model, the optimized retrieval model is used to encode the images and texts in the test data set, and a similarity matrix is output to determine the matching results of the image and the text according to the similarity matrix.
[0046] Based on the above Figure 1It can be seen from the implementation method that the embodiment of the present invention performs preset processing on the image modality data and the text modality data respectively, and obtains the input image and input text correspondingly; inputs the input text and the multi-layer text prompts into the text encoder, and outputs the text feature vector; determines the image feature vector according to the input image, the text prompts of each layer, the prompt learning module and the image encoder; inputs the learnable prompts, the text feature vector and the image feature vector into the adapter module respectively, and outputs the final text feature vector and the final image feature vector correspondingly; calculates the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector, and performs back propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model; inputs the test data set into the optimized retrieval model, and outputs the similarity matrix, so as to determine the matching results of the image and the text in the test data set according to the similarity matrix. In this way, multi-layer text prompts are used as input of the text encoder, the image feature vector is determined through each layer of text prompts, and the learnable prompts are used as input of the adapter module. Multi-layer text prompts and learnable prompts are used to retrieve image-text in the remote sensing field, so that the computational amount of the retrieval is smaller, and thus the retrieval consumes less computing power and time. In the process of obtaining the optimized retrieval model, only the parameters of the prompt learning module and the adapter module are trained, so that the parameters are less, and thus the retrieval flexibility is better.
[0047] As a refinement and expansion of the above embodiment, Figure 2 The process of an image-text retrieval method in the remote sensing field based on prompt learning in an embodiment of the present invention is as follows Figure 2 , see Figure 2 As shown, an image-text retrieval method in the remote sensing field based on prompt learning provided by an embodiment of the present invention may include:
[0048] S201 , performing preset processing on the image modality data and the text modality data respectively, and obtaining an input image and an input text correspondingly.
[0049] Specifically, the image modality data and the text modality data are respectively processed in a preset manner to obtain an input image and an input text correspondingly, including:
[0050] Step A1: Divide and encode the image modality data in sequence to obtain an input image.
[0051] Step A2: Input the text modal data into the tagger and output the input text.
[0052] The text modality data is input to a tagger to convert the text modality data into vectors and tag the locations.
[0053] S202, input the input text and the multi-layer text prompt into a text encoder, and output a text feature vector.
[0054] The input text and multi-layer text prompts are input into the text encoder to realize text encoding calculation and output text feature vector.
[0055] Among them, the text encoder is a text encoder based on a multi-layer Transformer, the text encoder includes multi-layer preset Transformer modules, the multi-layer preset Transformer modules include the first layer preset Transformer modules to the K-th layer preset Transformer modules, and the multi-layer text prompts include the first layer text prompts to the K-th layer text prompts.
[0056] The number of layers of multi-layer text prompts is the same as the number of layers of the default Transformer module.
[0057] Before inputting the input text and the multi-layer text prompt into the text encoder and outputting the text feature vector, the method also includes: randomly generating multi-layer prompts and determining the multi-layer prompts as multi-layer text prompts.
[0058] Multi-layer text prompts are added to the calculation process of text feature vectors and image feature vectors to achieve prompt learning.
[0059] Specifically, the input text and multi-layer text prompts are input into the text encoder, and the output text feature vector includes:
[0060] Step B1: Input the input text and the first layer text prompt into the first layer preset Transformer module, and output the first intermediate text feature vector.
[0061] Step B2: Input the first intermediate text feature vector and the second layer text prompt into the second layer preset Transformer module, and output the second intermediate text feature vector.
[0062] Step B3: until the K-1th intermediate text feature vector and the Kth layer text prompt are input into the Kth layer preset Transformer module and the text feature vector is output.
[0063] The following steps S203 to S204 are specific operations for determining the image feature vector based on the input image, the text prompts of each layer, the prompt learning module and the image encoder.
[0064] The prompt learning module includes the Transformer module and the fully connected layer.
[0065] S203, input each layer of text prompts into the Transformer module and the fully connected layer in sequence, and output multi-layer image prompts.
[0066] The number of layers of the multi-layer image prompt is the same as the number of layers of the multi-layer text prompt. The multi-layer image prompt includes the first layer image prompt to the Kth layer image prompt.
[0067] Specifically, each layer of text prompts is input into the Transformer module and the fully connected layer in turn, and multi-layer image prompts are output, including:
[0068] Step C1: Input the first layer of text prompts into the Transformer module and the fully connected layer, and output the first layer of image prompts.
[0069] Step C2: Input the second layer of text prompts into the Transformer module and the fully connected layer, and output the second layer of image prompts.
[0070] Step C3: until the K-th layer of text prompts are input into the Transformer module and the fully connected layer, and the K-th layer of image prompts are output.
[0071] S204, input the input image and the multi-layer image prompt, input the image encoder, and output the image feature vector.
[0072] The image encoder is a multi-layer Transformer-based image encoder, which includes a multi-layer target Transformer module, and the multi-layer target Transformer module includes a first-layer target Transformer module to a K-th-layer target Transformer module.
[0073] The number of layers for multi-layer image cues is the same as the number of layers in the target Transformer module and the number of layers for multi-layer text cues.
[0074] Specifically, the input image and the multi-layer image prompt are input into the image encoder, and the image feature vector is output, including:
[0075] Step D1: The input image and the first layer image prompt are input into the first layer target Transformer module, and the first intermediate image feature vector is output.
[0076] Step D2: The first intermediate image feature vector and the second layer image prompt are input into the second layer target Transformer module, and the second intermediate image feature vector is output.
[0077] Step D3: until the K-1th intermediate image feature vector and the Kth layer image prompt are input into the Kth layer target Transformer module and the image feature vector is output.
[0078] The following steps S205 to S206 are specific operations of inputting the learnable prompt, the text feature vector and the image feature vector into the adapter module respectively, and correspondingly outputting the final text feature vector and the final image feature vector.
[0079] S205: input the learnable prompt and text feature vector into the Transformer module, and output the final text feature vector.
[0080] The adapter module includes the Transformer module, and the adapter module requires learnable cues as input.
[0081] Learnable hints are randomly generated. Learnable hints are variables that can improve the text and image feature output.
[0082] S206: Input the learnable hint and the image feature vector into the Transformer module, and output the final image feature vector.
[0083] S207. Calculate the image-text contrast loss and the symmetry loss based on the final text feature vector and the final image feature vector, and perform back-propagation optimization based on the contrast loss and the symmetry loss to obtain an optimized retrieval model.
[0084] Specifically, according to the final text feature vector and the final image feature vector, the image-text contrast loss and the symmetry loss are calculated, including:
[0085] Step E1: Determine a similarity matrix based on the final text feature vector and the final image feature vector.
[0086] The similarity matrix includes multiple cosine similarities.
[0087] Specifically, the cosine similarity is calculated based on the final text feature vector and the final image feature vector to determine the similarity matrix.
[0088] The similarity matrix includes multiple elements, each element is a cosine similarity.
[0089] Step E2: Calculate the image-text contrast loss (itcLoss) based on the similarity matrix.
[0090] According to the cosine similarity and the number of sample pairs in a training batch, itcLoss is calculated using the following formula:
[0091]
[0092] Among them, L itcis the image-text contrast loss, N is the number of sample pairs in a training batch, exp() is the natural exponential function, and s i,j is the cosine similarity between image i and text j, τ is the temperature coefficient, i is the index of the image, and j is the index of the text.
[0093] Step E3: Calculate the symmetry loss (symLoss) according to the similarity matrix.
[0094] Specifically, according to the similarity matrix, the symmetry loss is calculated, including:
[0095] Based on multiple cosine similarities and the number of sample pairs in a training batch, the symmetry loss is calculated using the following formula:
[0096]
[0097] Among them, L sym is the symmetric loss, N is the number of sample pairs in a training batch, and s i,j is the cosine similarity between image i and text j, in s i,j Where i is the index of the image, j is the index of the text, and s j,i is the cosine similarity between image j and text i, in s j,i Here j is the index of the image and i is the index of the text.
[0098] S208: Input the test data set into the optimized retrieval model and output a similarity matrix to determine the matching results between the image and the text in the test data set according to the similarity matrix.
[0099] Specifically, the test data set is input into the optimized retrieval model, the optimized retrieval model is used to encode the images and texts in the test data set, and a similarity matrix is output to determine the matching results of the image and the text according to the similarity matrix.
[0100] Figure 3The overall framework diagram of image-text retrieval in the remote sensing field based on prompt learning is schematically shown, specifically: the overall retrieval model consists of four parts: CLIP basic module, prompt learning module (Transformer-based interactive prompts, TIP), adapter module (Shared Transformer prompt Adapter, STA) and loss function part. The CLIP basic module includes an image encoder and a text encoder. TIP consists of an interactive transformer (Interactive Transformer, InT) and a process of inputting multi-layer text prompts into the corresponding encoder. InT consists of a Transformer and a fully connected layer. The Transformer includes a multi-head attention layer (Multi-Head Attention), residual connection and layer normalization layer (Add&Norm), linear layer (FeedForward), and Add&Norm layer in turn. STA consists of a shared Transformer adapter (Shared Transformer adapter, ShT) and a series of learnable prompts. ShT is a Transformer that takes learnable prompts as input ( Figure 3 The rightmost gray input in the figure is the text feature vector or image feature vector. The structure of the Transformer in STA is the same as that in InT. Patch Embeded means that the image modality data is divided into blocks and encoded. Word Embeded means that the text modality data is marked and encoded. is an image encoder based on the K-th layer target Transformer module, The text encoding L based on the K-th layer preset Transformer module itc is the image-text comparison loss, L sym is the loss of symmetry.
[0101] Figure 3In the algorithm, first, the input image is passed through the image encoder to obtain the image feature vector, and the input text is passed through the text encoder to obtain the text feature vector. At the same time, a learnable multi-layer text prompt is generated and added to the text encoder calculation of each layer of Transformer. In addition, the multi-layer text prompt is converted into a multi-layer image prompt and added to the image encoder calculation of each layer of Transformer. Then, the image feature vector, text feature vector and learnable prompt are processed through a shared adapter module to obtain the final image feature vector and text feature vector. Finally, the cosine similarity between the image feature vector and the text feature vector is calculated to obtain the matching score. Finally, back-propagation optimization is performed by calculating itcLoss and symLoss.
[0102] The embodiment of the present invention first designs a network with a CLIP model as the backbone, and the CLIP model is composed of an image encoder and a text encoder, and the encoder has multiple layers of calculation. Secondly, the image modality data is passed through the image encoder to obtain an image feature vector, and the text modality data is passed through the text encoder to obtain a text feature vector. At the same time, a learnable multi-layer text prompt is generated and added to the text encoder calculation of each layer. In addition, the text prompt is converted into an image prompt and added to the image encoder calculation of each layer. Again, the image feature vector and the text feature vector are processed by a shared adapter module to obtain the final image feature vector and text feature vector. Again, the image feature vector and the text feature vector are used to calculate the cosine similarity to obtain a matching score. Again, back propagation optimization is performed by calculating itcLoss and symLoss to obtain an optimized retrieval model. Finally, the test data set is input into the optimized retrieval model, and a similarity matrix is output to determine the matching results of the image and text in the test data set according to the similarity matrix. In this way, the learnable multi-layer text prompts are added to the text encoder calculation of each layer, the text prompts are converted into image prompts and added to the image encoder calculation of each layer, and the learnable multi-layer text prompts are used to retrieve images and texts in the remote sensing field, so that the calculation amount of the retrieval is smaller, and thus the retrieval consumes less computing power and time. In the process of obtaining the optimized retrieval model, only the parameters of the prompt learning module and the adapter module are trained, so that the parameters are fewer, and thus the retrieval flexibility is better.
[0103] Based on the same inventive concept, as an implementation of the above-mentioned image-text retrieval method in the remote sensing field based on prompt learning, an embodiment of the present invention also provides an image-text retrieval device in the remote sensing field based on prompt learning. Figure 4 is a structural diagram of the device in the embodiment of the present invention, see Figure 4 As shown, the device may include:
[0104] The processing module 401 is used to perform preset processing on the image modality data and the text modality data respectively, and obtain the input image and the input text correspondingly;
[0105] A first input module 402 is used to input the input text and the multi-layer text prompt processed by the processing module 401 into a text encoder, and output a text feature vector;
[0106] A first determination module 403 is used to determine an image feature vector according to the input image processed by the processing module 401, the text prompts of each layer, the prompt learning module and the image encoder, wherein the prompt learning module includes a Transformer module and a fully connected layer;
[0107] A second input module 404 is used to input the learnable prompt, the text feature vector output by the first input module 402, and the image feature vector determined by the first determination module 403 into the adapter module, and output a final text feature vector and a final image feature vector respectively;
[0108] A calculation module 405 is used to calculate the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector output by the second input module 404, and perform back propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model;
[0109] The second determination module 406 is used to input the test data set into the optimized retrieval model obtained by the calculation module 405, and output a similarity matrix to determine the matching results of the image and text in the test data set according to the similarity matrix.
[0110] The processing module 401 is specifically used to sequentially divide and encode the image modality data to obtain an input image; input the text modality data into a marker and output the input text.
[0111] The first input module 402 is specifically used to input the input text and the first layer of text prompts into the first layer of preset Transformer module, and output the first intermediate text feature vector; input the first intermediate text feature vector and the second layer of text prompts into the second layer of preset Transformer module, and output the second intermediate text feature vector; until, the K-1th intermediate text feature vector and the Kth layer of text prompts are input into the Kth layer of preset Transformer module, and output the text feature vector; the text encoder includes multiple layers of preset Transformer modules, the multiple layers of preset Transformer modules include the first layer of preset Transformer modules to the Kth layer of preset Transformer modules, and the multiple layers of text prompts include the first layer of text prompts to the Kth layer of text prompts.
[0112] The first determination module 403 is specifically used to input each layer of text prompts into the Transformer module and the fully connected layer in sequence, output multi-layer image prompts, and the number of layers of multi-layer image prompts is the same as the number of layers of multi-layer text prompts; input the input image and the multi-layer image prompts into the image encoder, and output the image feature vector.
[0113] The first determination module 403 inputs each layer of text prompts into the Transformer module and the fully connected layer in sequence, and outputs multiple layers of image prompts, including: inputting the first layer of text prompts into the Transformer module and the fully connected layer, and outputting the first layer of image prompts; inputting the second layer of text prompts into the Transformer module and the fully connected layer, and outputting the second layer of image prompts; until, inputting the K-th layer of text prompts into the Transformer module and the fully connected layer, and outputting the K-th layer of image prompts; the multiple layers of image prompts include the first layer of image prompts to the K-th layer of image prompts.
[0114] The first determination module 403 inputs the input image and the multi-layer image prompt into an image encoder and outputs an image feature vector, including: inputting the input image and the first layer image prompt into a first layer target Transformer module and outputting a first intermediate image feature vector;
[0115] The first intermediate image feature vector and the second layer image prompt are input into the second layer target Transformer module, and the second intermediate image feature vector is output; until the K-1th intermediate image feature vector and the Kth layer image prompt are input into the Kth layer target Transformer module, and the image feature vector is output; the image encoder includes a multi-layer target Transformer module, and the multi-layer target Transformer module includes the first layer target Transformer module to the Kth layer target Transformer module.
[0116] The second input module 404 is specifically used to input the learnable prompt and text feature vector into the Transformer module and output the final text feature vector; input the learnable prompt and image feature vector into the Transformer module and output the final image feature vector; the adapter module includes the Transformer module.
[0117] The calculation module 405 calculates the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector, including: determining the similarity matrix according to the final text feature vector and the final image feature vector; calculating the image-text contrast loss according to the similarity matrix; and calculating the symmetry loss according to the similarity matrix.
[0118] The calculation module 405 calculates the symmetry loss according to the similarity matrix, including: calculating the symmetry loss according to multiple cosine similarities and the number of sample pairs in a training batch using the following formula:
[0119]
[0120] Among them, L sym is the symmetric loss, N is the number of sample pairs in a training batch, and s i,j is the cosine similarity between image i and text j, in s i,j Where i is the index of the image, j is the index of the text, and s j,i is the cosine similarity between image j and text i, in s j,i Where j is the index of the image, i is the index of the text; the similarity matrix includes multiple cosine similarities.
[0121] It should be pointed out here that the above description of the embodiment of the image-text retrieval device in the remote sensing field based on prompt learning is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the embodiment of the image-text retrieval device in the remote sensing field based on prompt learning of the embodiment of the present invention, please refer to the description of the method embodiment of the present invention for understanding.
[0122] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the 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.
Claims
1. An image-text retrieval method in remote sensing based on prompt learning, characterized in that: The image-text retrieval method comprises: Preset processing is performed on the image modality data and the text modality data respectively, and an input image and an input text are obtained correspondingly; Inputting the input text and the multi-layer text prompt into a text encoder and outputting a text feature vector; Determining an image feature vector according to the input image, the text prompts of each layer, a prompt learning module and an image encoder, wherein the prompt learning module includes a Transformer module and a fully connected layer; Inputting the learnable hint, the text feature vector and the image feature vector into an adapter module respectively, and outputting a final text feature vector and a final image feature vector correspondingly; Calculating the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector, and performing back-propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model; The test data set is input into the optimized retrieval model, and a similarity matrix is output to determine the matching results between the image and the text in the test data set according to the similarity matrix.
2. The image-text retrieval method according to claim 1, characterized in that: The image modality data and the text modality data are respectively processed in a preset manner to obtain an input image and an input text correspondingly, including: Sequentially dividing and encoding the image modality data to obtain the input image; The text modality data is input to a tokenizer, and the input text is output.
3. The image-text retrieval method according to claim 1, characterized in that: The text encoder includes multiple layers of preset Transformer modules, the multiple layers of preset Transformer modules include a first layer of preset Transformer modules to a Kth layer of preset Transformer modules, and the multiple layers of text prompts include a first layer of text prompts to a Kth layer of text prompts; The step of inputting the input text and the multi-layer text prompt into a text encoder and outputting a text feature vector comprises: Input the input text and the first layer text prompt into the first layer preset Transformer module, and output a first intermediate text feature vector; Input the first intermediate text feature vector and the second layer text prompt into the second layer preset Transformer module, and output the second intermediate text feature vector; Until the K-1th intermediate text feature vector and the Kth layer text prompt are input into the Kth layer preset Transformer module, and the text feature vector is output.
4. The image-text retrieval method according to claim 3, characterized in that: The step of determining an image feature vector according to the input image, the text prompts of each layer, the prompt learning module and the image encoder comprises: Inputting the layers of text prompts into the Transformer module and the fully connected layer in sequence, respectively, and outputting multi-layer image prompts, wherein the number of layers of the multi-layer image prompts is the same as the number of layers of the multi-layer text prompts; The input image and the multi-layer image prompt are input into the image encoder, and the image feature vector is output.
5. The image-text retrieval method according to claim 4, characterized in that: The multi-layer image prompt includes the first layer image prompt to the Kth layer image prompt, and the text prompts of each layer are input into the Transformer module and the fully connected layer in sequence, and the multi-layer image prompt is output, including: Input the first layer of text prompts into the Transformer module and the fully connected layer, and output the first layer of image prompts; Input the second layer of text prompts into the Transformer module and the fully connected layer, and output the second layer of image prompts; Until the K-th layer of text prompts is input into the Transformer module and the fully connected layer, and the K-th layer of image prompts is output.
6. The image-text retrieval method according to claim 5, characterized in that: The image encoder includes a multi-layer target Transformer module, the multi-layer target Transformer module includes a first layer target Transformer module to a K-th layer target Transformer module, the input image and the multi-layer image prompt are input into the image encoder, and the image feature vector is output, including: The input image and the first layer image prompt are input into the first layer target Transformer module, and a first intermediate image feature vector is output; Input the first intermediate image feature vector and the second layer image prompt into the second layer target Transformer module, and output the second intermediate image feature vector; Until the K-1th intermediate image feature vector and the Kth layer image prompt are input into the Kth layer target Transformer module, and the image feature vector is output.
7. The image-text retrieval method according to claim 1, characterized in that: The adapter module includes a Transformer module, and the learnable prompt, the text feature vector, and the image feature vector are respectively input into the adapter module, and the corresponding final text feature vector and final image feature vector are output, including: Input the learnable hint and the text feature vector into the Transformer module, and output the final text feature vector; The learnable hint and the image feature vector are input into the Transformer module, and the final image feature vector is output.
8. The image-text retrieval method according to claim 1, characterized in that: The calculating the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector includes: Determining a similarity matrix according to the final text feature vector and the final image feature vector; Calculating the image-text comparison loss according to the similarity matrix; The symmetry loss is calculated according to the similarity matrix.
9. The image-text retrieval method according to claim 8, characterized in that: The similarity matrix includes a plurality of cosine similarities, and the calculating the symmetry loss according to the similarity matrix includes: According to the multiple cosine similarities and the number of sample pairs in a training batch, the symmetry loss is calculated using the following formula: Among them, L sym is the symmetry loss, N is the number of sample pairs in a training batch, and s i,j is the cosine similarity between image i and text j, in s i,j Where i is the index of the image, j is the index of the text, and s j,i is the cosine similarity between image j and text i, in s j,i Here j is the index of the image and i is the index of the text.
10. An image-text retrieval device in the remote sensing field based on prompt learning, characterized in that: The image-text retrieval device comprises: A processing module, used to perform preset processing on the image modality data and the text modality data respectively, and obtain an input image and an input text correspondingly; A first input module, used for inputting the input text and the multi-layer text prompt into a text encoder, and outputting a text feature vector; A first determination module, configured to determine an image feature vector according to the input image, text prompts of each layer, a prompt learning module and an image encoder, wherein the prompt learning module includes a Transformer module and a fully connected layer; A second input module, used for inputting the learnable hint, the text feature vector and the image feature vector into an adapter module respectively, and outputting a final text feature vector and a final image feature vector correspondingly; A calculation module, used for calculating the image-text contrast loss and the symmetry loss according to the final text feature vector and the final image feature vector, and performing back propagation optimization according to the contrast loss and the symmetry loss to obtain an optimized retrieval model; The second determination module is used to input the test data set into the optimized retrieval model and output a similarity matrix to determine the matching results of the images and texts in the test data set according to the similarity matrix.
Citation Information
Patent Citations
Cross-modal retrieval confrontation and defense method based on prompt learning
CN115658954A
Novel unsupervised image quality evaluation method based on multi-mode prompt learning
CN117078656A
Small sample visual classification method and device based on retrieval enhancement mechanism and visual cue learning
CN117953282A
Cited By
Remote sensing image text retrieval method and device based on Mamba adapter and sharing prompt enhancement
CN120144816A
Trademark retrieval library generation method and device based on multi-modal representation generation model
CN120256664A
