A retrieval method, device, equipment and storage medium based on hash code
The eigenvectors are processed by the target projection matrix and the target rotation matrix, and a hash code distributed between 0 and 1 is generated, which solves the problem of large quantization loss under high-dimensional vectors and improves the retrieval performance.
Patent Information
- Application Number
- CN202210088542.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2042-01-25
AI Technical Summary
The existing hashing algorithms have large quantization losses caused by high-dimensional vectors, resulting in a decrease in the accuracy of cosine similarity, which in turn affects the retrieval performance.
The eigenvectors are calculated through the target projection matrix and the target rotation matrix, the score vector is generated, and each score element is encoded to generate the target hash code, so that it is distributed between 0 and 1, reducing the quantization error.
The cosine similarity accuracy of the hash code is improved and the retrieval performance is improved, so that the cosine similarity between information distributed between 0 and 1 can be more accurately reflected in the Hamming space.
Smart Images

Figure CN114417251B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and in particular to a retrieval method, apparatus, device and storage medium based on a hash code. Background Art
[0002] 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. However, with the popularization of the Internet and digital devices, it has become very common to manage databases with millions of images. In the face of massive data, the nearest neighbor search (ANN) has a wider application advantage than the exact search, thus becoming a key technology in information retrieval. In many past literatures on ANN methods, hashing technology has received more and more attention due to its low storage cost and high query efficiency.
[0003] The hash algorithm mainly learns the hash code by maintaining the similarity of the original vector in the Hamming space. Common similarity metrics include Euclidean distance and cosine distance. However, the Euclidean distance has the disadvantage of having a large range of values under high-dimensional vectors. In this case, the cosine distance can not only reflect the relative difference in direction, but also has a stable range and better applicability. Therefore, with the popularization of deep learning, high-dimensional vectors have become a common representation. Therefore, how to fully mine the cosine similarity information between data has important research significance.
[0004] However, since binary hash codes are discrete values, it is impossible to directly use the gradient descent algorithm to train and optimize deep neural networks. Most methods first learn a real-valued common space and then quantize the real-valued representation into a simple discrete hash code. The quantization process often leads to large quantization loss. Directly using it to calculate cosine similarity will result in reduced cosine similarity accuracy, resulting in low retrieval performance. Summary of the invention
[0005] The embodiments of the present application provide a hash code-based retrieval method, apparatus, device and storage medium for encoding each score element so that the compiled first target hash code can be well distributed between 0 and 1 and the quantization error is small, so that the cosine similarity based on the first target hash code in the Hamming space can more accurately reflect the cosine similarity between information distributed between 0 and 1, thereby improving the retrieval performance.
[0006] On the one hand, an embodiment of the present application provides a retrieval method based on a hash code, comprising:
[0007] Obtaining a first eigenvector corresponding to the information to be processed;
[0008] The first eigenvector is calculated using the target projection matrix and the target rotation matrix to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results;
[0009] For each score element in the first score vector, numerically compare the score element with each score element that appears before the score element to obtain a code value corresponding to the score element, wherein the code value corresponding to each score element is 0 or 1;
[0010] Generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector;
[0011] The first target retrieval information is determined according to the first target hash code.
[0012] On the other hand, the present application provides a retrieval device based on a hash code, comprising:
[0013] An acquisition unit, used for acquiring a first feature vector corresponding to the information to be processed;
[0014] A processing unit, configured to calculate the first eigenvector using a target projection matrix and a target rotation matrix to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results;
[0015] The processing unit is further configured to compare, for each score element in the first score vector, the score element with each score element that appears before the score element, so as to obtain a code value corresponding to the score element, wherein the code value corresponding to each score element is 0 or 1;
[0016] The processing unit is further used to generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector;
[0017] The processing unit is further configured to determine the first target retrieval information according to the first target hash code.
[0018] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0019] The processing unit is further configured to calculate the second eigenvector using the target projection matrix and the target rotation matrix to obtain a second score vector if the information to be processed corresponds to the second eigenvector;
[0020] The processing unit is further configured to, for each score element in the second score vector, perform a numerical comparison between the score element and each score element that appears before the score element, so as to obtain a code value corresponding to the score element;
[0021] The processing unit may be specifically configured to generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector and the encoded value of each score element in the second score vector.
[0022] In a possible design, in an implementation of another aspect of the embodiment of the present application, the acquisition unit may be specifically used to:
[0023] Perform feature extraction on the information to be processed to obtain a basic feature vector corresponding to the information to be processed;
[0024] Regularization is performed on the basic eigenvector to obtain the first eigenvector.
[0025] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0026] The processing unit is further used to calculate a first similarity between a first target hash code corresponding to the information to be processed and each hash code in the search library;
[0027] a determining unit, configured to determine, according to the first similarity, a first similar hash code to the first target hash code from each hash code in the search library;
[0028] The processing unit is further configured to use the information corresponding to the first similar hash code as the first target retrieval information.
[0029] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0030] The processing unit is further used to calculate a target weight matrix using a target hash matrix and a target weight, wherein the target hash matrix and the target weight are training results;
[0031] The processing unit is further used to calculate a second target hash code corresponding to the information to be processed according to the first eigenvector and the target weight matrix.
[0032] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0033] The processing unit is further used to calculate a second similarity between a second target hash code corresponding to the information to be processed and each hash code in the retrieval library;
[0034] The determining unit is further configured to determine, according to the second similarity, a second similar hash code of the second target hash code from each hash code in the search library;
[0035] The processing unit is further configured to use the information corresponding to the second similar hash code as second target retrieval information.
[0036] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0037] The acquisition unit is also used to acquire the sample feature vector corresponding to the sample information;
[0038] The processing unit is further used to use the original projection matrix, the original rotation matrix and the original hash matrix to perform loss calculation on the sample feature vector to obtain a first loss function, wherein the original rotation matrix is a randomly assigned orthogonal matrix, the original projection matrix is extracted based on the diagonal matrix corresponding to the sample feature vector, and the original hash matrix is randomly assigned;
[0039] The processing unit is further used to update the original projection matrix, the original rotation matrix and the original hash matrix according to the first loss function to obtain the target projection matrix, the target rotation matrix and the target hash matrix.
[0040] In a possible design, in an implementation of another aspect of the embodiment of the present application, the processing unit may be specifically used for:
[0041] According to the first loss function, the original projection matrix and the original rotation matrix are used to update the original hash matrix to obtain the target hash matrix;
[0042] According to the first loss function, the original hash matrix is used to update the original rotation matrix and the original projection matrix to obtain the target projection matrix and the target rotation matrix.
[0043] In a possible design, in an implementation of another aspect of the embodiment of the present application, the processing unit may be specifically used for:
[0044] The original projection matrix and the original rotation matrix are used to calculate the sample feature vector to obtain the sample score vector;
[0045] For each score element in the sample score vector, numerically compare the score element with each score element that appears before the score element to obtain the encoding value corresponding to each score element in the sample score vector;
[0046] Generate a sample hash code corresponding to the sample information according to the encoded value of each score element in the sample score vector;
[0047] Update the original hash matrix according to the sample hash codes to obtain the target hash code matrix.
[0048] In a possible design, in an implementation of another aspect of the embodiment of the present application, the processing unit may be specifically used for:
[0049] Using the original hash matrix, perform matrix decomposition on the first loss function to obtain a decomposed projection matrix and a decomposed rotation matrix;
[0050] The original rotation matrix and the original projection matrix are updated according to the decomposed projection matrix and the decomposed rotation matrix respectively to obtain the target projection matrix and the target rotation matrix.
[0051] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0052] The processing unit is further used to calculate the loss of the sample feature vector using the target hash matrix, the original weights and the original weight matrix to obtain a second loss function, wherein the original weights are obtained by random assignment;
[0053] The processing unit is also used to update the original weight matrix and the original weights according to the second loss function to obtain the target weight matrix and the target weights.
[0054] In a possible design, in an implementation of another aspect of the embodiment of the present application,
[0055] The processing unit is further used to calculate the product of the sample feature vector and the transpose of the sample feature vector;
[0056] The processing unit is further used to perform eigendecomposition on the product of the sample eigenvector and the transpose of the sample eigenvector to obtain a diagonal matrix corresponding to the sample eigenvector;
[0057] The processing unit is further used to extract features from the diagonal matrix according to the original rotation matrix to obtain the original projection matrix.
[0058] On the other hand, the present application provides a computer device, including: a memory, a transceiver, a processor, and a bus system;
[0059] Wherein, the memory is used to store programs;
[0060] The processor is used to implement the above-mentioned methods when executing the program in the memory;
[0061] The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
[0062] Another aspect of the present application provides a computer-readable storage medium, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer is enabled to execute the above-mentioned methods.
[0063] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0064] By obtaining the first eigenvector corresponding to the information to be processed, the target projection matrix and the target rotation matrix are used to calculate the first eigenvector to obtain the first score vector, and for each score element in the first score vector, the score element is numerically compared with each score element that appears before the score element to obtain the encoding value of 0 or 1 corresponding to the score element, and then, according to the encoding value of each score element in the first score vector, the first target hash code corresponding to the information to be processed can be generated, and the first target retrieval information can be determined according to the first target hash code. In the above manner, each score element can be encoded by converting the information to be processed into the first score vector to obtain the encoding value of 0 or 1 corresponding to the score element, so that the compiled first target hash code can be well distributed between 0 and 1 and the quantization error is small, so that the cosine similarity based on the target hash code in the Hamming space can more accurately reflect the cosine similarity between the information distributed between 0 and 1, thereby improving the retrieval performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 This is a schematic diagram of the architecture of a data object control system in an embodiment of the present application;
[0066] Figure 2 is a flowchart of an embodiment of a retrieval method based on a hash code in an embodiment of the present application;
[0067] Figure 3 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0068] Figure 4 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0069] Figure 5 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0070] Figure 6 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0071] Figure 7 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0072] Figure 8 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0073] Fig. 9 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0074] Fig.10 is another embodiment flow chart of the retrieval method based on hash code in the embodiment of the present application;
[0075] Fig.11 It is a schematic diagram of the distribution of cosine similarity of a retrieval method based on hash code in an embodiment of the present application;
[0076] Fig.12 It is a schematic diagram of obtaining cosine similarity in a retrieval method based on hash codes in an embodiment of the present application;
[0077] Fig.13 It is a schematic diagram of an embodiment of a retrieval device based on a hash code in an embodiment of the present application;
[0078] Fig.14 It is a schematic diagram of an embodiment of a computer device in an embodiment of the present application. DETAILED DESCRIPTION
[0079] The embodiments of the present application provide a hash code-based retrieval method, apparatus, device and storage medium for encoding each score element so that the compiled first target hash code can be well distributed between 0 and 1 and the quantization error is small, so that the cosine similarity based on the first target hash code in the Hamming space can more accurately reflect the cosine similarity between information distributed between 0 and 1, thereby improving the retrieval performance.
[0080] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "corresponding to" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0081] With the rapid development of information, artificial intelligence (AI) has gradually entered all aspects of people's lives. Artificial intelligence has broad practical significance in text translation, intelligent question and answer, and sentiment analysis. The emergence of artificial intelligence has also greatly facilitated people's lives. First of all, a brief explanation of artificial intelligence is given. Artificial intelligence is the theory, method, technology and application system that uses machines controlled by mathematical computers or digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology of computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0082] Artificial intelligence is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, and mechatronics. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning. In machine learning / deep learning technology, it is often used in combination with cloud technology.
[0083] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.
[0084] Among them, cloud security refers to the general term for security software, hardware, users, organizations, and security cloud platforms based on cloud computing business model applications. Cloud security integrates emerging technologies and concepts such as parallel processing, grid computing, and unknown virus behavior judgment. Through a large number of meshed clients, it monitors the abnormal behavior of software in the network, obtains the latest information of Trojans and malicious programs on the Internet, and sends it to the server for automatic analysis and processing, and then distributes virus and Trojan solutions to each client. The hash code-based retrieval method provided in the embodiment of the present application can be implemented through cloud computing technology and cloud security technology.
[0085] It should be understood that the retrieval method based on hash codes provided in the present application can be applied to cloud technology, artificial intelligence, smart transportation and other fields, and is used to complete image, text or video retrieval and other scenarios by quantizing hash codes. As an example, by calculating and comparing the Hamming distance between the hash code of the image to be queried and the hash codes of all images in the database, a set of images similar to the image to be queried can be quickly and accurately retrieved. As another example, by calculating and comparing the Hamming distance between the hash code of the text to be queried and the hash codes of all texts in the database, a set of texts similar to the text to be queried can be quickly and accurately retrieved. As another example, by calculating and comparing the Hamming distance between the hash code of the video to be queried and the hash codes of all videos in the database, a set of videos similar to the video to be queried can be quickly and accurately retrieved. In the above-mentioned scenarios, in order to obtain the hash code, it is usually by learning a real-valued common space, and then quantizing the real value to represent it as a simple discrete hash code. The quantization process often leads to a large quantization loss, and directly using it to calculate the cosine similarity will result in a decrease in the accuracy of the cosine similarity, thereby resulting in low retrieval performance.
[0086] In order to solve the above problems, this application proposes a retrieval method based on hash code, which is applied to Figure 1 The data object control system shown is shown in Figure 1 , Figure 1 FIG. 1 is a schematic diagram of an architecture of a data object control system in an embodiment of the present application. Figure 1 As shown, the server obtains the first eigenvector corresponding to the information to be processed provided by the terminal device, uses the target projection matrix and the target rotation matrix to calculate the first eigenvector, obtains the first score vector, and for each score element in the first score vector, compares the score element with each score element that appears before the score element, so as to obtain the encoding value of 0 or 1 corresponding to the score element, and then, according to the encoding value of each score element in the first score vector, generates the first target hash code corresponding to the information to be processed. In the above manner, each score element can be encoded by converting the information to be processed into the first score vector to obtain the encoding value of 0 or 1 corresponding to the score element, so that the compiled target hash code is well distributed between 0 and 1 and the quantization error is small, so that the cosine similarity based on the target hash code in the Hamming space can more accurately reflect the cosine similarity between the information distributed between 0 and 1, thereby improving the retrieval performance.
[0087] Understandably, Figure 1Only one type of terminal device is shown in the figure. In actual scenarios, more types of terminal devices may participate in the data processing process. Terminal devices include but are not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, car terminals, etc. The specific number and type depend on the actual scenario and are not limited here. Figure 1 One server is shown in the figure, but in actual scenarios, multiple servers may also be involved, especially in the scenario of multi-model training interaction. The number of servers depends on the actual scenario and is not limited here.
[0088] It should be noted that in this embodiment, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal device and the server can be directly or indirectly connected through wired or wireless communication, and the terminal device and the server can be connected to form a blockchain network, which is not limited in this application.
[0089] In order to solve the above problems, the present application proposes a retrieval method based on a hash code, which is generally executed by a server or a terminal device. Accordingly, a retrieval device based on a hash code is generally set in a server or a terminal device.
[0090] The following is an introduction to the hash code-based retrieval method in this application. Figure 2 In one embodiment of the present application, a retrieval method based on a hash code includes:
[0091] In step S101, a first feature vector corresponding to the information to be processed is obtained;
[0092] In this embodiment, when it is necessary to retrieve or quantify the features of the information to be processed, the information to be processed may be first sent to the server through the terminal device for feature processing to obtain a first feature vector corresponding to the information to be processed.
[0093] The information to be processed may be specifically expressed as text information such as a short article, a sentence or a comment, or may be expressed as image information such as an advertisement image, a frame of image captured from a video or a product image, or may be expressed in other forms such as video information, which are not specifically limited here. The first feature vector may be specifically expressed as an embedded vector of the information to be processed, or a row vector or column vector of a certain dimension, or other vector representations, which are not specifically limited here.
[0094] Specifically, when it is necessary to retrieve or quantify the features of the information to be processed, the information to be processed can be first sent to the server through the terminal device for feature processing, or feature extraction can be performed on the terminal device for the information to be processed, and no specific restrictions are made here. Feature extraction can be performed by extracting a first feature vector from the information to be processed through a deep neural network, or by performing feature processing on the information to be processed through a BERT model to obtain a first feature vector, or by other processing methods to obtain the first feature vector, and no specific restrictions are made here.
[0095] It can be understood that, by performing feature processing on the information to be processed, not only the first eigenvector can be obtained, but also the feature matrix corresponding to the information to be processed can be obtained. The feature matrix can specifically include multiple eigenvectors other than the first eigenvector, and the other multiple eigenvectors can specifically be represented by the second eigenvector.
[0096] In step S102, a target projection matrix and a target rotation matrix are used to calculate the first eigenvector to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results;
[0097] In this embodiment, after the first eigenvector of the information to be processed is obtained, the first eigenvector may be calculated using a pre-trained target projection matrix and a target rotation matrix to obtain a first score vector.
[0098] The target projection matrix is used to project the high-dimensional vector, namely the first eigenvector, into the subspace with the minimum mean square error. The target rotation matrix is used to rotate the first eigenvector and the target projection matrix as a whole to reduce the quantization error.
[0099] Specifically, in order to enable the discrete hash code to learn the cosine similarity of [0, +1], this embodiment adopts the objective function of the following formula (1):
[0100]
[0101] where X is the first eigenvector, The row vector of Represents the hash code b after L2 regularization i ∈{0,+1}.
[0102] Furthermore, since the variable B in formula (1) is discrete, in order to facilitate the solution, this embodiment converts formula (1) into the objective function of formula (2):
[0103]
[0104] Among them, Y is a continuous intermediate variable. Through characteristic decomposition, Y can be specifically expressed as Y = (X∧ r R), where ∧ r That is the target projection matrix, and R is the target rotation matrix.
[0105] Further, after obtaining the first eigenvector of the information to be processed, according to Y=(X∧ r R), the target projection matrix and the target rotation matrix can be used to calculate the first eigenvector to obtain the first score vector. For example, assuming that the first eigenvector is X = [x1, x2, ..., x n ], the target projection matrix and the target rotation matrix are used to calculate the first eigenvector, and the corresponding first score vector Y = [y1, y2, ..., y n ].
[0106] In step S103, for each score element in the first score vector, the score element is numerically compared with each score element that appears before the score element to obtain a code value corresponding to the score element, wherein the code value corresponding to each score element is 0 or 1;
[0107] In this embodiment, by considering In order to avoid the influence of the norm value domain, this embodiment can make X∧ r As a whole, therefore, the formula (2) can be Convert to represents Y and The inner product of , and then, after obtaining the first score vector, we can Convert to It can be understood as the first score vector Y = [y1, y2, ..., y n ] corresponds to the encoding value b of each score element in i To solve the problem, the score element may be numerically compared with each score element that appears before the score element to obtain the coded value corresponding to the score element.
[0108] Specifically, after obtaining the first score vector, the first score vector Y=[y1, y2, ..., y n ] can be based on Solve the code value b corresponding to each score element i , can be obtained by assuming that the number of +1 in b is k, if the position of +1 in b must correspond to y i The first k maximum values of This item is maximized, so we can use Get the encoding value b corresponding to each score element i, that is, to compare the value element with each value element that appears before the value element, specifically, y1 to y n Compare the first k maximum values in turn, and the encoding value b corresponding to the score element of the first k maximum values can be i Determined as +1, the code value corresponding to other score elements is b i Determined to be 0.
[0109] For example, suppose there is a first score vector Y = [y1, y2, ..., y n ] is Y = [1, 0, 2, 4, 3], and the code value b corresponding to the score element at each position is only when it is the first k maximum values. i If it is determined to be +1, otherwise it is 0. The encoding values corresponding to the score elements are b1=1, b2=0, b3=1, b4=1, b5=0.
[0110] In step S104, a first target hash code corresponding to the information to be processed is generated according to the encoded value of each score element in the first score vector.
[0111] In step S105, first target search information is determined according to the first target hash code.
[0112] In this embodiment, after obtaining the encoding value corresponding to each score element in the first score vector, the first target hash code corresponding to the information to be processed can be obtained according to the encoding value of each score element in the first score vector, and then, the first target retrieval information corresponding to the first target hash code can be recalled from the retrieval library according to the first target hash code, so that the first target retrieval information similar to the information to be processed can be quickly and accurately recalled based on the Hamming distance between the first target hash code of the information to be processed and the hash codes of all texts in the database, so as to obtain a message set.
[0113] Specifically, after obtaining the encoding value of each score element in the first score vector, the encoding value of each score element can be combined to obtain the first target hash code corresponding to the information to be processed. For example, the encoding values corresponding to the score elements are b1=1, b2=0, b3=1, b4=1, b5=0, and the encoding values corresponding to these obtained score elements are combined according to the positions of the elements to obtain the first target hash code R corresponding to the information to be processed, such as B=[1,0,1,1,0];
[0114] Furthermore, since the first target hash code can be well distributed between 0 and 1, the cosine similarity based on the first target hash code in the Hamming space can more accurately reflect the cosine similarity between the information distributed between 0 and 1. Therefore, after obtaining the first target hash code corresponding to the information to be processed, the cosine similarity between the first target hash code and the hash code corresponding to each information in the retrieval library can be calculated. Then, the information whose cosine similarity is greater than or equal to the preset similarity threshold can be determined as the first target retrieval information similar to the information to be processed, and then a message set similar to the information to be processed can be obtained based on several first target retrieval information.
[0115] In the embodiment of the present application, through the above method, each score element can be encoded by converting the information to be processed into a first score vector to obtain a coding value of 0 or 1 corresponding to the score element, so that the compiled first target hash code can be well distributed between 0 and 1 and the quantization error is small, so that the cosine similarity based on the target hash code in the Hamming space can more accurately reflect the cosine similarity between the information distributed between 0 and 1, thereby improving the retrieval performance.
[0116] Optionally, in the above Figure 2 Based on the corresponding embodiment, in another optional embodiment of the retrieval method based on hash code provided in the embodiment of the present application, as Figure 3 As shown, before generating the first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector, the method further includes: step S201 and step S202, and step S104 includes step S203;
[0117] In step S201, if the information to be processed corresponds to a second eigenvector, the target projection matrix and the target rotation matrix are used to calculate the second eigenvector to obtain a second score vector;
[0118] In step S202, for each score element in the second score vector, numerical comparison is performed between the score element and each score element that appears before the score element, so as to obtain a code value corresponding to the score element;
[0119] In step S203, a first target hash code corresponding to the information to be processed is generated according to the encoded value of each score element in the first score vector and the encoded value of each score element in the second score vector.
[0120] In this embodiment, after feature processing is performed on the information to be processed, if the information to be processed corresponds to a second eigenvector, the target projection matrix and the target rotation matrix can also be used to calculate the second eigenvector to obtain a second score vector, and then for each score element in the second score vector, the score element can be numerically compared with each score element that appears before the score element to obtain the encoding value corresponding to the score element, and then, according to the encoding value of each score element in the first score vector and the encoding value of each score element in the second score vector, the first target hash code corresponding to the information to be processed can be generated, and the information to be processed can be decomposed into the first score vector and the second score vector to encode each score element, so that the compiled first target hash code can be better and more completely distributed between 0 and 1, further reducing the quantization error.
[0121] Specifically, after obtaining the second eigenvector of the information to be processed, it can be obtained according to Y=(X∧ r R), continue to use the target projection matrix and the target rotation matrix to calculate the second eigenvector to obtain the second score vector. For example, assuming that the second eigenvector is X2 = [x 21 , x 22 , ..., x 2n ], the target projection matrix and the target rotation matrix are used to calculate the second eigenvector, and the corresponding second score vector Y2=[y 21 ,y 22 , ..., y 2n ].
[0122] Furthermore, after obtaining the second score vector, To get the encoding value b corresponding to each score element i , that is, the second score vector Y2 = [y 21 ,y 22 , ..., y 2n ] are numerically compared with the score elements that appear before the score element. Specifically, y 21 To 2n Compare the first k maximum values in turn. If the kth score element is the maximum value, the encoding value b corresponding to the kth score element is i is determined to be +1. Otherwise, if the kth score element is not the maximum value, the code value b corresponding to the kth score element is i is determined to be 0. For example, suppose there is a first score vector Y2=[y 21 ,y 22 , ..., y 2n ] is Y2 = [0, 1, 3, 2, 0], the code values corresponding to the score elements are b21 =0,b 22 =1,b 23 =1,b 24 =0,b 25 =0.
[0123] Furthermore, after obtaining the encoding value of each score element in the second score vector, the first target hash code corresponding to the information to be processed can be generated according to the encoding value of each score element in the first score vector and the encoding value of each score element in the second score vector. Specifically, the encoding value of each score element in the first score vector and the encoding value of each score element in the second score vector can be combined or concatenated. For example, the encoding value of each score element in the first score vector and the encoding value of each score element in the second score vector can be combined to obtain a hash code matrix, that is, the first target hash code corresponding to the information to be processed.
[0124] Optionally, in the above Figure 2 Based on the corresponding embodiment, in another optional embodiment of the retrieval method based on hash code provided in the embodiment of the present application, as Figure 3 As shown, obtaining the first feature vector corresponding to the information to be processed includes:
[0125] In step S301, feature extraction is performed on the information to be processed to obtain a basic feature vector corresponding to the information to be processed;
[0126] In step S302, regularization processing is performed on the basic eigenvector to obtain a first eigenvector.
[0127] In this embodiment, when it is necessary to retrieve or quantify the features of the information to be processed, feature extraction can be performed on the information to be processed to obtain the basic feature vector corresponding to the information to be processed. Then, since the weights need to be as small as possible in the process of model fitting to construct a model with relatively small parameters, it can be understood that for a linear regression equation, if the parameters are very large, then as long as the data is offset a little bit, it will have a great impact on the result, but if the parameters are small enough, a little more data offset will not have any effect on the result, that is, the model has strong anti-disturbance ability. Therefore, in order to prevent the model from overfitting, this embodiment can regularize the basic feature vector to obtain the first feature vector corresponding to the information to be processed.
[0128] Specifically, when it is necessary to retrieve or quantify the features of the information to be processed, feature extraction is performed on the information to be processed to obtain the basic feature vector corresponding to the information to be processed. Specifically, different feature extraction methods can be used for different information objects. For example, when the information to be processed is image information or video information, SIFT technology or GIST technology and other algorithms can be used for feature extraction. Other algorithms such as GoogLenet, VGGnet or caffe can also be used, and no specific restrictions are made here. Similarly, when the information to be processed is text information, hashing, recurrent neural network or word2vec algorithms can be used for feature extraction. Other algorithms can also be used, and no specific restrictions are made here.
[0129] Furthermore, after obtaining the basic eigenvector, the basic eigenvector can be regularized. Specifically, the basic eigenvector can be L2 regularized to obtain the first eigenvector. L2 regularization refers to the sum of the squares of each element in the weight vector w and then taking the square root, which is usually expressed as It is understandable that in order to prevent the overfitting phenomenon of the model, the basic feature vector can also be L1 regularized or normalized, and no specific limitation is made here.
[0130] Optionally, in the above Figure 2 Based on the corresponding embodiment, in another optional embodiment of the retrieval method based on hash code provided in the embodiment of the present application, as Figure 4 As shown, determining the first target retrieval information according to the first target hash code includes:
[0131] In step S401, a first similarity between a first target hash code corresponding to the information to be processed and each hash code in the search library is calculated;
[0132] In step S402, according to the first similarity, a first similar hash code of the first target hash code is determined from each hash code in the search library;
[0133] In step S403, information corresponding to the first similar hash code is used as first target retrieval information.
[0134] In this embodiment, after obtaining the first target hash code corresponding to the information to be processed, the first similarity between the first target hash code corresponding to the information to be processed and each hash code in the retrieval library can be calculated, and then according to the first similarity, the first similar hash code that is similar or identical to the first target hash code can be screened out from each hash code in the retrieval library, and then the information corresponding to the first similar hash code can be used as the first target retrieval information to obtain a first information set similar to the information to be processed, and it can be pushed to the terminal device so that the target object using the terminal device can promptly obtain the first information set with a high degree of similarity to the information to be processed.
[0135] Specifically, since the distance between two pieces of information 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 realizing the acceleration of the distance metric, after obtaining the first target hash code corresponding to the information to be processed, such as Fig.12 As shown, a hash code similar to the first target hash code can be queried in the Hamming space, specifically by calculating the cosine similarity, i.e., the first similarity, between the first target hash code and each hash code in the space, or by calculating the Euclidean distance, which is not specifically limited here.
[0136] Furthermore, after obtaining the cosine similarity, i.e., the first similarity, between the first target hash code and each hash code in the space, since the degree of similarity between hash codes is positively correlated with the first similarity, the first similarity between the first target hash code and each hash code in the retrieval library can be compared with a similarity threshold, and the hash code corresponding to the first similarity greater than or equal to the similarity threshold can be determined as a first similar hash code that is highly similar or identical to the first target hash code, and then, the information corresponding to the first similar hash code can be used as the first target retrieval information, and further, all the first target retrieval information obtained can be determined as a first information set similar to the information to be processed.
[0137] Optionally, in the above Figure 2 Based on the corresponding embodiment, in another optional embodiment of the retrieval method based on hash code provided in the embodiment of the present application, as Figure 5 As shown, after obtaining the first feature vector corresponding to the information to be processed, the method further includes:
[0138] In step S501, a target weight matrix is calculated using a target hash matrix and a target weight, wherein the target hash matrix and the target weight are training results;
[0139] In step S502, a second target hash code corresponding to the information to be processed is calculated based on the first eigenvector and the target weight matrix.
[0140] In this embodiment, after obtaining the first eigenvector corresponding to the information to be processed, the target hash matrix and the target weight can be used to calculate the target weight matrix. Then, the second target hash code corresponding to the information to be processed is directly calculated according to the first eigenvector and the target weight matrix. There is no need to iteratively encode each characteristic element in the first eigenvector. The first eigenvector can be directly encoded by the target weight matrix, which can save encoding time to a great extent, thereby improving encoding efficiency to a certain extent.
[0141] It can be understood that after training to obtain the target hash matrix B and the target weight λ, in order to enable the discrete hash code to learn the cosine similarity of [0, +1], this embodiment can use the target hash matrix B as the target of feature vector regression, and then the objective function of formula (1) can be converted into the objective function of the following formula (3):
[0142]
[0143] Where W is the target weight matrix. Based on the objective function of formula (3), the closed-form solution of the target weight matrix W can be directly obtained as follows:
[0144] W=(X T X+λI) -1 (X T B)∈R d×r (4);
[0145] Furthermore, based on equations (3) and (4), we can obtain the following equation (5): Using the target weight matrix to calculate the feature vector x q Encode to get the hash code b q :
[0146] b q =sign(x q W) (5);
[0147] Specifically, after obtaining the first eigenvector corresponding to the information to be processed, the calculation method of formula (4) can be used to calculate the target weight matrix through the target hash matrix and the target weight. Then, according to the encoding method of formula (5), the first eigenvector and the target weight matrix are substituted into formula (5) to directly calculate the second target hash code corresponding to the information to be processed.
[0148] Optionally, in the above Figure 5 Based on the corresponding embodiment, in another optional embodiment of the retrieval method based on hash code provided in the embodiment of the present application, as Figure 6 As shown, after calculating the second target hash code corresponding to the information to be processed according to the first eigenvector and the target weight matrix, the method further includes:
[0149] In step S601, a second similarity between a second target hash code corresponding to the information to be processed and each hash code in the search library is calculated;
[0150] In step S602, according to the second similarity, a second similar hash code of the second target hash code is determined from each hash code in the search library;
[0151] In step S603, information corresponding to the second similar hash code is used as second target search information.
[0152] In this embodiment, after the second target hash code corresponding to the information to be processed is obtained, since the encoding method of the first target hash code is different from the encoding method of the second target hash code, the obtained second target hash code may be the same as or different from the first target hash code. In order to ensure the integrity of the retrieved information, the second similarity between the second target hash code corresponding to the information to be processed and each hash code in the retrieval library can be calculated, and then according to the second similarity, a second similar hash code similar to or identical to the second target hash code can be screened out from each hash code in the retrieval library, and then the information corresponding to the second similar hash code can be used as the second target retrieval information to obtain a second information set similar to the information to be processed. It can be understood that the second information set can be similar or identical to the first information set, and the second information set similar to the information to be processed can be pushed to the terminal device, so that the target object using the terminal device can promptly obtain the second information set with a high degree of similarity to the information to be processed.
[0153] Specifically, Fig.12 As shown, a hash code similar to the second target hash code can be queried in the Hamming space, specifically by calculating the cosine similarity, i.e., the second similarity, between the second target hash code and each hash code in the space, or by calculating the Euclidean distance, which is not specifically limited here.
[0154] Furthermore, after obtaining the cosine similarity, i.e., the second similarity, between the second target hash code and each hash code in the space, since the degree of similarity between hash codes is positively correlated with the second similarity, the second similarity between the second target hash code and each hash code in the retrieval library can be compared with a similarity threshold, and the hash code corresponding to the second similarity greater than or equal to the similarity threshold can be determined as a second similar hash code that is highly similar or identical to the second target hash code. Then, the information corresponding to the second similar hash code can be used as the second target retrieval information, and further, all the second target retrieval information obtained can be determined as a second information set similar to the information to be processed.
[0155] Optionally, in the above Figure 5Based on the corresponding embodiments, in another alternative embodiment of the retrieval method based on hash codes provided by the embodiments of the present application, as Figure 7 shown, the method further includes:
[0156] In step S701, obtain the sample feature vector corresponding to the sample information;
[0157] In step S702, use the original projection matrix, the original rotation matrix, and the original hash matrix to calculate the loss of the sample feature vector to obtain the first loss function, where the original rotation matrix is an orthonormal matrix randomly assigned, the original projection matrix is obtained by extracting based on the diagonal matrix corresponding to the sample feature vector, and the original hash matrix is randomly assigned;
[0158] In step S703, update the original projection matrix, the original rotation matrix, and the original hash matrix according to the first loss function to obtain the target projection matrix, the target rotation matrix, and the target hash matrix.
[0159] In this embodiment, after obtaining the sample feature vector corresponding to the sample information, use the original projection matrix, the original rotation matrix, and the original hash matrix to calculate the loss of the sample feature vector to obtain the first loss function, and then, the first loss function can be used to update the original projection matrix, the original rotation matrix, and the original hash matrix to obtain the target projection matrix, the target rotation matrix, and the target hash matrix, so that the discrete hash code can learn the cosine similarity of [0, +1].
[0160] Specifically, since the hash algorithm is given a d-dimensional sample feature vector x i ∈R 1×d , through a mapping f(x): x i →b i , the sample feature vector is encoded into an r-dimensional binary hash code b i ∈{+1, -1} 1×r , where r << d. Since in the actual application scenario, even if the high-dimensional vector is L2-regularized, the distribution of the cosine similarity corresponding to the high-dimensional vector is usually non-uniform (as Fig.11 shown, the cosine similarity is basically in [0, +1]), while theoretically the distribution of the cosine similarity should be in [-1, 1]. If the cosine similarity of the binary hash code b i with positive and negative values of {-1, 1} is directly used, it is difficult to learn the cosine similarity of [0, +1] of the high-dimensional vector, and it is easy to cause a large quantization error. Therefore, this embodiment uses the objective function of (1) to make the discrete hash code learn the cosine similarity of [0, +1] and maintain the local structure between samples:
[0161]
[0162] Where X∈R n×d is the sample feature, where n is the number of samples, d is the feature dimension, and the X sample feature is L2 regularized; where XX T Elements in Used to represent the i-th sample x i With the jth sample x j Cosine similarity cos(x i ,x j ), we can consider the i-th sample x i With the jth sample x j The relationship between them allows the discrete hash code to learn the local structure between samples; The row vector of Represents the hash code b after L2 regularization i ∈{0,+1}.
[0163] Furthermore, since the variable B in formula (1) is discrete, formula (1) can be transformed into the first loss function of formula (2) as follows:
[0164]
[0165] Among them, Y is a continuous intermediate variable. Through characteristic decomposition, Y can be specifically expressed as Y = (X∧ r R), where ∧ r That is the target projection matrix, and R is the target rotation matrix.
[0166] Furthermore, after obtaining the sample feature vector corresponding to the sample information, we can use Y=(X∧ r R), we can use the original projection matrix ∧ r , the original rotation matrix R and the original hash matrix B, calculate the loss of the sample feature vector to obtain the first loss function, which can be specifically obtained by using the sample feature vector, the original projection matrix ∧ r , the original rotation matrix R is used to construct a continuous intermediate variable Y, and then the constructed intermediate variable Y and the original hash matrix B can be substituted into formula (2) for loss calculation to obtain the first loss function.
[0167] Furthermore, after obtaining the first loss function, we can transform X∧ in the intermediate variable Y into r As a whole, therefore, the formula (2) can be Convert to represents Y and The inner product of the sample feature vector X and the original projection matrix is a known variable. Therefore, the present embodiment can adopt an alternating optimization method to iteratively solve the target rotation matrix R and the target hash matrix B. Then, according to the mapping relationship between the projection matrix and the rotation matrix, the target projection matrix ∧ can be obtained based on the target rotation matrix R. r .
[0168] Optionally, in the above Figure 7 Based on the corresponding embodiment, in another optional embodiment of the hash code-based retrieval method provided in the embodiment of the present application, as Figure 8 As shown, the original projection matrix, the original rotation matrix, and the original hash matrix are updated according to the first loss function to obtain the target projection matrix, the target rotation matrix, and the target hash matrix, including:
[0169] In step S801, according to the first loss function, the original projection matrix and the original rotation matrix are used to update the original hash matrix to obtain a target hash matrix;
[0170] In step S802, according to the first loss function, the original hash matrix is used to update the original rotation matrix and the original projection matrix to obtain a target projection matrix and a target rotation matrix.
[0171] In this embodiment, since the sample eigenvector X and the original projection matrix are known variables, this embodiment can use an alternating optimization method to iteratively solve the target rotation matrix R and the target hash matrix B. Therefore, according to the first loss function, the original projection matrix and the original rotation matrix can be used to update the original hash matrix to obtain the target hash matrix. Similarly, according to the first loss function, the original hash matrix can be used to update the original rotation matrix and the original projection matrix to obtain the target projection matrix and the target rotation matrix.
[0172] Specifically, after obtaining the first loss function, the original hash matrix can be iteratively updated by fixing the original projection matrix and the original rotation matrix to obtain the target hash matrix. Similarly, the original rotation matrix and the original projection matrix can be iteratively updated by fixing the original hash matrix to obtain the target projection matrix and the target rotation matrix.
[0173] Optionally, in the above Figure 8 Based on the corresponding embodiment, in another optional embodiment of the hash code-based retrieval method provided in the embodiment of the present application, as Fig. 9 As shown, according to the first loss function, the original projection matrix and the original rotation matrix are used to update the original hash matrix to obtain the target hash matrix, including:
[0174] In step S901, the sample feature vector is calculated using the original projection matrix and the original rotation matrix to obtain a sample score vector;
[0175] In step S902, for each score element in the sample score vector, the score element is numerically compared with each score element that appears before the score element, so as to obtain a code value corresponding to each score element in the sample score vector;
[0176] In step S903, a sample hash code corresponding to the sample information is generated according to the encoding value of each score element in the sample score vector;
[0177] In step S904, the original hash matrix is updated according to the sample hash code to obtain a target hash code matrix.
[0178] In this embodiment, after obtaining the first loss function, the formula (2) can be Convert to That is, the original projection matrix and the original rotation matrix can be used to calculate the sample feature vector to obtain the sample score vector. Then, since the sample feature vector X and the original projection matrix are known variables, by fixing the original rotation matrix R, Convert to It can be understood as solving the coding value b corresponding to each score element in the sample score vector. The score elements can be numerically compared with the score elements that appear before the score elements to obtain the coding value corresponding to the score elements. The sample target hash code corresponding to the information to be processed can be obtained according to the coding value of each score element in the sample score vector. Then, the sample hash code updates the original hash matrix, so that the target hash code matrix can be better obtained.
[0179] Specifically, after obtaining the first loss function, since the sample feature vector X and the original projection matrix are known variables, by randomly initializing an original rotation matrix R and fixing the original rotation matrix R, Convert to To solve the encoding value b corresponding to each score element in the sample score vector.
[0180] It can be understood that when the original rotation matrix R is fixed, based on equations (1) and (2), we can know The number of +1 in the range ∈[1,r], but it cannot be directly determined b is the number of +1, so, as shown in Table 1 below, it can be assumed that The number of b+1 is k, then The position where b is +1 must correspond to the kth score element in the first k score elements of y being the maximum value, which can make The kth score element of is maximized, so it can be traversed by k∈[1,r] and record its corresponding value Then based on Compare the score element with the score elements that appear before it to obtain the encoding value b corresponding to each score element in the sample score vector:
[0181] Table 1
[0182]
[0183] Among them, score k represents the kth score element in the sample score vector, as shown in Table 1. k It is also L2 regularized, so based on You can
[0184] Furthermore, after the encoding value of each score element in the sample score vector is calculated according to the algorithm shown in Table 1, the encoding value of each score element in the sample score vector can be combined to obtain the sample hash code corresponding to the sample information, and then, the original hash code corresponding to the sample score element in the original hash matrix B can be updated to the sample hash code to obtain the target hash code matrix.
[0185] Optionally, in the above Figure 8 Based on the corresponding embodiment, in another optional embodiment of the hash code-based retrieval method provided in the embodiment of the present application, as Fig. 9 As shown, according to the first loss function, the original hash matrix is used to update the original rotation matrix and the original projection matrix to obtain the target projection matrix and the target rotation matrix, including:
[0186] In step S1001, the original hash matrix is used to perform matrix decomposition processing on the first loss function to obtain a decomposed projection matrix and a decomposed rotation matrix;
[0187] In step S1002, the original rotation matrix and the original projection matrix are updated according to the decomposed projection matrix and the decomposed rotation matrix respectively to obtain a target projection matrix and a target rotation matrix.
[0188] In this embodiment, after obtaining the first loss function, since the sample feature vector X and the original projection matrix are known variables, by fixing the original hash matrix B, the formula (2) can be Convert to Can Matrix decomposition processing is performed to obtain a decomposed projection matrix and a decomposed rotation matrix. Then, the original rotation matrix and the original projection matrix can be updated according to the decomposed projection matrix and the decomposed rotation matrix, respectively, so that the target projection matrix and the target rotation matrix can be better obtained.
[0189] Specifically, after obtaining the first loss function, since the sample feature vector X and the original projection matrix are known variables, an original hash matrix B is randomly initialized, and then, based on the hash matrix updated in step S904, the updated hash matrix can be fixed to obtain the value of (2). Convert to And the decomposition algorithm shown in Table 2 is used to A matrix decomposition process is performed to obtain a decomposed projection matrix and a decomposed rotation matrix.
[0190] Table 2
[0191]
[0192] Among them, as shown in Table 2, it can be understood that Perform SVD singular value decomposition, and then we have the following relationship (6):
[0193]
[0194] Then, the decomposition rotation matrix of the following formula (7) can be obtained:
[0195] R=SS T (7);
[0196] It can be understood that, as shown in Table 2, by specifying the number of iterations (e.g., 50 times), and iterating through steps S901 to S904, and through steps S1001 to S1002, until convergence, the converged target projection matrix ∧ can be saved. r and the target rotation matrix R.
[0197] Optionally, in the above Figure 7 Based on the corresponding embodiment, in another optional embodiment of the hash code-based retrieval method provided in the embodiment of the present application, as Fig.10 As shown, after the original projection matrix, the original rotation matrix and the original hash matrix are updated according to the first loss function to obtain the target projection matrix, the target rotation matrix and the target hash matrix, the method further includes:
[0198] In step S1101, the target hash matrix, the original weights and the original weight matrix are used to calculate the loss of the sample feature vector to obtain a second loss function, wherein the original weights are obtained by random assignment;
[0199] In step S1102, the original weight matrix and the original weights are updated according to the second loss function to obtain the target weight matrix and the target weights.
[0200] In this embodiment, after obtaining the target hash matrix, the target hash matrix, the original weights and the original weight matrix can be used to calculate the loss of the sample feature vector to obtain a second loss function. Then, the original weight matrix and the original weights can be updated based on the second loss function to obtain the target weight matrix and the target weights. A target weight matrix can be trained so that it is not necessary to iteratively encode each feature element in the feature vector during the encoding stage. The acquired feature vector can be directly encoded using the target weight matrix, which can save encoding time to a great extent, thereby improving encoding efficiency to a certain extent.
[0201] Specifically, after training to obtain the target hash matrix B, in order to enable the discrete hash code to learn the cosine similarity of [0, +1], this embodiment can use the target hash matrix B as the target of feature vector regression, and then construct a second loss function as shown in formula (3) based on the target hash matrix B, the original weight λ, the original weight matrix W and the sample feature vector.
[0202] Furthermore, based on the second loss function of formula (3), the target hash matrix can be fixed, and the original weight matrix and the original weight can be updated to obtain the closed-form solution of the target weight matrix W of formula (4) to obtain the target weight matrix and the target weight:
[0203] W=(X T X+λI) -1 (X T B)∈R d×r (4).
[0204] Optionally, in the above Figure 7 Based on the corresponding embodiment, in another optional embodiment of the hash code-based retrieval method provided in the embodiment of the present application, as Fig.10 As shown, the original projection matrix, the original rotation matrix and the original hash matrix are used to calculate the loss of the sample feature vector. Before obtaining the first loss function, the method further includes:
[0205] In step S1201, the product of the sample feature vector and the transpose of the sample feature vector is calculated;
[0206] In step S1202, eigendecomposition is performed on the product of the sample eigenvector and the transposed sample eigenvector to obtain a diagonal matrix corresponding to the sample eigenvector;
[0207] In step S1203, feature extraction is performed on the diagonal matrix according to the original rotation matrix to obtain the original projection matrix.
[0208] In this embodiment, after obtaining the sample feature vector of the sample information, according to the objective function shown in formula (2) The product XX of the sample eigenvector and the transpose of the sample eigenvector can be calculated T , and then, the product of the sample eigenvector and the transposed sample eigenvector can be eigen-decomposed to obtain the diagonal matrix corresponding to the sample eigenvector. Then, the diagonal matrix is feature-extracted according to the original rotation matrix to obtain the original projection matrix, so that the intermediate variable Y can be expressed as (X∧ r R) to better calculate the objective function.
[0209] Specifically, after obtaining the sample feature vector of the sample information, the product of the sample feature vector and the transpose of the sample feature vector can be calculated, and the product XX of the sample feature vector and the transpose of the sample feature vector can be calculated. T By performing feature decomposition, we can obtain the following relational expression (8):
[0210] XX T =H∧H T (8);
[0211] Among them, ∧ is the diagonal matrix corresponding to the eigenvalue, that is, the diagonal matrix corresponding to the sample eigenvector, and H is the eigenvector. The original projection matrix ∧ can be obtained by taking out the first r columns r ∈R d×r .
[0212] Furthermore, the characteristics of eigendecomposition can be used to obtain the following relationship (9):
[0213] XX T ≈(X∧ r R)(X∧ r R) T (9);
[0214] Among them, R is an orthogonal matrix, so we can have Y = (X∧ r R)∈R n×r .
[0215] The following is a detailed description of the hash code based retrieval device in this application. Fig.13 , Fig.13The following is a schematic diagram of an embodiment of a retrieval device based on a hash code in an embodiment of the present application. The retrieval device based on a hash code 20 includes:
[0216] An acquisition unit 201 is used to acquire a first feature vector corresponding to the information to be processed;
[0217] A processing unit 202 is used to calculate the first eigenvector using a target projection matrix and a target rotation matrix to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results;
[0218] The processing unit 202 is further configured to compare, for each score element in the first score vector, the score element with each score element that appears before the score element, to obtain a code value corresponding to the score element, wherein the code value corresponding to each score element is 0 or 1;
[0219] The processing unit 202 is further configured to generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector;
[0220] The processing unit 202 is further configured to determine first target retrieval information according to the first target hash code.
[0221] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0222] The processing unit 202 is further configured to calculate the second eigenvector using the target projection matrix and the target rotation matrix to obtain a second score vector if the information to be processed corresponds to the second eigenvector;
[0223] The processing unit 202 is further configured to perform, for each score element in the second score vector, a numerical comparison between the score element and each score element that appears before the score element, so as to obtain a code value corresponding to the score element;
[0224] The processing unit 202 may be specifically configured to generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector and the encoded value of each score element in the second score vector.
[0225] Optionally, in the above Fig.13 On the basis of the corresponding embodiment, in another embodiment of the retrieval device based on the hash code provided in the embodiment of the present application, the acquisition unit 201 can be specifically used for:
[0226] Perform feature extraction on the information to be processed to obtain a basic feature vector corresponding to the information to be processed;
[0227] Regularization is performed on the basic eigenvector to obtain the first eigenvector.
[0228] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0229] The processing unit 202 is further configured to calculate a first similarity between a first target hash code corresponding to the information to be processed and each hash code in the search library;
[0230] A determining unit 203 is configured to determine a first similar hash code to the first target hash code from each hash code in the search library according to the first similarity;
[0231] The processing unit 202 is further configured to use the information corresponding to the first similar hash code as first target retrieval information.
[0232] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0233] The processing unit 202 is further configured to calculate a target weight matrix using a target hash matrix and a target weight, wherein the target hash matrix and the target weight are training results;
[0234] The processing unit 202 is further configured to calculate a second target hash code corresponding to the information to be processed according to the first eigenvector and the target weight matrix.
[0235] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0236] The processing unit 202 is further configured to calculate a second similarity between a second target hash code corresponding to the information to be processed and each hash code in the search library;
[0237] The determining unit 203 is further configured to determine a second similar hash code to the second target hash code from each hash code in the search library according to the second similarity;
[0238] The processing unit 202 is further configured to use the information corresponding to the second similar hash code as second target retrieval information.
[0239] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0240] The acquisition unit 201 is also used to acquire a sample feature vector corresponding to the sample information;
[0241] The processing unit 202 is further used to use the original projection matrix, the original rotation matrix and the original hash matrix to perform loss calculation on the sample feature vector to obtain a first loss function, wherein the original rotation matrix is a randomly assigned orthogonal matrix, the original projection matrix is extracted based on the diagonal matrix corresponding to the sample feature vector, and the original hash matrix is randomly assigned;
[0242] The processing unit 202 is further configured to update the original projection matrix, the original rotation matrix, and the original hash matrix according to the first loss function to obtain a target projection matrix, a target rotation matrix, and a target hash matrix.
[0243] Optionally, in the above Fig.13 On the basis of the corresponding embodiment, in another embodiment of the retrieval device based on the hash code provided in the embodiment of the present application, the processing unit 202 can be specifically used for:
[0244] According to the first loss function, the original projection matrix and the original rotation matrix are used to update the original hash matrix to obtain the target hash matrix;
[0245] According to the first loss function, the original hash matrix is used to update the original rotation matrix and the original projection matrix to obtain the target projection matrix and the target rotation matrix.
[0246] Optionally, in the above Fig.13 On the basis of the corresponding embodiment, in another embodiment of the retrieval device based on the hash code provided in the embodiment of the present application, the processing unit 202 can be specifically used for:
[0247] The original projection matrix and the original rotation matrix are used to calculate the sample feature vector to obtain the sample score vector;
[0248] For each score element in the sample score vector, numerically compare the score element with each score element that appears before the score element to obtain the encoding value corresponding to each score element in the sample score vector;
[0249] Generate a sample hash code corresponding to the sample information according to the encoded value of each score element in the sample score vector;
[0250] Update the original hash matrix according to the sample hash codes to obtain the target hash code matrix.
[0251] Optionally, in the above Fig.13 On the basis of the corresponding embodiment, in another embodiment of the retrieval device based on the hash code provided in the embodiment of the present application, the processing unit 202 can be specifically used for:
[0252] Using the original hash matrix, perform matrix decomposition on the first loss function to obtain a decomposed projection matrix and a decomposed rotation matrix;
[0253] The original rotation matrix and the original projection matrix are updated according to the decomposed projection matrix and the decomposed rotation matrix respectively to obtain the target projection matrix and the target rotation matrix.
[0254] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0255] The processing unit 202 is further used to use the target hash matrix, the original weights and the original weight matrix to perform loss calculation on the sample feature vector to obtain a second loss function, wherein the original weights are obtained by random assignment;
[0256] The processing unit 202 is further used to update the original weight matrix and the original weights according to the second loss function to obtain the target weight matrix and the target weights.
[0257] Optionally, in the above Fig.13 Based on the corresponding embodiment, in another embodiment of the retrieval device based on hash code provided in the embodiment of the present application,
[0258] The processing unit 202 is further used to calculate the product of the sample feature vector and the transpose of the sample feature vector;
[0259] The processing unit 202 is further configured to perform eigendecomposition on the product of the sample eigenvector and the transposed sample eigenvector to obtain a diagonal matrix corresponding to the sample eigenvector;
[0260] The processing unit 202 is further configured to perform feature extraction on the diagonal matrix according to the original rotation matrix to obtain an original projection matrix.
[0261] On the other hand, the present application provides another schematic diagram of a computer device, such as Fig.14 As shown, Fig.143 is a schematic diagram of a computer device structure provided in an embodiment of the present application. The computer device 300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 310 (for example, one or more processors) and a memory 320, and one or more storage media 330 (for example, one or more mass storage devices) storing application programs 331 or data 332. Among them, the memory 320 and the storage medium 330 may be temporary storage or permanent storage. The program stored in the storage medium 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the computer device 300. Furthermore, the central processing unit 310 may be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the computer device 300.
[0262] The computer device 300 may also include one or more power supplies 340, one or more wired or wireless network interfaces 350, one or more input and output interfaces 360, and / or one or more operating systems 333, such as Windows Server 2000, Windows Server 2003, Windows Server 2003E, Windows Server 2003R ... TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0263] The computer device 300 is also used to perform the following steps: Figures 2 to 10 The steps in the corresponding embodiments.
[0264] Another aspect of the present application provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are executed on a computer, the computer executes the following Figures 2 to 10 The illustrated embodiments describe steps in a method.
[0265] Another aspect of the present application provides a computer program product comprising instructions, which when executed on a computer or a processor, causes the computer or the processor to execute the following Figures 2 to 10 The illustrated embodiments describe steps in a method.
[0266] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0267] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0268] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0269] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0270] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
Claims
1. A retrieval method based on hash code, characterized in that: include: Obtaining a first eigenvector corresponding to the information to be processed; Using a target projection matrix and a target rotation matrix, the first eigenvector is calculated to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results; For each score element in the first score vector, compare the score element with the score elements that appear before the score element, if the score element has the largest value, determine that the code value corresponding to the score element is 1; otherwise, determine that the code value corresponding to the score element is 0; Generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector; First target retrieval information is determined according to the first target hash code.
2. The method according to claim 1, characterized in that Before generating the first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector, the method further includes: If the information to be processed corresponds to a second eigenvector, the target projection matrix and the target rotation matrix are used to calculate the second eigenvector to obtain a second score vector; For each score element in the second score vector, compare the score element with the score elements that appear before the score element, if the score element has the largest value, determine that the code value corresponding to the score element is 1; otherwise, determine that the code value corresponding to the score element is 0; The step of generating a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector includes: The first target hash code corresponding to the information to be processed is generated according to the encoded value of each score element in the first score vector and the encoded value of each score element in the second score vector.
3. The method according to claim 1, characterized in that: The obtaining of the first feature vector corresponding to the information to be processed includes: Extracting features from the information to be processed to obtain a basic feature vector corresponding to the information to be processed; Regularization is performed on the basic feature vector to obtain the first feature vector.
4. The method according to any one of claims 1 to 2, characterized in that The determining the first target retrieval information according to the first target hash code includes: Calculating a first similarity between a first target hash code corresponding to the information to be processed and each hash code in the search library; Determine, according to the first similarity, a first similar hash code to the first target hash code from each hash code in the search library; The information corresponding to the first similar hash code is used as the first target retrieval information.
5. The method according to claim 1, characterized in that After obtaining the first feature vector corresponding to the information to be processed, the method further includes: Calculating a target weight matrix using a target hash matrix and a target weight, wherein the target hash matrix and the target weight are training results; A second target hash code corresponding to the information to be processed is obtained by calculation according to the first eigenvector and the target weight matrix.
6. The method according to claim 5, characterized in that After obtaining the second target hash code corresponding to the information to be processed by calculation according to the first eigenvector and the target weight matrix, the method further includes: Calculating a second similarity between a second target hash code corresponding to the information to be processed and each hash code in the search library; determining, according to the second similarity, a second similar hash code to the second target hash code from each hash code in the search library; The information corresponding to the second similar hash code is used as the second target retrieval information.
7. The method according to claim 5, characterized in that The method further comprises: Obtain the sample feature vector corresponding to the sample information; Using the original projection matrix, the original rotation matrix and the original hash matrix, the loss calculation of the sample feature vector is performed to obtain a first loss function, wherein the original rotation matrix is a randomly assigned orthogonal matrix, the original projection matrix is extracted based on the diagonal matrix corresponding to the sample feature vector, and the original hash matrix is randomly assigned; The original projection matrix, the original rotation matrix, and the original hash matrix are updated according to the first loss function to obtain the target projection matrix, the target rotation matrix, and the target hash matrix.
8. The method according to claim 7, characterized in that The updating of the original projection matrix, the original rotation matrix, and the original hash matrix according to the first loss function to obtain the target projection matrix, the target rotation matrix, and the target hash matrix includes: According to the first loss function, the original projection matrix and the original rotation matrix are used to update the original hash matrix to obtain the target hash matrix; According to the first loss function, the original hash matrix is used to update the original rotation matrix and the original projection matrix to obtain the target projection matrix and the target rotation matrix.
9. The method according to claim 8, characterized in that The updating of the original hash matrix by using the original projection matrix and the original rotation matrix according to the first loss function to obtain the target hash matrix includes: Using the original projection matrix and the original rotation matrix, the sample feature vector is calculated to obtain a sample score vector; For each score element in the sample score vector, the score element is numerically compared with each score element that appears before the score element. If the value of the score element is the largest, the code value corresponding to the score element is determined to be 1; otherwise, the code value corresponding to the score element is determined to be 0; Generate a sample hash code corresponding to the sample information according to the encoded value of each score element in the sample score vector; The original hash matrix is updated according to the sample hash code to obtain the target hash code matrix.
10. The method according to claim 8, characterized in that The method of updating the original rotation matrix and the original projection matrix according to the first loss function and using the original hash matrix to obtain the target projection matrix and the target rotation matrix includes: Using the original hash matrix, performing matrix decomposition processing on the first loss function to obtain a decomposed projection matrix and a decomposed rotation matrix; The original rotation matrix and the original projection matrix are updated according to the decomposed projection matrix and the decomposed rotation matrix respectively to obtain the target projection matrix and the target rotation matrix.
11. The method according to claim 7, characterized in that After updating the original projection matrix, the original rotation matrix, and the original hash matrix according to the first loss function to obtain the target projection matrix, the target rotation matrix, and the target hash matrix, the method further includes: Using the target hash matrix, the original weights and the original weight matrix, the loss calculation is performed on the sample feature vector to obtain a second loss function, wherein the original weights are obtained by random assignment; The original weight matrix and the original weights are updated according to the second loss function to obtain the target weight matrix and the target weights.
12. The method according to claim 7, characterized in that Before the original projection matrix, the original rotation matrix and the original hash matrix are used to perform loss calculation on the sample feature vector to obtain the first loss function, the method further includes: Calculating the product of the sample feature vector and the transpose of the sample feature vector; Performing eigendecomposition on the product of the sample eigenvector and the transpose of the sample eigenvector to obtain a diagonal matrix corresponding to the sample eigenvector; Feature extraction is performed on the diagonal matrix according to the original rotation matrix to obtain the original projection matrix.
13. A retrieval device based on hash code, characterized in that: include: An acquisition unit, used for acquiring a first feature vector corresponding to the information to be processed; A processing unit, configured to calculate the first eigenvector using a target projection matrix and a target rotation matrix to obtain a first score vector, wherein the target projection matrix and the target rotation matrix are training results; The processing unit is further configured to compare, for each score element in the first score vector, the value of the score element with the respective score elements that appear before the score element, and if the value of the score element is the largest, determine that the code value corresponding to the score element is 1; otherwise, determine that the code value corresponding to the score element is 0; The processing unit is further configured to generate a first target hash code corresponding to the information to be processed according to the encoded value of each score element in the first score vector; The processing unit is further configured to determine first target retrieval information according to the first target hash code.
14. A computer device, characterized in that: include: memories, transceivers, processors, and bus systems; Wherein, the memory is used to store programs; The processor is used to implement the method according to any one of claims 1 to 12 when executing the program in the memory; The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
15. A computer-readable storage medium comprising instructions, which, when executed on a computer, causes the computer to perform the method according to any one of claims 1 to 12.
16. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
