Method for obtaining image retrieval model, image retrieval method, device and equipment
By updating the image retrieval model and using sample images and quantized codebooks to optimize the image retrieval model, the problem of insufficient performance of the image retrieval model in the existing technology is solved and higher retrieval accuracy is achieved.
Patent Information
- Application Number
- CN202111235725.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-22
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2041-10-22
AI Technical Summary
In the prior art, the performance of the image retrieval model is insufficient, resulting in low accuracy of the search results, which is difficult to meet the needs of improving the accuracy of the image retrieval results.
By obtaining the sample image and the initial image retrieval model, the feature module and the feature quantification module are called, the target loss value is determined based on the sample quantization vector and the quantization codebook, and the initial image retrieval model is updated to obtain the target image retrieval model.
The accuracy of the image retrieval model is improved, the retrieval results are more accurate, and the performance of image retrieval is enhanced.
Smart Images

Figure CN114299306B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method for obtaining an image retrieval model, an image retrieval method, a device and an apparatus. Background Art
[0002] With the continuous development of computer technology, more and more fields involve image retrieval, and there are more and more ways to search for images. Using image retrieval models for image retrieval is one of them.
[0003] When an image retrieval model is used for image retrieval, the performance of the image retrieval model determines the accuracy of the retrieval results. Therefore, how to obtain an image retrieval model with better performance is the key to improving the accuracy of image retrieval results. Summary of the invention
[0004] The embodiment of the present application provides a method for obtaining an image retrieval model, an image retrieval method, a device and an apparatus, which can be used to improve the accuracy of image retrieval. The technical solution is as follows:
[0005] On the one hand, an embodiment of the present application provides a method for obtaining an image retrieval model, the method comprising:
[0006] Acquire a sample image and an initial image retrieval model, wherein the initial image retrieval model includes a feature module, a feature quantization module, and a quantization codebook module, wherein the feature module is used to acquire a feature vector corresponding to the sample image, the feature quantization module is used to acquire a quantization vector corresponding to the feature vector, and the quantization codebook module is used to provide a quantization codebook, wherein the quantization codebook is updated as the initial image retrieval model is updated;
[0007] Calling the feature module to obtain a sample feature vector corresponding to the sample image;
[0008] Calling the feature quantization module to obtain a sample quantization vector corresponding to the sample feature vector;
[0009] Determine a target loss value based on the sample quantization vector and the quantization codebook;
[0010] The initial image retrieval model is updated based on the target loss value to obtain a target image retrieval model.
[0011] On the other hand, an embodiment of the present application provides an image retrieval method, the method comprising:
[0012] Obtaining a target image to be retrieved and a target image retrieval model, wherein the target image retrieval model is obtained by the method for obtaining an image retrieval model as described above;
[0013] Inputting the target image into the target image retrieval model to obtain a quantization vector corresponding to the target image;
[0014] An image retrieval result is obtained based on a quantization vector corresponding to the target image and a quantization codebook in the target image retrieval model.
[0015] On the other hand, an embodiment of the present application provides a device for obtaining an image retrieval model, the device comprising:
[0016] An acquisition module, used to acquire a sample image and an initial image retrieval model, wherein the initial image retrieval model includes a feature module, a feature quantization module and a quantization codebook module, wherein the feature module is used to acquire a feature vector corresponding to the sample image, the feature quantization module is used to acquire a quantization vector corresponding to the feature vector, and the quantization codebook module is used to provide a quantization codebook, which is updated as the initial image retrieval model is updated;
[0017] The acquisition module is used to call the feature module to acquire the sample feature vector corresponding to the sample image;
[0018] The acquisition module is used to call the feature quantization module to obtain the sample quantization vector corresponding to the sample feature vector;
[0019] A determination module, configured to determine a target loss value based on the sample quantization vector and the quantization codebook;
[0020] An updating module is used to update the initial image retrieval model based on the target loss value to obtain a target image retrieval model.
[0021] In a possible implementation manner, the determination module is used to determine a reference loss value based on the sample quantization vector and the quantization codebook, where the reference loss value includes at least one of a reconstruction error loss value and a reconstruction metric loss value;
[0022] The target loss value is determined based on the reference loss value and the weight corresponding to the reference loss value.
[0023] In a possible implementation manner, the reference loss value includes a reconstruction error loss value;
[0024] The determining module is used to obtain a reconstruction vector corresponding to the sample quantization vector based on the quantization codebook;
[0025] The reconstruction error loss value is determined based on the reconstruction vector and the sample quantization vector.
[0026] In a possible implementation, the determining module is used to segment the sample quantization vector to obtain a plurality of sub-vectors, each of which has the same dimension;
[0027] Acquire a quantization code corresponding to each subvector based on the quantization codebook and the multiple subvectors;
[0028] The quantization codes corresponding to each of the sub-vectors are concatenated to obtain a reconstructed vector corresponding to the sample quantization vector.
[0029] In a possible implementation manner, the determining module is configured to obtain multiple quantization codebooks corresponding to each segment based on the quantization codebook;
[0030] For any sub-vector, the distance between the sub-vector and a plurality of quantization codebooks corresponding to the segment where the sub-vector is located is determined, and the quantization codebook whose distance meets the requirement is used as the quantization code corresponding to the sub-vector.
[0031] In a possible implementation manner, the determination module is configured to use the distance between the reconstruction vector and the sample quantization vector as the reconstruction error loss value.
[0032] In a possible implementation, the reference loss value includes a reconstruction metric loss value;
[0033] The determination module is used to obtain a reconstruction vector corresponding to the sample quantization vector;
[0034] Obtaining a positive sample image and a negative sample image corresponding to the sample image;
[0035] Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image;
[0036] The reconstruction metric loss value is determined based on the reconstruction vector, the first quantization vector, and the second quantization vector.
[0037] In a possible implementation manner, the determining module is used to determine the distance between the reconstructed vector and the first quantized vector to obtain a first distance;
[0038] Determine a distance between the reconstructed vector and the second quantized vector to obtain a second distance;
[0039] The reconstruction metric loss value is determined based on the first distance, the second distance and a first reference value.
[0040] In a possible implementation manner, the determining module is used to determine a difference between the first distance and the second distance;
[0041] Determine a first candidate value based on a difference between the first distance and the second distance;
[0042] The maximum value between the first candidate value and the first reference value is used as the reconstruction metric loss value.
[0043] In a possible implementation, the reference loss value also includes a triplet loss value;
[0044] The determination module is used to obtain a positive sample image and a negative sample image corresponding to the sample image;
[0045] Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image;
[0046] Determine a distance between the sample quantization vector and the first quantization vector to obtain a third distance;
[0047] Determine a distance between the sample quantization vector and the second quantization vector to obtain a fourth distance;
[0048] The triplet loss value is determined based on the third distance, the fourth distance and a second reference value.
[0049] In a possible implementation manner, the reference loss value also includes a quantized loss value;
[0050] The determination module is used to determine the square difference between the numerical values corresponding to each dimension in the sample quantization vector and the sample feature vector;
[0051] The sum of the squares of the differences between the values corresponding to each dimension is used as the quantization loss value.
[0052] In a possible implementation, the updating module is used to update the initial image retrieval model according to a gradient descent algorithm in response to the target loss value being greater than a loss threshold, to obtain an updated image retrieval model;
[0053] Based on the updated image retrieval model, obtaining an updated target loss value;
[0054] In response to the target loss value after the update being not greater than the loss threshold, the updated image retrieval model is used as the target image retrieval model.
[0055] In a possible implementation manner, the acquisition module is configured to, for each dimension in the sample feature vector, determine the value corresponding to the dimension as a first value in response to the value corresponding to the dimension being less than a target value, or determine the value corresponding to the dimension as a second value in response to the value corresponding to the dimension being not less than the target value;
[0056] A sample quantization vector corresponding to the sample feature vector is obtained according to a numerical value corresponding to each dimension in the sample feature vector, wherein the first numerical value is smaller than the second numerical value.
[0057] On the other hand, an embodiment of the present application provides an image retrieval device, the device comprising:
[0058] An acquisition module, used to acquire a target image to be retrieved and a target image retrieval model, wherein the target image retrieval model is obtained by the device for acquiring an image retrieval model as described above;
[0059] A determination module, used for inputting the target image into the target image retrieval model to obtain a quantization vector corresponding to the target image;
[0060] The acquisition module is used to acquire the image retrieval result based on the quantization vector corresponding to the target image and the quantization codebook in the target image retrieval model.
[0061] On the other hand, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor to enable the electronic device to implement the method for obtaining an image retrieval model described above, or to implement the image retrieval method described above.
[0062] On the other hand, a computer-readable storage medium is also provided, in which at least one program code is stored. The at least one program code is loaded and executed by a processor so that the computer implements the method for obtaining an image retrieval model as described above, or implements the image retrieval method as described above.
[0063] On the other hand, a computer program or a computer program product is also provided, wherein at least one computer instruction is stored in the computer program or the computer program product, and the at least one computer instruction is loaded and executed by a processor so that the computer implements the method for obtaining an image retrieval model as described above, or implements the image retrieval method as described above.
[0064] The technical solution provided by the embodiments of the present application brings at least the following beneficial effects:
[0065] In the technical solution provided in the embodiment of the present application, the quantization codebook included in the quantization codebook module in the initial image retrieval model is updated as the initial image retrieval model is updated, so that the quantization codebook included in the quantization codebook module is constantly changing, thereby making the quantization codebook included in the quantization codebook module match the current feature quantization module, so that the accuracy of the loss value obtained based on the quantization codebook and the quantization vector is higher. The initial image retrieval model is updated using a loss value with higher accuracy, so that the update process is more accurate, thereby making the accuracy of the target image retrieval model obtained higher, and the retrieval accuracy when using the target image retrieval model for retrieval is higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0067] Figure 1 It is a method for obtaining an image retrieval model and a schematic diagram of an implementation environment of the image retrieval method provided in an embodiment of the present application;
[0068] Figure 2 is a flow chart of a method for obtaining an image retrieval model provided in an embodiment of the present application;
[0069] Figure 3 It is a schematic diagram of a network structure of a residual module corresponding to a Conv2-x convolutional layer provided in an embodiment of the present application;
[0070] Figure 4 is a flow chart of an image retrieval method provided in an embodiment of the present application;
[0071] Figure 5 It is a framework diagram for determining a target loss value provided by an embodiment of the present application;
[0072] Figure 6 It is a structural schematic diagram of a device for obtaining an image retrieval model provided in an embodiment of the present application;
[0073] Figure 7 is a structural schematic diagram of an image retrieval device provided in an embodiment of the present application;
[0074] Figure 8 is a schematic diagram of the structure of a terminal provided in an embodiment of the present application;
[0075] Fig. 9 It is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0076] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0077] Figure 1 is a schematic diagram of a method for obtaining an image retrieval model and an implementation environment of the image retrieval method provided in an embodiment of the present application, such as Figure 1 As shown, the implementation environment includes: a terminal 101 and a server 102 .
[0078] Both the terminal 101 and the server 102 can independently implement the method for obtaining an image retrieval model and the image retrieval method provided in the embodiment of the present application. The method for obtaining an image retrieval model and the image retrieval method provided in the embodiment of the present application can also be implemented based on the interaction between the terminal 101 and the server 102. For example, the terminal 101 obtains a sample image, sends the sample image to the server 102, and the server 102 updates the initial image retrieval model based on the sample image to obtain a target image retrieval model. The terminal 101 obtains a target image, sends the target image to the server 102, and the server 102 retrieves the target image to obtain an image retrieval result, and the server 102 sends the image retrieval result to the terminal 101.
[0079] The terminal 101 may be at least one of a smart phone, a game console, a desktop computer, a tablet computer, a laptop computer, an e-book reader, a player, a smart TV, a vehicle-mounted terminal, etc. A client for image retrieval is installed and running in the terminal 101 .
[0080] The server 102 may be a single server, or a server cluster consisting of multiple servers, or any one of a cloud computing platform and a virtualization center, which is not limited in the present embodiment. The server 102 is connected to the terminal 101 via a wired network or a wireless network. Of course, the server 102 may also have other functions, which are not limited in the present embodiment.
[0081] Based on the above implementation environment, the present application embodiment provides a method for obtaining an image retrieval model. Figure 2 As an example, the flowchart of a method for obtaining an image retrieval model provided in an embodiment of the present application is shown. The method can be executed by an electronic device, which can be Figure 1 The terminal 101 in Figure 1 Server 102 in. Figure 2 As shown, the method comprises the following steps:
[0082] In step 201, a sample image and an initial image retrieval model are obtained.
[0083] In an exemplary embodiment of the present application, a plurality of positive sample pairs are stored in an electronic device, each positive sample pair includes two similar samples, a sample image is any sample included in any positive sample pair, and a sample image is an image that needs to be retrieved. The sample image can be any sample selected by a user in a positive sample pair, or the sample image can be a sample randomly selected from a selected positive sample pair by the electronic device randomly selecting a positive sample pair from multiple positive sample pairs. Of course, the sample image can also be an image uploaded by a user, or an image obtained based on a search engine, and the embodiment of the present application does not limit the source of the sample image. The category of the sample image can be a person, an animal, a plant, or any other type of image, and the embodiment of the present application does not limit the category of the sample image.
[0084] In a possible implementation, the initial image retrieval model includes a feature module, a feature quantization module and a quantization codebook module. The feature module is used to obtain a feature vector corresponding to a sample image, the feature quantization module is used to obtain a quantization vector corresponding to the feature vector, and the quantization codebook module is used to provide a quantization codebook, which is updated as the initial image retrieval model is updated.
[0085] Optionally, the feature module can be a convolutional neural network (CNN) module. Among them, the convolutional neural network can be a Resnet-101 network (a network), where 101 is used to indicate that the number of hidden layers contained in the network is 101 layers. Of course, the convolutional neural network can also be a Resnet-18 network (a network), or a Resnet-50 network (a network), or an inception v4 network (a network), or a mobilenet v2 network (a network). The embodiment of the present application does not limit the type of convolutional neural network. Among them, the convolutional neural network is a Resnet-101 network, as shown in the following Table 1, which is the learning parameters of the convolutional neural network provided in the embodiment of the present application.
[0086] Table 1
[0087]
[0088]
[0089] In Table 1 above, Conv1, Conv2-x, Conv3-x, Conv4-x, and Conv5-x are five different convolutional layers. The output size of each convolutional layer is different, and the network structure of the residual module (block) corresponding to each convolutional layer is also different. ×3blocks means that the Conv2-x convolutional layer is stacked by three residual modules.
[0090] like Figure 3 Shown is a schematic diagram of the network structure of the residual module corresponding to the Conv2-x convolution layer provided in an embodiment of the present application. In the residual module, a 256-dimensional (256-d) vector is input, and a 64-dimensional vector is obtained after passing through a 1×1 convolution layer. Then it is rectified (relu) through a 3×3 convolution layer to obtain a 64-dimensional vector. Then it is rectified through a 1×1 convolution layer to obtain a 256-dimensional vector. In order to prevent the loss of some features during dimensionality reduction, the original 256-dimensional vector is added to the 256-dimensional vector obtained after the 1×1 convolution layer, and the added vector is rectified to obtain the final output vector.
[0091] Optionally, the feature quantization module may be a hash feature module, which is used to quantize feature vectors into binary features, that is, to convert floating point features into binary features. The following Table 2 shows the learning parameters of the hash feature module provided in the embodiment of the present application.
[0092] Table 2
[0093]
[0094] In Table 2 above, the pooling layer in the feature quantization module in the initial image retrieval model uses the maximum pooling layer, and the output size of the pooling layer is 1×2048. The encoding layer uses a fully connected layer, and the output size of the encoding layer is 1×128. Among them, the full connection layer uses multi-layer tanh activation. The full connection is initialized with a Gaussian distribution with a variance of 0.01 and a mean of 0.
[0095] Optionally, the learning rate of the initial image retrieval model is 0.0005.
[0096] Optionally, as shown in Table 3 below, a table of learning parameters of a quantization codebook module provided in an embodiment of the present application is provided.
[0097] Table 3
[0098]
[0099] In the above Table 3, the quantization codebook module includes feature vectors of N sample images, and the feature vector of each sample image is 1×M dimensional. The feature vector of each sample image is divided into D segments, and the dimension of each segment is M / D dimension. Each segment maintains a codebook of K clustering centers. Therefore, there are a total of K×D quantization centers that need to be learned.
[0100] The quantization codebook module stores multiple quantization codebooks included in each segment. Since the multiple quantization codebooks included in each segment are cluster centers of each segment, the quantization codebook module stores multiple cluster centers of each segment.
[0101] Exemplarily, feature vectors of 100 sample images are obtained, each feature vector has a dimension of 128, and each feature vector is evenly divided into 4 segments, each segment has a dimension of 32. Therefore, a total of 4×100 sub-vectors are obtained, and the quantization codebooks included in the 4 segments can be obtained. The acquisition process of the quantization codebook included in the first segment is as follows: cluster the 100 sub-vectors included in the first segment to obtain 64 first cluster centers, and these 64 first cluster centers are the quantization codebooks included in the first segment. Each first cluster center includes one or more sub-vectors.
[0102] The process of obtaining the quantization codebook included in the second segment is as follows: clustering the 100 subvectors included in the second segment to obtain 64 second cluster centers, which are the quantization codebook included in the second segment. Each second cluster center includes one or more subvectors.
[0103] The process of obtaining the quantization codebook included in the third segment is as follows: clustering the 100 subvectors included in the third segment to obtain 64 third cluster centers, which are the quantization codebook included in the third segment. Each third cluster center includes one or more subvectors.
[0104] The process of obtaining the quantization codebook included in the fourth segment is as follows: cluster the 100 subvectors included in the fourth segment to obtain 64 fourth cluster centers, and the 64 fourth cluster centers are the quantization codebook included in the fourth segment, and each fourth cluster center includes one or more subvectors.
[0105] Among them, clustering can be performed using a K-means clustering algorithm (K-means clustering algorithm), and other clustering algorithms can also be used for clustering, which is not limited in the embodiments of the present application.
[0106] Optionally, since the quantization codebook needs to have the ability to describe the sample image, as the hash feature module is learned and optimized, the old quantization codebook may not be optimal for the current hash feature module. Therefore, the quantization codebook included in the quantization codebook module needs to be updated regularly. Each time the initial image retrieval model is trained, the quantization codebook included in the quantization codebook module is updated. The update process of the quantization codebook included in the quantization codebook module is shown in the above example and will not be repeated here.
[0107] It should be noted that when the initial image retrieval model is trained for the first round, since the quantization codebook does not have the representation capability yet, it is not necessary to learn the quantization codebook and the reconstruction error loss value and the reconstruction metric loss value. After the first round of learning, if the retrieval accuracy of the initial image retrieval model has not yet met the requirements, for example, the accuracy rate has not reached the reference value, the quantization codebook is updated in the second round of training, and the target loss value is learned based on the updated quantization codebook. At this time, the target loss value includes but is not limited to at least one of the reconstruction error loss value and the reconstruction metric loss value. Optionally, the target loss value may also include at least one of the triple loss value and the quantization loss value.
[0108] In step 202, a feature module is called to obtain a sample feature vector corresponding to a sample image.
[0109] In a possible implementation, the process of calling the feature module to obtain the sample feature vector corresponding to the sample image is: inputting the sample image into the feature module, and obtaining the sample feature vector corresponding to the sample image based on the output result of the feature module.
[0110] Exemplarily, the sample image is Image 1, and the sample feature vector corresponding to the sample image is (0.01, -10.1, 12.04, -1.02).
[0111] In step 203, a feature quantization module is called to obtain a sample quantization vector corresponding to the sample feature vector.
[0112] In a possible implementation, the process of calling the feature quantization module to obtain the sample quantization vector corresponding to the sample feature vector is as follows: for each dimension in the sample feature vector, in response to the value corresponding to the dimension being less than the target value, the value corresponding to the dimension is determined as a first value, in response to the value corresponding to the dimension being not less than the target value, the value corresponding to the dimension is determined as a second value, and the sample quantization vector corresponding to the sample feature vector is obtained according to the value corresponding to each dimension in the sample feature vector, wherein the first value is less than the second value.
[0113] Optionally, the feature quantization module obtains a sample quantization vector corresponding to the sample feature vector according to the following formula (1).
[0114]
[0115] In the above formula (1), b i is the value corresponding to the i-th dimension in the sample quantization vector corresponding to the sample feature vector, u i is the value corresponding to the i-th dimension in the sample feature vector, A is the first value, B is the second value, and n is the target value.
[0116] Exemplarily, taking the first value A as -1, the second value B as 1, and the target value as 0 as an example, the sample feature vector (0.01, -10.1, 12.04, -1.02) obtained in the above step 202 is obtained. The value corresponding to the first dimension in the sample feature vector is 0.01. Since the value corresponding to the first dimension is greater than 0, the value corresponding to the first dimension is determined to be 1. The value corresponding to the second dimension in the sample vector feature is -10.1. Since the value corresponding to the second dimension is less than 0, the value corresponding to the second dimension is determined to be -1. The value corresponding to the third dimension in the sample vector feature is 12.04. Since the value corresponding to the third dimension is greater than 0, the value corresponding to the third dimension is determined to be 1. The value corresponding to the fourth dimension in the sample vector feature is -1.02. Since the value corresponding to the fourth dimension is less than 0, the value corresponding to the fourth dimension is determined to be -1. Based on the values corresponding to each dimension, the sample quantization vector corresponding to the sample feature vector is determined to be (1, -1, 1, -1).
[0117] In step 204, a target loss value is determined based on the sample quantization vector and the quantization codebook.
[0118] In a possible implementation, the process of determining the target loss value based on the sample quantization vector and the quantization codebook is as follows: based on the sample quantization vector and the quantization codebook, a reference loss value is determined, the reference loss value includes at least one of a reconstruction error loss value and a reconstruction metric loss value. Based on the reference loss value and a weight corresponding to the reference loss value, a target loss value is determined.
[0119] Optionally, the reference loss value includes a reconstruction error loss value. In response to the reference loss value being a reconstruction error loss value, the process of determining the reconstruction error loss value based on the sample quantization vector and the quantization codebook is as follows: obtaining a reconstruction vector corresponding to the sample quantization vector based on the quantization codebook, and determining the reconstruction error loss value based on the reconstruction vector and the sample quantization vector.
[0120] In one possible implementation, the process of obtaining a reconstructed vector corresponding to a sample quantization vector based on a quantization codebook is as follows: segmenting the sample quantization vector to obtain multiple sub-vectors, each of which has the same dimension; based on the quantization codebook and the multiple sub-vectors, obtaining a quantization code corresponding to each sub-vector; and concatenating the quantization codes corresponding to each sub-vector to obtain a reconstructed vector corresponding to the sample quantization vector.
[0121] Optionally, based on the quantization codebook and multiple sub-vectors, a method for obtaining the quantization code corresponding to each sub-vector includes but is not limited to: based on the quantization codebook, obtaining multiple quantization codebooks corresponding to each segment; for any sub-vector, determining the distance between any sub-vector and multiple quantization codebooks corresponding to the segment where any sub-vector is located; and using the quantization codebook whose distance meets the requirements as the quantization code corresponding to any sub-vector.
[0122] Optionally, the distance is a Hamming distance, or may be a Euclidean distance, or may be other distances, which are not limited in the embodiments of the present application. The quantization codebook whose distance meets the requirement refers to the quantization codebook with the shortest distance.
[0123] Exemplarily, the sample quantization vector is divided into 4 segments, and the process of obtaining the quantization code of the sub-vector corresponding to the first segment of the sample quantization vector is as follows: obtain multiple quantization codebooks belonging to the first segment in the quantization codebook provided by the quantization codebook module; determine the distances between the sub-vector corresponding to the first segment of the sample quantization vector and the multiple quantization codebooks, and use the quantization codebook with the smallest distance as the quantization code of the sub-vector corresponding to the first segment of the sample quantization vector.
[0124] Optionally, after obtaining the quantization codes of the sub-vectors corresponding to each segment of the sample quantization vector, the quantization codes of the sub-vectors corresponding to each segment of the sample quantization vector are concatenated to obtain a reconstructed vector of the sample quantization vector.
[0125] Optionally, based on the reconstruction vector and the sample quantization vector, the process of determining the reconstruction error loss value is: taking the distance between the reconstruction vector and the sample quantization vector as the reconstruction error loss value.
[0126] The following formula (2) is a calculation formula for the reconstruction error loss value provided in an embodiment of the present application.
[0127]
[0128] In the above formula (2), L code-error is the reconstruction error loss value, To reconstruct the vector, x a is the sample quantization vector, C k is the quantization code corresponding to the Kth segmented subvector in the sample quantization vector, Z k is the weight value of the quantization code corresponding to the Kth segmented subvector in the sample quantization vector, Z k The value of is 1.
[0129] It should be noted that since the sample quantization vector is variable and the quantization codebook consists of only a limited number of codebooks, it is impossible to ensure that each reconstructed vector is completely consistent with the sample quantization vector. Therefore, it is only necessary to ensure that the quantization codebook reconstructs each segment of the sample quantization vector as much as possible.
[0130] Optionally, the reference loss value includes a reconstruction metric loss value. In response to the reference loss value being a reconstruction metric loss value, the process of determining the reconstruction metric loss value based on the sample quantization vector and the quantization codebook is as follows: obtaining a reconstruction vector corresponding to the sample quantization vector; obtaining a positive sample image and a negative sample image corresponding to the sample image; obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image; and determining the reconstruction metric loss value based on the reconstruction vector, the first quantization vector, and the second quantization vector.
[0131] Among them, the process of obtaining the reconstruction vector corresponding to the sample quantization vector can be seen in detail in the process of determining the reconstruction vector when the reference loss value is the reconstruction error loss value, which will not be repeated here. The process of obtaining the positive sample image and the negative sample image corresponding to the sample image; the process of obtaining the first quantization vector corresponding to the positive sample image and the second quantization vector corresponding to the negative sample image can be seen in detail in the process of determining the triplet loss value when the reference loss value also includes the triplet loss value, which will not be repeated here.
[0132] Optionally, based on the reconstruction vector, the first quantization vector and the second quantization vector, the process of determining the reconstruction metric loss value includes but is not limited to the following methods: determining the distance between the reconstruction vector and the first quantization vector to obtain a first distance; determining the distance between the reconstruction vector and the second quantization vector to obtain a second distance; determining the reconstruction metric loss value based on the first distance, the second distance and the first reference value.
[0133] Optionally, based on the first distance, the second distance and the first reference value, determining the reconstruction metric loss value includes but is not limited to the following methods: determining the difference between the first distance and the second distance; determining a first candidate value based on the difference between the first distance and the second distance; and taking the maximum value between the first candidate value and the first reference value as the reconstruction metric loss value.
[0134] The first distance and the second distance may be L1 norm distance, L2 norm distance, Euclidean distance or Hamming distance, which is not limited in the embodiment of the present application.
[0135] Optionally, the difference between the first distance and the second distance can be directly used as the first candidate value, and a first hyperparameter can be added on the basis of the difference between the first distance and the second distance to obtain the first candidate value. The embodiment of the present application does not limit the method for determining the first candidate value. The first hyperparameter can be an empirical value, or it can be adjusted in real time during the model training process, which is not limited in the embodiment of the present application.
[0136] It should be noted that the first reference value may be any value, which is not limited in the embodiments of the present application. Exemplarily, the first reference value is zero.
[0137] Taking the case where the first distance and the second distance are L2 norm distances and the first reference value is zero as an example, the following formula (3) is a calculation formula for a reconstruction metric loss value provided in an embodiment of the present application.
[0138] L code-triplet =max(‖R a -x p ‖-‖R a -x n ‖+β,0) (3)
[0139] In the above formula (6), R a To reconstruct the vector, x p is the first quantized vector, x n is the second quantization vector, and β is the first hyperparameter. ||R a -x p || is the first distance, ||R a -x n || is the second distance, and the value of β can be an empirical value, such as 15, or can be obtained based on other methods, such as adjusting the value of β in real time through model training.
[0140] Optionally, the reference loss value may also include a triplet loss value. In response to the reference loss value including the triplet loss value, the triplet loss value is determined as follows: a positive sample image corresponding to the sample image and a negative sample image corresponding to the sample image are obtained; a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image are obtained, and the triplet loss value is determined based on the sample quantization vector, the first quantization vector and the second quantization vector.
[0141] Optionally, the process of obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image includes but is not limited to the following methods: obtaining a first feature vector corresponding to the positive sample image and obtaining a second feature vector corresponding to the negative sample image; obtaining a first quantization vector corresponding to the first feature vector and obtaining a second quantization vector corresponding to the second feature vector.
[0142] It should be noted that the process of obtaining the first eigenvector corresponding to the positive sample image and the process of obtaining the second eigenvector corresponding to the negative sample image are consistent with the process of obtaining the sample eigenvector corresponding to the sample image, and will not be repeated here. The process of obtaining the first quantization vector corresponding to the first eigenvector and the process of obtaining the second quantization vector corresponding to the second eigenvector are consistent with the process of obtaining the sample quantization vector corresponding to the sample eigenvector, and will not be repeated here.
[0143] Optionally, the process of determining the triplet loss value based on the sample quantization vector, the first quantization vector and the second quantization vector includes but is not limited to the following methods: determining the distance between the sample quantization vector and the first quantization vector to obtain a third distance; determining the distance between the sample quantization vector and the second quantization vector to obtain a fourth distance; determining the triplet loss value based on the third distance, the fourth distance and the second reference value.
[0144] The third distance and the fourth distance may be L1 norm distance, L2 norm distance, Euclidean distance or Hamming distance, which is not limited in the embodiment of the present application.
[0145] Optionally, the process of obtaining a positive sample image corresponding to a sample image and a negative sample image corresponding to the sample image is as follows: since a plurality of positive sample pairs are stored in the electronic device, each positive sample pair includes two similar samples, the other sample image in the same positive sample pair as the sample image is used as the positive sample image. A sample is determined in each of the remaining plurality of positive sample pairs to obtain a plurality of candidate sample images, and the distances between the plurality of candidate sample images and the sample image are determined, and the candidate sample images whose distances meet the distance requirements are used as negative sample images.
[0146] Optionally, the process of determining the distances between the multiple candidate sample images and the sample image is as follows: based on the feature vector corresponding to each candidate sample image and the sample feature vector corresponding to the sample image, the distance between each candidate sample image and the sample image is determined. The distance may be the Euclidean distance, the Hamming distance, or other distances, which are not limited in the embodiments of the present application.
[0147] Wherein, when the distance is the Euclidean distance, the distance between each candidate sample image and the sample image is determined directly based on the feature vector corresponding to each candidate sample image and the sample feature vector corresponding to the sample image. The following formula (4) is a calculation formula for the distance between the candidate sample image I and the sample image provided in an embodiment of the present application.
[0148]
[0149] In the above formula (4), I1 is the value corresponding to the first dimension of the candidate sample image I, X1 is the value corresponding to the first dimension of the sample image, I2 is the value corresponding to the second dimension of the candidate sample image I, X2 is the value corresponding to the second dimension of the sample image, I N is the value corresponding to the Nth dimension of the candidate sample image I, X N is the value corresponding to the Nth dimension of the sample image.
[0150] Optionally, when the distance is a Hamming distance, a quantization vector of each candidate sample image is obtained based on a feature vector of each candidate sample image. A Hamming distance between each candidate sample image and the sample image is determined based on the quantization vector of each candidate sample image and the sample quantization vector of the sample image.
[0151] Among them, the quantized vector consists of two different numerical values, and the Hamming distance represents the number of different corresponding bits in two vectors of the same dimension.
[0152] Exemplarily, the quantization vector of the candidate sample image I is (0, 0, 0, 1), and the sample quantization vector of the sample image is (1, 1, 0, 1), then the Hamming distance between the candidate sample image I and the sample image is 2. The process of determining the Hamming distance between other candidate sample images and sample images is similar to that between the candidate sample image I and the sample image, and will not be repeated here.
[0153] Optionally, after obtaining the distances between the multiple candidate sample images and the sample image, the multiple candidate sample images are sorted in order of distance from small to large, and the sample images before the target position in the multiple candidate sample images can all be used as negative sample images corresponding to the sample image. The target position is any position, for example, the target position is the 21st position, that is, the first 20 candidate sample images can all be used as negative sample images.
[0154] Optionally, based on the third distance, the fourth distance and the second reference value, the process of determining the triplet loss value is: obtaining the difference between the third distance and the fourth distance, obtaining the second candidate value based on the difference between the third distance and the fourth distance, and taking the maximum value between the second candidate value and the second reference value as the triplet loss value.
[0155] Among them, the difference between the third distance and the fourth distance can be directly used as the second candidate value, and a second hyperparameter can be added on the basis of the difference between the third distance and the fourth distance to obtain the second candidate value. The embodiment of the present application does not limit the method for determining the second candidate value. The second hyperparameter can be an empirical value, or it can be adjusted in real time during the model training process, which is not limited in the embodiment of the present application.
[0156] It should be noted that the second reference value may be any value, which is not limited in the embodiments of the present application. Exemplarily, the second reference value is zero.
[0157] Taking the case where the third distance and the fourth distance are L2 norm distances and the second reference value is zero as an example, the following formula (5) is a calculation formula for a triplet loss value provided in an embodiment of the present application.
[0158] L triplet =max(||xa -x p ||-||x a -x n ||+α,0) (5)
[0159] In the above formula (3), L triplet is the triple loss value, x a is the sample quantization vector, x p is the first quantized vector, x n is the second quantized vector, ||x a -x p || is the third distance, ||x a -x n || is the fourth distance, α is the second hyperparameter, and the value of α can be an empirical value, such as 20, or can be obtained based on other methods, such as adjusting the value of α in real time through model training.
[0160] Optionally, the reference loss value may further include a quantization loss value. In response to the reference loss value including the quantization loss value, the quantization loss value is obtained as follows: the square difference between the numerical values corresponding to each dimension in the sample quantization vector and the sample feature vector is determined, and the sum of the square differences between the numerical values corresponding to each dimension is used as the quantization loss value.
[0161] The following formula (6) is a calculation formula for a quantitative loss value provided in an embodiment of the present application.
[0162]
[0163] In the above formula (6), n is the dimension of the sample feature vector, b i is the value of the i-th dimension in the sample quantization vector, u i is the value of the i-th dimension in the sample feature vector.
[0164] Optionally, in response to the reference loss value including a triplet loss value, a quantization loss value, a reconstruction error loss value, and a reconstruction metric loss value, a process of determining the target loss value based on the reference loss value and a weight corresponding to the reference loss value is as follows:
[0165] A target loss value is determined based on the triplet loss value, the quantization loss value, the reconstruction error loss value, the reconstruction metric loss value, the triplet loss weight, the quantization loss weight, the reconstruction error loss weight and the reconstruction metric loss weight.
[0166] Optionally, based on the triplet loss value, the quantization loss value, the reconstruction error loss value, the reconstruction metric loss value, the triplet loss weight, the quantization loss weight, the reconstruction error loss weight and the reconstruction metric loss weight, the target loss value is determined according to the following formula (7).
[0167] L total =w1*L triplet +w2*L quantization +w3*L code-error +w4*L code-triplet (7)
[0168] In the above formula (7), L total is the target loss value, L triplet is the triple loss value, L quantization To quantify the loss value, L code-error is the reconstruction error loss value, L code-triplet is the reconstruction metric loss value. w1 is the triplet loss weight, w2 is the quantization loss weight, w3 is the reconstruction error loss weight, and w4 is the reconstruction metric loss weight.
[0169] Among them, the triplet loss weight, quantization loss weight, reconstruction error loss weight and reconstruction metric loss weight can be manually set parameters, or can be adjusted based on the application scenario, which is not limited in the embodiments of the present application. For example, the triplet loss weight is 1, the quantization loss weight is 0.1, the reconstruction error loss weight is 0.01, and the reconstruction metric loss weight is 0.5.
[0170] In step 205, the initial image retrieval model is updated based on the target loss value to obtain a target image retrieval model.
[0171] In one possible implementation, after determining the target loss value, in response to the target loss value being not greater than the loss threshold, it is indicated that the initial image retrieval model has good retrieval capability, and the initial image retrieval model is directly used as the target image retrieval model. In response to the target loss value being greater than the loss threshold, the initial image retrieval model is updated according to the gradient descent algorithm to obtain an updated image retrieval model; based on the updated image retrieval model, an updated target loss value is obtained, and in response to the updated target loss value being not greater than the loss threshold, the updated image retrieval model is used as the target image retrieval model. In response to the updated target loss value still being greater than the loss threshold, the updated image retrieval model is updated again until the updated target loss value is not greater than the loss threshold, and the image retrieval model corresponding to the updated target loss value being not greater than the loss threshold is used as the target image retrieval model.
[0172] The process of updating the initial image retrieval model according to the gradient descent algorithm to obtain the updated image retrieval model is as follows: performing gradient backward calculation on the target loss value to obtain the updated value of the model parameter in the initial image retrieval model, and updating the initial image retrieval model based on the updated value of the model parameter to obtain the updated image retrieval model. Optionally, the gradient descent algorithm is a stochastic gradient descent algorithm.
[0173] Optionally, in response to the target loss value being greater than the loss threshold, the initial image retrieval model is updated according to the gradient descent algorithm. Before obtaining the updated image retrieval model, it is also necessary to determine whether there is a historical memory unit in the initial image retrieval model. If there is a historical memory unit, the historical memory unit is cleared. The historical memory unit is used to store a quantization codebook. After the historical memory unit is cleared, the quantization codebook included in the quantization codebook module is updated in the next training process, and the quantization codebook updated in the next training process is stored in the historical memory unit.
[0174] In the above method, the quantization codebook included in the quantization codebook module in the initial image retrieval model is updated as the initial image retrieval model is updated, so that the quantization codebook included in the quantization codebook module is constantly changing, thereby matching the quantization codebook included in the quantization codebook module with the current feature quantization module, thereby making the loss value obtained based on the quantization codebook and the quantization vector more accurate. The initial image retrieval model is updated using a loss value with higher accuracy, making the update process more accurate, thereby making the accuracy of the target image retrieval model obtained higher, and the retrieval accuracy when using the target image retrieval model for retrieval is higher.
[0175] Figure 4 FIG. 1 is a flowchart of an image retrieval method provided by an embodiment of the present application. The method can be executed by an electronic device, which can be Figure 1 The terminal 101 in Figure 1 The server 102 in the method comprises the following steps:
[0176] In step 401, a target image to be retrieved and a target image retrieval model are obtained.
[0177] Among them, the target image retrieval model is based on the above Figure 2 The embodiment shown is obtained.
[0178] In the exemplary embodiment of the present application, the target image may be an image uploaded by a user, an image randomly obtained from the storage space of an electronic device, an image obtained based on an image search engine, or an image obtained by other means. The embodiment of the present application does not limit the method of obtaining the target image. The category of the target image may be a person, an animal, or a plant. The embodiment of the present application does not limit the category of the target image.
[0179] Optionally, the acquisition process of the target image retrieval model is detailed in the above Figure 2 The embodiments shown will not be described in detail here.
[0180] In step 402, the target image is input into the target image retrieval model to obtain a quantization vector corresponding to the target image.
[0181] In a possible implementation, the target image retrieval model includes a feature module and a feature quantization module, wherein the feature module is used to obtain a feature vector of an image, and the feature quantization module is used to obtain a quantization vector corresponding to the feature vector.
[0182] Optionally, the process of inputting the target image into the target image retrieval model to obtain the quantization vector corresponding to the target image includes but is not limited to the following methods: inputting the target image into the feature module of the target image retrieval model to obtain the feature vector of the target image. Inputting the feature vector of the target image into the feature quantization module of the target image retrieval model to obtain the quantization vector of the target image.
[0183] The process of inputting the target image into the feature module of the target image retrieval model to obtain the feature vector of the target image is the same as the above Figure 2 The process of obtaining the sample feature vector corresponding to the sample image in the embodiment shown is similar and will not be repeated here. The process of inputting the feature vector of the target image into the feature quantization module of the target image retrieval model to obtain the quantization vector of the target image is the same as the above Figure 2 The process of obtaining the sample quantization vector corresponding to the sample feature vector in the illustrated embodiment is similar and will not be described in detail here.
[0184] In step 403, an image retrieval result is obtained based on a quantization vector corresponding to the target image and a quantization codebook in the target image retrieval model.
[0185] In a possible implementation, the target image retrieval model further includes a quantization codebook module, which is used to provide a quantization codebook. The process of obtaining the image retrieval result based on the quantization vector corresponding to the target image and the quantization codebook in the target image retrieval model is:
[0186] Segment the quantization vector corresponding to the target image to obtain C sub-vectors. Based on the quantization codebook and the C sub-vectors, obtain the quantization codebook with the closest distance to each sub-vector to obtain C quantization codebooks. Recall all sample images under the C quantization codebooks. Obtain the intersection of all sample images under the C quantization codebooks to obtain D sample images. Determine the distance between the D sample images and the target image respectively, and use the sample images whose distances meet certain requirements as image retrieval results.
[0187] The method of determining the distances between the D sample images and the target image includes but is not limited to: determining the distances between the quantized vectors of the D sample images and the quantized vector of the target image. The distance may be a Euclidean distance or a Hamming distance, which is not limited in the present embodiment.
[0188] Optionally, the union of all sample images under C quantization codebooks may be obtained to obtain E sample images, the distances between the E sample images and the target image are determined, and the sample images whose distances meet certain requirements are used as image retrieval results.
[0189] Among them, C, D, and E are all positive integers, and the value of E is greater than the value of D.
[0190] It should be noted that the sample images whose distances meet certain requirements are sorted from small to large according to the distances, and the sample images ranked in the top target digits are used as the image retrieval results. For example, the sample images ranked in the top 10 are used as the image retrieval results, and the image retrieval results include 10 sample images.
[0191] In the above method, since the target image retrieval model is obtained by training the initial image retrieval model, and the quantization codebook included in the quantization codebook module in the initial image retrieval model is updated as the initial image retrieval model is updated, the quantization codebook included in the quantization codebook module is constantly changing, thereby matching the quantization codebook included in the quantization codebook module with the current feature quantization module, thereby making the loss value obtained based on the quantization codebook and the quantization vector more accurate. Using a more accurate loss value to update the initial image retrieval model makes the update process more accurate, thereby making the accuracy of the target image retrieval model obtained higher, and the retrieval accuracy when using the target image retrieval model for retrieval is higher.
[0192] Figure 5 The figure shows a framework diagram for determining a target loss value provided by an embodiment of the present application. Figure 5 In , the sample image is input into the feature module to obtain the feature vector of the sample image. The feature vector of the sample image is input into the feature quantization module to obtain the quantization vector corresponding to the feature vector. The triplet loss value and the quantization loss value are obtained based on the quantization vector. The quantization codebook module is used to provide a quantization codebook. As the target loss value updates the model, the quantization codebook in the quantization codebook module is also updated. Based on the quantization vector and the quantization codebook module, the vector of the sample image is reconstructed to obtain a reconstructed vector. The reconstruction error loss value and the reconstruction metric loss value are determined based on the reconstruction vector. The target loss value is determined based on the triplet loss value, the quantization loss value, the reconstruction metric loss value and the reconstruction error loss value.
[0193] Figure 6 FIG. 1 is a schematic diagram of a structure of a device for obtaining an image retrieval model provided in an embodiment of the present application. Figure 6 As shown, the device comprises:
[0194] An acquisition module 601 is used to acquire a sample image and an initial image retrieval model. The initial image retrieval model includes a feature module, a feature quantization module and a quantization codebook module. The feature module is used to acquire a feature vector corresponding to the sample image. The feature quantization module is used to acquire a quantization vector corresponding to the feature vector. The quantization codebook module is used to provide a quantization codebook. The quantization codebook is updated as the initial image retrieval model is updated.
[0195] An acquisition module 601 is used to call a feature module to acquire a sample feature vector corresponding to a sample image;
[0196] An acquisition module 601 is used to call a feature quantization module to acquire a sample quantization vector corresponding to a sample feature vector;
[0197] A determination module 602, configured to determine a target loss value based on a sample quantization vector and a quantization codebook;
[0198] The updating module 603 is used to update the initial image retrieval model based on the target loss value to obtain a target image retrieval model.
[0199] In a possible implementation, the determination module 602 is configured to determine a reference loss value based on the sample quantization vector and the quantization codebook, where the reference loss value includes at least one of a reconstruction error loss value and a reconstruction metric loss value;
[0200] Based on the reference loss value and the weight corresponding to the reference loss value, a target loss value is determined.
[0201] In one possible implementation, the reference loss value includes a reconstruction error loss value;
[0202] A determination module 602 is used to obtain a reconstruction vector corresponding to a sample quantization vector based on a quantization codebook;
[0203] Based on the reconstruction vector and the sample quantization vector, a reconstruction error loss value is determined.
[0204] In a possible implementation, the determination module 602 is configured to segment the sample quantization vector to obtain a plurality of sub-vectors, each of which has the same dimension;
[0205] Obtaining a quantization code corresponding to each subvector based on a quantization codebook and a plurality of subvectors;
[0206] The quantization codes corresponding to each sub-vector are concatenated to obtain a reconstructed vector corresponding to the sample quantization vector.
[0207] In a possible implementation, the determination module 602 is configured to obtain multiple quantization codebooks corresponding to each segment based on the quantization codebook;
[0208] For any sub-vector, the distance between any sub-vector and multiple quantization codebooks corresponding to the segment where any sub-vector is located is determined, and the quantization codebook whose distance meets the requirement is used as the quantization code corresponding to any sub-vector.
[0209] In a possible implementation, the determination module 602 is configured to use the distance between the reconstruction vector and the sample quantization vector as a reconstruction error loss value.
[0210] In one possible implementation, the reference loss value includes a reconstruction metric loss value;
[0211] A determination module 602 is used to obtain a reconstruction vector corresponding to the sample quantization vector;
[0212] Obtain the positive sample image and the negative sample image corresponding to the sample image;
[0213] Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image;
[0214] A reconstruction metric loss value is determined based on the reconstruction vector, the first quantization vector, and the second quantization vector.
[0215] In a possible implementation, the determination module 602 is configured to determine a distance between the reconstructed vector and the first quantized vector to obtain a first distance;
[0216] Determine the distance between the reconstructed vector and the second quantized vector to obtain a second distance;
[0217] A reconstruction metric loss value is determined based on the first distance, the second distance, and the first reference value.
[0218] In a possible implementation, the determination module 602 is configured to determine a difference between the first distance and the second distance;
[0219] Determine a first candidate value based on a difference between the first distance and the second distance;
[0220] The maximum value between the first candidate value and the first reference value is used as the reconstruction metric loss value.
[0221] In a possible implementation, the reference loss value also includes a triplet loss value;
[0222] A determination module 602 is used to obtain a positive sample image and a negative sample image corresponding to the sample image;
[0223] Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image;
[0224] Determine the distance between the sample quantization vector and the first quantization vector to obtain a third distance;
[0225] Determine the distance between the sample quantization vector and the second quantization vector to obtain a fourth distance;
[0226] Based on the third distance, the fourth distance and the second reference value, a triplet loss value is determined.
[0227] In a possible implementation, the reference loss value also includes a quantized loss value;
[0228] A determination module 602 is used to determine the square difference between the values corresponding to each dimension in the sample quantization vector and the sample feature vector;
[0229] The sum of the squared differences between the values corresponding to each dimension is taken as the quantization loss value.
[0230] In a possible implementation, the updating module 603 is used to update the initial image retrieval model according to the gradient descent algorithm in response to the target loss value being greater than the loss threshold, to obtain an updated image retrieval model;
[0231] Based on the updated image retrieval model, obtain the updated target loss value;
[0232] In response to the target loss value after updating being not greater than the loss threshold, the updated image retrieval model is used as the target image retrieval model.
[0233] In a possible implementation, the acquisition module 601 is configured to, for each dimension in the sample feature vector, determine the value corresponding to the dimension as a first value in response to the value corresponding to the dimension being less than a target value, or determine the value corresponding to the dimension as a second value in response to the value corresponding to the dimension being not less than the target value;
[0234] A sample quantization vector corresponding to the sample feature vector is obtained according to the numerical value corresponding to each dimension in the sample feature vector, and the first numerical value is smaller than the second numerical value.
[0235] The quantization codebook included in the quantization codebook module in the initial image retrieval model of the above-mentioned device is updated as the initial image retrieval model is updated, so that the quantization codebook included in the quantization codebook module is constantly changing, thereby making the quantization codebook included in the quantization codebook module match the current feature quantization module, so that the loss value obtained based on the quantization codebook and the quantization vector is more accurate. The initial image retrieval model is updated using a loss value with higher accuracy, so that the update process is more accurate, thereby making the accuracy of the target image retrieval model obtained higher, and the retrieval accuracy when using the target image retrieval model for retrieval is higher.
[0236] Figure 7FIG. 1 is a schematic diagram of the structure of an image retrieval device provided in an embodiment of the present application. Figure 7 As shown, the device comprises:
[0237] The acquisition module 701 is used to acquire the target image to be retrieved and the target image retrieval model. The target image retrieval model is as described above. Figure 6 The device shown is obtained;
[0238] A determination module 702 is used to input the target image into a target image retrieval model to obtain a quantization vector corresponding to the target image;
[0239] The acquisition module 701 is used to acquire the image retrieval result based on the quantization vector corresponding to the target image and the quantization codebook in the target image retrieval model.
[0240] In the above device, since the target image retrieval model is obtained by training the initial image retrieval model, and the quantization codebook included in the quantization codebook module in the initial image retrieval model is updated as the initial image retrieval model is updated, the quantization codebook included in the quantization codebook module is constantly changing, thereby matching the quantization codebook included in the quantization codebook module with the current feature quantization module, thereby making the loss value obtained based on the quantization codebook and the quantization vector more accurate. Using a more accurate loss value to update the initial image retrieval model makes the update process more accurate, thereby making the accuracy of the target image retrieval model obtained higher, and the retrieval accuracy when using the target image retrieval model for retrieval is higher.
[0241] It should be understood that the above Figure 6 or Figure 7 When the device provided realizes its functions, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0242] Figure 8 A structural block diagram of a terminal 800 provided by an exemplary embodiment of the present application is shown.
[0243] Typically, the terminal 800 includes a processor 801 and a memory 802 .
[0244] The processor 801 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 801 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 801 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 801 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 801 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0245] The memory 802 may include one or more computer-readable storage media, which may be non-transitory. The memory 802 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 802 is used to store at least one instruction, which is executed by the processor 801 to implement the present application. Figure 2 The method for obtaining an image retrieval model provided by the method embodiment shown, or implementing the method in this application Figure 4 The method embodiment shown provides an image retrieval method.
[0246] In some embodiments, the terminal 800 may further optionally include: a peripheral device interface 803 and at least one peripheral device. The processor 801, the memory 802 and the peripheral device interface 803 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 803 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 804, a display screen 805, a camera assembly 806, an audio circuit 807 and a power supply 809.
[0247] The peripheral device interface 803 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 801 and the memory 802. In some embodiments, the processor 801, the memory 802, and the peripheral device interface 803 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 801, the memory 802, and the peripheral device interface 803 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0248] The radio frequency circuit 804 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 804 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 804 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 804 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 804 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 804 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.
[0249] The display screen 805 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 805 is a touch display screen, the display screen 805 also has the ability to collect touch signals on the surface or above the surface of the display screen 805. The touch signal can be input to the processor 801 as a control signal for processing. At this time, the display screen 805 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 805 can be one, set on the front panel of the terminal 800; in other embodiments, the display screen 805 can be at least two, respectively set on different surfaces of the terminal 800 or in a folding design; in other embodiments, the display screen 805 can be a flexible display screen, set on the curved surface or folding surface of the terminal 800. Even, the display screen 805 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 805 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode, organic light-emitting diode).
[0250] The camera assembly 806 is used to capture images or videos. Optionally, the camera assembly 806 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal 800, and the rear camera is arranged on the back of the terminal 800. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 806 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0251] The audio circuit 807 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 801 for processing, or input them into the radio frequency circuit 804 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal 800. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 801 or the radio frequency circuit 804 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 807 may also include a headphone jack.
[0252] The power supply 809 is used to power various components in the terminal 800. The power supply 809 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 809 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery charged through a wired line, and a wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0253] In some embodiments, the terminal 800 further includes one or more sensors 810 , including but not limited to: an acceleration sensor 811 , a gyroscope sensor 812 , a pressure sensor 813 , an optical sensor 815 , and a proximity sensor 816 .
[0254] The acceleration sensor 811 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal 800. For example, the acceleration sensor 811 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 801 can control the display screen 805 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 811. The acceleration sensor 811 can also be used to collect game or user motion data.
[0255] The gyroscope sensor 812 can detect the body direction and rotation angle of the terminal 800, and the gyroscope sensor 812 can cooperate with the acceleration sensor 811 to collect the user's 3D actions on the terminal 800. The processor 801 can implement the following functions based on the data collected by the gyroscope sensor 812: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0256] The pressure sensor 813 can be set on the side frame of the terminal 800 and / or the lower layer of the display screen 805. When the pressure sensor 813 is set on the side frame of the terminal 800, it can detect the user's holding signal of the terminal 800, and the processor 801 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 813. When the pressure sensor 813 is set on the lower layer of the display screen 805, the processor 801 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 805. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0257] The optical sensor 815 is used to collect the ambient light intensity. In one embodiment, the processor 801 can control the display brightness of the display screen 805 according to the ambient light intensity collected by the optical sensor 815. Specifically, when the ambient light intensity is high, the display brightness of the display screen 805 is increased; when the ambient light intensity is low, the display brightness of the display screen 805 is reduced. In another embodiment, the processor 801 can also dynamically adjust the shooting parameters of the camera assembly 806 according to the ambient light intensity collected by the optical sensor 815.
[0258] The proximity sensor 816, also called a distance sensor, is usually disposed on the front panel of the terminal 800. The proximity sensor 816 is used to collect the distance between the user and the front of the terminal 800. In one embodiment, when the proximity sensor 816 detects that the distance between the user and the front of the terminal 800 is gradually decreasing, the processor 801 controls the display screen 805 to switch from the screen-on state to the screen-off state; when the proximity sensor 816 detects that the distance between the user and the front of the terminal 800 is gradually increasing, the processor 801 controls the display screen 805 to switch from the screen-off state to the screen-on state.
[0259] Those skilled in the art will understand that Figure 8 The structure shown in the figure does not constitute a limitation on the terminal 800, and the terminal 800 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0260] Fig. 9 The schematic diagram of the structure of the server provided in the embodiment of the present application, the server 900 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 901 and one or more memories 902, wherein the one or more memories 902 store at least one program code, and the at least one program code is loaded and executed by the one or more processors 901 to implement the present application. Figure 2 The method for obtaining an image retrieval model provided by the method embodiment shown, or implementing the method in this application Figure 4 The image retrieval method provided by the method embodiment shown. Of course, the server 900 may also have components such as a wired or wireless network interface, a keyboard, and an input / output interface for input and output, and the server 900 may also include other components for realizing device functions, which will not be described in detail here.
[0261] In an exemplary embodiment, a computer-readable storage medium is also provided, wherein at least one program code is stored in the storage medium, and the at least one program code is loaded and executed by a processor to enable a computer to implement the above Figure 2 The method for obtaining the image retrieval model provided by the method embodiment shown in the figure, or implementing the above Figure 4 The method embodiment shown provides an image retrieval method.
[0262] Optionally, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0263] In an exemplary embodiment, a computer program or a computer program product is also provided, wherein at least one computer instruction is stored in the computer program or the computer program product, and the at least one computer instruction is loaded and executed by a processor to enable a computer to implement the above Figure 2 The method for obtaining the image retrieval model provided by the method embodiment shown in the figure, or implementing the above Figure 4 The method embodiment shown provides an image retrieval method.
[0264] It should be understood that the "plurality" mentioned in this article refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0265] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0266] The above description is only an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for obtaining an image retrieval model, characterized in that: The method comprises: Acquire a sample image and an initial image retrieval model, wherein the initial image retrieval model includes a feature module, a feature quantization module, and a quantization codebook module, wherein the feature module is used to acquire a feature vector corresponding to the sample image, the feature quantization module is used to acquire a quantization vector corresponding to the feature vector, and the quantization codebook module is used to provide a quantization codebook, wherein the quantization codebook is updated as the initial image retrieval model is updated; Calling the feature module to obtain a sample feature vector corresponding to the sample image; Calling the feature quantization module to obtain a sample quantization vector corresponding to the sample feature vector; Based on the sample quantization vector and the quantization codebook, a reference loss value is determined, the reference loss value includes at least one of a reconstruction error loss value and a reconstruction metric loss value, the reconstruction error loss value is determined based on a reconstruction vector and the sample quantization vector, the reconstruction vector is determined based on quantization codes corresponding to a plurality of subvectors obtained by segmenting the sample quantization vector, and the quantization code corresponding to any subvector is determined based on the any subvector and the quantization codebook; the reconstruction metric loss value is determined based on a first candidate value, the first candidate value is determined based on a first distance and a second distance, the first distance being the distance between the reconstruction vector and a first quantization vector of a positive sample image corresponding to the sample image, and the second distance being the distance between the reconstruction vector and a second quantization vector of a negative sample image corresponding to the sample image; Determining a target loss value based on the reference loss value and a weight corresponding to the reference loss value; The initial image retrieval model is updated based on the target loss value to obtain a target image retrieval model.
2. The method according to claim 1, characterized in that The reference loss value includes a reconstruction error loss value; The determining a reference loss value based on the sample quantization vector and the quantization codebook includes: Segmenting the sample quantization vector to obtain a plurality of sub-vectors, each of which has the same dimension; Acquire a quantization code corresponding to each subvector based on the quantization codebook and the multiple subvectors; splicing the quantization codes corresponding to each of the sub-vectors to obtain a reconstructed vector corresponding to the sample quantization vector; The reconstruction error loss value is determined based on the reconstruction vector and the sample quantization vector.
3. The method according to claim 2, characterized in that The obtaining, based on the quantization codebook and the multiple subvectors, a quantization code corresponding to each subvector includes: Acquire multiple quantization codebooks corresponding to each segment based on the quantization codebook; For any sub-vector, the distance between the sub-vector and a plurality of quantization codebooks corresponding to the segment where the sub-vector is located is determined, and the quantization codebook whose distance meets the requirement is used as the quantization code corresponding to the sub-vector.
4. The method according to claim 2, characterized in that: The determining the reconstruction error loss value based on the reconstruction vector and the sample quantization vector comprises: The distance between the reconstruction vector and the sample quantization vector is used as the reconstruction error loss value.
5. The method according to claim 1, characterized in that The reference loss value includes a reconstruction metric loss value; The determining a reference loss value based on the sample quantization vector and the quantization codebook includes: Segmenting the sample quantization vector to obtain a plurality of sub-vectors, each of which has the same dimension; Acquire a quantization code corresponding to each subvector based on the quantization codebook and the multiple subvectors; splicing the quantization codes corresponding to each of the sub-vectors to obtain a reconstructed vector corresponding to the sample quantization vector; Obtaining a positive sample image and a negative sample image corresponding to the sample image; Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image; Determine a distance between the reconstructed vector and the first quantized vector to obtain a first distance; Determine a distance between the reconstructed vector and the second quantized vector to obtain a second distance; determining a difference between the first distance and the second distance; Determine a first candidate value based on a difference between the first distance and the second distance; The maximum value between the first candidate value and the first reference value is used as the reconstruction metric loss value.
6. The method according to claim 1, characterized in that The reference loss value also includes a triplet loss value; The determining a reference loss value based on the sample quantization vector and the quantization codebook includes: Obtaining a positive sample image and a negative sample image corresponding to the sample image; Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image; Determine a distance between the sample quantization vector and the first quantization vector to obtain a third distance; Determine a distance between the sample quantization vector and the second quantization vector to obtain a fourth distance; Obtaining a difference between the third distance and the fourth distance; Acquire a second candidate value based on a difference between the third distance and the fourth distance; The maximum value between the second candidate value and the second reference value is used as the triplet loss value.
7. The method according to claim 1, characterized in that The reference loss value also includes a quantized loss value; The determining a reference loss value based on the sample quantization vector and the quantization codebook includes: Determine the square of the difference between the numerical values corresponding to each dimension in the sample quantization vector and the sample feature vector; The sum of the squares of the differences between the values corresponding to each dimension is used as the quantization loss value.
8. The method according to any one of claims 1 to 7, characterized in that: The updating of the initial image retrieval model based on the target loss value to obtain a target image retrieval model includes: In response to the target loss value being greater than a loss threshold, updating the initial image retrieval model according to a gradient descent algorithm to obtain an updated image retrieval model; Based on the updated image retrieval model, obtaining an updated target loss value; In response to the target loss value after the update being not greater than the loss threshold, the updated image retrieval model is used as the target image retrieval model.
9. The method according to any one of claims 1 to 7, characterized in that: The calling the feature quantization module to obtain the sample quantization vector corresponding to the sample feature vector includes: For each dimension in the sample feature vector, in response to a value corresponding to the dimension being less than a target value, determining the value corresponding to the dimension as a first value, or, in response to a value corresponding to the dimension being not less than the target value, determining the value corresponding to the dimension as a second value; A sample quantization vector corresponding to the sample feature vector is obtained according to a numerical value corresponding to each dimension in the sample feature vector, wherein the first numerical value is smaller than the second numerical value.
10. An image retrieval method, characterized in that: The method comprises: Obtain a target image to be retrieved and a target image retrieval model, wherein the target image retrieval model is obtained by any method as claimed in claims 1 to 9; Inputting the target image into the target image retrieval model to obtain a quantization vector corresponding to the target image; An image retrieval result is obtained based on a quantization vector corresponding to the target image and a quantization codebook in the target image retrieval model.
11. A device for obtaining an image retrieval model, characterized in that: The device comprises: An acquisition module, used to acquire a sample image and an initial image retrieval model, wherein the initial image retrieval model includes a feature module, a feature quantization module and a quantization codebook module, wherein the feature module is used to acquire a feature vector corresponding to the sample image, the feature quantization module is used to acquire a quantization vector corresponding to the feature vector, and the quantization codebook module is used to provide a quantization codebook, which is updated as the initial image retrieval model is updated; The acquisition module is used to call the feature module to acquire the sample feature vector corresponding to the sample image; The acquisition module is used to call the feature quantization module to obtain the sample quantization vector corresponding to the sample feature vector; A determination module, configured to determine a reference loss value based on the sample quantization vector and the quantization codebook, wherein the reference loss value includes at least one of a reconstruction error loss value and a reconstruction metric loss value, wherein the reconstruction error loss value is determined based on a reconstruction vector and the sample quantization vector, wherein the reconstruction vector is determined based on quantization codes corresponding to a plurality of subvectors obtained by segmenting the sample quantization vector, and the quantization code corresponding to any subvector is determined based on the any subvector and the quantization codebook; wherein the reconstruction metric loss value is determined based on a first candidate value, wherein the first candidate value is determined based on a first distance and a second distance, wherein the first distance is the distance between the reconstruction vector and a first quantization vector of a positive sample image corresponding to the sample image, and the second distance is the distance between the reconstruction vector and a second quantization vector of a negative sample image corresponding to the sample image; wherein a target loss value is determined based on the reference loss value and a weight corresponding to the reference loss value; An updating module is used to update the initial image retrieval model based on the target loss value to obtain a target image retrieval model.
12. The device according to claim 11, characterized in that The reference loss value includes a reconstruction error loss value; The determination module is used to segment the sample quantization vector to obtain multiple sub-vectors, each sub-vector having the same dimension; Acquire a quantization code corresponding to each subvector based on the quantization codebook and the multiple subvectors; splicing the quantization codes corresponding to each of the sub-vectors to obtain a reconstructed vector corresponding to the sample quantization vector; The reconstruction error loss value is determined based on the reconstruction vector and the sample quantization vector.
13. The device according to claim 12, characterized in that The determining module is used to obtain multiple quantization codebooks corresponding to each segment based on the quantization codebook; For any sub-vector, the distance between the sub-vector and a plurality of quantization codebooks corresponding to the segment where the sub-vector is located is determined, and the quantization codebook whose distance meets the requirement is used as the quantization code corresponding to the sub-vector.
14. The device according to claim 12, characterized in that The determination module is used to use the distance between the reconstruction vector and the sample quantization vector as the reconstruction error loss value.
15. The device according to claim 11, characterized in that The reference loss value includes a reconstruction metric loss value; The determination module is used to segment the sample quantization vector to obtain multiple sub-vectors, each sub-vector having the same dimension; Acquire a quantization code corresponding to each subvector based on the quantization codebook and the multiple subvectors; splicing the quantization codes corresponding to each of the sub-vectors to obtain a reconstructed vector corresponding to the sample quantization vector; Obtaining a positive sample image and a negative sample image corresponding to the sample image; Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image; Determine a distance between the reconstructed vector and the first quantized vector to obtain a first distance; Determine a distance between the reconstructed vector and the second quantized vector to obtain a second distance; determining a difference between the first distance and the second distance; Determine a first candidate value based on a difference between the first distance and the second distance; The maximum value between the first candidate value and the first reference value is used as the reconstruction metric loss value.
16. The device according to claim 11, characterized in that The reference loss value also includes a triplet loss value; The determination module is used to obtain a positive sample image and a negative sample image corresponding to the sample image; Obtaining a first quantization vector corresponding to the positive sample image and a second quantization vector corresponding to the negative sample image; Determine a distance between the sample quantization vector and the first quantization vector to obtain a third distance; Determine a distance between the sample quantization vector and the second quantization vector to obtain a fourth distance; Obtaining a difference between the third distance and the fourth distance; Acquire a second candidate value based on a difference between the third distance and the fourth distance; The maximum value between the second candidate value and the second reference value is used as the triplet loss value.
17. The device according to claim 11, characterized in that The reference loss value also includes a quantized loss value; The determination module is used to determine the square difference between the numerical values corresponding to each dimension in the sample quantization vector and the sample feature vector; The sum of the squares of the differences between the values corresponding to each dimension is used as the quantization loss value.
18. The device according to any one of claims 11 to 17, characterized in that The updating module is used for updating the initial image retrieval model according to a gradient descent algorithm in response to the target loss value being greater than a loss threshold, so as to obtain an updated image retrieval model; Based on the updated image retrieval model, obtaining an updated target loss value; In response to the target loss value after the update being not greater than the loss threshold, the updated image retrieval model is used as the target image retrieval model.
19. The device according to any one of claims 11 to 17, characterized in that The acquisition module is configured to, for each dimension in the sample feature vector, determine the value corresponding to the dimension as a first value in response to the value corresponding to the dimension being less than a target value, or determine the value corresponding to the dimension as a second value in response to the value corresponding to the dimension being not less than the target value; A sample quantization vector corresponding to the sample feature vector is obtained according to a numerical value corresponding to each dimension in the sample feature vector, wherein the first numerical value is smaller than the second numerical value.
20. An image retrieval device, characterized in that: The device comprises: An acquisition module, used for acquiring a target image to be retrieved and a target image retrieval model, wherein the target image retrieval model is obtained by the device according to any one of claims 11 to 19; A determination module, used for inputting the target image into the target image retrieval model to obtain a quantization vector corresponding to the target image; The acquisition module is used to acquire the image retrieval result based on the quantization vector corresponding to the target image and the quantization codebook in the target image retrieval model.
21. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor so that the electronic device implements the method for obtaining an image retrieval model as described in any one of claims 1 to 9, or implements the image retrieval method as described in claim 10.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program code, and the at least one program code is loaded and executed by a processor to enable the computer to implement the method for obtaining an image retrieval model as described in any one of claims 1 to 9, or to enable the computer to implement the image retrieval method as described in claim 10.
23. A computer program product, characterized in that The computer program product stores at least one computer instruction, and the at least one computer instruction is loaded and executed by a processor to enable the computer to implement the method for obtaining an image retrieval model as described in any one of claims 1 to 9, or to enable the computer to implement the image retrieval method as described in claim 10.
Citation Information
Patent Citations
Data retrieval method based on Hash learning of dimension analysis quantizer
CN112241475A