Image retrieval method based on reinforcement learning
By automatically optimizing the ball tree index parameters through reinforcement learning, the problem of insufficient parameter settings in existing technologies is solved, improving the efficiency and accuracy of image retrieval, adapting to different datasets and query characteristics, and reducing resource overhead.
Patent Information
- Application Number
- CN202410347637.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-25
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-03-25
AI Technical Summary
Existing methods for optimizing ball tree index parameters rely on empirical settings or greedy approaches, which fail to fully utilize the characteristics of specific datasets, resulting in insufficient query efficiency and accuracy for image retrieval, especially performing poorly on large-scale and complex datasets.
A reinforcement learning-based approach is used to automatically optimize the parameters of the ball tree index. By constructing a real nearest neighbor distribution estimation model and using the Q-learning algorithm, the branching factor and leaf node size are dynamically adjusted to improve query latency and precision.
It achieves more efficient query performance in image retrieval, reduces resource overhead, and adapts to different datasets and query characteristics, thereby improving the efficiency and accuracy of image retrieval.
Smart Images

Figure CN118245625B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image retrieval technology, and more specifically, relates to an image retrieval method based on reinforcement learning. Background Technology
[0002] Approximate Nearest Neighbor Search (ANNS) is an important technique in computer science, especially when dealing with large-scale datasets. Its goal is to quickly find the element in the dataset that is most similar to a given query. ANNs have wide applications in various fields, including image retrieval, recommender systems, and machine learning.
[0003] To efficiently execute the ANNS algorithm, an index structure is typically needed to organize the data. The design of the index structure is crucial to the efficiency and accuracy of queries. Common index structures include KD-trees, R-trees, and ball trees. A ball tree index is a particularly suitable index structure for high-dimensional data. It organizes data by grouping data points into multiple nested hyperspheres. The key advantage of ball trees is their ability to adapt to the inherent dimensional structure of the data, thus enabling efficient searching in high-dimensional space. Although ball trees are an efficient index structure, their performance is highly dependent on the settings of several parameters, such as tree depth, branching factor, and leaf node size. The optimal values of these parameters often depend on the specific dataset and query characteristics; therefore, finding the best parameter configuration is a challenge.
[0004] Currently, the optimization of ball tree index parameters mainly relies on empirical settings or simple greedy methods. These methods may fail to fully utilize the characteristics of specific datasets, resulting in slightly lower query efficiency and accuracy. Furthermore, in fields such as image retrieval, as the size and complexity of datasets increase, traditional parameter optimization methods are becoming increasingly inadequate. Therefore, further research is needed on how to automatically optimize these parameters using more intelligent methods to adapt to different data and query needs. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide an image retrieval method based on reinforcement learning. This method utilizes reinforcement learning to automatically optimize the parameters of the ball tree index and applies the optimized ball tree index to the field of approximate image retrieval, thereby improving the performance of image retrieval.
[0006] To achieve the above-mentioned objectives, the image retrieval method based on reinforcement learning of the present invention includes the following steps:
[0007] S1: Collect N images according to actual needs to obtain image set A;
[0008] S2: Construct a true nearest neighbor distribution estimation model according to actual needs. The input is a parameter vector (B,L,K) consisting of the ball tree index distribution factor B, leaf node size L, and the number of query neighbors K. The output is a W-dimensional distribution vector. Each dimension of the distribution vector corresponds to a leaf partition, and the corresponding element value represents the proportion of finding K true nearest neighbors in the corresponding partition.
[0009] The ranges of values for distribution factor B, leaf node size L, and the number of nearest neighbors K are determined respectively. Several parameter vectors are obtained by randomly selecting values. A spherical index is constructed for image set A based on the distribution factor and leaf node size in each parameter vector. Then, the corresponding distribution vector is obtained to obtain the training sample. The training sample is used to train the real nearest neighbor distribution estimation model to obtain the trained real nearest neighbor distribution estimation model.
[0010] S3: Reinforcement learning is used to determine the distribution factor B and leaf node size L of the ball tree index. The parameter settings in reinforcement learning are as follows:
[0011] Set status s t = (B t ,L t ,ΔT t-1 ,P t-1 ), where t represents time, B t L represents the distribution factor at time t. t ΔT represents the size of the leaf node at time t. t-1 P represents the query delay at time t-1. t-1 The precision is expressed at time t-1.
[0012] Set action a t =(ΔB) t ,ΔL t ), ΔB t Let B represent the adjustment amount of the distribution factor at time t, and B t+1 =B t +ΔB t ∈[B min B max ], B t+1 B represents the distribution factor at time t+1. min B max ΔL represents the minimum and maximum values of the distribution factor. t L represents the leaf node size adjustment at time t, and L t+1 =L t +ΔL t ∈[L min ,L max ], L t+1 L represents the size of the leaf node at time t+1. min L maxThis represents the minimum and maximum values of the leaf node size;
[0013] The reward function is calculated as follows:
[0014] The query latency ΔT is calculated using the following formula. t :
[0015]
[0016] Where λ represents a preset constant;
[0017] Then the current parameter vector (B) t +ΔB t ,L t +ΔL t K) Input the trained real nearest neighbor distribution estimation model to obtain a W-dimensional distribution vector, and calculate the precision P using the following formula. t :
[0018] P t =log(W)-H
[0019] Where H represents the entropy of the distribution vector, and its calculation formula is:
[0020]
[0021] Where, p w This represents the value of the w-th element in the distribution vector, which is the proportion of the w-th leaf node that finds K true nearest neighbors within its partition.
[0022] Then, the current reward function R is calculated using the following formula. t :
[0023] R t =ΔT t +P t
[0024] S4: Construct a spherical tree index for image set A based on the distribution factor and leaf node size determined in step S3;
[0025] S5: The constructed ball tree index is used to search the image to be retrieved, and the search results are composed of the K images with the highest similarity.
[0026] This invention relates to an image retrieval method based on reinforcement learning. It constructs and trains a true nearest neighbor distribution estimation model for measuring the precision of key parameter combinations. Reinforcement learning is used to determine the distribution factor and leaf node size of the ball tree index. The reward function is calculated based on the query latency and precision of the key parameter combinations. A ball tree index of the image set is constructed according to the determined distribution factor and leaf node size, and then image retrieval is performed based on the ball tree index.
[0027] The present invention has the following beneficial effects:
[0028] 1) This invention utilizes reinforcement learning to automatically optimize ball tree index parameters. By autonomously exploring the parameter space, it automatically learns the optimal parameter configuration to improve query latency and accuracy.
[0029] 2) The method for determining the ball tree index in this invention is an adaptive method. Compared with existing static or heuristic methods, this method can better adapt to different datasets and query characteristics, thus providing superior performance.
[0030] 3) This invention obtains the parameters of the ball tree index through reinforcement learning, which can effectively improve image retrieval efficiency while reducing certain resource overhead. Attached Figure Description
[0031] Figure 1 This is a flowchart illustrating a specific implementation of the reinforcement learning-based image retrieval method of the present invention.
[0032] Figure 2 This is a flowchart of the reinforcement learning process based on the Q-learning algorithm in this embodiment. Detailed Implementation
[0033] The specific embodiments of the present invention will now be described with reference to the accompanying drawings to enable those skilled in the art to better understand the invention. It should be particularly noted that in the following description, detailed descriptions of known functions and designs that might obscure the main content of the invention will be omitted here.
[0034] Example
[0035] To better illustrate the technical solution of the present invention, the technical principles of the present invention will be briefly explained first.
[0036] To improve image retrieval efficiency, the image dataset in this invention employs a ball-tree index. In constructing a ball-tree index, a deeper tree may improve query accuracy, but it increases construction time and memory usage. Therefore, two parameters are crucial for ball-tree indexes: the branching factor and the leaf size. The branching factor represents the number of child nodes each node splits into; a higher branching factor can reduce tree depth but may increase processing time per node. The leaf size represents the maximum number of points contained in a leaf node; a smaller leaf size may improve retrieval accuracy but increases memory usage and construction time.
[0037] Therefore, obtaining the optimal combination of key parameters for a ball tree index is a multi-parameter joint optimization problem. This involves two parameters: the branching factor and the leaf node size. This invention employs reinforcement learning (RL) to solve this multi-parameter joint optimization problem. The goal of reinforcement learning is to optimize the two key parameters of the ball tree index: the branching factor and the leaf node size. Each parameter has a predefined range, within which an integer value can be chosen, thus allowing for multiple alternative combinations of key parameters.
[0038] To select the optimal combination of key parameters, this invention uses two performance metrics to evaluate the effectiveness of alternative parameter combinations: query latency and precision. Query latency can be approximated using tree depth. Precision approximation is difficult to achieve without data-driven methods; that is, it's hard to approximate precision without considering data characteristics such as data distribution. Therefore, this invention chooses to calculate approximate precision by constructing a small query dataset. To obtain an efficient index structure with minimal cost, this invention proposes using the compactness of the true nearest neighbor distribution of the query vector in the ball tree stage instead of precision. In other words, if the ball regions containing more true nearest neighbors of the query point can be selected more accurately, the precision will be higher. When the true nearest neighbor distribution is sufficiently compact—that is, if the true nearest neighbors of a query point are concentrated in a few ball regions—the probability of selecting these regions will be higher, thereby improving precision. This invention sets up a true nearest neighbor distribution estimation model to estimate the true nearest neighbor distribution of different alternative parameter combinations, thereby calculating precision.
[0039] Based on the above analysis, this invention proposes an image retrieval method based on reinforcement learning. Figure 1 This is a flowchart illustrating a specific implementation of the reinforcement learning-based image retrieval method of the present invention. Figure 1 As shown, the specific steps of the reinforcement learning-based image retrieval method of the present invention include:
[0040] S101: Image Collection
[0041] Collect N images according to actual needs to obtain image set A.
[0042] S102: Construct and train a real nearest neighbor distribution estimation model:
[0043] A true nearest neighbor distribution estimation model is constructed based on actual needs. The input is a parameter vector (B,L,K) consisting of the ball tree index distribution factor B, the leaf node size L, and the number of query neighbors K. The output is a W-dimensional distribution vector, where each dimension of the distribution vector corresponds to a leaf partition, and the corresponding element value represents the proportion of finding K true nearest neighbors in the corresponding partition.
[0044] The ranges of values for the distribution factor B, leaf node size L, and the number of nearest neighbors K are determined, and several parameter vectors are obtained by random selection. A sphere tree index is constructed for the image set A based on the distribution factor and leaf node size in each parameter vector, and then the corresponding distribution vector is obtained, thus yielding the training samples. The training samples are used to train the real nearest neighbor distribution estimation model, resulting in a well-trained real nearest neighbor distribution estimation model.
[0045] In this embodiment, the true nearest neighbor distribution estimation model uses a multilayer perceptron.
[0046] S103: Determining ball tree index parameters based on reinforcement learning:
[0047] Next, reinforcement learning is used to determine the distribution factor B of the ball tree index and the leaf node size L. The parameter settings in reinforcement learning are as follows:
[0048] Set status s t = (B t ,L t ,ΔT t-1 ,P t-1 ), where t represents time, B t L represents the distribution factor at time t. t ΔT represents the size of the leaf node at time t. t-1 P represents the query delay at time t-1. t-1 This represents the precision at time t-1.
[0049] Set action a t =(ΔB) t ,ΔL t ), ΔB t Let B represent the adjustment amount of the distribution factor at time t, and B t+1 =B t +ΔB t ∈[B min B max ], B t+1 B represents the distribution factor at time t+1. min B max ΔL represents the minimum and maximum values of the distribution factor. t L represents the leaf node size adjustment at time t, and L t+1 =L t +ΔL t∈[L min ,L max ], L t+1 L represents the size of the leaf node at time t+1. min L max This represents the minimum and maximum values of the leaf node size.
[0050] For the reward function, in this invention, the reward function is calculated from the query latency and the precision. The calculation method of the reward function is as follows:
[0051] The query latency ΔT is calculated using the following formula. t :
[0052]
[0053] Here, λ represents a preset constant used to make the result closer to the true value, which can be set based on experience.
[0054] Then the current parameter vector (B) t +ΔB t ,L t +ΔL t K) Input the trained real nearest neighbor distribution estimation model to obtain a W-dimensional distribution vector, and calculate the precision P using the following formula. t :
[0055] P t =log(W)-H
[0056] Where H represents the entropy of the distribution vector, and its calculation formula is:
[0057]
[0058] Where, p w This represents the value of the w-th element in the distribution vector, which is the proportion of the w-th leaf node's partition to find K true nearest neighbors.
[0059] As can be seen from the above formula, by subtracting the actual entropy value from the maximum possible entropy, the precision can be increased when the distribution is more concentrated, thereby improving the efficiency of reinforcement learning.
[0060] Then, the current reward function R is calculated using the following formula. t :
[0061] R t =ΔT t +P t
[0062] In terms of specific reinforcement learning methods, Q-learning is a model-free reinforcement learning algorithm that learns the optimal policy through interaction with the environment, that is, choosing the action that maximizes long-term reward in a given state. The core of Q-learning is a data structure called a Q-table, which assigns a value (Q-value) to each state-action pair, representing the expected utility of taking a certain action in a given state. The goal of this algorithm is to learn a policy that maximizes cumulative reward, i.e., obtains the maximum benefit in the long run. The advantages of the Q-learning algorithm lie in its flexibility and versatility; it does not require prior knowledge of the dynamics of the environment and is applicable to various complex decision-making problems. Therefore, this embodiment uses the Q-learning algorithm for reinforcement learning. Figure 2 This is a flowchart of the reinforcement learning process based on the Q-learning algorithm in this embodiment. For example... Figure 2 As shown, the specific steps of reinforcement learning based on the Q-learning algorithm in this embodiment include:
[0063] S201: Initialize Q-table:
[0064] First, a Q-table needs to be initialized. This is a state-action table that stores the Q-value (state-action value function) of the actions that can be taken in each state. Initially, all Q-values in the Q-table can be set to zero or other initial values.
[0065] S202: Define the state space and action space:
[0066] Define the state space, which is the set of all possible states, and define the action space, which is the set of all possible actions.
[0067] S203: Let the iteration number t = 1.
[0068] S204: Select Action:
[0069] In each training step, an action a is selected based on the current state and the Q-table. t A greedy strategy can often be used to strike a balance between exploration and exploitation.
[0070] S205: Perform the action and observe the reward and the next state:
[0071] Execute the selected action a t Then calculate the reward function R. t Observe the next state s t+1 This refers to the new index structure configuration and performance metrics.
[0072] S206: Update Q value:
[0073] Use Q-learning to update the rules based on the reward function R. t The Q-value of the selected action in the current state is updated using the Q-value of the next state. The update rule is usually as follows:
[0074]
[0075] Where Q(s) t ,a t ), Q(s) t+1 ,a t+1 ) are the Q values of the current state and the next state, respectively, where α represents the learning rate and γ represents the discount factor.
[0076] S207: Determine if the termination condition has been met. If not, proceed to step S208; otherwise, proceed to step S209. The termination condition can be reaching a certain number of training rounds or the Q-value converging to a stable level.
[0077] S208: Let t = t + 1, then return to step S205.
[0078] S209: Strategy Extraction:
[0079] After training, the optimal parameter combination strategy is extracted from the Q-table, that is, the action with the highest Q value is selected for each state, so as to obtain the parameter configuration suggestions in different states.
[0080] S104: Constructing the spherical tree index:
[0081] Based on the distribution factor and leaf node size determined in step S103, a sphere tree index is constructed for image set A. The sphere tree index is a common index structure, and its specific construction method will not be elaborated here.
[0082] S105: Image Retrieval
[0083] The constructed ball-tree index is used to search the image to be retrieved, and the search results consist of the K images with the highest similarity. Image retrieval based on ball-tree index is also a common retrieval method, and its specific process will not be elaborated here.
[0084] To better illustrate the technical effects of the present invention, a specific example is used for experimental verification. In this embodiment, the dataset fashion-mnist-794 is used for experimental verification. Table 1 is a comparison table of retrieval latency before and after optimization of key parameters in this embodiment.
[0085]
[0086] Table 1
[0087] As shown in Table 1, under the same precision, the optimized parameters obtained by reinforcement learning can reduce latency by up to 50% compared to the default parameters.
[0088] Although the illustrative specific embodiments of the present invention have been described above to enable those skilled in the art to understand the invention, it should be understood that the invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the invention as defined and determined by the appended claims, and all inventions utilizing the concept of the present invention are protected.
Claims
1. An image retrieval method based on reinforcement learning, characterized in that, Includes the following steps: S1: Collect N images according to actual needs to obtain image set A; S2: Construct a true nearest neighbor distribution estimation model according to actual needs. The input is a parameter vector (B,L,K) consisting of the ball tree index distribution factor B, leaf node size L, and the number of query neighbors K. The output is a W-dimensional distribution vector. Each dimension of the distribution vector corresponds to a leaf partition, and the corresponding element value represents the proportion of finding K true nearest neighbors in the corresponding partition. The ranges of values for distribution factor B, leaf node size L, and the number of nearest neighbors K are determined respectively. Several parameter vectors are obtained by randomly selecting values. A spherical index is constructed for image set A based on the distribution factor and leaf node size in each parameter vector. Then, the corresponding distribution vector is obtained to obtain the training sample. The training sample is used to train the real nearest neighbor distribution estimation model to obtain the trained real nearest neighbor distribution estimation model. S3: Reinforcement learning is used to determine the distribution factor B and leaf node size L of the ball tree index. The parameter settings in reinforcement learning are as follows: Set status s t = (B t ,L t ,ΔT t-1 ,P t-1 ), where t represents time, B t L represents the distribution factor at time t. t ΔT represents the size of the leaf node at time t. t-1 P represents the query delay at time t-1. t-1 The precision is expressed at time t-1. Set action a t =(ΔB) t ,ΔL t ), ΔB t Let B represent the adjustment amount of the distribution factor at time t, and B t+1 =B t +ΔB t ∈[B min B max ], B t+1 B represents the distribution factor at time t+1. min B max ΔL represents the minimum and maximum values of the distribution factor. t L represents the leaf node size adjustment at time t, and L t+1 =L t +ΔL t ∈[L min ,L max ], L t+1 L represents the size of the leaf node at time t+1. min L max This represents the minimum and maximum values of the leaf node size; The reward function is calculated as follows: The query latency ΔT is calculated using the following formula. t : Where λ represents a preset constant; Then the current parameter vector (B) t +ΔB t ,L t +ΔL t K) Input the trained real nearest neighbor distribution estimation model to obtain a W-dimensional distribution vector, and calculate the precision P using the following formula. t : Q t =log(W)-H Where H represents the entropy of the distribution vector, and its calculation formula is: Where, p w This represents the value of the w-th element in the distribution vector, which is the proportion of the w-th leaf node that finds K true nearest neighbors within its partition. Then, the current reward function R is calculated using the following formula. t : R t =ΔT t +P t S4: Construct a spherical tree index for image set A based on the distribution factor and leaf node size determined in step S3; S5: The constructed ball tree index is used to search the image to be retrieved, and the search results are composed of the K images with the highest similarity.
2. The image retrieval method according to claim 1, characterized in that, The true nearest neighbor distribution estimation model employs a multilayer perceptron.
3. The image retrieval method according to claim 1, characterized in that, The reinforcement learning in step S3 adopts a Q-learning algorithm and includes the following steps: S3.1: First, initialize a Q-table to store the Q-value of the action that can be taken in each state; S3.2: Define the state space and action space; S3.3: Let the iteration number t = 1; S3.4: Based on the current state and the Q-table, select an action a. t ; S3.5: Execute the selected action a t Then calculate the reward function R. t Observe the next state s t+1 ; S3.6: Update the rules using Q-learning, based on the reward function R. t The Q-value of the selected action in the current state is updated using the Q-value of the next state. S3.7: Determine whether the termination condition has been met. If not, proceed to step S3.8; otherwise, proceed to step S3.
9. S3.8: Let t = t + 1, then return to step S3.5; S3.9: Extract the optimal parameter combination strategy from the Q-table after training is complete.
