A method of continual learning based on nearest neighbor search enhancement
Patent Information
- Application Number
- CN202311701794.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-12
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2043-12-12
AI Technical Summary
[0004]在现有技术中,基于回放的持续学习方法存在数据不平衡、高训练成本、过度拟合等问题
[0022] Compared to traditional retraining-based continuous learning methods, kNN-CL offers several distinct advantages:
Smart Images

Figure CN117669682B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer data processing technology, and more specifically, to a continuous learning method based on nearest neighbor retrieval enhancement. Background Technology
[0002] Modern deep neural networks have made significant progress on a wide range of tasks. However, they struggle when dealing with sequential data streams. When these networks update their parameters to learn new knowledge, they inadvertently impair previously acquired knowledge, leading to the catastrophic forgetting problem in neural networks. This catastrophic forgetting has spurred extensive research into continuous learning, a method designed to mitigate forgetting in neural networks while preserving their ability to learn new tasks. Continuous learning methods can generally be categorized into three types: 1) Regularization-based methods, which introduce explicit regularization terms during training to constrain model parameter updates; 2) Architecture-based techniques, where the network is augmented to assign a unique set of parameters for each distinct task; and 3) Rehearsal-based strategies, involving retaining a subset of data from each task in an episodic memory, which is then used for training to adapt to new tasks. Among these methods, rehearsal-based continuous learning has proven highly effective, consistently achieving strong performance on benchmark datasets.
[0003] However, rehearsal-based methods still face several key challenges. First, the increased demand for replay data as the number of tasks increases leads to higher training costs and limits the scalability of episodic memory. Second, limited episodic memory challenges accurately representing the distribution of historical task data, resulting in data imbalance. This imbalance introduces bias when retraining the model using replay, making it difficult to approximate the joint probability distribution of all previous tasks. The model is affected by forgetting when test instances from previous tasks show minimal similarity to samples in episodic memory. Furthermore, recent research has found that episodic memory samples from past tasks are repeatedly trained with the influx of new tasks, leading to overfitting of their own representations. This phenomenon prevents them from adequately representing the distribution of historical task data, exacerbating the model forgetting problem. Third, while existing methods maintain stability across all historical tasks, it is recognized from a practical perspective that test instances from all past tasks will not always occur with the same frequency in real-world scenarios. Overemphasizing stability can lead to a "wheel-spinning" phenomenon, inefficient resource utilization, and interference between tasks hindering generalization. Summary of the Invention
[0004] In existing technologies, playback-based continuous learning methods suffer from problems such as data imbalance, high training costs, and overfitting. To address these issues, this invention proposes a continuous learning method based on nearest neighbor retrieval enhancement. kNN-CL introduces k-nearest neighbor retrieval technology, eliminating the need for additional training costs, effectively addressing data imbalance, resolving overfitting, and improving generalization performance. Unlike traditional methods, kNN-CL can selectively retrieve data storage for various tasks by retrieving the k-nearest neighbors of a given test data point, where each k-nearest neighbor is only relevant to that specific test data point, thus saving time and resources.
[0005] To achieve the above objectives, the present invention provides the following technical solution:
[0006] A continuous learning method based on nearest neighbor retrieval enhancement, comprising the following steps:
[0007] Step 1, Model Building Stage: In the scenarios of task incremental learning and class incremental learning, given a data stream of T tasks, a fixed pre-trained model that does not change with the task is used as a pre-trained encoder specifically for image retrieval. This model is used to encode the samples of each task and convert them into vector representations, which are then stored in the data storage of each task.
[0008] Step 2, Model Inference Stage: The test data is encoded to obtain the retrieval key vector. If the task ID is known, only the data storage of the corresponding task is retrieved; if the task ID is unknown, the data storage of all tasks is retrieved. The weights are calculated based on the retrieval results to obtain the output probability of the KNN model. The output of the basic model and the output of the KNN model are fused through linear interpolation to obtain the probability of the final model output label.
[0009] A further optimization of this technical solution involves incremental task learning in step one: given a data stream of T tasks, i.e., D = (D1, D2, ..., D...). T , where the training set for the t-th task is represented as Where, n t This indicates the length of the dataset for task t. Representing data, This represents the corresponding data label. For different tasks with task IDs i and j, P(X) t Let P(Xi) represent the data distribution for task t. Then, under the task incremental learning setting, P(Xi) ≠ P(Xj). During the training and inference phases of task t, a corresponding task ID will be provided;
[0010] Incremental learning: No corresponding task ID is provided during the inference phase of task t; the rest of the settings are the same as for task incremental learning.
[0011] This technical solution is further optimized, and the specific steps of the model construction stage are as follows:
[0012] The episodic memory for each task consists of a key-value pair database, using a fixed encoder, Enc(·), which is independent of the task. For the t-th task, it contains the image data. Encode as a fixed-dimensional key vector value vector Equal to label data The contextual memory module (K) for the t-th task i V i It consists of key-value pairs corresponding to all the data in the training set for this task:
[0013]
[0014] (K, V) = {(K t V t )|t=1,2,…T}.
[0015] This technical solution is further optimized, and the specific steps of the model inference stage are as follows:
[0016] For a certain test data of the t-th task The retrieval key vector is obtained through the encoder Enc(·). If the current task ID is known, then only the context memory (K) of task t is accessed. t V t If the current task ID is unknown, then search the context memory (K, V) of all tasks t to obtain its k nearest neighbors. Finally, the weight is calculated by determining the distance between the current search key vector and the key vectors of the neighbor set. Let the distance calculation function between two vectors a and b be d(a,b). The corresponding model output labels are The KNN model outputs probability p KNN for:
[0017]
[0018] Assume the output of the basic model used for training and prediction is Then, the output of the basic model and the output of the KNN model are linearly interpolated, with a fusion weight of λ. The final model output label is then obtained. The probability p is:
[0019]
[0020] In a further optimization of this technical solution, the fixed pre-trained encoder is a pre-trained neural network model.
[0021] Further optimizations to this technical solution include the following basic models: a continuous learning model based on synaptic intelligence, a Riemann walk model, an elastic weight consolidation model, an experience replay model, an experience replay model based on complementary learning system theory, and a dark experience replay model.
[0022] Compared to traditional retraining-based continuous learning methods, kNN-CL offers several distinct advantages:
[0023] As a nonparametric model, kNN-CL does not incur additional training costs. It stores past knowledge offline in a structured manner and can be seamlessly integrated into the base model, achieving a plug-and-play approach. This design helps avoid overfitting previous tasks when incorporating new tasks.
[0024] By employing an instance-centric approach, kNN-CL effectively addresses the model bias problem caused by data imbalance in episodic memory. It effectively tackles this issue by identifying samples that closely match the test instances.
[0025] kNN-CL avoids the need to maintain the stability of all past tasks and selectively retrieves necessary samples based on actual requirements, thereby optimizing time and resource usage. This technical approach provides a method for enhancing continuous learning, fully utilizing knowledge from previous tasks while effectively addressing the challenges of data imbalance and resource consumption. Attached Figure Description
[0026] Figure 1 This is a flowchart of a continuous learning method based on nearest neighbor retrieval enhancement. Detailed Implementation
[0027] To explain in detail the technical content, structural features, objectives, and effects of the technical solution, the following description is provided in conjunction with specific embodiments and accompanying drawings.
[0028] This invention introduces a technical solution called kNN-CL (k-Nearest Neighbor Retrieval in Continual Learning), aiming to enhance the effectiveness of continuous learning. kNN-CL is a technique that determines test instance labels using k-nearest neighbor retrieval (kNN Retrieval) and then probabilistically fuses them with the output of the base model. This technical solution also includes a domain adaptation mechanism to calibrate test instances to align with historical tasks, thus acting as a correction mechanism. Specifically, kNN-CL employs a fixed pre-trained encoder specifically designed for image retrieval to encode samples and convert them into vector representations, which are then stored in the data store for each task. During the inference phase, kNN-CL re-retrieves the k nearest neighbor data and combines the output of the base model with the kNN results using an interpolation method.
[0029] I. Problem Definition: Includes two continuous learning settings.
[0030] Task incremental learning (TIL): Given a data stream of T tasks, i.e., D = (D1, D2, ..., D...). T , where the training set for the t-th task is represented as Where, n t This indicates the length of the dataset for task t. Representing data, This represents the corresponding data label. For different tasks with task IDs i and j, P(X) t If represents the data distribution of task t, then under the TIL setting, P(Xi) ≠ P(Xj). During the training and inference phases of task t, a corresponding task ID will be provided.
[0031] Class incremental learning (CIL): No corresponding task ID is provided during the inference phase of task t; the rest of the settings are the same as for task incremental learning (TIL).
[0032] II. Model Building and Reasoning.
[0033] Process flow: In the construction phase, kNN-CL employs a fixed pre-trained encoder (such as a pre-trained AlexNet) specifically for image retrieval to encode samples for each task and convert them into vector representations, which are then stored in the data store for each task. In the model inference phase, kNN-CL re-retrieves the k nearest neighbor data and combines the output of the base model with the kNN results using an interpolation method.
[0034] 1. Model Building Stage:
[0035] The contextual memory for each task consists of a key-value datastore. A fixed encoder, Enc(·), is used, which does not change with the task. For the t-th task, its image data... Encoded as a fixed-dimensional key vector Value vector Equal to label data The contextual memory module (K) for the t-th task i V i It consists of key-value pairs corresponding to all the data in the training set of this task.
[0036]
[0037] (K, V) = {(K t V t |t=1,2,…T}
[0038] 2. Model Inference Stage:
[0039] For a certain test data of the t-th task (A testinstance), its retrieval key vector is obtained through the encoder Enc(·). If the current task ID is known, then only the context memory (K) of task t is accessed. t V t If the current task ID is unknown, then search the context memory (K, V) of all tasks t to obtain its k nearest neighbors. Finally, the weight is calculated by determining the distance between the current search key vector and the key vectors of the neighbor set. Let the distance calculation function between two vectors a and b be d(a,b). The corresponding model output labels are The KNN model outputs probability p KNN for:
[0040]
[0041] Suppose the base model used for training and prediction (the foundational model for sequentially learning a series of incremental learning tasks, such as using AlexNet to learn 10 tasks) outputs as follows: KNN-CL directly interpolates the output of the base model with the output of the KNN model using linear interpolation, with a fusion weight of λ. The final model output label is then... The probability p is:
[0042]
[0043] III. Experimental Results.
[0044] The base models include non-replay methods: SI (Synaptic Intelligence), RWALK (Riemannian Walk), and EWC (Elastic Weight Consolidation), and replay methods: ER (Experience Replay), CLSER (Experience Replay Method Based On The Complementary Learning Systems Theory), and DER++ (Dark Experience Replay). Experiments were conducted on two datasets, CIFAR-100-RS-20T and CIFAR-100-SC-20T, with combined results from two experimental settings: Task Incremental Learning (TIL) and Class Incremental Learning (CIL). The evaluation metric AX (A-10, A-20, etc. in the table) represents the average classification accuracy of the model on tasks 1 to X after learning task X.
[0045] The experimental results are shown in Table 1. The results demonstrate that for non-replay methods (SI, RWALK, EWC), stacking kNN-CL significantly improves the performance of the base model on both datasets. Taking SI as an example, on the CIFAR-100-RS-20T dataset, A-20 improved from 62.97% to 67.36% under TIL, and from 24.62% to 28.77% under CIL. Similar improvements were also observed in the RWALK and EWC methods.
[0046] For replay-based methods (ER, CLSER, DER++), the kNN-CL model is built using the replay samples stored for each task, without requiring additional data. Although these methods already have storage and replay mechanisms, kNN-CL still offers additional performance improvements over the three replay-based methods. For example, in ER, after stacking kNN-CL in TIL and CIL scenarios, the average performance on the CIFAR-100-RS-20T and CIFAR-100-SC-20T datasets increased from 46.86% to 48.06%. Among ER, CLSER, and DER++, DER++ shows a more significant improvement on A-10 and A-20.
[0047] Finally, the kNN-CL method superimposed on the DER++ method achieves state-of-the-art performance.
[0048] Table 1: Performance of various continuation learning methods after adding kNN-CL
[0049]
[0050] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Unless otherwise specified, an element defined by the phrase "comprising..." or "including..." does not exclude the presence of additional elements in the process, method, article, or terminal device that includes said element. Additionally, in this document, "greater than," "less than," "exceeding," etc., are understood to exclude the stated number; "above," "below," "within," etc., are understood to include the stated number.
[0051] Although the above embodiments have been described, those skilled in the art, once they understand the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the above descriptions are merely embodiments of the present invention and do not limit the scope of patent protection of the present invention. Any equivalent structural or procedural transformations made using the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A continuous learning method based on nearest neighbor retrieval enhancement, characterized in that, The method includes the following steps: Step 1, Model Building Stage: In the scenarios of task incremental learning and class incremental learning, given a data stream of T tasks, a fixed pre-trained model that does not change with the task is used as a pre-trained encoder specifically for image retrieval. This model is used to encode the samples of each task and convert them into vector representations, which are then stored in the data storage of each task. Incremental learning of the task in step one: given The data flow of each task, i.e. The training set for the t-th task is represented as... ,in, Indicates task The length of the dataset, Representing data, This represents the corresponding data label, for task ID as and Different tasks, Indicates task The data distribution, under the task incremental learning setting, , In the mission During the training and inference phases, corresponding task IDs will be provided; Incremental learning: No corresponding task ID is provided during the inference phase of task t; the rest of the settings are the same as for task incremental learning. The specific steps in the model construction phase are as follows: The contextual memory for each task consists of a key-value pair database, using a fixed encoder that does not change with the task. For the first One task is to process its image data. Encode as a fixed-dimensional key vector And value vector Equal to label data , No. Contextual memory module for each task It consists of key-value pairs corresponding to all the data in the training set for this task: The specific steps of the model inference phase are as follows: For the A specific test data point for a task via encoder Obtain its retrieval key vector If the current task ID is known, then only send an application to the task. Contextual memory If the current task ID is unknown, search all tasks. Contextual memory Perform a search to obtain its k nearest neighbors. Finally, the weight is calculated by measuring the distance between the current search key vector and the key vectors of the neighbor set. Let's say there are two vectors... The distance calculation function between them is: This data The corresponding model output labels are Then the KNN model outputs the probability. for: Assume the output of the basic model used for training and prediction is Then, the output of the basic model and the output of the KNN model are linearly interpolated, and the fusion weights are... The final model output label is probability for: Step 2, Model Inference Stage: The test data is encoded to obtain the retrieval key vector. If the task ID is known, only the data storage of the corresponding task is retrieved; if the task ID is unknown, the data storage of all tasks is retrieved. The weights are calculated based on the retrieval results to obtain the output probability of the KNN model. The output of the basic model and the output of the KNN model are fused through linear interpolation to obtain the probability of the final model output label.
2. The continuous learning method based on nearest neighbor retrieval enhancement as described in claim 1, characterized in that, The fixed pre-trained encoder is a pre-trained neural network model.
3. The continuous learning method based on nearest neighbor retrieval enhancement as described in claim 1, characterized in that, The basic models are: a continuous learning model based on synaptic intelligence, a Riemann walk model, an elastic weight consolidation model, an experience replay model, an experience replay model based on complementary learning system theory, and a dark experience replay model.
Citation Information
Patent Citations
3D model retrieval method and 3D model retrieval apparatus based on slow increment features
CN105320764A
Image incremental learning method based on dynamic correction vector
CN111199242A