A similar image search method, device and storage medium
By performing dimensionality reduction and hash code processing on image feature vectors in a master-slave node architecture, and establishing a tree structure for parallel search, the problem of long search time and low efficiency in existing similar image search technologies is solved, and fast and efficient similar image search is achieved.
Patent Information
- Application Number
- CN202310730968.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-19
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-06-19
AI Technical Summary
Existing similar image search methods compare the feature vector of the image to be searched with the feature vectors of each original image in the image database one by one, resulting in long search times and low efficiency.
A master-slave node architecture is adopted. By performing dimensionality reduction and hash code processing on the feature vector of the image to be searched, hash codes are generated using randomly generated vectors, and a tree structure is built on the slave nodes to perform parallel search, thereby reducing the actual amount of search data.
It enables the rapid retrieval of target sample images with high similarity to the image to be searched, shortening the search time and improving search efficiency.
Smart Images

Figure CN116932801B_ABST
Abstract
Description
Technical Field
[0001] This application relates to image processing technology, and more particularly to a similar image search method, device, and storage medium. Background Technology
[0002] Current similar image search methods compare the similarity between the feature vector of the image to be searched and the feature vectors of each original image in the image database to determine the similar images corresponding to the image to be searched. This search method is labor-intensive, resulting in long search time and poor search efficiency. Summary of the Invention
[0003] This application aims to provide a similar image search method, device, and storage medium.
[0004] The technical solution of this application is implemented as follows:
[0005] Firstly, a similar image search method is provided, applied to a main node, the method comprising:
[0006] Obtain the image to be searched, and extract the image features of the image to be searched to obtain the K-dimensional feature vector of the image to be searched;
[0007] The K-dimensional feature vector of the image to be searched is reduced in dimensionality to obtain the Q-dimensional feature vector of the image to be searched; K > Q;
[0008] The K-dimensional feature vector of the image to be searched is processed based on P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched.
[0009] If the first hash code is found in the preset hash code set, a target sample image similar to the image to be searched is searched in parallel on the trees corresponding to N slave nodes according to the first hash code and Q-dimensional feature vector of the image to be searched; wherein, multiple trees are built on the slave nodes, and different trees are built based on the Q-dimensional feature vector of the sample images corresponding to different hash codes.
[0010] Secondly, a similar image search device is provided, applied to a master node, the device comprising:
[0011] An extraction unit is used to acquire the image to be searched and extract the image features of the image to be searched to obtain the K-dimensional feature vector of the image to be searched;
[0012] The processing unit is used to reduce the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched; K > Q;
[0013] And to process the K-dimensional feature vector of the image to be searched based on P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched;
[0014] And when it is determined that the first hash code exists in the preset hash code set, a target sample image similar to the image to be searched is searched in parallel on the trees corresponding to N slave nodes according to the first hash code and Q-dimensional feature vector of the image to be searched; wherein, multiple trees are established on the slave nodes, and different trees are established based on the Q-dimensional feature vector of the sample image corresponding to different hash codes.
[0015] Thirdly, an electronic device is provided, comprising: a processor and a memory configured to store a computer program capable of running on the processor, wherein the processor is configured to perform the steps of the method of the first aspect when running the computer program.
[0016] Fourthly, a computer-readable storage medium is provided having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method of the first aspect.
[0017] This application discloses a method, device, and storage medium for similar image search. The application uses a system architecture with one master node and N slave nodes, and establishes tree structures on each of the N slave nodes based on the Q-dimensional feature vectors of sample images corresponding to different hash codes. All images indicated by the same hash code are similar. Therefore, when performing a similar image search, the first hash code of the image to be searched is used to find the tree corresponding to the first hash code on each of the N slave nodes. All sample images indicated by all Q-dimensional feature vectors on the tree are similar to the image to be searched. From these similar sample images, target sample images with high similarity to the image to be searched can be quickly found. This search method significantly reduces the actual amount of search data, thus shortening the search time and improving search efficiency. Attached Figure Description
[0018] Figure 1 This is a schematic diagram of the first process of the similar image search method in the embodiments of this application;
[0019] Figure 2 This is a schematic diagram of the second process of the similar image search method in the embodiments of this application;
[0020] Figure 3 This is a schematic diagram of the third process of the similar image search method in the embodiments of this application;
[0021] Figure 4 This is a schematic diagram of the fourth process of the similar image search method in the embodiments of this application;
[0022] Figure 5This is a schematic diagram of the composition structure of the similar image search device in the embodiments of this application;
[0023] Figure 6 This is a schematic diagram of the electronic device structure in an embodiment of this application. Detailed Implementation
[0024] In order to gain a more detailed understanding of the features and technical content of the embodiments of this application, the implementation of the embodiments of this application will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for reference and illustration only and are not intended to limit the embodiments of this application.
[0025] This application provides a method for searching similar images. Figure 1 This is a schematic diagram of the first process of the similar image search method in this application embodiment. This application embodiment uses a master-slave architecture, which is logically one master and multiple slaves. Assuming there are N slave nodes in total, both the master and slave nodes should be deployed as a cluster to form a master-slave node in the form of a cluster, thus maintaining high availability.
[0026] The following explanation uses the master node as the execution entity. Figure 1 As shown, the similar image search method may specifically include:
[0027] Step 101: Obtain the image to be searched and extract its image features to obtain the K-dimensional feature vector.
[0028] In this embodiment of the application, the scene to be searched is captured by the camera on the terminal to obtain the image to be searched; or, a pre-stored image is obtained from the album as the image to be searched, etc.
[0029] In some embodiments, extracting image features from the image to be searched to obtain a K-dimensional feature vector of the image to be searched includes:
[0030] The image to be searched is input into the trained classification model, and the value of the penultimate fully connected layer in the trained classification model is recorded as the K-dimensional feature vector of the image to be searched.
[0031] Here, the value of the second-to-last fully connected layer in the trained classification model is used as the feature vector of the image to be searched. It is assumed that the number of nodes in the second-to-last fully connected layer in the trained classification model is K, that is, the feature vector of the image to be searched is K-dimensional.
[0032] It should be noted that the reason why the penultimate fully connected layer is selected to represent the image features of the image to be searched in this embodiment is because the number of nodes in the last fully connected layer is usually equal to the number of categories, which is too small to represent the image features.
[0033] The application fields of the similar image search method in this application include at least the field of skin disease treatment and the field of product recommendation, but are not specifically limited here.
[0034] Here, the trained classification model is obtained by training a pre-defined classification model based on M sample images. For example, a dataset of M collected facial acne images undergoes medical data annotation, that is, the types of lesions are labeled using the knowledge of professional doctors. After annotation, a convolutional neural network is built and trained for the corresponding computer vision classification task. Common classification neural networks such as ResNet are used, and a pre-defined classification model is loaded to train the classification of facial acne. When the loss decreases to a certain accuracy, training stops, and the trained classification model is obtained.
[0035] Step 102: Reduce the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched; K > Q.
[0036] For example, Principal Components Analysis (PCA) can be used to reduce the dimensionality of the K-dimensional feature vectors of the image to be searched. Here, the main purpose of PCA is dimensionality reduction, that is, to reduce the dimensionality of the data by performing linear transformations on the matrices, while preserving as much of the original data as possible.
[0037] In some embodiments, step 102 specifically includes: obtaining a K-row, Q-column transformation matrix;
[0038] The K-dimensional feature vector of the image to be searched is multiplied by the K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0039] In other words, a linear transformation is performed on the K-dimensional feature vector of the image to be searched using a K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0040] In some embodiments, obtaining the K-row Q-column transformation matrix includes:
[0041] Extract image features from M sample images to obtain K-dimensional feature vectors for the M sample images;
[0042] Randomly extract the K-dimensional feature vectors of m sample images from the K-dimensional feature vectors of the M sample images;
[0043] During the process of reducing the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, the K-row Q-column transformation matrix is obtained.
[0044] It should be noted that the value of m can be a preset proportion of M, with the preset proportion ranging from 0 to 1. Typically, M is much larger than m. Therefore, to reduce the computational cost of dimensionality reduction, m K-dimensional feature vectors of m sample images are randomly extracted from the K-dimensional feature vectors of the M sample images. During the dimensionality reduction of the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, a K-row Q-column transformation matrix is obtained. This K-row Q-column transformation matrix can then be used to linearly transform the K-dimensional feature vector of the image to be searched, obtaining the Q-dimensional feature vector of the image. Alternatively, the K-row Q-column transformation matrix can be used to linearly transform the K-dimensional feature vectors of the M sample images respectively, obtaining the Q-dimensional feature vectors of the M sample images; where K > Q.
[0045] Here, regarding how to extract the K-dimensional feature vectors from M sample images, refer to the method for extracting the K-dimensional feature vectors from the image to be searched.
[0046] Step 103: Process the K-dimensional feature vector of the image to be searched based on the P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched.
[0047] Here, P randomly generated K-dimensional random vectors are used to process the K-dimensional feature vector of the image to be searched, resulting in the P-dimensional first hash code (Locality Sensitive Hashing, LSH) of the image to be searched. Typically, K >> P > Q, where Q is generally less than 5, P is generally less than 10, and K is generally greater than 512.
[0048] This involves using random variables to transform a high-dimensional vector into a low-dimensional vector.
[0049] It should be noted that the similarity of two images is determined by comparing whether their hash codes are equal. Specifically, if the hash codes of two images are equal, the two images are similar; if the hash codes of two images are not equal, the two images are dissimilar.
[0050] Step 104: If the first hash code exists in the preset hash code set, then search in parallel on the trees corresponding to the N slave nodes for target sample images similar to the image to be searched, based on the first hash code and Q-dimensional feature vector of the image to be searched. Among them, multiple trees are built on the slave nodes, and different trees are built based on the Q-dimensional feature vectors of the sample images corresponding to different hash codes.
[0051] In some embodiments, the number of Q-dimensional feature vectors of the sample images corresponding to the same hash code is equal across the N slave nodes.
[0052] In this embodiment, for each hash code in the preset hash code set (HCS), the following steps are performed sequentially: The master node finds the Q-dimensional feature vector of all sample images corresponding to each hash code, divides it into N equal parts, and then transmits them to N slave nodes respectively. In this way, each slave node builds a tree (e.g., KDTree, BallTree) based on the Q-dimensional feature vector of all transmitted sample images. Thus, the Q-dimensional feature vector of all sample images corresponding to the t-th hash code in the preset hash code set is divided into N equal parts and stored in the t-th tree of the slave nodes.
[0053] In some embodiments, step 104 specifically includes: sending a search request to the N slave nodes, so that the N slave nodes search for the corresponding tree based on the identifier of the first hash code in the search request, and then search for N times the first preset number of candidate sample images similar to the image to be searched on the corresponding tree based on the Q-dimensional feature vector of the image to be searched in the search request.
[0054] The similarity between the N images to be searched returned by the nodes and N times the first preset number of candidate sample images is received.
[0055] Sort the candidate sample images N times the first preset number according to their similarity from largest to smallest;
[0056] The first preset number of candidate sample images ranked first are used as the target sample images.
[0057] In other words, after receiving a search request, the node first searches the corresponding tree based on the identifier of the first hash code in the search request. Then, based on the Q-dimensional feature vector of the image to be searched in the search request, it searches the corresponding tree for N times the first preset number of candidate sample images that are similar to the image to be searched. The similarity between the image to be searched and the N times the first preset number of candidate sample images is returned to the master node. Next, the master node sorts the N times the first preset number of candidate sample images in descending order of similarity and uses the first preset number of candidate sample images at the top of the sorted list as the target sample image. The first preset number can be set according to experimental results or the experimenter's experience.
[0058] Similarity is determined based on the Q-dimensional feature vector of the image to be searched and the Q-dimensional feature vector of the candidate image. For example, the Euclidean distance between the Q-dimensional feature vectors of the image to be searched and the candidate image is calculated, and the similarity between the two images is determined by the magnitude of the Euclidean distance. Of course, similarity can be measured not only by Euclidean distance but also by Hamming distance, etc., without specific limitations.
[0059] Here, the execution entity for steps 101 to 104 can be the processor of an electronic device.
[0060] Using the above technical solution, this application employs a system architecture with one master node and N slave nodes. A tree structure is established on each of the N slave nodes based on the Q-dimensional feature vectors of sample images corresponding to different hash codes. All images indicated by the same hash code are similar. Therefore, when searching for similar images, the first hash code of the image to be searched is used to find the corresponding tree on each of the N slave nodes. All sample images indicated by all Q-dimensional feature vectors on the tree are similar to the image to be searched. From these similar sample images, target sample images with high similarity to the image to be searched can be quickly found. This search method significantly reduces the actual amount of search data, thus shortening the search time and improving search efficiency.
[0061] To better illustrate the purpose of this application, further examples are provided based on the above embodiments. Figure 2 This is a schematic diagram of the second process of the similar image search method in the embodiments of this application, such as... Figure 2 As shown, the similar image search method specifically includes:
[0062] Step 201: Obtain the image to be searched and extract its image features to obtain the K-dimensional feature vector of the image to be searched.
[0063] In some embodiments, extracting image features from the image to be searched to obtain a K-dimensional feature vector of the image to be searched includes:
[0064] The image to be searched is input into the trained classification model, and the value of the penultimate fully connected layer in the trained classification model is recorded as the K-dimensional feature vector of the image to be searched.
[0065] Step 202: Reduce the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched; K > Q.
[0066] In some embodiments, step 202 specifically includes: obtaining a K-row, Q-column transformation matrix;
[0067] The K-dimensional feature vector of the image to be searched is multiplied by the K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0068] In other words, a linear transformation is performed on the K-dimensional feature vector of the image to be searched using a K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0069] In some embodiments, obtaining the K-row Q-column transformation matrix includes:
[0070] Extract image features from M sample images to obtain K-dimensional feature vectors for the M sample images;
[0071] Randomly extract the K-dimensional feature vectors of m sample images from the K-dimensional feature vectors of the M sample images;
[0072] During the process of reducing the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, the K-row Q-column transformation matrix is obtained.
[0073] Step 203: Perform an inner product of the K-dimensional feature vector of the image to be searched with P K-dimensional random vectors to obtain a vector with one row and P columns.
[0074] Here, the K-dimensional feature vector of the image to be searched is dot-producted with the first K-dimensional random vector, and the result of the dot-product 1 is used as the value of the first row and first column of the vector; the K-dimensional feature vector of the image to be searched is dot-producted with the second K-dimensional random vector, and the result of the dot-product 2 is used as the value of the first row and second column of the vector; the K-dimensional feature vector of the image to be searched is dot-producted with the third K-dimensional random vector, and the result of the dot-product 3 is used as the value of the first row and third column of the vector; and so on, until a vector with one row and P columns is finally obtained.
[0075] For example, the inner product of three-dimensional vectors (a1, a2, a3) and (b1, b2, b3) is a1*b1 + a2*b2 + a3*b3. The prerequisite for performing an inner product of two vectors is that the two vectors have the same dimension.
[0076] Step 204: Number the inner product results of different columns according to the preset numbering rules of different columns to obtain the first hash code of the image to be searched.
[0077] Here, the preset numbering rules for different columns can be the same or different.
[0078] In some embodiments, the preset numbering rule can be: for example, setting a column to have W numbers and W value ranges, where the inner product result is set to number 1 if it falls within a first value range, number 2 if it falls within a second value range, and number 3 if it falls within a third value range; wherein the maximum value of the first value range is less than the minimum value of the second value range, the maximum value of the second value range is less than the minimum value of the third value range, and so on. The more refined the setting, the more accurate the resulting first hash code.
[0079] In other embodiments, the preset numbering rule may also be: extracting image features from M sample images to obtain K-dimensional feature vectors of the M sample images;
[0080] The inner product of the K-dimensional feature vectors of the M sample images and the P K-dimensional random vectors is used to obtain an M-row, P-column matrix.
[0081] Determine the minimum and maximum values of the j-th column of the matrix; j is an integer from 1 to P;
[0082] Divide the minimum and maximum values of the j-th column into a second preset number of intervals, and number the M inner product results of the j-th column;
[0083] The preset numbering rule corresponding to the j-th column is determined based on the numbering result of the j-th column.
[0084] The second preset quantity can be set based on experimental results or the experimenter's experience.
[0085] For example, if the values in column j include 11, 10, 100, 12, and 200, and the minimum value of column j is determined to be 10 and the maximum value to be 200, if a clustering method (such as k-means) is used to divide the minimum and maximum values of column j into a second preset number of intervals, such as 3, then 11, 10, and 12 are numbered 1, 100 is numbered 2, and 200 is numbered 3. Thus, the preset numbering rule for column j could be: when the inner product result is close to 11, 10, and 12, the inner product result is numbered 1; when the inner product result is close to 100, the inner product result is numbered 2; and when the inner product result is close to 200, the inner product result is numbered 3. Alternatively, a uniform division method can be used; this application does not specifically limit the interval division method.
[0086] In some embodiments, after numbering all the inner product results of the j-th column, the method further includes:
[0087] The hash code of the i-th sample image is obtained by concatenating the numbers corresponding to the P inner product results in the i-th row of the matrix; i is an integer from 1 to M.
[0088] Obtain the hash codes of M sample images, and perform random sampling without replacement on the hash codes of the M sample images;
[0089] The extracted hash codes are stored in the preset hash code set until the preset hash code set stores a third preset number of non-repeating hash codes; wherein the third preset number is a preset multiple of the total number of hash codes.
[0090] Here, the numbers corresponding to the P inner product results of each row in the M rows of the matrix are concatenated to obtain the hash codes of the M sample images. After removing duplicate hash codes, the total number of hash codes is determined.
[0091] Typically, the number of hash codes stored in the preset hash code set (i.e., the third preset number) is a preset multiple of the total number of hash codes. For example, the preset multiple can be 0.2.
[0092] In this embodiment of the application, random sampling without replacement is performed on the hash codes of M sample images. Before storing them into a preset hash code set, it is determined whether there is a hash code being sampled in the preset hash code set. If there is no hash code, it is stored; if there is a hash code, it is discarded. This process continues until the preset hash code set is full.
[0093] Step 205: If the first hash code exists in the preset hash code set, then search in parallel on the trees corresponding to the N slave nodes for target sample images similar to the image to be searched, based on the first hash code and Q-dimensional feature vector of the image to be searched. Among them, multiple trees are built on the slave nodes, and different trees are built based on the Q-dimensional feature vectors of the sample images corresponding to different hash codes.
[0094] In some embodiments, the number of Q-dimensional feature vectors of the sample images corresponding to the same hash code is equal across the N slave nodes.
[0095] In this embodiment, for each hash code in the preset hash code set (HCS), the following steps are performed sequentially: The master node finds the Q-dimensional feature vector of all sample images corresponding to each hash code, divides it into N equal parts, and then transmits them to N slave nodes respectively. In this way, each slave node builds a tree (e.g., KDTree, BallTree) based on the Q-dimensional feature vector of all transmitted sample images. Thus, the Q-dimensional feature vector of all sample images corresponding to the t-th hash code in the preset hash code set is divided into N equal parts and stored in the t-th tree of the slave nodes.
[0096] In some embodiments, step 205 specifically includes: sending a search request to the N slave nodes, so that the N slave nodes search for the corresponding tree based on the identifier of the first hash code in the search request, and then search for N times the first preset number of candidate sample images similar to the image to be searched on the corresponding tree based on the Q-dimensional feature vector of the image to be searched in the search request.
[0097] The similarity between the N images to be searched returned by the nodes and N times the first preset number of candidate sample images is received.
[0098] Sort the candidate sample images N times the first preset number according to their similarity from largest to smallest;
[0099] The first preset number of candidate sample images ranked first are used as the target sample images.
[0100] Using the above technical solution, this application employs a system architecture with one master node and N slave nodes. A tree structure is established on each of the N slave nodes based on the Q-dimensional feature vectors of sample images corresponding to different hash codes. All images indicated by the same hash code are similar. Therefore, when searching for similar images, the first hash code of the image to be searched is used to find the corresponding tree on each of the N slave nodes. All sample images indicated by all Q-dimensional feature vectors on the tree are similar to the image to be searched. From these similar sample images, target sample images with high similarity to the image to be searched can be quickly found. This search method significantly reduces the actual amount of search data, thus shortening the search time and improving search efficiency.
[0101] Based on the above embodiments, this application further provides a similar image search method. Figure 3 This is a schematic diagram of the third process of the similar image search method in the embodiments of this application. The similar image search method specifically includes:
[0102] Step 301: Obtain the image to be searched and extract its image features to obtain the K-dimensional feature vector of the image to be searched.
[0103] In some embodiments, extracting image features from the image to be searched to obtain a K-dimensional feature vector of the image to be searched includes:
[0104] The image to be searched is input into the trained classification model, and the value of the penultimate fully connected layer in the trained classification model is recorded as the K-dimensional feature vector of the image to be searched.
[0105] Step 302: Reduce the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched; K > Q.
[0106] In some embodiments, step 302 specifically includes: obtaining a K-row, Q-column transformation matrix;
[0107] The K-dimensional feature vector of the image to be searched is multiplied by the K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0108] In other words, a linear transformation is performed on the K-dimensional feature vector of the image to be searched using a K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0109] In some embodiments, obtaining the K-row Q-column transformation matrix includes:
[0110] Extract image features from M sample images to obtain K-dimensional feature vectors for the M sample images;
[0111] Randomly extract the K-dimensional feature vectors of m sample images from the K-dimensional feature vectors of the M sample images;
[0112] During the process of reducing the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, the K-row Q-column transformation matrix is obtained.
[0113] Step 303: Perform an inner product of the K-dimensional feature vector of the image to be searched with P K-dimensional random vectors to obtain a vector with one row and P columns.
[0114] Step 304: Number the inner product results of different columns according to the preset numbering rules of different columns to obtain the first hash code of the image to be searched.
[0115] Here, the preset numbering rules for different columns can be the same or different.
[0116] In some embodiments, the preset numbering rule can be: for example, setting a column to have W numbers, where the inner product result is set to number 1 if it falls within a first value range; number 2 if it falls within a second value range; and number 3 if it falls within a third value range; wherein the maximum value of the first value range is less than the minimum value of the second value range, the maximum value of the second value range is less than the minimum value of the third value range, and so on. The more refined the setting, the more accurate the resulting first hash code.
[0117] In other embodiments, the preset numbering rule may also be: extracting image features from M sample images to obtain K-dimensional feature vectors of the M sample images;
[0118] The inner product of the K-dimensional feature vectors of the M sample images and the P K-dimensional random vectors is used to obtain an M-row, P-column matrix.
[0119] Determine the minimum and maximum values of the j-th column of the matrix; j is an integer from 1 to P;
[0120] Divide the minimum and maximum values of the j-th column into a second preset number of intervals, and number the M inner product results of the j-th column;
[0121] The preset numbering rule corresponding to the j-th column is determined based on the numbering result of the j-th column.
[0122] The second preset quantity can be set based on experimental results or the experimenter's experience.
[0123] For example, if the values in column j include 11, 10, 100, 12, and 200, and the minimum value of column j is determined to be 10 and the maximum value to be 200, if a clustering method (such as k-means) is used to divide the minimum and maximum values of column j into a second preset number of intervals, such as 3, then 11, 10, and 12 are numbered 1, 100 is numbered 2, and 200 is numbered 3. Thus, the preset numbering rule for column j could be: when the inner product result is close to 11, 10, and 12, the inner product result is numbered 1; when the inner product result is close to 100, the inner product result is numbered 2; and when the inner product result is close to 200, the inner product result is numbered 3. Alternatively, a uniform division method can be used; this application does not specifically limit the interval division method.
[0124] In some embodiments, after numbering all the inner product results of the j-th column, the method further includes:
[0125] The hash code of the i-th sample image is obtained by concatenating the numbers corresponding to the P inner product results in the i-th row of the matrix; i is an integer from 1 to M.
[0126] Obtain the hash codes of M sample images, and perform random sampling without replacement on the hash codes of the M sample images;
[0127] The extracted hash codes are stored in the preset hash code set until the preset hash code set stores a third preset number of non-repeating hash codes; wherein the third preset number is a preset multiple of the total number of hash codes.
[0128] Here, the numbers corresponding to the P inner product results of each row in the M rows of the matrix are concatenated to obtain the hash codes of the M sample images. After removing duplicate hash codes, the total number of hash codes is determined.
[0129] Typically, the number of hash codes stored in the preset hash code set (i.e., the third preset number) is a preset multiple of the total number of hash codes. For example, the preset multiple can be 0.2.
[0130] In this embodiment of the application, random sampling without replacement is performed on the hash codes of M sample images. Before storing them into a preset hash code set, it is determined whether there is a hash code being sampled in the preset hash code set. If there is no hash code, it is stored; if there is a hash code, it is discarded. This process continues until the preset hash code set is full.
[0131] In this embodiment, for each hash code in the preset hash code set (HCS), the following steps are performed sequentially: The master node finds the Q-dimensional feature vector of all sample images corresponding to each hash code, divides it into N equal parts, and then transmits them to N slave nodes respectively. Each slave node then builds a tree (e.g., KDTree, BallTree) based on the transmitted Q-dimensional feature vectors of all sample images. Thus, the Q-dimensional feature vector of all sample images corresponding to the t-th hash code in the preset hash code set is divided into N equal parts and stored in the t-th tree of the slave nodes. This corresponds to step 306.
[0132] For the remaining hash codes (i.e., hash codes not recorded in the hash code set), each hash code is processed sequentially as follows: The master node finds the Q-dimensional feature vectors of all sample images corresponding to each hash code, divides them into N equal parts, and then transmits them to N slave nodes. The slave nodes save the Q-dimensional feature vectors of all transmitted sample images sequentially into a file according to each hash code, and save it on the hard disk to save memory resources. This corresponds to step 307.
[0133] Step 305: Determine whether the first hash code exists in the preset hash code set; if yes, proceed to step 306; if no, proceed to step 307.
[0134] Step 306: Based on the first hash code and Q-dimensional feature vector of the image to be searched, search in parallel on the trees corresponding to the N slave nodes to find target sample images similar to the image to be searched; wherein, multiple trees are built on the slave nodes, and different trees are built based on the Q-dimensional feature vectors of the sample images corresponding to different hash codes.
[0135] In some embodiments, the number of Q-dimensional feature vectors of the sample images corresponding to the same hash code is equal across the N slave nodes.
[0136] In some embodiments, step 306 specifically includes: sending a search request to the N slave nodes, so that the N slave nodes search for the corresponding tree based on the identifier of the first hash code in the search request, and then search for N times the first preset number of candidate sample images similar to the image to be searched on the corresponding tree based on the Q-dimensional feature vector of the image to be searched in the search request.
[0137] The similarity between the N images to be searched returned by the nodes and N times the first preset number of candidate sample images is received.
[0138] Sort the candidate sample images N times the first preset number according to their similarity from largest to smallest;
[0139] The first preset number of candidate sample images ranked first are used as the target sample images.
[0140] Step 307: Based on the first hash code and Q-dimensional feature vector of the image to be searched, search for target sample images similar to the image to be searched in the hard disks corresponding to the N slave nodes; wherein, the hard disks store different files corresponding to different hash codes, and the different files store the Q-dimensional feature vectors of the sample images corresponding to different hash codes.
[0141] In some embodiments, step 307 specifically includes: sending a search request to the N slave nodes, so that the N slave nodes search for the corresponding file on the hard disk based on the identifier of the first hash code in the search request, and then search for N times the first preset number of candidate sample images similar to the image to be searched in the corresponding file based on the Q-dimensional feature vector of the image to be searched in the search request;
[0142] The similarity between the N images to be searched returned by the nodes and N times the first preset number of candidate sample images is received.
[0143] Sort the candidate sample images N times the first preset number according to their similarity from largest to smallest;
[0144] The first preset number of candidate sample images ranked first are used as the target sample images.
[0145] In other words, after receiving a search request, the slave node first searches for the corresponding file on the hard drive based on the identifier of the first hash code in the search request. Then, based on the Q-dimensional feature vector of the image to be searched in the search request, it searches for N times the first preset number of candidate sample images that are similar to the image to be searched from the corresponding file, and returns the similarity between the image to be searched and the N times the first preset number of candidate sample images to the master node. Next, the master node sorts the N times the first preset number of candidate sample images in descending order of similarity, and uses the first preset number of candidate sample images as the target sample image. The first preset number can be set according to experimental results or the experimenter's experience.
[0146] Similarity is determined based on the Q-dimensional feature vector of the image to be searched and the Q-dimensional feature vector of the candidate image. For example, the Euclidean distance between the Q-dimensional feature vectors of the image to be searched and the candidate image is calculated, and the similarity between the two images is determined by the magnitude of the Euclidean distance. Of course, similarity can be measured not only by Euclidean distance but also by Hamming distance, etc., without specific limitations.
[0147] In some embodiments, the method further includes: recording the number of queries for the first hash code during the search for similar images; wherein the first hash code is stored in or outside the hash code set;
[0148] Based on the number of queries to the first hash code, the set of hash codes and the trees on the N slave nodes are updated using the Least Recently Used algorithm.
[0149] The Least Recently Used (LRU) algorithm is a cache eviction strategy. Since the hash code set has a limited capacity, by recording the query count of the first queried hash code, the least recently used hash code is removed from the hash code set (simultaneously deleting the corresponding N slave nodes' trees). This ensures that the cached hash codes in the hash code set are those that have been queried the most. In this way, the hash code of the image to be searched is highly likely to exist in the hash code set, allowing for parallel queries of similar images across N slave nodes. This significantly reduces the actual amount of data searched, thus shortening the search time and improving search efficiency.
[0150] Correspondingly, hash codes that were not previously recorded in the hash code set will be added to the hash code set, and the corresponding tree for that hash code will be built on N slave nodes.
[0151] Based on the above embodiments, this application also provides a similar image search method. Figure 4 This is a schematic diagram of the fourth process of the similar image search method in the embodiments of this application.
[0152] like Figure 4 As shown, this similar image search method consists of two parts: an offline construction process and a search process. The specific steps are as follows:
[0153] Offline construction process:
[0154] Step 401: Train a preset classification model based on M sample images to obtain the trained classification model.
[0155] Specifically, the collected facial acne dataset of M sample images undergoes medical data annotation, that is, the types of lesions are labeled using the knowledge of professional doctors. After annotation, a convolutional neural network is built and trained for the corresponding computer vision classification task. Common classification neural networks such as ResNet are used, and a preset classification model is loaded to train the classification of facial acne. When the loss decreases to a certain accuracy, training is stopped, and the trained classification model is obtained.
[0156] Step 402: Extract the K-dimensional feature vectors of the M sample images.
[0157] Specifically, M sample images are sequentially passed through the trained classification model. The values of the second-to-last fully connected layer in the trained classification model are recorded as the feature vectors of the corresponding sample images. Let the second-to-last fully connected layer have K nodes, meaning the feature vectors are K-dimensional. This yields the K-dimensional feature vectors of the M sample images.
[0158] Step 403: Reduce the dimensionality of the K-dimensional feature vectors of the M sample images to obtain the Q-dimensional feature vectors of the M sample images; K > Q.
[0159] Specifically, for the K-dimensional feature vectors of M sample images, random sampling is performed at a certain ratio to obtain the K-dimensional feature vectors of m sample images. Principal Component Analysis (PCA) is used to reduce the dimensionality of the K-dimensional feature vectors of the m sample images to obtain the Q-dimensional feature vectors of the m sample images. During the dimensionality reduction process from the K-dimensional feature vectors of the m sample images to the Q-dimensional feature vectors, a K-row Q-column transformation matrix is obtained. This K-row Q-column transformation matrix is then used to perform linear transformations on the K-dimensional feature vectors of the M sample images to obtain the Q-dimensional feature vectors of the M sample images.
[0160] Step 404: Process the K-dimensional feature vectors of the M sample images based on the P randomly generated K-dimensional random vectors to obtain the hash codes of the M sample images.
[0161] Specifically, P K-dimensional random vectors are randomly generated. The j-th K-dimensional random vector is then multiplied by the K-dimensional feature vectors of the M sample images. The result of the multiplication is represented by matrix S, i.e., s. i,j Let represent the inner product of the i-th eigenvector and the j-th random vector. For the j-th column of matrix S, find the maximum value `max`. j and minimum value min j Then min j and max j Divide into c j There are 1 (i.e., the second preset number) intervals, and all inner product results in the j-th column are numbered. The partitioning method can use uniform partitioning, clustering (such as k-means), etc. The interval numbers in each column range from 1 to c. j There are c in total j The hash code of the i-th sample image is obtained by concatenating the indices corresponding to the P inner product results in the i-th row of matrix S. This leads to a mapping relationship where the M sample images correspond to P-dimensional hash codes, K-dimensional feature vectors, and Q-dimensional feature vectors. Typically, K >> P > Q, where Q is generally less than 5, P is generally less than 10, and K is generally greater than 512.
[0162] Step 405: Perform random sampling without replacement on the hash codes of the M sample images, and store the extracted hash codes in a hash code set that can store a third preset number of hash codes.
[0163] Specifically, duplicate hash codes are removed from the hash codes of the M sample images to determine the total number of hash codes. Random sampling without replacement is performed on the hash codes of the M sample images, and the extracted hash codes are stored in a hash code set until the hash code set contains a third preset number of unique hash codes. The third preset number is a preset multiple c of the total number of hash codes. The preset multiple c can be 0.2.
[0164] Step 406: Divide the Q-dimensional feature vector of all sample images corresponding to each hash code in the hash code set into N parts and distribute them to N slave nodes to build a tree structure.
[0165] Specifically, after the master node records the preset hash code set, it performs the following steps for each hash code in the preset hash code set: The master node finds the Q-dimensional feature vector of all sample images corresponding to each hash code, divides it into N equal parts, and then transmits them to N slave nodes respectively. In this way, each slave node builds a tree (e.g., KDTree, BallTree) based on the Q-dimensional feature vector of all sample images transmitted. Thus, the Q-dimensional feature vector of all sample images corresponding to the t-th hash code in the preset hash code set is divided into N equal parts and stored in the t-th tree of the slave nodes.
[0166] Step 407: Divide the Q-dimensional feature vectors of all sample images corresponding to each hash code that is not recorded in the hash code set into N parts and distribute them to N slave nodes for storage on the hard disk.
[0167] Specifically, for the remaining hash codes (i.e. hash codes not recorded in the hash code set), each hash code is processed in the following steps: the master node finds the Q-dimensional feature vectors of all sample images corresponding to each hash code, divides them into N equal parts, and then transmits them to N slave nodes respectively. The slave nodes save the Q-dimensional feature vectors of all transmitted sample images into a file according to each hash code, and save it on the hard disk to save memory resources.
[0168] Search process:
[0169] Step 408: When searching for similar images, determine the first hash code of the image to be searched.
[0170] Specifically, when a search image needs to find B (i.e., a first preset number) similar target sample images, the search image is input into the trained classification model at the master node, and the value of the penultimate fully connected layer in the trained classification model is recorded as the K-dimensional feature vector of the search image. The K-dimensional feature vector of the search image is then reduced in dimensionality to obtain the Q-dimensional feature vector of the search image. Finally, P randomly generated K-dimensional random vectors are used to process the K-dimensional feature vector of the search image to obtain the P-dimensional first hash code of the search image.
[0171] Step 409: If the first hash code exists in the preset hash code set, query N*B (i.e., the first preset number) candidate sample images in parallel on the corresponding tree structure of the N slave nodes.
[0172] Step 410: If the first hash code does not exist in the preset hash code set, query N*B (i.e., the first preset number) candidate sample images in the files corresponding to the first hash code on the hard drives of the N slave nodes.
[0173] Step 411: The master node sorts the N*B (i.e., the first preset number) candidate sample images according to the order of similarity from largest to smallest, and selects the top B candidate sample images as target sample images that are similar to the image to be searched.
[0174] For example, in a scenario with M = 10^9 sample images, when N = 10, Q = 4, and in the hash code configuration, P = 4, c j =10 (1≤j≤4), with a preset multiplier c=0.2, meaning the hash code set HCS caches 2000 trees. If KDTree is used, the search will involve exactly 20% of the hot data, resulting in a search complexity of O(n log n). The efficiency is approximately on the order of 10^3, which is 10^6 less than the original 10^9 linear search, significantly improving efficiency.
[0175] To implement the method of the embodiments of this application, based on the same inventive concept, a similar image search device is also provided in the embodiments of this application. Figure 5 This is a schematic diagram of the composition structure of the similar image search device in the embodiments of this application, such as... Figure 5 As shown, the similar image search device 50 includes:
[0176] Extraction unit 501 is used to acquire the image to be searched and extract the image features of the image to be searched to obtain the K-dimensional feature vector of the image to be searched;
[0177] Processing unit 502 is used to reduce the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched; K > Q;
[0178] And to process the K-dimensional feature vector of the image to be searched based on P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched;
[0179] And when it is determined that the first hash code exists in the preset hash code set, a target sample image similar to the image to be searched is searched in parallel on the trees corresponding to N slave nodes according to the first hash code and Q-dimensional feature vector of the image to be searched; wherein, multiple trees are established on the slave nodes, and different trees are established based on the Q-dimensional feature vector of the sample image corresponding to different hash codes.
[0180] Using the above technical solution, this application employs a system architecture with one master node and N slave nodes. A tree structure is established on each of the N slave nodes based on the Q-dimensional feature vectors of sample images corresponding to different hash codes. All images indicated by the same hash code are similar. Therefore, when searching for similar images, the first hash code of the image to be searched is used to find the corresponding tree on each of the N slave nodes. All sample images indicated by all Q-dimensional feature vectors on the tree are similar to the image to be searched. From these similar sample images, target sample images with high similarity to the image to be searched can be quickly found. This search method significantly reduces the actual amount of search data, thus shortening the search time and improving search efficiency.
[0181] In some embodiments, the processing unit 502 is specifically used to perform an inner product of the K-dimensional feature vector of the image to be searched with the P K-dimensional random vectors to obtain a vector with one row and P columns.
[0182] The inner product results of different columns are numbered according to the preset numbering rules of different columns to obtain the first hash code of the image to be searched.
[0183] In some embodiments, the processing unit 502 is specifically used to extract image features from M sample images to obtain a K-dimensional feature vector of the M sample images;
[0184] The inner product of the K-dimensional feature vectors of the M sample images and the P K-dimensional random vectors is used to obtain an M-row, P-column matrix.
[0185] Determine the minimum and maximum values of the j-th column of the matrix; j is an integer from 1 to P; divide the minimum and maximum values of the j-th column into a second preset number of intervals, and number the M inner product results of the j-th column;
[0186] The preset numbering rule corresponding to the j-th column is determined based on the numbering result of the j-th column.
[0187] In some embodiments, the processing unit 502 is specifically used to concatenate the numbers corresponding to the P inner product results in the i-th row of the matrix to obtain the hash code of the i-th sample image; i is an integer from 1 to M.
[0188] Obtain the hash codes of M sample images, and perform random sampling without replacement on the hash codes of the M sample images;
[0189] The extracted hash codes are stored in the preset hash code set until the preset hash code set stores a third preset number of non-repeating hash codes; wherein the third preset number is a preset multiple of the total number of hash codes.
[0190] In some embodiments, the processing unit 502 is specifically used to, when it is determined that the first hash code does not exist in the preset hash code set, search for a target sample image similar to the image to be searched in the hard disks corresponding to the N slave nodes according to the first hash code of the image to be searched and the Q-dimensional feature vector of the image to be searched.
[0191] The hard disk stores different files corresponding to different hash codes, and the different files store the Q-dimensional feature vectors of sample images corresponding to different hash codes.
[0192] In some embodiments, during the process of searching for similar images, the processing unit 502 records the number of queries for the first hash code; wherein the first hash code is stored in or outside the hash code set.
[0193] Based on the number of queries to the first hash code, the set of hash codes and the trees on the N slave nodes are updated using the Least Recently Used algorithm.
[0194] In some embodiments, the processing unit 502 is specifically used to obtain a K-row Q-column transformation matrix;
[0195] The K-dimensional feature vector of the image to be searched is multiplied by the K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
[0196] In some embodiments, the processing unit 502 is specifically used to extract image features from M sample images to obtain a K-dimensional feature vector of the M sample images;
[0197] Randomly extract the K-dimensional feature vectors of m sample images from the K-dimensional feature vectors of the M sample images;
[0198] During the process of reducing the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, the K-row Q-column transformation matrix is obtained.
[0199] In some embodiments, the processing unit 502 is specifically configured to send a search request to the N slave nodes, so that the N slave nodes search for the corresponding tree based on the identifier of the first hash code in the search request, and then search for N times the first preset number of candidate sample images similar to the image to be searched on the corresponding tree based on the Q-dimensional feature vector of the image to be searched in the search request.
[0200] The similarity between the N images to be searched returned by the nodes and N times the first preset number of candidate sample images is received.
[0201] Sort the candidate sample images N times the first preset number according to their similarity from largest to smallest;
[0202] The first preset number of candidate sample images ranked first are used as the target sample images.
[0203] In some embodiments, the processing unit 502 is specifically used to input the image to be searched into a trained classification model and record the value of the penultimate fully connected layer in the trained classification model as the K-dimensional feature vector of the image to be searched.
[0204] This application also provides another electronic device. Figure 6 This is a schematic diagram of the electronic device composition structure in the embodiments of this application, such as... Figure 6 As shown, the electronic device 60 includes: a processor 601 and a memory 602 configured to store computer programs capable of running on the processor;
[0205] The processor 601 is configured to execute the method steps in the foregoing embodiments when running a computer program.
[0206] Of course, in practical applications, such as Figure 6 As shown, the various components in the electronic device 60 are coupled together via a bus system 603. It is understood that the bus system 603 is used to implement communication between these components. In addition to a data bus, the bus system 603 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 6 The general designated all buses as Bus System 603.
[0207] In practical applications, the aforementioned processor can be at least one of the following: Application-Specific Integrated Circuit (ASIC), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field-Programmable Gate Array (FPGA), controller, microcontroller, and microprocessor. It is understood that, for different devices, the electronic devices used to implement the functions of the aforementioned processor can also be other types, and the embodiments of this application do not specifically limit this.
[0208] The aforementioned memory can be volatile memory, such as random-access memory (RAM); or non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); or a combination of the above types of memory, and provides instructions and data to the processor.
[0209] In an exemplary embodiment, this application also provides a computer-readable storage medium for storing a computer program.
[0210] Optionally, the computer-readable storage medium can be applied to any of the methods in the embodiments of this application, and the computer program causes the computer to execute the corresponding processes implemented by the processor in the various methods of the embodiments of this application. For the sake of brevity, it will not be described in detail here.
[0211] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0212] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0213] Furthermore, in the various embodiments of the present invention, all functional units can be integrated into one processing module, or each unit can be a separate unit, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units. Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0214] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0215] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0216] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0217] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A similar image search method, applied to a master node, characterized in that, The method includes: Obtain the image to be searched, and extract the image features of the image to be searched to obtain the K-dimensional feature vector of the image to be searched; The K-dimensional feature vector of the image to be searched is reduced in dimensionality to obtain the Q-dimensional feature vector of the image to be searched; K > Q; The K-dimensional feature vector of the image to be searched is processed based on P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched. If the first hash code is found in the preset hash code set, target sample images similar to the image to be searched are searched in parallel on the trees corresponding to N slave nodes according to the first hash code and Q-dimensional feature vector of the image to be searched; wherein, multiple trees are built on the slave nodes, and different trees are built based on the Q-dimensional feature vectors of sample images corresponding to different hash codes; The step of searching in parallel on trees corresponding to N slave nodes for target sample images similar to the image to be searched, based on the first hash code and Q-dimensional feature vector of the image to be searched, includes: sending search requests to the N slave nodes, causing the N slave nodes to search for corresponding trees based on the identifier of the first hash code in the search request, and then searching for N times a first preset number of candidate sample images similar to the image to be searched on the corresponding trees based on the Q-dimensional feature vector of the image to be searched in the search request; receiving the similarity between the image to be searched and the N times a first preset number of candidate sample images returned by the N slave nodes; sorting the N times a first preset number of candidate sample images in descending order of similarity; and taking the first preset number of candidate sample images as the target sample image.
2. The method according to claim 1, characterized in that, The process of processing the K-dimensional feature vector of the image to be searched based on P randomly generated K-dimensional random vectors to obtain the first hash code of the image to be searched includes: The inner product of the K-dimensional feature vector of the image to be searched with the P K-dimensional random vectors is obtained to obtain a vector with one row and P columns. The inner product results of different columns are numbered according to the preset numbering rules of different columns to obtain the first hash code of the image to be searched.
3. The method according to claim 2, characterized in that, The method further includes: Extract image features from M sample images to obtain K-dimensional feature vectors for the M sample images; The inner product of the K-dimensional feature vectors of the M sample images and the P K-dimensional random vectors is used to obtain an M-row, P-column matrix. Determine the minimum and maximum values of the j-th column of the matrix; j is an integer from 1 to P; Divide the minimum and maximum values of the j-th column into a second preset number of intervals, and number the M inner product results of the j-th column; The preset numbering rule corresponding to the j-th column is determined based on the numbering result of the j-th column.
4. The method according to claim 3, characterized in that After numbering the M inner product results in the j-th column, the method further includes: The hash code of the i-th sample image is obtained by concatenating the numbers corresponding to the P inner product results in the i-th row of the matrix; i is an integer from 1 to M. Obtain the hash codes of M sample images, and perform random sampling without replacement on the hash codes of the M sample images; The extracted hash codes are stored in the preset hash code set until the preset hash code set stores a third preset number of non-repeating hash codes; wherein the third preset number is a preset multiple of the total number of hash codes.
5. The method according to claim 1, characterized in that, The method further includes: If it is determined that the first hash code does not exist in the preset hash code set, a target sample image similar to the image to be searched is found in the hard disks corresponding to the N slave nodes based on the first hash code of the image to be searched and the Q-dimensional feature vector of the image to be searched. The hard disk stores different files corresponding to different hash codes, and the different files store the Q-dimensional feature vectors of sample images corresponding to different hash codes.
6. The method according to claim 1 or 5, characterized in that, The method further includes: During the search for similar images, the number of queries for the first hash code is recorded; wherein, the first hash code is stored either within or outside the hash code set; Based on the number of queries to the first hash code, the set of hash codes and the trees on the N slave nodes are updated using the Least Recently Used algorithm.
7. The method according to claim 1, characterized in that, The step of reducing the dimensionality of the K-dimensional feature vector of the image to be searched to obtain the Q-dimensional feature vector of the image to be searched includes: Obtain the K-row, Q-column transformation matrix; The K-dimensional feature vector of the image to be searched is multiplied by the K-row Q-column transformation matrix to obtain the Q-dimensional feature vector of the image to be searched.
8. The method according to claim 7, characterized in that, The process of obtaining the K-row, Q-column transformation matrix includes: Extract image features from M sample images to obtain K-dimensional feature vectors for the M sample images; Randomly extract the K-dimensional feature vectors of m sample images from the K-dimensional feature vectors of the M sample images; During the process of reducing the K-dimensional feature vectors of the m sample images to Q-dimensional feature vectors, the K-row Q-column transformation matrix is obtained.
9. The method according to claim 1, characterized in that, The step of extracting image features from the image to be searched to obtain a K-dimensional feature vector of the image to be searched includes: The image to be searched is input into the trained classification model, and the value of the penultimate fully connected layer in the trained classification model is recorded as the K-dimensional feature vector of the image to be searched.
10. An electronic device, characterized in that, The electronic device includes: a processor and a memory configured to store computer programs capable of running on the processor. Wherein, when the processor is configured to run the computer program, it performs the steps of the method according to any one of claims 1 to 9.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any one of claims 1 to 9.
Citation Information
Patent Citations
Deep hash and GPU acceleration-based large-scale image retrieval method
CN108920720A
Image retrieval method and device thereof
CN112307248A