Text-to-pedestrian image retrieval method based on pre-training model and storage medium

Through self-attention and cross-attention mechanism alignment of image and text features, combined with full-word mask modeling and cross-modal encoder, the problem of visual and language heterogeneity gap is solved, and the performance of text-to-peerman image retrieval and applicability.

CN118887703APending Publication Date: 2024-11-01GUILIN UNIV OF ELECTRONIC TECH

Patent Information

Application Number
CN202411061423.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-01

Smart Images

  • Figure CN118887703A_ABST
    Figure CN118887703A_ABST
Patent Text Reader

Abstract

The invention discloses a pre-training model-based cross-modal text-to-pedestrian image retrieval method and a storage medium, and aims to improve a masking language modeling strategy and use a full-word mask strategy to better mine a fine-grained relationship between an image and a text. The invention further provides a model fusion module based on soft attention, the model information interaction between the same semantic category can be promoted by adding the model fusion module, and the model information interaction between the same semantic category can be promoted by utilizing the characteristic of the text attribute and utilizing a cross-modal encoder to carry out fusion interaction between the text and the image so as to learn more information. Therefore, better retrieval performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer application technology, and in particular to a cross-modal text-to-pedestrian image retrieval method and storage medium based on a pre-training model. Background Art

[0002] Text descriptions provide a natural and comprehensive way to describe person attributes, which is easier to obtain than images. Text-to-person image retrieval aims to find people matching a given text description from a large image library, which is a subtask of image-to-text retrieval and image-based person re-identification (Re-ID).

[0003] However, this task remains challenging due to the appearance of people in different environments and the relatively large representation gap between vision and language. The former challenge is that the visual appearance of people varies due to factors such as pose, perspective, lighting, etc., while the text description varies due to description order and text ambiguity; the latter challenge is the core issue of cross-modal tasks and stems from the heterogeneous gap between vision and language. To address these issues, the key to text-to-person image retrieval lies in exploring better feature representation extraction methods and designing superior cross-modal matching methods to align images and texts into a joint embedding space.

[0004] Early global matching methods align images and text into a joint embedding space by designing a cross-modal matching loss function. These methods usually only use matching loss at the end of the network to learn cross-modal alignment, failing to achieve sufficient modal interaction in the middle layers, which is crucial to bridging the feature-level modality gap.

[0005] Therefore, some later methods introduced local matching strategies by establishing correspondences between body parts and text entities. Although local matching strategies help improve retrieval performance, they inevitably introduce noise and uncertainty in the retrieval process. In addition, this strategy requires extracting and storing multiple local representations of images and texts, and calculating the pairwise similarities between all these representations during reasoning will waste a lot of resources. These resource-demanding characteristics limit their applicability in actual large-scale scenarios. Summary of the invention

[0006] In view of the shortcomings of the prior art, the present invention provides a text-to-pedestrian image retrieval method that can effectively improve retrieval performance. The method is specifically embodied in:

[0007] (1) Using the image encoder and text encoder, respectively, the original text and image are converted into a text feature vector representation B1 and an image feature vector representation A1 through self-attention and cross-attention mechanisms.

[0008] (2) The global image feature A1 and the text feature B1 are aligned through an improved soft attention modality fusion module, effectively improving the performance of the text-to-pedestrian image retrieval task.

[0009] (3) Use full-word mask modeling to perform implicit relationship reasoning, implicitly mine fine-grained relationships, and learn more information from different modalities.

[0010] (4) By extracting text attributes, the masked text attributes are extracted using a text encoder to extract feature B4, which is fed together with the image feature A1 into the cross-modal encoder for interaction.

[0011] (5) Based on the distribution consistency loss, the cosine similarity distributions of N image-text pair features are merged into the KL divergence. The image-text similarity distribution and the standardized label matching distribution are aligned by minimizing the KL divergence to achieve cross-modal matching.

[0012] The technical solution of the present invention specifically comprises the following steps:

[0013] S1: Obtain N groups of image-text paired training data, including training images and training texts for describing the training images.

[0014] S2: The pedestrian image to be processed and the corresponding text description are converted into feature vector representation through self-attention and cross-attention mechanisms, and trained using the image encoder and text encoder of the pre-trained model. The specific training method is as follows:

[0015] The image encoder and the text encoder are used to perform feature extraction to obtain the original image features A1 and text features B1. The image encoder and the text encoder both include a multi-head self-attention layer, a residual connection layer, and a feedforward fully connected layer.

[0016] Preferably, this step can be specifically implemented as follows:

[0017] The multi-head self-attention layer passes the query vector, key vector and value vector to multiple independent attention heads respectively; in each attention head, the query vector is dot-producted with the key vector and divided by the square root of the model feature dimension for scaling, and then the scores are normalized by the softmax function to obtain weights, and then the weights are used to weighted sum each value vector to obtain the output of each attention head; the outputs of multiple attention heads are spliced ​​together and reduced in dimension by linear transformation, and finally the output of the multi-head self-attention layer is obtained.

[0018] The residual connection layer adds a shortcut connection to the output of the multi-head self-attention layer of the network, directly connecting to the output of this layer; the output of the shortcut connection is added to the output of this layer to obtain the final output of this layer.

[0019] The feed-forward fully connected layer takes the output of the multi-head self-attention layer as input, randomly assigns weights and biases to each neuron, multiplies the input of each neuron by its weight value, adds them together, and then adds the bias value to the result, resulting in a single number. This number is then passed to the activation function, which maps it to another range and generates the final output.

[0020] S3: Use the soft attention modality fusion module to align the original image feature A1 and the original text feature B1.

[0021] Furthermore, the specific implementation process of this step is as follows:

[0022] S3-1: Calculate the feature matching degree of the matched image-text pair (A1, B1)

[0023] S3-2: Calculate the correlation between a single original text feature B1 and each original image feature A1 to calculate feature similarity

[0024] S3-3: Calculate the matching degree of image-text pairs The normalized weights are used to assign a larger weight ratio to the original image feature A1 related to the text query, and then these weights are used to perform weighted average calculation on the feature vectors in the original image feature A1 to obtain the aligned text and image features.

[0025] S3-4: The aligned text and image features are fused with the original text and image features, and then the fused image features A2 and text features B2 are obtained through layer normalization.

[0026] S3-5: Construct ID loss function and distribution consistency loss function to train the text to pedestrian image retrieval model based on the pre-trained model.

[0027] S4: Use the cross-modal encoder to interact the image feature A1 with the text attribute feature B4.

[0028] Preferably, this step can be specifically implemented as follows:

[0029] S4-1: The cross-modal encoder consists of 12 layers of BERT and MLM layers.

[0030] S4-2: For the original text description T, extract the attributes of the text description T and reconstruct the attributes into a text description Using MLM Obtaining masking

[0031] S4-3: Use the text encoder to It is converted into a text feature representation B4, which is fed into the cross-modal encoder together with the original image feature representation A1 for interaction, and finally the masked attributes are predicted using MLM.

[0032] S4-4: Construct an attribute learning loss function to train the text-to-person image retrieval model based on the pre-trained model.

[0033] Preferably, the construction of the attribute learning loss function comprises the following steps:

[0034] (1) For the original text, extract attributes from the text, reconstruct a paragraph based on the obtained attributes, and obtain a new text;

[0035] (2) Masking the new text using masked language modeling, and then using a text encoder and an image encoder to extract the features of the new text and image features respectively;

[0036] (3) The obtained text features and image features are jointly fed into a cross-modal encoder, which includes an MLM head to predict masked words.

[0037] S5: Leverage a multimodal collaborative encoder to implicitly mine fine-grained relations via full-word mask modeling to learn discriminative global features for fine-grained interactions.

[0038] Preferably, this step can be specifically implemented as follows:

[0039] S5-1: The multimodal collaborative encoder consists of a multi-head cross-attention layer and a four-layer Transformer block.

[0040] S5-2: For the original text description T, randomly select 20% of the words and add a “##” mark in front to indicate that they may be part of a compound word.

[0041] S5-3: These text tokens are randomly masked with a probability of 10% and replaced with a special token [MASK].

[0042] S5-4: Actual masking is performed on the text, where 80% of the tokens are masked, 10% of the tokens remain unchanged, and another 10% of the tokens are replaced with random labels.

[0043] S5-5: The final text feature B3 and image feature A2 are jointly fed into the multimodal collaborative encoder.

[0044] S5-6: Construct a mask inference loss function to train the text-to-pedestrian image retrieval model based on the pre-trained model.

[0045] In addition, the present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned text-to-pedestrian image retrieval method are implemented.

[0046] Technical features and beneficial effects of the present invention:

[0047] By extracting the attributes of the text, masking the attributes with masked language modeling, and using a cross-modal encoder to interact with image features and text attribute features, more information can be learned.

[0048] The whole-word mask relation reasoning module leverages the whole-word mask modeling task to implicitly mine fine-grained relations to assist the image encoder and text encoder in learning discriminative global features without the need for additional supervision and inference cost.

[0049] The soft attention modality fusion module is used to promote the interaction of modal information of the same category, which effectively improves the retrieval performance of the text-to-pedestrian image retrieval model based on the pre-trained model. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a structural diagram of the present invention;

[0051] Figure 2 is a structural diagram of a text encoder in an embodiment of the present invention;

[0052] Figure 3 It is a flow chart of the soft attention modality fusion module in an embodiment of the present invention. DETAILED DESCRIPTION

[0053] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments to facilitate a better understanding of the technical solution of the present invention.

[0054] The cross-modal pedestrian retrieval method based on a pre-trained model provided by the present invention enhances global image-text matching by learning and reasoning about the relationship between local visual-text tags without the need for additional supervision and reasoning costs.

[0055] In a specific embodiment, a visual language pre-training model is used, as follows:

[0056] The model backbone network is initialized using the image and text encoders of the pre-trained model in order to enhance the image-text alignment capability of the text-person image retrieval model foundation.

[0057] Enter the text into x t, the classic Transformer structure in the text encoder is used to extract text representation. First, the text input is marked using byte pair encoding (BPE) with a length of 49152 bytes, where the text description adds start and end tags, represented as [SOS] and [EOS] respectively, and then the text sequence is Feed into Transformer.

[0058] The training image x i ∈R H×W×C Cut to Q = H·W / M 2 A fixed-size non-overlapping patch sequence is then mapped to a one-dimensional After adding positional embedding and the special [CLS] tag, the sequence Input into Transformer.

[0059] In a specific embodiment, the modality fusion module includes:

[0060] The original text features and the original image features Compute matching image-text pairs Feature matching

[0061] The feature matching formula is as follows:

[0062] Analyze a single raw text feature And each original image feature The correlation of the feature similarity Calculate the feature matching degree of image and text The normalized weights of the original text features related to the text query Related original image features Assign a larger weight ratio, and then use these weights to the original image feature N v The eigenvectors in are weighted averaged to re-express That is, the aligned text features The specific formula is as follows:

[0063] Image features to be aligned Aligned text features With the original image features Original text features Add them together and then process them through layer normalization to get the fused image features. and text features The specific formula is as follows:

[0064]

[0065]

[0066] The LN in the formula represents layer normalization, which aims to ensure the stability of data feature distribution during the optimization process, enhance the generalization ability of the model, and accelerate model convergence.

[0067] In a specific embodiment, the text attribute learning loss function includes:

[0068] First, obtain the original text description T and extract the attributes of the text description T, such as: man, red clothes, wearing a hat, etc.

[0069] Reorganize the attributes into a text description For example: "This is a man; this man is wearing clothes; this man is wearing a hat."

[0070] Using MLM Masking is performed where 80% of the tokens are masked, 10% of the tokens remain unchanged, and another 10% of the tokens are replaced with random tokens.

[0071] The text features and image features are fed into a cross-modal encoder, fused using a cross-attention mechanism, and finally an MLM head is used to predict the masked attributes.

[0072] In a specific embodiment, the multimodal collaborative encoder includes:

[0073] First, the original text is converted into masked text through the whole word masking task. For a given input text description T, 20% of the words are randomly selected and a “##” mark is added in front of them to indicate that they may be part of a compound word.

[0074] Randomly mask these text tags with a probability of 10% and replace them with a special tag [MASK]. If the selected word has a "##" tag, the previous word is also [MASK].

[0075] Actual masking is performed on the text, where 80% of the tokens are masked, 10% of the tokens remain unchanged, and another 10% of the tokens are replaced with random tokens.

[0076] Multimodal collaborative encoder, consisting of a multi-head cross-attention layer and four layers of Transformer blocks:

[0077]

[0078] Where MHA is multi-head cross attention, d is the embedding dimension of masked tokens, Λ is the masked text feature, Υ and Γ are image features.

[0079] The masked text is defined as After processing according to the described process, the final hidden state is obtained and are jointly fed into the multimodal interaction encoder.

[0080] For each masking position We use a multi-layer perceptron (MLP) classifier to predict the corresponding original label The probability of ; |Ε| is the size of the vocabulary Ε; N represents the set of masked texts.

[0081] In the MLP classifier of this embodiment, the input vector passes through multiple layers of fully connected layers, and nonlinear transformation and Dropout layers are added between the fully connected layers for regularization to prevent overfitting. A softmax function is added after the last fully connected layer to convert the output of the network into a probability distribution, so as to classify and predict the masked text words; the objective function of the masked inference model is obtained:

[0082]

[0083] where Υ represents the set of masked text tokens and |Ε| is the size of the vocabulary Ε. i is the predicted label probability distribution, y i is a one-hot vector of the true label, where the probability of the true label is 1.

[0084] In a specific embodiment, utilizing distribution consistency loss includes:

[0085] Distribution consistency loss, merges the cosine similarity distribution of N image-text pair features into the KL difference, and aligns the image-text similarity distribution and the standardized label matching distribution by minimizing the KL divergence to achieve cross-modal matching.

[0086] According to each image global representation The set of image-text pairs is constructed as where y i.j represents the true matching label, y i,j =1 means it is a positive match, otherwise it is a negative match.

[0087] The softmax function is used to calculate the probability of a matching pair. The formula is as follows:

[0088]

[0089] Among them, τ is a temperature hyperparameter used to control the peak value of probability distribution, sim(uv) = u T v / ||u||||v|| represents the L2 normalized cosine similarity between u and v, with a matching probability b i,j can be considered as in small batches and The cosine similarity score between and The ratio of the sum of the cosine similarity scores between .

[0090] The image-to-text distribution consistency loss can be expressed as:

[0091]

[0092] where ε is a small number to avoid numerical problems, is the true matching probability; symmetrically, the loss can be expressed as:

[0093] L dc =L i2t +L t2i .

[0094] In a specific embodiment, the function used in the training process is:

[0095] L=L ms +L dc +L id +L ita .

[0096] Among them, L ms represents the objective function of the mask inference model, L dc represents the bidirectional distribution consistency loss function, L id represents the ID loss function, L ita represents the attribute learning loss function;

[0097]

[0098] in and They represent the logits output by the image and text classification networks for category i, and y represents the true label.

Claims

1. A text-to-person image retrieval method based on a pre-trained model, characterized in that: The method comprises: Obtain multiple sets of training samples for text-to-pedestrian image retrieval, and use the pre-trained model to extract image features A1 and text features B1 from the training samples; The image feature A1 and the text feature B1 are fed into the soft attention modality fusion module for further fusion and alignment processing to obtain the aligned image feature A2 and text feature B2; The full-word mask modeling is used to mask the text of the initial training sample, and the masked text feature B3 is extracted using the text encoder; Obtain an initial training sample of text, extract text attributes from the initial training text, mask the attributes using masked language modeling, and then use a text encoder to extract masked text attribute features B4; Feed the image feature A1 and the masked text attribute feature B4 into the cross-modal encoder for fusion interaction; Construct ID loss function, distribution consistency loss function, mask inference loss function and attribute learning loss function to train the text-to-pedestrian image retrieval model; Inputting the pedestrian text description into the trained text-to-pedestrian image retrieval model to obtain corresponding retrieval results; The fusion alignment processing process of the soft attention modality fusion module includes the following steps: (1) Input the obtained text feature B1 and image feature A1 into the soft attention modality fusion module to evaluate the feature matching degree d of the image-text pair k r u ; (2) Calculate the correlation between a single original text feature B1 and each original image feature A1 to calculate the feature similarity d u v w ; (3) Calculate the feature matching degree d of the image-text pair k r u The normalized weights of the original image feature A1 related to the text query are given a larger weight ratio, and then these weights are used to perform weighted average calculation on the feature vectors in the original image feature A1 to obtain the aligned text and image features; (4) The aligned text and image features are fused with the original text and image features, and then layer normalization is performed to obtain the fused image features A2 and text features B2.

2. The method according to claim 1, characterized in that The construction of the attribute learning loss function includes the following steps: (1) For the original text, extract attributes from the text, reconstruct a paragraph based on the obtained attributes, and obtain a new text; (2) Masking the new text using masked language modeling, and then using a text encoder and an image encoder to extract the features of the new text and image features respectively; (3) The obtained text features and image features are jointly fed into a cross-modal encoder, which includes an MLM head to predict masked words.

3. A non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the text-to-pedestrian image retrieval method described in claim 1 or 2.

Citation Information

Patent Citations

  • Multi-modal pedestrian re-identification method based on multi-level cross-modal difference harmonic

    CN116682144A

  • Unsupervised pre-training of geometric vision models

    EP4354353A1

  • Single stream multi-level alignment for vision-language pretraining

    US20230281963A1

  • Systems and methods for vision-and-language representation learning

    WO2022250745A1

Cited By

  • Image geographic positioning method, device and equipment based on multi-modal large model

    CN119206385A

  • News scene multi-level image-text retrieval method based on mask guidance information fusion

    CN119441515A

  • Text-to-image pedestrian retrieval method and device based on mask denoising and medium

    CN120804351A

  • Cross-modal feature extraction model training method, retrieval method, system and product

    CN120832506A

  • Pedestrian re-identification model training method and device, equipment, medium and program product

    CN121147969A