Data Retrieval Method, Apparatus, Computer Device, and Storage Medium
Through the combination of anchor graph hashing algorithm and Gaussian kernel function, the problems of poor quantization error and performance of traditional hashing algorithms in high-dimensional data are solved, and more accurate hash encoding and more efficient data retrieval are achieved.
Patent Information
- Application Number
- CN202210679144.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-16
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-06-16
AI Technical Summary
Traditional hashing algorithms have problems of quantization error and poor performance when processing high-dimensional data, especially when the cosine similarity is distributed within the range of [-1, +1], resulting in degradation in data retrieval performance.
By introducing an anchor graph hashing algorithm and Gaussian kernel function, the similarity parameter matrix and relationship matrix of anchor points and sample data are used to carry out hash coding training, generate target hash coding of target data, expand the dimension of the target feature matrix and reduce quantization errors, and improve the accuracy of hash coding.
It achieves the accuracy of hash encoding, improves the efficiency and performance of data retrieval, and can maintain high similarity on target data at any distribution, breaking through the limitations of the original feature dimensions.
Smart Images

Figure CN115129713B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a data retrieval method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Art
[0002] With the rapid development of the Internet, the rapid growth of multimedia data such as images, texts, and videos has made large-scale data retrieval a research hotspot. In the face of massive data, nearest neighbor retrieval has broader application advantages compared to exact retrieval, and thus has become a key technology in information retrieval. Among them, hashing technology has received increasing attention due to its low storage cost and high query efficiency, and has been widely applied to data retrieval.
[0003] The hashing algorithm can encode high-dimensional data into low-dimensional compact binary hash codes. In traditional technologies, since the cosine similarity of two samples tends to be distributed in the range greater than 0 and less than 1, the cosine similarity of the {0, +1} hash code can be used to reconstruct the cosine similarity of the high-dimensional vector [0, +1], which can reduce the quantization error of the hash code, thereby improving the performance of data retrieval. However, considering that the cosine similarity of some samples may still fall within [-1, +1], in this case, the traditional method has certain limitations, resulting in poor performance of data retrieval. Summary of the Invention
[0004] Based on this, it is necessary to provide a data retrieval method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve the performance of data retrieval for the above technical problems.
[0005] In a first aspect, this application provides a data retrieval method. The method includes:
[0006] Obtain a target feature matrix of target data, and obtain a similarity parameter matrix between anchor points and a parameter relationship matrix between an anchor point and sample data obtained by performing hashing encoding training on a sample feature matrix based on sample data; the anchor point is the clustering center of the sample data;
[0007] Calculate a target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix;
[0008] Based on the parameter relationship matrix, calculate a score for the target similarity matrix to obtain a target score matrix of the target data;
[0009] Generate a target hash code matched by the target data according to the target score matrix;
[0010] Retrieve data through the target hash code to determine the retrieval result of the target data.
[0011] In a second aspect, the present application also provides a data retrieval device. The device includes:
[0012] A data acquisition module, configured to acquire a target feature matrix of target data, and acquire a similarity parameter matrix between anchor points and a parameter relationship matrix between anchor points and sample data obtained by performing hash code training on a sample feature matrix based on sample data; the anchor points are the clustering centers of the sample data;
[0013] A similarity calculation module, configured to calculate a target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix;
[0014] A score calculation module, configured to calculate a score of the target similarity matrix based on the parameter relationship matrix to obtain a target score matrix of the target data;
[0015] A data encoding module, configured to generate a target hash code matched by the target data according to the target score matrix;
[0016] A result determination module, configured to retrieve data through the target hash code to determine the retrieval result of the target data.
[0017] In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0018] Acquire a target feature matrix of target data, and acquire a similarity parameter matrix between anchor points and a parameter relationship matrix between anchor points and sample data obtained by performing hash code training on a sample feature matrix based on sample data; the anchor points are the clustering centers of the sample data;
[0019] Calculate a target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix;
[0020] Calculate a score of the target similarity matrix based on the parameter relationship matrix to obtain a target score matrix of the target data;
[0021] Generate a target hash code matched by the target data according to the target score matrix;
[0022] Retrieve data through the target hash code to determine the retrieval result of the target data.
[0023] Fourthly, the present application also provides a computer-readable storage medium. On the computer-readable storage medium, there is a computer program stored, and when the computer program is executed by a processor, the following steps are implemented:
[0024] Obtain the target feature matrix of target data, and obtain the similarity parameter matrix between anchor points and the parameter relationship matrix between anchor points and sample data obtained by performing hash encoding training on the sample feature matrix based on sample data; the anchor points are the clustering centers of the sample data;
[0025] Calculate the target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix;
[0026] Based on the parameter relationship matrix, perform score calculation on the target similarity matrix to obtain the target score matrix of the target data;
[0027] Generate the target hash code matched by the target data according to the target score matrix;
[0028] Perform data retrieval through the target hash code to determine the retrieval result of the target data.
[0029] Fifthly, the present application also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0030] Obtain the target feature matrix of target data, and obtain the similarity parameter matrix between anchor points and the parameter relationship matrix between anchor points and sample data obtained by performing hash encoding training on the sample feature matrix based on sample data; the anchor points are the clustering centers of the sample data;
[0031] Calculate the target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix;
[0032] Based on the parameter relationship matrix, perform score calculation on the target similarity matrix to obtain the target score matrix of the target data;
[0033] Generate the target hash code matched by the target data according to the target score matrix;
[0034] Perform data retrieval through the target hash code to determine the retrieval result of the target data.
[0035] The above data retrieval method, device, computer device, computer-readable storage medium, and computer program product can obtain the similarity parameter matrix between anchor points and the parameter relationship matrix between anchor points and sample data by performing hash coding training based on the sample feature matrix of sample data. The anchor points are the clustering centers of the sample data. Accordingly, when performing hash coding processing on target data to generate the target hash coding of the target data, various parameters can be directly obtained and used, which can improve the processing efficiency of hash coding processing for target data. By obtaining the target feature matrix of the target data, further calculate the target similarity matrix matched by the target data according to the similarity parameter matrix obtained by hash coding training and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix. Accordingly, by introducing the kernel similarity, for target data with any distribution, the value of its kernel similarity can be made to fall within a predetermined value range. By introducing anchor points, the similarity between data is approximated by the similarity between data and anchor points, which can realize the expansion of the dimension of the target feature matrix of the target data, making the length of the subsequent obtained target hash coding longer, that is, the target hash coding can break through the limitation of the dimension of the target feature matrix, which is beneficial to subsequent data retrieval. Further, based on the parameter relationship matrix, calculate the score matrix of the target data for the target similarity matrix to obtain the target score matrix of the target data, and generate the target hash coding matched by the target data according to the target score matrix, which can improve the accuracy of the generated target hash coding. Finally, data retrieval can be performed through the target hash coding to determine the retrieval result of the target data, which can improve the efficiency and performance of data retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 FIG. is an application environment diagram of the data retrieval method in an embodiment;
[0037] Figure 2 FIG. is a schematic diagram of the similarity processing method of the traditional data retrieval method in an embodiment;
[0038] Figure 3 FIG. is a schematic diagram of the similarity determination method of the traditional data retrieval method in an embodiment;
[0039] Figure 4 FIG. is a schematic diagram of the similarity distribution of the traditional data retrieval method in an embodiment;
[0040] Figure 5 FIG. is a schematic flowchart of the data retrieval method in an embodiment;
[0041] Figure 6 FIG. is a schematic diagram of the Gaussian kernel function distribution of data in the data retrieval method in an embodiment;
[0042] Figure 7Schematic diagram of the similarity between data and anchor points in a data retrieval method for an embodiment;
[0043] Figure 8 Flow schematic diagram of a data retrieval method in a specific embodiment;
[0044] Figure 9 Schematic diagram table of the retrieval performance of a data retrieval method in an embodiment;
[0045] Figure 10 Structural block diagram of a data retrieval device in an embodiment;
[0046] Figure 11 Internal structure diagram of a computer device in an embodiment;
[0047] Figure 12 Internal structure diagram of a computer device in another embodiment. Detailed implementation manners
[0048] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] It should be noted that the data involved in the present application, including but not limited to sample data, target data, candidate data, etc. for analysis, are all data that have been fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0050] In one embodiment, the data retrieval method provided by the present application can be applied to an application environment as shown in Figure 1 The application environment involves a terminal 102 and a server 104. In some embodiments, a terminal 106 is also involved at the same time. Among them, the terminal 102 and the terminal 106 communicate with the server 104 through a network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or can be placed on the cloud or other servers.
[0051] Server 104 can obtain sample data from terminal 102 and / or terminal 106, and determine the cluster center of the sample data as an anchor point. The sample data can be the data stored in terminal 102 and terminal 106, or it can also be the sample data obtained from a public dataset. Server 104 performs hash coding training based on the sample feature matrix of the sample data to obtain a similarity parameter matrix between anchor points and a parameter relationship matrix between anchor points and sample data. Then, server 104 can obtain target data from terminal 102 and / or terminal 106. The target data is independent of the sample data, and a target feature matrix of the target data is determined. According to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix, a target similarity matrix matched by the target data is calculated; based on the parameter relationship matrix, a score calculation is performed on the target similarity matrix to obtain a target score matrix of the target data; according to the target score matrix, a target hash code matched by the target data is generated. Thus, server 104 can perform data retrieval through the target hash code, determine the retrieval result of the target data, and send the retrieval result to terminal 102 and / or terminal 106 for display to achieve data display or data recommendation.
[0052] In one embodiment, when the data processing capability of terminal 102 meets the data processing requirements, the application environment may only involve terminal 102. Specifically, terminal 102 obtains sample data, determines the cluster center of the sample data as an anchor point, performs hash coding training based on the sample feature matrix of the sample data to obtain a similarity parameter matrix between anchor points and a parameter relationship matrix between anchor points and sample data. Then, terminal 102 obtains the target feature matrix of the target data, finally generates the target hash code of the target data, performs data retrieval through the target hash code, determines the retrieval result of the target data and displays it to achieve data display or data recommendation.
[0053] Among them, terminal 102 and terminal 106 can be, but are not limited to, various desktop computers, laptop computers, smartphones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart in-vehicle devices, etc. The portable wearable devices can be smart watches or bracelets, etc. Server 104 can be implemented by an independent server or a server cluster composed of multiple servers.
[0054] With the rapid development of the Internet, multimedia data such as images, texts, and videos have increased dramatically, and large-scale data retrieval has become a research hotspot. Faced with massive data, Approximate Nearest Neighbor (ANN) retrieval has a wider application advantage than exact retrieval, thus becoming a key technology in information retrieval. Among them, hash technology has received more and more attention due to its low storage cost and high query efficiency, and has been widely used in data retrieval.
[0055] The hash algorithm can encode high-dimensional data into low-dimensional and compact binary hash codes. Specifically, given a d-dimensional sample feature vector x i ∈R 1×d , hashing technology aims to achieve Encode the sample feature vector into an r-dimensional binary hash code b i ∈{+1,-1} 1×r , where r<<d. After hash coding, the Euclidean distance between two sample feature vectors can be approximated by the Hamming distance, and the calculation of the Hamming distance can be supported by the bitwise exclusive OR operation (XOR) of the computer, thereby accelerating the distance measurement.
[0056] See also Figure 2 , the sample image includes a first image and a second image, and the first image feature of the first image is represented by (x1, x2, …x n ), the second image feature of the second image is represented by (y1,y2,…y n ), the Euclidean distance between sample images is expressed as After hash coding, the first image feature is encoded as [1,0,1,…1], and the second image feature is encoded as [0,1,1,…0]. The Euclidean distance can be approximated by the Hamming distance, and the distance measurement can be accelerated by bit counting.
[0057] The hashing algorithm learns the hash code by maintaining the similarity of the original vector in the Hamming space, see Figure 3 Common similarity metrics include Euclidean distance and cosine distance. Euclidean distance can better reflect the absolute difference between two vectors in value, so most hashing methods are designed based on the similarity of Euclidean distance. However, Euclidean distance has the disadvantage of too large a range of values under high-dimensional vectors. In this case, cosine distance reflects the relative difference in direction, and its range is stable, so it has better applicability. In actual scenarios, due to the popularity of deep learning, high-dimensional vectors have become a common representation. Therefore, hashing algorithms need to be able to fully mine the cosine similarity information under samples.
[0058] In traditional technologies, hash-based retrieval algorithms can generally be divided into two categories: data-independent hash algorithms and data-dependent hash algorithms. The hash functions of data-independent hash algorithms are usually obtained by manual construction or random projection and are independent of specific training data. For example, the Locality-Sensitive Hashing (LSH) algorithm is a classic data-independent hash method. It maps the original data into binary codes through random projection, and adjacent sample codes are still likely to be similar in the Hamming space with a high probability. However, data-independent hash algorithms often require more bits to achieve sufficient performance, which means higher storage costs.
[0059] Data-dependent hash algorithms obtain more compact hash codes by training hash functions with given data, and they can be divided into two categories: supervised hashing and unsupervised hashing. Supervised hashing methods use class label information to learn hash functions and hash codes, thus achieving superior retrieval performance. However, in actual application scenarios, class label information is costly. Since unsupervised hashing does not need to rely on class label information to perform hash coding on data, it has a wider range of applicability.
[0060] Among them, the Iterative Quantization (ITQ) algorithm uses the Principal Component Analysis (PCA) method to map the original data into low-dimensional real-valued features, and then reduces the quantization error caused by mapping the low-dimensional real-valued features into the Hamming space through orthogonal rotation. The Spectral Hashing (SH) algorithm is a hash method based on manifold learning. It constructs an adjacency matrix W ∈ R n×n , and then solves the eigenvectors of the graph Laplacian matrix and quantizes them to obtain binary codes. Although the spectral hashing algorithm achieves good performance by exploring the local structure of data, when the number of samples n increases, the construction cost of the adjacency matrix W is extremely high.
[0061] To overcome this problem, an Anchor Graph Hashing (AGH) algorithm is proposed. It first clusters the training samples to obtain m clustering centers, called anchor points. By calculating the similarity between samples and anchor points, an approximate adjacency matrix is constructed, thus significantly reducing the computational complexity of constructing similarity.
[0062] For the above-mentioned hash algorithms, they mainly learn hash codes by maintaining the consistency of similarity before and after hash coding in the Euclidean space. In addition, some researchers also focus on the cosine distance information of samples. For example, the Angular Quantization-based Binary Codes (AQBC) algorithm proposes the following loss function:
[0063]
[0064] where x i is the sample feature of the sample, and its value is non-negative. b i ∈{0,1} r is the hash code corresponding to the sample represented by x i . R is an orthogonal matrix, which means a projection matrix learned by minimizing the angle between each sample feature and its own hash code. However, there is a prerequisite assumption in this angular quantization hash code algorithm, that is, the value of x i in the sample vector is non-negative. However, the values in the actual sample feature vectors are positive and negative. Therefore, the angular quantization hash code algorithm has great limitations in actual applications. Moreover, the angular quantization hash code algorithm learns its hash code based on a single sample itself, and to some extent ignores the local structure information of the data.
[0065] After a large number of observations, it is determined that the cosine similarity XX n×d of the sample feature matrix X∈[-1,+1] T ideally should be distributed between [-1,+1], but in fact it shows Figure 4 the asymmetric distribution shown in, that is, most of the cosine similarity values tend to be distributed in the range greater than 0 and less than 1. Therefore, an Angular Quantization (AQ) algorithm is proposed, aiming to make the cosine similarity of the hash code matrix B with {0,+1} reconstruct the cosine similarity XX T ∈[0,+1] n×n to reduce the quantization error, and its objective function is as follows:
[0066]
[0067] Since the cosine similarity of the sample data tends to be distributed in the range greater than 0 and less than 1, therefore, reconstructing the cosine similarity of the high-dimensional vector [0,+1] with the cosine similarity of the {0,+1} hash code can achieve good performance in most cases. However, considering that the cosine similarity of some sample data may still fall between [-1,+1], in this case, the angular quantization algorithm still has certain limitations.
[0068] Therefore, the embodiments of this application aim to expand the angular quantization algorithm, and propose an Angular Gaussian Quantization (AGQ) algorithm based on Gaussian kernel, so that samples with any distribution of cosine similarity can be approximated with {0, +1} hash codes with a small quantization error. At the same time, the hash codes can break through the limitations of the original features in terms of dimension and reach longer hash codes. Thus, the accuracy of determining the hash code corresponding to the data is effectively improved, and better retrieval performance can be achieved during data retrieval.
[0069] In one embodiment, as Figure 5 shown, a data retrieval method is provided. Taking the method applied to the Figure 1 server 104 as an example, it includes:
[0070] Step S202, obtain the target feature matrix of the target data, and obtain the similarity parameter matrix between the anchor points and the parameter relationship matrix between the anchor points and the sample data obtained by training the hash code based on the sample feature matrix of the sample data; the anchor points are the clustering centers of the sample data.
[0071] The sample data refers to the data used in the hash code training process. The target data refers to the data for which the hash code needs to be generated. The data types of the target data and the sample data can be, but are not limited to, images, texts, videos, etc. The features of the sample data are called sample feature vectors, and the sample feature matrix refers to the feature matrix composed of the sample feature vectors of the sample data. The features of the target data are called target feature vectors, and the target feature matrix refers to the feature matrix composed of the target feature vectors of the target data. Hash code training refers to the process of training the loss function of the hash code based on the sample feature matrix of the sample data. Through hash code training, the hash code corresponding to the sample data can be determined.
[0072] Specifically, when data retrieval or feature quantization is required, the target data can be obtained first, and the target data can be processed for feature extraction to obtain the target feature matrix of the target data. The method of feature extraction processing can be set according to the data type of the target data and based on actual technical needs. For example, when the target data is text data, a pre-trained text model can be used for feature extraction, such as a natural language processing model. When the target data is image data, algorithms such as Histogram of Oriented Gradients (HOG) and Scale-Invariant Feature Transform (SIFT) can be used for feature extraction. It can be understood that the method of obtaining the target feature matrix of the target data is the same as the method of obtaining the sample feature matrix of the sample data during hash code training.
[0073] It should be noted that for a sample data or a target data, each feature can be respectively represented as a 1×d dimensional feature vector, so that an n×d dimensional feature matrix composed of feature vectors can be obtained. That is to say, the feature vector is the row vector of the feature matrix. It can be understood that when the number of rows and columns of the feature matrix is interchanged, the feature vector can also be the column vector of the feature matrix. In this embodiment, in order to facilitate the distinction of the manifestation forms of features, the feature vector is represented by a lowercase letter. For example, the feature vector is represented as x, and the feature matrix corresponding to the feature vector is represented by the capital letter corresponding to the lowercase letter. For example, the feature matrix composed of the feature vector x is represented as X.
[0074] An anchor point refers to a determined positioning marker point, and the number of anchor points is multiple. In this embodiment, the anchor points can be determined according to the training data. Specifically, the sample feature matrix of the sample data is obtained, the sample data matrix is clustered, the clustering center of the sample data is obtained, and the clustering center of the sample data is determined as the anchor point, that is, the anchor point is the clustering center of the sample data. The clustering process can be based on the similarity or distance between the sample feature matrices, and the sample data is divided into multiple clustering clusters. The similarity of the sample data in each clustering cluster is relatively high, and the similarity of the sample data in different clustering clusters is relatively low. The clustering center is the center of the clustering cluster. The algorithm for the clustering process can be any one of the partitioning method, hierarchical method, density algorithm, grid algorithm, etc.
[0075] The similarity parameter matrix refers to the matrix determined based on the similarity between anchor points during the hash coding training process. The parameter relationship matrix refers to the matrix obtained after parameter operations based on the similarity between anchor points and sample data during the hash coding training process, and there is more than one parameter relationship matrix. The parameter relationship matrix can reduce the quantization error during the hash coding process of the target feature matrix.
[0076] Specifically, after the hash coding training is performed based on the sample feature matrix of the sample data, the similarity parameter matrix between anchor points and the parameter relationship matrix between anchor points and sample data can be obtained. Thus, in the subsequent processing process, the similarity parameter matrix and the parameter relationship matrix can be directly used to perform hash coding on the target data to determine the hash coding corresponding to the target data.
[0077] It should be noted that the calculation method of the similarity between anchor points needs to be consistent with the calculation method of the similarity between anchor points and sample data to ensure the consistency and accuracy of the obtained matrix.
[0078] Step S204, calculate the target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix.
[0079] The anchor feature of an anchor point is called an anchor feature vector, and the anchor feature vectors can form an anchor feature matrix. A kernel function refers to a function that can achieve the transformation from a low-dimensional space to a high-dimensional space, including but not limited to linear kernel functions, polynomial kernel functions, Gaussian kernel functions, etc. Kernel similarity refers to the similarity parameter between the anchor feature matrix and the target feature matrix obtained by calculation through the kernel function. The target similarity matrix refers to the matrix matched by the target data obtained after parameter operations based on the kernel similarity and the similarity parameter matrix.
[0080] The type of kernel function can be selected according to actual technical needs. In this embodiment, by means of the kernel trick, the similarity [-1, +1] of the original data is mapped to a new space so that its value range is [0, +1]. Thus, the mapped similarity can be fed into the angle quantization (AQ) algorithm to reduce the quantization error brought by the angle quantization algorithm. For the convenience of understanding, in this embodiment, the Gaussian kernel function is selected as an example for illustration. The Gaussian kernel function can be positioned as a monotonic function of the Euclidean distance between any point x in the space i to a certain center point x j , and the calculation formula is expressed as:
[0081]
[0082] where x i and x j respectively represent the feature vectors of the data, ||x i -x j || 2 represents the Euclidean distance between the vectors x i and x j . As the distance between the two vectors increases, the Gaussian kernel function value decreases monotonically, and σ 2 represents a hyperparameter.
[0083] Please refer to Figure 6 for the schematic diagram of the Gaussian kernel function distribution. It can be seen from Figure 6 that for any distributed data x i and x j , through the Gaussian kernel function, its Gaussian kernel similarity K(x i , x j ) can fall within the range of [0, +1]. Thus, subsequently, the angle quantization algorithm can be ideally used to further quantize it.
[0084] In this embodiment, the idea of an anchor graph is introduced, combining the Gaussian kernel similarity with the anchor points, and describing the similarity between data and data by means of the similarity between data and anchor points. Please refer to Figure 7Schematic diagram of the similarity distribution between the data in and the anchor points. Assume that there are feature vectors x of data with any distribution i and x j , and the anchor points are m1, m2, and m3. Then the Gaussian kernel similarity K(x i , x j ) can be approximated by the similarities K(x i , m1), K(x i , m2), K(x j , m2), and K(x j , m3) between the data and the anchor points. By introducing the anchor points, the dimension of the target feature matrix is expanded, which can make the length of the hash code of the finally obtained target data break through the limitation of the dimension of the target feature matrix, so that the length of the hash code can be longer and the representation of the hash code is more accurate, thereby effectively improving the performance of data retrieval.
[0085] It should be noted that in the above embodiments, the Gaussian kernel function is taken as an example of the kernel function for illustration. If other types of kernel functions are selected, the kernel similarity between the anchor point feature matrix of the anchor points and the target feature matrix can be determined according to the specific calculation formula of the kernel function, and finally the target similarity matrix matched by the target data can be obtained.
[0086] Step S206: Calculate the scores of the target similarity matrix based on the parameter relationship matrix to obtain the target score matrix of the target data.
[0087] Score calculation refers to the operation performed on the target similarity matrix based on the parameter relationship matrix. The target score matrix refers to the matrix obtained after performing score calculation based on the parameter relationship matrix and the target similarity matrix. The row vectors of the target score matrix are called score vectors.
[0088] Specifically, the method of score calculation can be set according to actual technical needs. In this embodiment, score calculation refers to performing matrix multiplication operation on the parameter relationship matrix and the target similarity matrix, and the obtained target score matrix is the result of the matrix multiplication operation of the parameter relationship matrix and the target similarity matrix.
[0089] Step S208: Generate the target hash code matched by the target data according to the target score matrix.
[0090] The target hash code refers to the hash code matched by the target data, and the hash code is composed of 0 and +1. After determining the target score matrix, for each score vector in the target score matrix, there is a corresponding determined hash code. After determining the hash codes corresponding to all the score vectors in the target score matrix, the target hash code of the target data can be determined.
[0091] Specifically, an association relationship between a score vector and a hash code can be pre-set, and according to the association relationship, the hash code corresponding to each score vector in the target score matrix is determined. Alternatively, it can also be based on the numerical magnitudes of the score vectors in the target score matrix to assign a hash code to each score vector, determine the hash code corresponding to the score vector, and finally generate the target hash code matching the target data.
[0092] Step S210, perform data retrieval through the target hash code to determine the retrieval result of the target data.
[0093] Data retrieval refers to a way of retrieving and determining data associated with the target data from a large amount of data. The retrieval result refers to the specific data type, data content, etc. of the data associated with the target data determined through data retrieval. The data type of the data associated with the target data can be the same as or different from the data type of the target data, which is not restricted here.
[0094] Performing data retrieval through the target hash code can be to calculate the similarity between the target hash code and the hash codes of other data, and determine the retrieval result of the target data according to the similarity. Among them, the hash codes of other data and the target hash code need to have the same length to improve the accuracy of the retrieval result. After determining the retrieval result of the target data, the candidate data corresponding to the retrieval result can be recalled, and then data display or data recommendation, etc. can be performed according to actual technical needs.
[0095] Specifically, the similarity between hash codes can be determined using the Hamming distance. The Hamming distance is the number of different corresponding bits of two hash codes of the same length. For example, there are two different bits between 1011101 and 1001001, so the Hamming distance is 2. Performing data retrieval based on hash codes has small time complexity, space complexity, and storage overhead, can improve the efficiency and accuracy of data retrieval, and save storage space.
[0096] In the above data retrieval method, hash coding training is performed based on the sample feature matrix of sample data, and a similarity parameter matrix between anchor points and a parameter relationship matrix between anchor points and sample data can be obtained. The anchor points are the clustering centers of the sample data. Accordingly, when performing hash coding processing on target data to generate the target hash code of the target data, various parameters can be directly obtained and used, which can improve the processing efficiency of hash coding processing for target data. By obtaining the target feature matrix of the target data, and further calculating the target similarity matrix matched by the target data according to the similarity parameter matrix obtained from the hash coding training and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix. Accordingly, by introducing the kernel similarity, for target data with any distribution, the value of its kernel similarity can be made to fall within a predetermined value range. By introducing anchor points, the similarity between data is approximated by the similarity between the data and the anchor points, which can achieve the expansion of the dimension of the target feature matrix of the target data, making the length of the subsequent obtained target hash code longer, that is, the target hash code can break through the limitation of the dimension of the target feature matrix, which is beneficial to subsequent data retrieval. Further, based on the parameter relationship matrix, a score calculation is performed on the target similarity matrix to obtain the target score matrix of the target data, and based on the target score matrix, the target hash code matched by the target data is generated, which can improve the accuracy of the generated target hash code. Finally, data retrieval can be performed through the target hash code to determine the retrieval result of the target data, which can improve the efficiency and performance of data retrieval.
[0097] In one embodiment, when calculating the similarity through a kernel function, the feature vectors of the data used can be regularized, so as to effectively prevent overfitting and improve the generalization ability. Therefore, regularization processing is required when obtaining the target feature matrix of the target data. Specifically, obtaining the target feature matrix of the target data includes: performing feature extraction processing on the target data to obtain the initial feature matrix of the target data; performing regularization processing on the initial feature matrix to obtain the target feature matrix of the target data.
[0098] The initial feature matrix refers to the feature matrix directly obtained after performing feature extraction processing on the target data. Regularization processing is an effective way to prevent overfitting. The target feature matrix is the initial feature matrix after regularization processing.
[0099] The method of feature extraction for the target data can be selected according to the data type of the target data, and specifically can include using a pre-trained neural network model or a classical algorithm. The regularization processing can be determined according to the operation requirements of the kernel function. When the kernel function is a Gaussian kernel function, specifically, L2 regularization processing, also known as L2 normalization processing, can be performed on the initial feature matrix to obtain the target feature matrix of the target data, denoted as XQ = {x i}。
[0100] It can be understood that when the kernel function is a kernel function of other types, the specific manner of regularization processing can change accordingly. When the kernel function is adaptable to various ways of regularization processing, the regularization processing of the initial feature matrix can also be L1 regularization or normalization processing, etc.
[0101] In this embodiment, by performing regularization processing on the initial feature matrix of the target data to obtain the target feature matrix, the regularized target feature matrix is used in the subsequent operation process, so as to effectively prevent overfitting, improve the generalization ability, and improve the accuracy of subsequent hash encoding of the target data.
[0102] In one embodiment, taking the Gaussian kernel function as an example, the target similarity matrix matched by the target data is calculated according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix, including: calculating the Gaussian kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix through the Gaussian kernel function to obtain the Gaussian kernel similarity matrix between the anchor point and the target data; performing matrix multiplication operation on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain the target similarity matrix matched by the target data.
[0103] The Gaussian kernel similarity refers to the kernel similarity parameter obtained through the operation of the Gaussian kernel function, and the Gaussian kernel similarity matrix refers to the matrix formed based on the calculated Gaussian kernel similarity between the anchor point and the target data. The similarity parameter matrix is obtained based on hash encoding training and can be directly obtained and used when processing the target data. The matrix multiplication operation refers to multiplying multiple matrices.
[0104] Specifically, the anchor point is represented as m i , the anchor feature matrix is represented as M = {m i}, and through the Gaussian kernel function, the Gaussian kernel similarity between the anchor feature matrix and the target feature matrix is calculated, and the Gaussian kernel similarity is represented as K(X, M). For each target feature vector in the target feature matrix, its corresponding Gaussian kernel similarity is represented as K(x i , M). The similarity parameter matrix is represented as C, and matrix multiplication operation is performed on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain the target similarity matrix matched by the target data. The target similarity matrix is represented as F = K(X, M)C, and each target similarity vector in the target similarity matrix is represented as f i = M(x i , M)C.
[0105] It should be noted that when performing matrix multiplication operations, two matrices can be multiplied only when the number of columns of one matrix is equal to the number of rows of the other matrix. Therefore, the positional relationship between the two matrices in the above matrix multiplication operation can be adaptively adjusted according to the actual matrix dimensions.
[0106] In this embodiment, a Gaussian kernel function is used to obtain a Gaussian kernel similarity matrix between the anchor points and the target data. For data with any distribution, the similarity between the data can be made to fall within the range of [0, +1]. By approximating the similarity between the data with the similarity between the data and the anchor points, a matrix multiplication operation is performed on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain the target similarity matrix matched by the target data, realizing the expansion of the dimension of the target feature matrix of the target data, enabling the length of the hash code of the finally obtained target data to break through the limitation of the dimension of the target feature matrix, making the hash code length longer and the representation of the hash code more accurate, thereby effectively improving the performance of data retrieval.
[0107] In one embodiment, the target hash code matched by the target data can be obtained by first calculating the target score matrix corresponding to the target similarity matrix and then performing hash code assignment according to the target score matrix. Specifically, based on the parameter relationship matrix, a score calculation is performed on the target similarity matrix to obtain the target score matrix of the target data, including: based on the parameter relationship matrix, a score calculation is performed on the target similarity matrix to determine the initial score matrix of the target data; the elements of each score vector in the initial score matrix are respectively sorted to obtain the target score matrix of the target data.
[0108] The parameter relationship matrix is obtained based on hash code training and can be directly obtained and used when processing the target data. The initial score matrix refers to the matrix directly determined by the operation of the parameter relationship matrix and the target similarity matrix. The sorting process refers to sorting according to the size of the elements. The target score matrix refers to the matrix obtained after sorting the elements of each score vector in the initial score matrix.
[0109] Specifically, through hash code training, it is determined that the parameter relationship matrix includes a projection matrix and a rotation matrix. The projection matrix is denoted as ∧ r and the rotation matrix is denoted as R. The initial score matrix is denoted as Y, and each score vector in the initial score matrix is denoted as y i , y i = f i ∧ r R. The sorting process can be performed in descending order of the numerical values of the elements, so that the elements in the score vector are in descending order, and finally the target score matrix Y of the target data is obtained.
[0110] In this embodiment, since the maximum value among the top k score vectors needs to be determined in the subsequent target hash encoding process, each element of the score vectors in the initial score matrix is sorted respectively to keep each element in descending order, and finally the target score matrix of the target data is obtained. In this way of descending order sorting, it is more convenient to determine the maximum value. When k increases by one, the previous results can be reused without traversing all the results, which can improve the efficiency of hash encoding processing for the target data.
[0111] In one embodiment, after determining the target score matrix, the target hash encoding corresponding to the target data can be determined according to the target score matrix. Specifically, according to the target score matrix, generating the target hash encoding matched by the target data includes: comparing the value of each score vector with the value of the score vector before it according to the position of each score vector in the target score matrix to obtain the comparison result of each score vector; performing hash encoding assignment based on the comparison result of each score vector to generate the hash encoding corresponding to each score vector; and combining the hash encodings of each score vector in the order of the score vectors to obtain the target hash encoding matched by the target data.
[0112] The position of the score vector refers to its position in the target score matrix. Since the score vector is a row vector of the target score matrix, the position of the score vector can be defined according to the row number where the score vector is located. Hash encoding assignment means assigning the hash encoding corresponding to the score vector. The score vector order refers to the position order of the score vectors in the target score matrix. For example, if the number of rows of the target score matrix is three, that is, it includes three score vectors, the hash encoding corresponding to the score vector in the first row is 1, the hash encoding corresponding to the score vector in the second row is 0, and the hash encoding corresponding to the score vector in the third row is 1, then the target hash encoding is 101.
[0113] Specifically, the hash encoding corresponding to the score vector is related to the size of the score vector. Since the hash encoding in this embodiment consists of 0 and +1, assuming the number of +1 in the target hash encoding is k, thus, it is defined that when and only when a certain score vector y i ′ is the maximum value among the top k score vectors, then Otherwise That is, it is necessary to determine whether the score vector is the maximum value among the top k score vectors according to the comparison result of each score vector. When the score vector is the maximum value, the corresponding hash encoding is +1, otherwise 0.
[0114] For example, assume that the target score matrix Y′ = [y1′, y2′,..., y n′, specifically Y′ = [1, 0, 2, 4, 3]. Among them, the score vector 1 is the maximum value in the previous score vector, so the corresponding hash code is 1. The score vector 0 is not the maximum value in the previous two score vectors, so the corresponding hash code is 0. The score vector 2 is the maximum value in the previous three score vectors, so the corresponding hash code is 1. The score vector 4 is the maximum value in the previous four score vectors, so the corresponding hash code is 1. The score vector 3 is not the maximum value in the previous five score vectors, so the corresponding hash code is 0. Thus, the numerical values of the hash codes corresponding to each score vector can be determined as b1 = 1, b2 = 0, b3 = 1, b4 = 1, b5 = 0. Therefore, the target hash code corresponding to the target data can be determined as 10110.
[0115] In this embodiment, through the position and value of each score vector in the target score matrix, the hash code corresponding to each score vector is generated, and then the hash codes are combined in the order of the score vectors. Finally, the target hash code matched by the target data is obtained, which can make the obtained target hash code more accurate.
[0116] In one embodiment, after determining the target hash code matched by the target data, data retrieval can be performed according to the target hash code. Specifically, data retrieval is performed through the target hash code to determine the retrieval result of the target data, including: calculating the similarity between the target hash code and the candidate hash codes corresponding to each candidate data for the target data to obtain a similarity result; based on the similarity result, screening out the similar hash codes that meet the similarity condition from each candidate hash code; and taking the candidate data corresponding to the similar hash codes as the retrieval result of the target data.
[0117] Candidate data refers to data that may be associated with the target data, and candidate data can be data in the retrieval database. Candidate hash code refers to the hash code matched by the candidate data. The similarity condition refers to the condition that the candidate hash code of the candidate data similar to the target data needs to meet. The similarity condition can be determined according to the calculation method of similarity. For example, when calculating the cosine similarity, it can be set that the cosine similarity is greater than the set cosine similarity threshold. When calculating the Hamming distance, it can be set that the Hamming distance is less than the set Hamming distance threshold. Both the cosine similarity threshold and the Hamming distance threshold can be set according to actual technical needs. Similar hash code refers to the candidate hash code that can meet the similarity condition.
[0118] Specifically, the calculation method of the similarity between the target hash code and the candidate hash codes corresponding to each candidate data for the target data can be to determine the Hamming distance between the target hash code and the candidate hash code to obtain a similarity result. Thus, similar hash codes that meet the similarity condition can be screened out from each candidate hash code, the candidate data corresponding to the similar hash codes can be determined, and the candidate data corresponding to the similar hash codes can be used as the retrieval result of the target data.
[0119] It should be noted that in this embodiment, in order to save processing time and effectively improve the efficiency of data retrieval, candidate data for the target data can be set in advance according to the target data, so that it is not necessary to determine the similarity between a large amount of data and the target data. It can be understood that when the data processing ability of the computer device is sufficient and the amount of retrievable data is limited, it is also possible not to determine candidate data and directly calculate the similarity between the target data and all other data.
[0120] In this embodiment, by setting candidate data for the target data and performing data retrieval based on the target hash code and the candidate hash codes of the candidate data, processing time can be saved and the efficiency of data retrieval can be improved.
[0121] In one embodiment, during the hash code training process, a similarity parameter matrix between anchor points can be determined based on sample data and directly obtained and used when processing target data. Specifically, the method further includes: calculating the Gaussian kernel similarity between anchor points through a Gaussian kernel function to obtain a Gaussian kernel similarity matrix between anchor points; performing matrix decomposition processing on the inverse matrix corresponding to the Gaussian kernel similarity matrix between anchor points to obtain a similarity parameter matrix between anchor points.
[0122] Matrix decomposition processing refers to splitting a matrix into the product of multiple matrices. The method of matrix decomposition processing can be one of triangular decomposition method, QR decomposition method, and singular value decomposition method, and can be specifically selected according to actual technical needs. The similarity parameter matrix is related to anchor points, and anchor points are the clustering centers of sample data, that is, determined by performing clustering processing on sample data. Therefore, after determining the sample data, the similarity parameter matrix can be determined during the hash code training process.
[0123] Specifically, through the Gaussian kernel function, the Gaussian kernel similarity between anchor points is calculated. The Gaussian kernel similarity matrix between anchor points is expressed as K(M,M), and its inverse matrix is expressed as K - (M,M), and this inverse matrix can be determined through matrix operations. Perform matrix decomposition processing on this inverse matrix to determine K - (M,M) = CC T , and thus the similarity parameter matrix C between anchor points can be obtained.
[0124] In this embodiment, the Gaussian kernel similarity between the anchor points is calculated through the Gaussian kernel function, and then further processed to obtain the similarity parameter matrix between the anchor points, so that the similarity parameter matrix is associated with the anchor points. During the process of performing hash coding processing on the target data, the target similarity matrix can also be associated with the anchor points, improving the accuracy of the target similarity matrix.
[0125] In one embodiment, for the convenience of understanding, the following provides relevant descriptions regarding the hash coding training process. During the hash coding training process, the parameter relationship matrix between the anchor points and the sample data can be determined based on the sample data and directly obtained for use when processing the target data.
[0126] Specifically, the method further includes: calculating the sample similarity matrix matched by the sample data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix and the sample feature matrix of the anchor points; performing matrix decomposition processing on the sample similarity matrix to obtain the initial parameter relationship matrix between the anchor points and the sample data; calculating the loss function of the hash coding matched by the sample features based on the sample similarity matrix and the initial parameter relationship matrix to obtain the hash coding loss function of the sample data; and updating the data of the initial parameter relationship matrix according to the hash coding loss function to obtain the parameter relationship matrix between the anchor points and the sample data.
[0127] The kernel similarity between the anchor feature matrix and the sample feature matrix is also determined based on the kernel function. The kernel function in this embodiment is the same as the kernel function used when processing the target data. The sample similarity matrix refers to the matrix matched by the sample data obtained after performing parameter operations on the kernel similarity calculated from the sample data and the similarity parameter matrix. The initial parameter relationship matrix refers to the matrix obtained by directly performing matrix decomposition processing on the sample similarity matrix. The hash coding loss function refers to the loss function in the hash coding training process determined with reference to the angular quantization hashing (AQ) algorithm according to the parameter calculation methods in this embodiment. The parameter relationship matrix refers to the matrix finally determined at the end of the hash coding training. The parameter relationship matrix includes the projection matrix ∧ r and the rotation matrix R.
[0128] Specifically, the sample feature matrix is represented as X = R n×d The anchor points are represented as M = R m×d The length of the hash code is represented as r. Please refer to Figure 7 The Gaussian kernel similarity between the sample data can be approximated by the Gaussian kernel similarity between the sample data and the anchor points, and its relationship can be expressed in the following form:
[0129] XX T ≈ K(X, M)K - (M, M)K(M, X) T
[0130] Perform matrix decomposition on the inverse matrix K - (M,M) corresponding to the Gaussian kernel similarity matrix between anchor points, and we can obtain:
[0131] K - (M,M) = CC T
[0132] Among them, the similarity parameter matrix between anchor points is C. Therefore, there is the following expression:
[0133] XX T ≈K(X,M)K - (M,M)K(M,X) T =K(X,M)CC T K(M,X) T
[0134] According to the above expression, the sample similarity matrix matched by the sample data can be defined as: F = K(X,M)C. It can be determined that the dimension of the sample similarity matrix F is n×m, where m is the number of anchor points. The original hash coding loss function is expressed as:
[0135]
[0136] Based on the sample similarity matrix F, the original hash coding loss function can be approximately expressed as follows:
[0137]
[0138] That is, the hash coding loss function in this embodiment is determined as follows:
[0139]
[0140] Among them, in the above formula represents the hash coding of the sample data, is a discrete variable. For easy solution, a continuous Y is introduced as an intermediate variable, and the hash coding loss function of this embodiment is transformed into:
[0141]
[0142] In the above hash coding loss function, the initial parameter relationship matrix can be determined according to the intermediate variable Y, and then, by operating on the hash coding loss function, that is, also updating the data of the initial parameter relationship matrix, the parameter relationship matrix between the anchor points and the sample data can be finally obtained.
[0143] In this embodiment, the original hash coding loss function is combined with the parameter calculation methods in this embodiment to obtain the hash coding loss function. By solving the hash coding loss function, the parameter relationship matrix between the anchor points and the sample data is finally obtained, which can improve the accuracy of the obtained parameter relationship matrix.
[0144] In one embodiment, the solution of the initial parameter relationship matrix between the anchor points and the sample data according to the hash coding loss function can be regarded as the solution of the first item in the hash coding loss function to obtain the initial parameter relationship matrix, that is, the initial projection matrix ∧ r and the initial rotation matrix R.
[0145] Specifically, matrix decomposition processing is performed on the sample similarity matrix to obtain the initial parameter relationship matrix between the anchor points and the sample data, including: calculating the product of the transpose of the sample similarity matrix and the sample similarity matrix to obtain the matrix product result; performing matrix decomposition processing on the matrix product result to obtain the initial parameter relationship matrix between the anchor points and the sample data.
[0146] Specifically, calculate the transpose F T of the sample similarity matrix and the product of the sample similarity matrix F to obtain the matrix product result, denoted as FF T , and this matrix product result FF T is also a part of the expression of the first item in the hash coding loss function. Perform matrix decomposition processing on the matrix product result FF T to obtain the following expression:
[0147] FF T = H∧H T
[0148] where ∧ is the diagonal matrix corresponding to the eigenvalues, and H is the eigenmatrix. Take its first r columns to obtain ∧ r ∈R m×r , r is the length of the hash code, that is, the initial projection matrix ∧ r is determined. Since the dimension of F is n×m, the value of r can be greater than d, which proves that the introduction of the anchor points can make the finally obtained hash code break through the limitation of the feature dimension. Then, using the characteristics of matrix decomposition, it can be determined that:
[0149] FF T ≈(F∧ r R)(F∧ r R) T
[0150] where R is an orthogonal matrix, that is, the initial rotation matrix R. The continuous variable introduced in the above embodiment can be defined as Y=(F∧ rR) ∈ R n×r to facilitate subsequent solution of the hash coding loss function.
[0151] In this embodiment, by processing the first term in the hash coding loss function, the solution of the hash coding loss function can be made more targeted, improving the speed of hash coding training.
[0152] In one embodiment, after determining the initial parameter relationship matrix, the solution of the parameter relationship matrix between the anchor point and the sample data can be regarded as the solution of the second term in the hash coding loss function. The solution method can be iterative solution using the alternating optimization method, which can be to first perform parameter initialization and then fix one variable and update the other variable.
[0153] Specifically, according to the hash coding loss function, data update is performed on the initial parameter relationship matrix to obtain the parameter relationship matrix between the anchor point and the sample data, including: taking the minimization of the value of the hash coding loss function as the goal, using the initial parameter relationship matrix as a fixed value, updating the hash coding matrix matched by the sample data to obtain an updated coding matrix; using the updated coding matrix as a fixed value, updating the initial parameter relationship matrix, and when the data update reaches the update end condition, obtaining the parameter relationship matrix between the anchor point and the sample data.
[0154] The updated coding matrix refers to the hash coding matrix used in the hash coding training process, that is, the discrete variable in the above embodiment The update end condition refers to the condition corresponding to the end of hash coding training, which can be set according to actual technical needs. For example, the update end condition can be set to the iteration number reaching the set iteration number, or the hash coding loss function converges.
[0155] Specifically, the expression of the intermediate variable Y = (F ∧ r R) ∈ R n×r has been determined in the above embodiment. Therefore, the second term of the hash coding loss function can be expressed as follows:
[0156]
[0157] where R can be understood as rotating F ∧ r to reduce the quantization error. Considering that is L2-normalized, that is, there is Therefore, in order to avoid the influence brought by the norm value range, F ∧ r is regarded as a whole and also L2-normalized.
[0158] The solution target of the second term can be transformed into solving where Denote the inner product of Y and , F and ∧ r are known variables, R and are variables to be solved. First, randomly initialize R, and then fix one variable and update the other variable, that is, fix R and update and fix to update R. Finally, when the data update reaches the update end condition, obtain the parameter relationship matrix between the anchor point and the sample data.
[0159] Specifically, when fixing R and updating , the solution objective of the second term can be transformed into successively solving for the row vectors of Solve Since there is However the number of +1s in is uncertain, but it is known that the number range of +1s is [1, r]. If it is assumed that the number of +1s in is k, then the positions of +1s in must correspond to the first k maximum values of y, so as to maximize this term. Therefore, traverse k ∈ [1, r] and record its corresponding value Finally, use to obtain where argmax is a function that finds the parameter set of a function. The calculation process of the above embodiment can be described as follows:
[0160] Algorithm 1: Solve
[0161] Input: y = f∧ r R;
[0162] Define the score = [0,..., 0] 1×r ;
[0163] Sort the elements in y to keep them in descending order;
[0164] For k = 1,..., r;
[0165] Define b k , whose elements at each position are when and only when y i is among the first k maximum values, otherwise
[0166] Calculate
[0167] Output: b k , where k = arg max(score k)。
[0168] Among them, the above-mentioned score k represents the k-th element in the score vector.
[0169] Specifically, under the condition of fixing and updating R, regarding F∧ r as a whole, for perform singular value decomposition, and we can get: Therefore, the rotation matrix R can be expressed as: R = SS T 。
[0170] During the process of hash code training, set the end condition of data update to reach the set number of iterations T, and regard one execution of fixing R update one execution of fixing updating R as one iteration operation. Perform iterative operations in a loop until the set number of iterations is reached, and finally obtain the parameter relationship matrix between the anchor point and the sample data, including the projection matrix ∧ r and the rotation matrix R. The hash code training process can be described as follows:
[0171] Algorithm 2: Hash Code Training
[0172] Input: Sample feature matrix X ∈ R^(n×d), anchor point M ∈ R^(m×d), length r of the hash code, number of iterations T;
[0173] Calculate K(X, M) and K(M, M) through the Gaussian kernel function K(·, ·);
[0174] Perform matrix decomposition on K - (M, M) to obtain C ∈ R m×m ;
[0175] Calculate F = K(X, M)C;
[0176] Perform matrix decomposition on FF T to obtain H∧H T , define Y = (F∧ r R);
[0177] Randomly initialize R r×r ;
[0178] For t = 1, …, T;
[0179] For i = 1, …, n;
[0180] Fix R d×r , generate the hash code b i corresponding to x i ;
[0181] Fix B n×r , perform singular value decomposition on , and update R = SS T ;
[0182] Output: similarity parameter matrix C, projection matrix ∧ r and rotation matrix R.
[0183] In this embodiment, by processing the second term in the hash coding loss function, specifically, an alternating optimization method is used for iterative update to solve the data, and finally the parameter relationship matrix, that is, the projection matrix ∧ r and rotation matrix R, can be obtained. Accordingly, the training speed of hash coding can be improved, and the accuracy of the determined parameter relationship can also be enhanced.
[0184] In one embodiment, after the hash coding training based on the sample feature matrix of the sample data is completed, the similarity parameter matrix C between the anchor points, the projection matrix ∧ r between the anchor points and the sample data, and the rotation matrix R can be obtained. When the target data for which hash coding is required is given, first use the same Gaussian kernel function as in the hash coding training process to determine the kernel similarity between the anchor point feature matrix and the target feature matrix, and then use Algorithm 1 to generate the target hash code matched by the target data. The algorithm for this process can be described as follows:
[0185] Algorithm 3: Hash Coding of Target Data;
[0186] Input: target feature matrix X Q ∈R m×d , anchor point M ∈ R m×d , similarity parameter matrix C, projection matrix ∧ r , rotation matrix R;
[0187] For i = 1, …, m;
[0188] Calculate f i = K(x i , M)C;
[0189] Generate the corresponding hash code b i of f through Algorithm 1 i ;
[0190] Output: hash code B Q ∈ {0, 1} m×r .
[0191] In this embodiment, after the hash coding training is completed, by directly obtaining the various parameters obtained from the hash coding training and determining the target hash code matching the target data in a manner corresponding to the training process, the accuracy of the obtained target hash code can be improved, and the processing efficiency of hash coding processing can be improved.
[0192] The following further details the present application in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0193] In a specific embodiment, taking the kernel function as the Gaussian kernel function as an example, the method of this embodiment is also called the angle quantization algorithm based on the Gaussian kernel. The following describes the specific processing procedures of hash coding training of sample data, generating the target hash code matching the target data, and data retrieval according to the target hash code.
[0194] Step S801, obtain the sample feature matrix of the sample data.
[0195] Specifically, the sample feature matrix is a matrix processed by L2 regularization, denoted as X = R n×d .
[0196] Step S802, perform clustering processing on the sample feature matrix to obtain the clustering center of the sample data, and determine the clustering center of the sample data as the anchor point.
[0197] Specifically, the clustering algorithm can be any one of the partitioning method, hierarchical method, density algorithm, grid algorithm, etc. By performing clustering processing on the sample feature matrix, the clustering center of the sample data can be obtained, and thus, the clustering center of the sample data can be determined as the anchor point, denoted as M = R m×d .
[0198] Step S803, calculate the Gaussian kernel similarity between the anchor points through the Gaussian kernel function to obtain the Gaussian kernel similarity matrix between the anchor points; perform matrix decomposition processing on the inverse matrix corresponding to the Gaussian kernel similarity matrix between the anchor points to obtain the similarity parameter matrix between the anchor points.
[0199] Specifically, the Gaussian kernel similarity between the sample data can be approximated by the Gaussian kernel similarity between the sample data and the anchor points, and their relationship can be expressed in the following form:
[0200] XX T ≈K(X,M)K - (M,M)K(M,X) T
[0201] For the inverse matrix K corresponding to the Gaussian kernel similarity matrix between the anchor points -Performing matrix factorization on (M, M) yields:
[0202] K - (M, M) = CC T
[0203] Among them, the similarity parameter matrix between the anchor points is C. Therefore, there is the following expression:
[0204] XX T ≈ K(X, M)K - (M, M)K(M, X) T = K(X, M)CC T K(M, X) T
[0205] Step S804: Calculate the sample similarity matrix matched by the sample data according to the similarity parameter matrix and the Gaussian kernel similarity between the anchor feature matrix of the anchor points and the sample feature matrix.
[0206] Specifically, according to the above expression, the sample similarity matrix matched by the sample data can be defined as F = K(X, M)C.
[0207] Step S805: Calculate the product of the transpose of the sample similarity matrix and the sample similarity matrix to obtain the matrix product result; perform matrix factorization on the matrix product result to obtain the initial parameter relationship matrix between the anchor points and the sample data.
[0208] Step S806: Calculate the hash coding loss function of the sample data based on the sample similarity matrix and the initial parameter relationship matrix for the hash coding matched by the sample features.
[0209] Specifically, the original hash coding loss function is expressed as:
[0210]
[0211] Based on the sample similarity matrix F, the original hash coding loss function can be approximately expressed as follows:
[0212]
[0213] That is, it is determined that the hash coding loss function in this embodiment is expressed as follows:
[0214]
[0215] Among them, in the above formula represents the hash coding of the sample data, is a discrete variable. To facilitate the solution, a continuous Y is introduced as an intermediate variable, and the hash coding loss function of this embodiment is transformed into:
[0216]
[0217] Calculate the transpose F of the sample similarity matrix T Multiply it by the sample similarity matrix F to obtain the matrix product result, denoted as FF T This matrix product result FF T is also a part of the expression of the first term in the hash coding loss function. For the matrix product result FF T perform matrix decomposition processing to obtain the following expression:
[0218] FF T = H∧H T
[0219] where ∧ is the diagonal matrix corresponding to the eigenvalues, and H is the eigenmatrix. Take its first r columns to obtain ∧ r ∈R m×r , r is the length of the hash code, that is, the initial projection matrix ∧ in the initial parameter relationship matrix is determined r . Then, using the properties of matrix decomposition, it can be determined that:
[0220] FF T ≈(F∧ r R)(F∧ r R) T
[0221] where R is an orthogonal matrix, that is, the initial rotation matrix R in the initial parameter relationship matrix is determined. The continuous variable introduced in the above embodiment can be defined as Y = (F∧ r R)∈R n×r , which is convenient for subsequent solving of the hash coding loss function.
[0222] Step S807: Taking the minimization of the value of the hash coding loss function as the goal, using the initial parameter relationship matrix as a fixed value, update the hash coding matrix matched by the sample data to obtain the updated coding matrix; using the updated coding matrix as a fixed value, update the initial parameter relationship matrix, and when the data update reaches the update end condition, obtain the parameter relationship matrix between the anchor point and the sample data.
[0223] Specifically, the expression of the intermediate variable Y = (F∧ r R)∈R n×r has been determined in the above embodiment. Therefore, the second term of the hash coding loss function can be expressed as follows:
[0224]
[0225] where R can be understood as the result of operating on F∧ rPerform rotation to reduce quantization error. Considering that is L2-normalized, that is, there exists Therefore, to avoid the influence brought by the norm value range, regard F∧ r as a whole and perform L2 normalization on it as well.
[0226] The solution objective of the second term can be transformed into solving where represents the inner product of Y and F and ∧ r are known variables, and R and are variables to be solved. First, randomly initialize R, and then fix one variable and update the other variable, that is, fix R and update and fix to update R. Finally, when the data update reaches the update end condition, obtain the parameter relationship matrix between the anchor point and the sample data.
[0227] Specifically, when fixing R and updating , the solution objective of the second term can be transformed into successively solving for the row vectors to solve Since there exists However the number of +1s in is uncertain, but it is known that the number range of +1s is [1, r]. If it is assumed that the number of +1s in is k, then the positions of +1s in must correspond to the first k maximum values of y, so as to maximize this term. Therefore, traverse k ∈ [1, r] and record its corresponding value Finally, use to obtain where argmax is a function that finds the set of parameters of a function. The calculation process of the above embodiment can be described as follows:
[0228] Algorithm 1: The solution of
[0229] Input: y = f∧ r R;
[0230] Define score = [0,..., 0] 1×r ;
[0231] Sort the elements in y to keep them in descending order;
[0232] For k = 1,..., r;
[0233] Define b k whose elements at each position are When and only when y i is among the top k maximum values, otherwise
[0234] calculate
[0235] Output: b k , where k = arg max(score k ).
[0236] Specifically, with R fixed and updated, regarding F∧ r as a whole, perform singular value decomposition on to obtain: Therefore, the rotation matrix R can be expressed as: R = SS T .
[0237] During the process of hash code training, set the end condition for data update to reach the set number of iterations T, and consider one execution of fixed R update one fixed update of R as one iteration operation. Perform iterative operations in a loop until the set number of iterations is reached, and finally obtain the parameter relationship matrix between the anchor points and the sample data, including the projection matrix ∧ r and the rotation matrix R. The hash code training process can be described as follows:
[0238] Algorithm 2: Hash Code Training
[0239] Input: Sample feature matrix X ∈ R^(n×d), anchor points M ∈ R^(m×d), length r of the hash code, number of iterations T;
[0240] Calculate K(X, M) and K(M, M) through the Gaussian kernel function K(·, ·);
[0241] Perform matrix decomposition on K - (M, M) to obtain C ∈ R m×m ;
[0242] Calculate F = K(X, M)C;
[0243] Perform matrix decomposition on FF T to obtain H∧H T , define Y = (F∧ r R);
[0244] Randomly initialize R r×r ;
[0245] For t = 1, …, T;
[0246] For i = 1, …, n;
[0247] Fix R d×r , generate x through Algorithm 1 i The corresponding hash code b i ;
[0248] Fix B n×r , for perform singular value decomposition, update R = SS T ;
[0249] Output: similarity parameter matrix C, projection matrix ∧ r and rotation matrix R.
[0250] Step S808, obtain the target feature matrix of the target data.
[0251] Specifically, the target feature matrix is a matrix processed by L2 regularization, denoted as X Q ∈R m×d .
[0252] Step S809, through the Gaussian kernel function, calculate the Gaussian kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix of the target data to obtain the Gaussian kernel similarity matrix between the anchor point and the target data; perform matrix multiplication on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain the target similarity matrix matched by the target data.
[0253] Step S810, based on the parameter relationship matrix, calculate the scores of the target similarity matrix to determine the initial score matrix of the target data; sort the elements of each score vector in the initial score matrix to obtain the target score matrix of the target data.
[0254] Step S811, according to the position of each score vector in the target score matrix, compare the value of each score vector with the value of the score vector before it to obtain the comparison result of each score vector; assign hash codes based on the comparison results of each score vector to generate the hash code corresponding to each score vector; combine the hash codes of each score vector in the order of the score vectors to obtain the target hash code matched by the target data.
[0255] Specifically, in the above embodiment, when given the target data that needs to be hashed, first use the same Gaussian kernel function as in the hash code training process to determine the kernel similarity between the anchor feature matrix and the target feature matrix, and then use Algorithm 1 to generate the target hash code matched by the target data. The algorithm of this process can be described as follows:
[0256] Algorithm 3: Hash code of target data;
[0257] Input: target feature matrix XQ ∈R m×d , the anchor point M ∈ R m×d , the similarity parameter matrix C, the projection matrix ∧ r , the rotation matrix R;
[0258] For i = 1, …, m;
[0259] Calculate f i = K(x i , M)C;
[0260] Generate f through Algorithm 1 i The corresponding hash code b i ;
[0261] Output: Hash code B Q ∈ {0, 1} m×r .
[0262] Step S812, according to the target hash code, calculate the similarity between the target hash code and the candidate hash codes corresponding to each candidate data for the target data, and obtain a similarity result; based on the similarity result, screen out the similar hash codes that meet the similarity condition from each candidate hash code; use the candidate data corresponding to the similar hash codes as the retrieval result of the target data.
[0263] Specifically, according to the target hash code, the similarity result can be obtained by calculating the Hamming distance between the target hash code and the candidate hash codes corresponding to each candidate data for the target data. Then, based on the similarity result, the similar hash codes that meet the similarity condition can be screened out from each candidate hash code; use the candidate data corresponding to the similar hash codes as the retrieval result of the target data, so that the candidate data corresponding to the retrieval result can be recalled to achieve data display or data recommendation.
[0264] To verify the effectiveness of the method in this embodiment for data retrieval in an actual application scenario, experiments were carried out on a publicly available image dataset. Randomly select 512-dimensional floating-point features corresponding to 3783 images as both the training set and the retrieval database, and randomly select the features of 1000 images from the remaining data as the test set. Use the evaluation metric MAP@K to verify the performance of data retrieval based on hash codes.
[0265] Specifically, the evaluation metric MAP@K refers to given c query samples and specifying to return the first K sample numbers, and its average retrieval precision is defined as:
[0266]
[0267] where, g j is Among the retrieval results, the number of correctly retrieved samples. P(i) is defined as the prediction accuracy of the first i retrieval results, and σ(i) is an indicator function, which is equal to 1 if the i-th retrieved sample is predicted correctly, and 0 otherwise. The larger the value of MAP@K, the better the retrieval performance.
[0268] Using the method of this embodiment, 2048 samples are randomly selected from the training set as anchor points, and the parameter σ in the Gaussian kernel function 2 is set as follows:
[0269]
[0270] where μ is the average value of the Euclidean distance ||m i -m j || 2 between the anchor points M, and β is set to 0.5. The Iterative Quantization (ITQ) algorithm and the Angular Quantization Hash Code (AQ) algorithm are used as comparison methods, and the retrieval performance is compared under different hash code lengths of 64 bits, 128 bits, 256 bits, and 512 bits. At the same time, the retrieval performance corresponding to the original 512-dimensional features is listed as a standard.
[0271] Please refer to Figure 9 for the schematic diagram of the retrieval performance comparison. It can be determined from this that, under different hash code length settings, the method of this embodiment has a significant improvement in retrieval performance compared with the iterative quantization algorithm and the angular quantization hash code algorithm. For example, at 64 bits, the method of this embodiment has a 7.40% improvement compared with the iterative quantization algorithm and a 5.75% improvement compared with the angular quantization hash code algorithm; at 512 bits, the method of this embodiment has a 2.86% improvement compared with the iterative quantization algorithm and a 1.83% improvement compared with the angular quantization hash code algorithm. The significant improvement compared with the angular quantization hash code algorithm is due to the conversion of the Gaussian kernel to the similarity value range, which verifies the effectiveness of this embodiment in data retrieval. Moreover, as the hash code length increases, the retrieval performance of the hash code also continuously climbs. At 512 bits, the performance of the binary hash code quantized by the method of this embodiment only drops by 1.35% compared with the floating-point features of the same dimension. It can be seen from this that the method of this embodiment is effective in data retrieval in practical application scenarios.
[0272] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are sequentially shown according to the indications of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this document, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0273] Based on the same inventive concept, an embodiment of the present application further provides a data retrieval device for implementing the data retrieval method described above. The solution provided by this device for solving problems is similar to the solution described in the above method. Therefore, the specific limitations in one or more embodiments of the data retrieval device provided below can refer to the limitations on the data retrieval method in the above text, and will not be repeated here.
[0274] In one embodiment, as Figure 10 shown, a data retrieval device is provided, including: a data acquisition module 10, a similarity calculation module 20, a score calculation module 30, a data encoding module 40, and a result determination module 50, where:
[0275] The data acquisition module 10 is configured to acquire a target feature matrix of target data, and acquire a similarity parameter matrix between anchor points and a parameter relationship matrix between an anchor point and sample data obtained by performing hash encoding training on a sample feature matrix based on sample data; the anchor point is the clustering center of the sample data.
[0276] The similarity calculation module 20 is configured to calculate a target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix.
[0277] The score calculation module 30 is configured to calculate a score of the target similarity matrix based on the parameter relationship matrix to obtain a target score matrix of the target data.
[0278] The data encoding module 40 is configured to generate a target hash code matched by the target data according to the target score matrix.
[0279] The result determination module 50 is configured to perform data retrieval through the target hash code to determine the retrieval result of the target data.
[0280] In one embodiment, the data acquisition module 10 includes:
[0281] A matrix acquisition unit, configured to perform feature extraction processing on target data to obtain an initial feature matrix of the target data.
[0282] A matrix processing unit, configured to perform regularization processing on the initial feature matrix to obtain a target feature matrix of the target data.
[0283] In one embodiment, the similarity calculation module 20 includes:
[0284] A similarity matrix calculation unit, configured to calculate the Gaussian kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix through a Gaussian kernel function, to obtain a Gaussian kernel similarity matrix between the anchor point and the target data.
[0285] A matrix product calculation unit, configured to perform a matrix product operation on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain a target similarity matrix matched by the target data.
[0286] In one embodiment, the score calculation module 30 includes:
[0287] A score calculation unit, configured to calculate scores for the target similarity matrix based on the parameter relationship matrix to determine an initial score matrix of the target data.
[0288] An element sorting unit, configured to respectively perform sorting processing on the elements of each score vector in the initial score matrix to obtain a target score matrix of the target data.
[0289] In one embodiment, the data encoding module 40 includes:
[0290] A numerical comparison unit, configured to, according to the position of each score vector in the target score matrix, perform a numerical comparison between the value of each score vector and the value of the score vector located before the score vector to obtain a comparison result of each score vector.
[0291] An encoding assignment unit, configured to perform hash encoding assignment based on the comparison result of each score vector to generate a hash encoding corresponding to each score vector.
[0292] An encoding combination unit, configured to combine the hash encodings of each score vector in the order of the score vectors to obtain a target hash encoding matched by the target data.
[0293] In one embodiment, the result determination module 50 includes:
[0294] A similarity calculation unit, configured to calculate a similarity between the target hash code and candidate hash codes corresponding to each candidate data for the target data according to the target hash code, so as to obtain a similarity result.
[0295] A similarity screening unit, configured to screen out similar hash codes that meet the similarity condition from each of the candidate hash codes based on the similarity result.
[0296] A retrieval result determination unit, configured to use the candidate data corresponding to the similar hash code as the retrieval result of the target data.
[0297] In one embodiment, the apparatus further includes a data determination module.
[0298] In one embodiment, the data determination module includes:
[0299] A Gaussian kernel similarity matrix calculation unit, configured to calculate a Gaussian kernel similarity between the anchor points through a Gaussian kernel function, so as to obtain a Gaussian kernel similarity matrix between the anchor points.
[0300] A similarity parameter matrix determination unit, configured to perform matrix decomposition processing on an inverse matrix corresponding to the Gaussian kernel similarity matrix between the anchor points to obtain a similarity parameter matrix between the anchor points.
[0301] In one embodiment, the apparatus further includes a data update module.
[0302] In one embodiment, the data update module includes:
[0303] A sample similarity matrix calculation unit, configured to calculate a sample similarity matrix matched by the sample data according to the similarity parameter matrix and a kernel similarity between an anchor feature matrix of the anchor points and the sample feature matrix.
[0304] An initial parameter relationship matrix determination unit, configured to perform matrix decomposition processing according to the sample similarity matrix to obtain an initial parameter relationship matrix between the anchor points and the sample data.
[0305] A hash code loss function calculation unit, configured to calculate a loss function for a hash code matched by the sample feature based on the sample similarity matrix and the initial parameter relationship matrix, so as to obtain a hash code loss function of the sample data.
[0306] A data update unit, configured to update data of the initial parameter relationship matrix according to the hash code loss function to obtain a parameter relationship matrix between the anchor points and the sample data.
[0307] In one embodiment, the initial parameter relationship matrix determination unit further includes:
[0308] A product calculation unit for calculating the product of the transpose of the sample similarity matrix and the sample similarity matrix to obtain a matrix product result.
[0309] A matrix determination unit for performing matrix decomposition processing on the matrix product result to obtain an initial parameter relationship matrix between the anchor points and the sample data.
[0310] In one embodiment, the hash coding loss function calculation unit further includes:
[0311] A first data update unit for taking the minimization of the value of the hash coding loss function as the goal, taking the initial parameter relationship matrix as a fixed value, and updating the hash coding matrix matched by the sample data to obtain an updated coding matrix.
[0312] A second data update unit for taking the updated coding matrix as a fixed value, updating the initial parameter relationship matrix, and obtaining a parameter relationship matrix between the anchor points and the sample data when the data update reaches the update end condition.
[0313] Each module in the above data retrieval device can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory of the computer device in the form of software, so as to facilitate the processor to call and execute the operations corresponding to each of the above modules.
[0314] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 11 shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store various types of data involved in the data retrieval method. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. The computer program, when executed by the processor, implements a data retrieval method.
[0315] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structural diagram may be as shown in Figure 12 . The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface, the display unit, and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used for exchanging information between the processor and external devices. The communication interface of the computer device is used for communicating with external terminals in a wired or wireless manner. The wireless manner can be implemented through WIFI, a mobile cellular network, NFC (Near Field Communication), or other technologies. The computer program, when executed by the processor, implements a data retrieval method. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen may be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device may be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0316] Those skilled in the art can understand that Figure 11 and Figure 12 the structure shown in
[0317] is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0318] In one embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps of the above-mentioned data retrieval method are implemented.
[0319] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, the steps of the above-mentioned data retrieval method are implemented.
[0320] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0321] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0322] The above embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A data retrieval method, characterized in that, The method includes: Obtaining a target feature matrix of target data, and obtaining a similarity parameter matrix between anchor points and a parameter relationship matrix between an anchor point and sample data obtained by performing hash encoding training on a sample feature matrix based on sample data; the anchor points are the clustering centers of the sample data; the parameter relationship matrix refers to a matrix obtained by performing parameter operations based on the similarity between an anchor point and sample data during the hash encoding training process; Calculating a target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix; Calculating a score of the target similarity matrix based on the parameter relationship matrix to obtain a target score matrix of the target data; Generating a target hash code matched by the target data according to the target score matrix; Performing data retrieval through the target hash code to determine a retrieval result of the target data.
2. The method according to claim 1, wherein The obtaining of the target feature matrix of the target data includes: Performing feature extraction processing on the target data to obtain an initial feature matrix of the target data; Performing regularization processing on the initial feature matrix to obtain the target feature matrix of the target data.
3. The method according to claim 1, wherein The calculating of the target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix includes: Calculating the Gaussian kernel similarity between the anchor feature matrix of the anchor point and the target feature matrix through a Gaussian kernel function to obtain a Gaussian kernel similarity matrix between the anchor point and the target data; Performing matrix multiplication on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain the target similarity matrix matched by the target data.
4. The method according to claim 1, characterized in that The calculating of the score of the target similarity matrix based on the parameter relationship matrix to obtain the target score matrix of the target data includes: Calculating the score of the target similarity matrix based on the parameter relationship matrix to determine an initial score matrix of the target data; Performing sorting processing on the elements of each score vector in the initial score matrix to obtain the target score matrix of the target data.
5. The method according to claim 4, wherein The generating of the target hash code matched by the target data according to the target score matrix includes: According to the position of each score vector in the target score matrix, comparing the value of each score vector with the value of the score vector before the score vector to obtain a comparison result of each score vector; Performing hash code assignment based on the comparison result of each score vector to generate a hash code corresponding to each score vector; Combining the hash codes of each score vector in the order of the score vectors to obtain the target hash code matched by the target data.
6. The method according to any one of claims 1 to 5, characterized in that, The performing of data retrieval through the target hash code to determine the retrieval result of the target data includes: Calculating the similarity between the target hash code and candidate hash codes corresponding to each candidate data for the target data according to the target hash code to obtain a similarity result; Based on the similarity results, screen out similar hash codes that meet the similarity conditions from each of the candidate hash codes; Use the candidate data corresponding to the similar hash codes as the retrieval result of the target data.
7. The method according to claim 1, characterized in that, The method further includes: Calculate the Gaussian kernel similarity between the anchor points through a Gaussian kernel function to obtain the Gaussian kernel similarity matrix between the anchor points; Perform matrix decomposition processing on the inverse matrix corresponding to the Gaussian kernel similarity matrix between the anchor points to obtain the similarity parameter matrix between the anchor points.
8. The method according to claim 1, characterized in that The method further includes: Calculate the sample similarity matrix matched by the sample data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the sample feature matrix; Perform matrix decomposition processing on the sample similarity matrix to obtain the initial parameter relationship matrix between the anchor points and the sample data; Based on the sample similarity matrix and the initial parameter relationship matrix, calculate the loss function of the hash code matched by the sample feature to obtain the hash code loss function of the sample data; According to the hash code loss function, update the data of the initial parameter relationship matrix to obtain the parameter relationship matrix between the anchor points and the sample data.
9. The method according to claim 8, wherein The performing matrix decomposition processing on the sample similarity matrix to obtain the initial parameter relationship matrix between the anchor points and the sample data includes: Calculate the product of the transpose of the sample similarity matrix and the sample similarity matrix to obtain a matrix product result; Perform matrix decomposition processing on the matrix product result to obtain the initial parameter relationship matrix between the anchor points and the sample data.
10. The method according to claim 8, wherein The updating the data of the initial parameter relationship matrix according to the hash code loss function to obtain the parameter relationship matrix between the anchor points and the sample data includes: Taking the minimization of the value of the hash code loss function as the goal, using the initial parameter relationship matrix as a fixed value, update the hash code matrix matched by the sample data to obtain an updated code matrix; Use the updated code matrix as a fixed value to update the initial parameter relationship matrix, and when the data update reaches the update end condition, obtain the parameter relationship matrix between the anchor points and the sample data.
11. A data retrieval device, characterized in that, The device includes: A data acquisition module, configured to acquire the target feature matrix of the target data, and acquire the similarity parameter matrix between the anchor points obtained by performing hash code training on the sample feature matrix based on the sample data and the parameter relationship matrix between the anchor points and the sample data; the anchor points are the clustering centers of the sample data; the parameter relationship matrix refers to the matrix obtained by performing parameter operations based on the similarity between the anchor points and the sample data during the hash code training process; A similarity calculation module, configured to calculate the target similarity matrix matched by the target data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the target feature matrix; A score calculation module, configured to calculate the score of the target similarity matrix based on the parameter relationship matrix to obtain the target score matrix of the target data; A data encoding module, configured to generate a target hash code matched by the target data according to the target score matrix; A result determination module, configured to perform data retrieval through the target hash code to determine a retrieval result of the target data.
12. The device according to claim 11, wherein, The data acquisition module includes: A matrix acquisition unit, configured to perform feature extraction processing on target data to obtain an initial feature matrix of the target data; A matrix processing unit, configured to perform regularization processing on the initial feature matrix to obtain a target feature matrix of the target data.
13. The device according to claim 11, characterized in that, The similarity calculation module includes: A similarity matrix calculation unit, configured to calculate a Gaussian kernel similarity between an anchor feature matrix of an anchor point and the target feature matrix through a Gaussian kernel function to obtain a Gaussian kernel similarity matrix between the anchor point and the target data; A matrix multiplication calculation unit, configured to perform a matrix multiplication operation on the Gaussian kernel similarity matrix and the similarity parameter matrix to obtain a target similarity matrix matched by the target data.
14. The device according to claim 11, wherein The score calculation module includes: A score calculation unit, configured to perform score calculation on the target similarity matrix based on the parameter relationship matrix to determine an initial score matrix of the target data; An element sorting unit, configured to perform sorting processing on elements of each score vector in the initial score matrix to obtain a target score matrix of the target data.
15. The device according to claim 14, characterized in that, The data encoding module includes: A numerical comparison unit, configured to numerically compare the value of each score vector in the target score matrix with the value of the score vector located before the score vector according to the position of each score vector in the target score matrix to obtain a comparison result of each score vector; An encoding assignment unit, configured to perform hash encoding assignment based on the comparison result of each score vector to generate a hash code corresponding to each score vector; An encoding combination unit, configured to combine the hash codes of each score vector in the order of the score vectors to obtain a target hash code matched by the target data.
16. The device according to any one of claims 11 to 15, characterized in that, The result determination module includes: A similarity calculation unit, configured to calculate a similarity between the target hash code and candidate hash codes corresponding to each candidate data for the target data according to the target hash code to obtain a similarity result; A similarity screening unit, configured to screen out similar hash codes that meet the similarity condition from each candidate hash code based on the similarity result; A retrieval result determination unit, configured to use the candidate data corresponding to the similar hash code as the retrieval result of the target data.
17. The device according to claim 11, wherein The apparatus further includes a data determination module, and the data determination module includes: A Gaussian kernel similarity matrix calculation unit, configured to calculate a Gaussian kernel similarity between anchor points through a Gaussian kernel function to obtain a Gaussian kernel similarity matrix between the anchor points; A similarity parameter matrix determination unit, configured to perform matrix decomposition processing on an inverse matrix corresponding to the Gaussian kernel similarity matrix between the anchor points to obtain a similarity parameter matrix between the anchor points.
18. The device according to claim 11, characterized in that, The apparatus further includes a data update module, and the data update module includes: A sample similarity matrix calculation unit, configured to calculate a sample similarity matrix matched by the sample data according to the similarity parameter matrix and the kernel similarity between the anchor feature matrix of the anchor points and the sample feature matrix; An initial parameter relationship matrix determination unit, configured to perform matrix decomposition processing on the sample similarity matrix to obtain an initial parameter relationship matrix between the anchor points and the sample data; A hash coding loss function calculation unit, configured to calculate a loss function of the hash coding matched by the sample features based on the sample similarity matrix and the initial parameter relationship matrix, to obtain a hash coding loss function of the sample data; A data update unit, configured to update data of the initial parameter relationship matrix according to the hash coding loss function to obtain a parameter relationship matrix between the anchor points and the sample data.
19. The device according to claim 18, wherein The initial parameter relationship matrix determination unit further includes: A product calculation unit, configured to calculate a product of the transpose of the sample similarity matrix and the sample similarity matrix to obtain a matrix product result; A matrix determination unit, configured to perform matrix decomposition processing on the matrix product result to obtain an initial parameter relationship matrix between the anchor points and the sample data.
20. The apparatus according to claim 18, characterized in that, The hash coding loss function calculation unit further includes: A first data update unit, configured to target minimizing the value of the hash coding loss function, take the initial parameter relationship matrix as a fixed value, and update the hash coding matrix matched by the sample data to obtain an updated coding matrix; A second data update unit, configured to take the updated coding matrix as a fixed value, update the initial parameter relationship matrix, and obtain a parameter relationship matrix between the anchor points and the sample data when the data update reaches an update end condition.
21. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
22. 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 method according to any one of claims 1 to 10 are implemented.
23. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Target clustering method based on iterative adaptive affinity propagation algorithm
CN112926635A
Data retrieval method and device, electronic equipment, storage medium and computer product
CN113590898A