Image similarity matching method based on attention weight distribution of external memory

Through the attention weight allocation method based on external memory, the problem of poor correlation evaluation in traditional image similarity matching in complex scenes is solved, a more accurate and flexible image similarity evaluation is achieved, and the expressive ability and applicability of the model are enhanced. sex.

CN118674948AActive Publication Date: 2024-09-20HEFEI UNIV OF TECH
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202410770987.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-20
Estimated Expiration
2044-06-14

AI Technical Summary

Technical Problem

When traditional single-modal image similarity matching methods deal with complex scenes and object relationships, it is difficult to accurately evaluate the correlation between images, resulting in inaccurate or incomplete retrieval results.

Method used

An attention weight allocation method based on external memory is used to extract image features through a convolutional neural network, build an external sample and relationship selection model, optimize the selection model to allocate attention weights, and comprehensively evaluate the similarity between images.

Benefits of technology

It significantly improves the accuracy of image similarity matching and the expressive ability of the model, enhances the ability to abstract and understand image features, adapts to different application scenarios and task requirements, and provides more accurate image retrieval results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118674948A
    Figure CN118674948A
Patent Text Reader

Abstract

The invention discloses an image similarity matching method based on attention weight distribution of external memory. The method comprises the following steps: 1, acquiring original image features of an image data set; 2, replacing the original features of the image with a representation learning result to obtain a high-level representation of the representation learning result; 3, performing simple similarity calculation on the input sample to obtain an external initial memory of the input sample; 4, constructing two external selection models to allocate external memory selection weights, wherein the external selection models comprise an external sample selection model and an external relationship selection model; 5, performing optimization training on the external selection model through a selection optimization training method and a global optimization training method to obtain an optimal training model; and 6, detecting an input sample by using the trained external selection model to obtain an image pair with the highest external memory selection weight, and taking the image pair as the most similar image pair. According to the method, the similarity learning effect can be improved, so that the globally most similar image can be obtained, and the image matching result has better interpretability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of image retrieval, and mainly relates to an image similarity matching method based on external memory attention weight allocation. Background Art

[0002] In today's era, the massive growth of image data has led to the need for efficient methods of image data management and utilization. Image retrieval technology has emerged to address the challenge of quickly locating the images required by users from huge image databases.

[0003] In the field of image retrieval, common retrieval algorithms include feature-based methods, content-based image retrieval (CBIR), and advanced methods based on deep learning. However, existing traditional algorithms mostly evaluate the correlation between input samples from a single modality perspective, which limits their ability to handle complex scenes and object relationships in images. For example, when a user seeks an image similar to an image containing multiple objects, traditional algorithms may only rely on a single modality such as pixel values ​​or feature vectors for similarity matching, ignoring the relationship between objects and their semantic information, which may lead to inaccurate or incomplete retrieval results.

[0004] Therefore, the correlation evaluation of traditional single-modal image similarity matching methods is often unsatisfactory when faced with complex situations in practical applications. Summary of the invention

[0005] In order to overcome the defects in the above-mentioned prior art, the present invention provides a novel image similarity matching method. The method is based on an external memory mechanism and allocates attention weights in order to obtain different similarities between samples under different relationships, thereby obtaining the image pair with the highest external memory selection weight as the most similar image pair.

[0006] In order to solve the technical problem, the present invention adopts the following technical solution:

[0007] The image similarity matching method based on external memory attention weight allocation of the present invention is characterized in that it is carried out according to the following steps:

[0008] Step 1: Get an image dataset containing m samples Among them, x p represents the pth sample; m represents the number of samples in the data set;

[0009] Use convolutional neural network to train image datasets The pth sample x in p Perform feature extraction to obtain the high-level feature representation Φ of the pth sample with feature dimension k p =Φ(x p,ω), where ω is the set of parameters to be learned in the convolutional neural network;

[0010] Step 2: Get n relationship vectors with dimension k Among them, a y represents the yth relationship vector; n represents the number of relationship vectors;

[0011] Step 3: Use formula (1) to construct the pth sample x p and the qth sample x q In the yth relationship vector a y The similarity of As external initial memory:

[0012]

[0013] In formula (1), sig represents the sigmoid function; T represents the transpose; Φ q is the qth sample x q High-level feature representation processed by convolutional neural networks;

[0014] Step 4: construct two external selection models, including: an external sample selection model and an external relationship selection model, which are used to allocate external memory selection weights to obtain external sample memory selection weights and external relationship memory selection weights;

[0015] Step 4.1: The external sample selection model uses formula (2) to calculate the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The external sample memory selection weight of the jth nearest neighbor sample

[0016]

[0017] In formula (2), Indicates that in the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The similarity difference between the jth nearest neighbor sample and the pth sample and the qth sample is obtained by formula (3);

[0018]

[0019] In formula (3), softplus represents the Softplus function; Φ p (i) represents the pth sample x p The i-th nearest neighbor sample, Φ q (j) represents the qth sample xq The jth nearest neighbor sample of ;

[0020] Step 4.2: The external relationship selection model uses equation (4) to calculate the relationship vector a in the yth y The next p-th sample x p and the qth input sample x q The external relationship between memory selection weight α y (pq):

[0021]

[0022] In formula (4), exp represents the exponential function;

[0023] Step 5: Optimize the external selection model by selecting the optimization method and the global optimization method, and construct a loss function L to measure the difference between the output of each external selection model and the actual label to obtain the best external selection model;

[0024] Step 6: Set the pth sample x p is the index sample, the qth sample x q The trained optimal external selection model is used to detect the index sample and the test sample, and the image pairs composed of the index sample and its neighboring samples and the test sample and its neighboring samples under various relationship vectors and their corresponding external memory selection weights are obtained. Then, they are sorted according to the size of the external memory selection weights, so as to obtain the image pair with the highest external memory selection weight and take it as the most similar image pair.

[0025] The image similarity matching method based on external memory attention weight allocation described in the present invention is also characterized in that step 5 is performed according to the following steps:

[0026] Step 5.1: First optimize the external sample selection model, and then optimize the external relationship selection model to obtain a more accurate similarity value;

[0027] Step 5.1.1: Use equation (5) to get the pth sample x p and the qth sample x q The comprehensive similarity s under external sample memory s pq :

[0028]

[0029] In formula (5), is the y-th relationship vector a y The next p-th sample x p The nearest neighbor sample and the qth sample x qThe weighted similarity of is obtained by formula (6):

[0030]

[0031] Step 5.1.2: Use equation (7) to get the pth sample x p and the qth sample x q The comprehensive similarity s under external relation memory r pq :

[0032]

[0033] Step 5.2: Optimize the external sample memory model and the external relationship memory model simultaneously:

[0034] Using formula (8), we can get the pth sample x p and the qth sample x q The comprehensive similarity s under external sample memory and external relation memory pq :

[0035]

[0036] Step 5.3: Use formula (9) to construct the loss function L:

[0037]

[0038] In formula (9), I + For image dataset The set of positive sample images with the same label in I - For image dataset A collection of negative sample images with different labels in s pq- Represents the pth sample x p The qth input sample x has a different label q In the yth relationship vector a y The similarity under pq+ Represents the pth sample x p The qth input sample x with the same label q In the yth relationship vector a y The similarity below.

[0039] An electronic device of the present invention includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the image similarity matching method, and the processor is configured to execute the program stored in the memory.

[0040] The present invention provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and the computer program executes the steps of the image similarity matching method when the computer program is executed by a processor.

[0041] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0042] 1. The method of the present invention uses a multi-feature fusion method to comprehensively explore the relationship between features and features, making the representation learning effect significantly better than the method of directly using raw data features. This fusion strategy not only improves the expression ability of the model, but also enhances the abstraction and understanding of image features;

[0043] 2. The method of the present invention provides two external memory selection mechanisms, sample-based and relationship-based, which can flexibly select the characteristics of input samples and the relationship between samples according to specific needs. By giving high weights to highlight the sample characteristics and relationships that meet current needs, and giving low weights to ignore irrelevant information, the effect of similarity learning is effectively improved. This mechanism enables the model to adapt to different application scenarios and task requirements more intelligently, and enhances the generalization ability and applicability of the model;

[0044] 3. The image similarity matching model trained by the method of the present invention can bring more accurate image retrieval and matching results in actual application scenarios, providing strong support for image processing and application. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a schematic diagram of the structure of the method of the present invention. DETAILED DESCRIPTION

[0046] In this embodiment, a similarity learning method for allocating attention weights using external memory is to first perform a high-level representation and simple similarity calculation on the image data set to obtain its external initial memory; then construct two external memory selection models to allocate external memory selection weights, including an external sample selection model and an external relationship selection model; the external sample memory selection model finds different neighboring samples of a given sample, uses different neighboring samples to describe different characteristics of the given sample, and selects it through the initial memory between the given samples, giving a higher weight to the sample pair that is more in line with the actual conditions; the external relationship memory selection model selects different relationships between samples and samples through the initial memory, and gives a higher weight to the relationship vector that is more in line with the actual conditions; then the external selection model is optimized and trained by two training methods, namely, selection optimization and global optimization; finally, the input sample (index sample and test sample) is detected on the trained model, and the pair with the highest external memory selection weight of the index sample and its neighboring sample and the test sample and its neighboring sample under various relationship vectors is obtained as the most similar image pair. When the test sample changes, the external memory selection weight changes with the change of the test sample, reflecting the commonality and implicit relationship between the index sample and the test sample. Specifically, it is carried out in the following steps:

[0047] Step 1: Get an image dataset containing m samples Among them, x p represents the pth sample; m represents the number of samples in the data set;

[0048] Use convolutional neural network to train image datasets The pth sample x in p Perform feature extraction to obtain the high-level feature representation Φ of the pth sample with feature dimension k p =Φ(x p ,ω), where ω is the set of parameters to be learned in the convolutional neural network; the original image features of the sample are taken as input to obtain its high-level representation.

[0049] Step 2: Get n relationship vectors with dimension k Among them, a y represents the yth relationship vector; n represents the number of relationship vectors;

[0050] Step 3: Use formula (1) to construct the pth sample x p and the qth sample x q In the yth relationship vector a y The similarity of As external initial memory:

[0051]

[0052] In formula (1), sig represents the sigmoid function; T represents the transpose; Φ q is the qth sample x q High-level feature representation processed by convolutional neural network; external initial memory is generated through a most basic multimodal similarity equation.

[0053] Step 4: construct two external selection models, including: an external sample selection model and an external relationship selection model, which are used to allocate external memory selection weights to obtain external sample memory selection weights and external relationship memory selection weights;

[0054] Step 4.1: The external sample selection model uses formula (2) to calculate the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The external sample memory selection weight of the jth nearest neighbor sample

[0055]

[0056] In formula (2), Indicates that in the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The similarity difference between the jth nearest neighbor sample and the pth sample and the qth sample is obtained by formula (3);

[0057]

[0058] In formula (3), softplus represents the Softplus function; Φ p (i) represents the pth sample x p The i-th nearest neighbor sample, Φ q (j) represents the qth sample x q The jth nearest neighbor sample of a given sample; by finding different neighboring samples of a given sample, using different neighboring samples to describe the different characteristics of the given sample, and selecting them through the initial memory between given samples, higher weights will be given to sample pairs that are more in line with actual conditions.

[0059] Step 4.2: The external relationship selection model uses equation (4) to calculate the relationship vector a in the yth y The next p-th sample x p and the qth input sample x q The external relationship between memory selection weight α y (pq):

[0060]

[0061] In formula (4), exp represents an exponential function. By selecting different relationships between samples through initial memory, while ensuring that the sum of the weights is 1, more significant sample pairs and relationship vectors under given training requirements are highlighted.

[0062] Step 5: Optimize and train the external selection model by using the selection optimization method and the global optimization method, and construct a loss function L to measure the difference between the output of each model and the actual label to obtain the best external selection model;

[0063] Step 5.1: Select optimization, that is, first optimize the external sample selection model separately, and then optimize the external relationship selection model separately to obtain a more accurate similarity value;

[0064] Step 5.1.1: Based on the external sample memory selection weights obtained from formula (3), construct the similarity calculation formula shown in formula (5) to obtain the pth sample x p and the qth sample x q The comprehensive similarity s under external sample memory s pq :

[0065]

[0066] In formula (5), is the y-th relationship vector a y The next p-th sample x p The nearest neighbor sample and the qth sample x q The similarity of the neighboring samples of and the external sample memory selection weights are weighted and summed to obtain the similarity, which is obtained by formula (6):

[0067]

[0068] The selection optimization first optimizes the external sample selection model separately through formula (5), that is, the external sample memory selection weight obtained by formula (3) and the similarity between each neighboring sample obtained by formula (6) are used for weighted summation to obtain the comprehensive similarity between the p-th sample and the q-th sample under the external sample memory as a more accurate similarity value.

[0069] Step 5.1.2: Based on the external relation memory selection weight obtained from formula (4), construct the similarity calculation formula shown in formula (7) to obtain the pth sample x p and the qth sample x q The comprehensive similarity s under external relation memory r pq :

[0070]

[0071] Then, the external relation memory selection model is optimized separately by formula (7), that is, the external relation memory selection weight obtained by formula (4) and the external initial memory obtained by formula (1) are weighted summed to obtain the comprehensive similarity between the p-th sample and the q-th sample under the external relation memory as a more accurate similarity value.

[0072] Step 5.2: Global optimization, that is, optimizing the external sample memory model and the external relationship memory model at the same time:

[0073] According to the external sample memory selection weight obtained by formula (3) and the external relationship memory selection weight obtained by formula (4), the similarity calculation formula shown in formula (8) is constructed to obtain the p-th sample x p and the qth sample x q The comprehensive similarity s under external sample memory and external relation memory pq :

[0074]

[0075] The external sample memory selection model and the external relationship memory selection model are optimized simultaneously by formula (8), that is, the external relationship memory selection weight obtained by formula (4) and the similarity between each neighboring sample obtained by formula (6) are weighted summed to obtain the comprehensive similarity between the p-th sample and the q-th sample under the external sample memory and external relationship memory as a more accurate similarity value.

[0076] Step 5.3: Using the loss function L shown in formula (9), the comprehensive similarity corresponding to the above optimized external selection model is calculated to measure the difference between the output of each external selection model and the actual label, and the best external selection model is obtained through comparison:

[0077]

[0078] In formula (9), I + For image dataset The set of positive sample images with the same label in I - For image dataset A collection of negative sample images with different labels in s pq- Represents the pth sample x p The qth input sample x has a different label q In the yth relationship vector a y The similarity under pq+ Represents the pth sample x pThe qth input sample x with the same label q In the yth relationship vector a y Through the optimization process, the similarity of positive image pairs is made higher, while the similarity of negative image pairs is made lower. And the error range of 1 is added to the loss function to prevent overfitting during the optimization process.

[0079] Step 6: Set the pth sample x p is the index sample, the qth sample x q The trained optimal external selection model is used to detect the index sample and the test sample, and the image pairs composed of the index sample and its neighboring samples and the test sample and its neighboring samples under various relationship vectors and their corresponding external memory selection weights are obtained. Then, they are sorted according to the size of the external memory selection weights, so as to obtain the image pair with the highest external memory selection weight and take it as the most similar image pair.

[0080] By sorting the size relationship of the external memory selection weights of the obtained index samples and their neighboring samples and the test samples and their neighboring samples under different relationship vectors, the image pairs with the highest external memory selection weights can be obtained, and different attention weights can be assigned according to the different characteristics of the samples and the different relationships between samples under specific tasks. In addition, when the test sample changes, the external memory selection weight changes accordingly. This reflects the commonality and implicit relationship between the index sample and the test sample.

[0081] like Figure 1 As shown, the red and blue lines represent the links with the highest memory selection weights, and the black dotted lines represent the links that are not strengthened. The triangles represent the input samples whose similarity needs to be calculated, the squares represent the different neighboring samples of each sample, and the circles represent different relationship vectors.

[0082] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.

[0083] In this embodiment, a computer-readable storage medium stores a computer program on the computer-readable storage medium, and the computer program executes the steps of the above method when executed by a processor.

Claims

1. An image similarity matching method based on attention weight allocation based on external memory, characterized in that: The steps are as follows: Step 1: Get an image dataset containing m samples Among them, x p represents the pth sample; m represents the number of samples in the data set; Use convolutional neural network to train image datasets The pth sample x in p Perform feature extraction to obtain the high-level feature representation Φ of the pth sample with feature dimension k p =Φ(x p ,ω), where ω is the set of parameters to be learned in the convolutional neural network; Step 2: Get n relationship vectors with dimension k Among them, a y represents the yth relationship vector; n represents the number of relationship vectors; Step 3: Use formula (1) to construct the pth sample x p and the qth sample x q In the yth relationship vector a y The similarity of As external initial memory: In formula (1), sig represents the sigmoid function; T represents the transpose; Φ q is the qth sample x q High-level feature representation processed by convolutional neural networks; Step 4: construct two external selection models, including: an external sample selection model and an external relationship selection model, which are used to allocate external memory selection weights to obtain external sample memory selection weights and external relationship memory selection weights; Step 4.1: The external sample selection model uses formula (2) to calculate the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The external sample memory selection weight of the jth nearest neighbor sample In formula (2), Indicates that in the yth relationship vector a y The next p-th sample x p The i-th nearest neighbor sample and the q-th sample x q The similarity difference between the jth nearest neighbor sample and the pth sample and the qth sample is obtained by formula (3); In formula (3), softplus represents the Softplus function; Φ p (i) represents the pth sample x p The i-th nearest neighbor sample, Φ q (j) represents the qth sample x q The jth nearest neighbor sample of ; Step 4.2: The external relationship selection model uses equation (4) to calculate the relationship vector a in the yth y The next p-th sample x p and the qth input sample x q The external relationship between memory selection weight α y (pq): In formula (4), exp represents the exponential function; Step 5: Optimize the external selection model by selecting the optimization method and the global optimization method, and construct a loss function L to measure the difference between the output of each external selection model and the actual label to obtain the best external selection model; Step 6: Set the pth sample x p is the index sample, the qth sample x q The trained optimal external selection model is used to detect the index sample and the test sample, and the image pairs composed of the index sample and its neighboring samples and the test sample and its neighboring samples under various relationship vectors and their corresponding external memory selection weights are obtained. Then, they are sorted according to the size of the external memory selection weights, so as to obtain the image pair with the highest external memory selection weight and take it as the most similar image pair.

2. The image similarity matching method based on external memory attention weight allocation according to claim 1, characterized in that: The step 5 is carried out as follows: Step 5.1: First optimize the external sample selection model, and then optimize the external relationship selection model to obtain a more accurate similarity value; Step 5.1.1: Use equation (5) to get the pth sample x p and the qth sample x q The comprehensive similarity s under external sample memory s pq : In formula (5), is the y-th relationship vector a y The next p-th sample x p The nearest neighbor sample and the qth sample x q The weighted similarity of is obtained by formula (6): Step 5.1.2: Use equation (7) to get the pth sample x p and the qth sample x q The comprehensive similarity s under external relation memory r pq : Step 5.2: Optimize the external sample memory model and the external relationship memory model simultaneously: Using formula (8), we can get the pth sample x p and the qth sample x q The comprehensive similarity s under external sample memory and external relation memory pq : Step 5.3: Use formula (9) to construct the loss function L: In formula (9), I + For image dataset The set of positive sample images with the same label in I - For image dataset A collection of negative sample images with different labels in ; Represents the pth sample x p The qth input sample x has a different label q In the yth relationship vector a y The similarity under Represents the pth sample x p The qth input sample x with the same label q In the yth relationship vector a y The similarity below.

3. An electronic device, comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the image similarity matching method according to claim 1 or 2, and the processor is configured to execute the program stored in the memory.

4. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the image similarity matching method according to claim 1 or 2 are executed.

Citation Information

Patent Citations

  • Zero sample learning method and system based on semantic attribute attention redistribution mechanism

    CN110163258A

  • Cross-modal retrieval model construction and retrieval method based on image-text collaborative attention

    CN114201621A

  • Cross-modal retrieval model training method, cross-modal retrieval method, equipment and medium

    CN114841243A

  • Pedestrian re-identification method based on relation attention transformer

    CN116012771A

  • Method and system for rapid retrieval of target images based on artificial intelligence

    US20230134531A1