Continuous learning method based on prototype prompt and virtual logic value
By introducing technical means of class prototype prompts and virtual logic values in the continuous learning method, the problems of cue query inhomogeneity and confusion among tasks are solved, significantly improving the performance maintenance and classification accuracy of the model, and avoiding catastrophic forgetting.
Patent Information
- Application Number
- CN202510148888.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-11
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2045-02-11
AI Technical Summary
The existing continuous learning method based on prompts has problems with cue query inhomogeneity and inter-task confusion, resulting in serious catastrophic forgetting.
The continuous learning method based on class prototype prompts and virtual logic values is adopted, and the query function and classifier output are optimized by updating prompts and adding virtual logic values to improve the uniformity of prompt query and the clarity of classification boundaries.
It effectively eliminates the problem of uneven queries, reduces confusion among tasks, and significantly improves the model's performance maintenance ability on old tasks and the classification accuracy on new tasks.
Smart Images

Figure CN119598272A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of pattern recognition, and in particular to a continuous learning method based on class prototype prompts and virtual logic values. Background Art
[0002] Continuous learning enables a single model to acquire knowledge from a series of tasks in a non-static data stream, which can effectively classify the categories of new tasks while maintaining the performance on old tasks, thus avoiding catastrophic forgetting. However, when the model parameters are fixed during the learning process, the model can only generalize to known categories. If the model parameters are updated through new category samples, the model often has difficulty maintaining the classification performance on old tasks. This limitation severely restricts the potential of deep learning models in practical applications.
[0003] In recent years, the success of pre-trained models and fine-tuning techniques has promoted the use of prompt-based methods as an emerging continuous learning strategy that outperforms traditional continuous learning methods. Traditional methods usually do not rely on a prompt pool, but instead use other strategies to prevent catastrophic forgetting. For example, parameter regularization-based methods impose constraints on important parameters to enhance the stability of the model, but this can cause serious overlap of new and old category features and make them difficult to distinguish. Data playback-based methods allow a small amount of old category data to be saved and input into the model for training together with new data. This method is simple and efficient, but it is sensitive to old data and may cause privacy issues. Network structure-based methods dynamically expand the network structure during incremental learning, but most of these methods require the addition of a large number of additional parameters, resulting in high computational complexity and significant time and space overhead.
[0004] Existing prompt-based continuous learning methods usually incrementally learn a set of global prompts or task-specific prompts during training, and use a key-value query mechanism to calculate the cosine distance with the query key based on the query features extracted by the pre-trained visual transformer (ViT) during inference, and select appropriate prompts from the prompt pool and input them into ViT together with the sample for classification. For example, the L2P method introduced prompt learning into continuous learning for the first time, trained a prompt pool containing multiple prompt words, and dynamically selected prompt combinations for different samples based on the key-value query mechanism. The DualPrompt method further proposed to train two types of prompts: global prompts and task-specific prompts, which encode global knowledge and task-local knowledge respectively, and the two work together to better complete downstream tasks. However, these methods usually adopt a fixed key-value query mechanism to select and optimize fixed prompts from the prompt pool, which is easy to fall into local optimality. In addition, their query functions usually directly use the rough query features extracted by the pre-trained ViT model, which are difficult to accurately represent each sample, resulting in different categories tending to use the same prompt.
[0005] Existing methods also generally train a separate classifier for each task during training, and merge all classifiers for classification during testing. Since the classifiers are trained independently, the prediction scores between different tasks cannot be directly compared. This may result in the highest scoring classifier being suboptimal even if the prompts are assigned correctly (i.e., the inter-task confusion problem).
[0006] In summary, current prompt-based continuous learning methods have not effectively solved the problem of uneven prompt queries, nor have they fully alleviated the confusion between tasks, resulting in serious catastrophic forgetting. Summary of the invention
[0007] In view of the above-mentioned deficiencies in the prior art, the present invention provides a continuous learning method based on prototype-like prompts and virtual logical values, which solves the problem of prompt query unevenness in the prior art and the problem of failing to fully alleviate confusion between tasks, resulting in serious catastrophic forgetting.
[0008] In order to achieve the above-mentioned invention object, the technical solution adopted by the present invention is: a continuous learning method based on class prototype prompts and virtual logic values, comprising the following steps: S1: In the query function fine-tuning phase, the image of the current task and the introduced prompt are input into the pre-trained encoder for training, and the classifier parameters and prompts are updated through the cross-entropy loss backpropagation of the training samples; S2: Based on the updated hint and the hint in the previous task query function, the hint is updated using momentum and combined with the pre-trained encoder to obtain the query function of the current task; S3: Based on the query function of the current task and the image of the current task, the query features of the training samples are extracted, and a class prototype is calculated for each category sample of the current task through the query features, and the class prototype is stored in the prototype pool; S4: In the prompt fine-tuning stage based on virtual logical values, the image and prompt of the current task are input into another pre-trained encoder, the cross entropy loss of the training sample is calculated by adding the virtual logical value, and the classifier and prompt are updated by backpropagation according to the cross entropy loss, and the updated prompt is stored in the prompt pool; S5: Repeat the above steps S1-S4 until the training of the current task is completed, and based on the stored class prototypes and prompts, use the test samples of the current task to test, obtain classification results, and complete continuous learning based on class prototype prompts and virtual logical values.
[0009] Furthermore, the S1 includes the following sub-steps: S11: Initialize the model parameters and input the image of the current task and the introduced prompts into the pre-trained encoder to obtain image features; S12: Input the image features into the classifier, and obtain the output obtained by forward propagation through the classifier. The formula is:
[0010] in, is the output obtained by forward propagation, are the initialized classifier parameters, For the current task The query function, For samples; S13: Based on the output obtained by forward propagation, calculate the first cross entropy loss of each sample , and update the classifier and prompt through back propagation, the formula is:
[0011] in, For sample The corresponding label, For the current task The model classifier parameters of , the superscript - distinguishes the query function fine-tuning stage from the prompt fine-tuning stage based on the virtual logical value, For the current task By back-propagating the updated hint, is the process of back-propagation update, is the query function of the previous task, is the model classifier of the previous task, For the training set.
[0012] Furthermore, in S2, based on the updated prompt and the prompt in the previous task query function, the prompt is updated using momentum, and the formula is:
[0013] in, As a reminder of the momentum update, Query the prompt in the previous task function. For momentum.
[0014] Furthermore, in S3, a class prototype is calculated for each class sample of the current task by querying the features, and the formula is:
[0015] in, For the current task No. The class prototype of the category, For Category The total number of samples in For the of the categories The samples correspond to the extracted features. For the current task The query function updated by momentum, For the of the categories Characteristics of a sample.
[0016] Furthermore, the S4 includes the following sub-steps: S41: Input the image and prompt of the current task into another pre-trained encoder to obtain image features; S42: Input the image features into the classifier, and obtain the output logic value obtained by forward propagation through the classifier. The formula is:
[0017] in, is the output logic value obtained by forward propagation, For samples; S43: Generate a virtual logic value using a virtual logic value generator , and the virtual logic value Add to the output logic value obtained by forward propagation to obtain the extended logic value , the formula is:
[0018] in, Indicates a connection operation. The sample corresponds to The output logical value of each category, is the total number of categories of the current task; S44: Using extended logic values Calculate the second cross entropy loss for each sample , and update the classifier and prompt through back propagation, the formula is:
[0019] in, is the hint updated by back-propagation, is the process of back-propagation update, Add a reminder for the previous task After the encoder, is the training set, is the second cross entropy loss; S45: Based on the update , store it in the prompt pool, the formula is:
[0020] in, A collection of hints for all tasks. Hints for all tasks.
[0021] Furthermore, the virtual logic value in S43 for:
[0022] in, is a virtual logic value generator, To get a random value, and is a hyperparameter.
[0023] Furthermore, the S5 performs testing based on the stored class prototypes and prompts using the test samples of the current task to obtain classification results, including the following sub-steps: S51: Select a test sample from the test set , and the test sample Input to the query function updated by momentum Extract its query features; S52: Calculate the distance between the extracted query features and the class prototypes stored in the prototype pool, and select the task label corresponding to the nearest neighbor class prototype , the formula is:
[0024] in, represents the Euclidean distance, Indicates that the task is fixed first For Category Minimize and then re-assign the task Minimize, and finally get the task label corresponding to the nearest neighbor prototype ; S53: Based on task tags Select the corresponding hint stored in the hint pool , and will prompt With test samples Input into the model In the ; S54: Features Input into the classifier to obtain the classification result.
[0025] The beneficial effects of the present invention are as follows: the present invention provides a continuous learning method based on class prototype prompts and virtual logic values, the method trains a task-specific prompt for each task, proposes a class prototype-based prompt query mechanism in terms of the method for selecting and adding prompts, and adds prompt momentum to the originally fixed query function to update, eliminating the problem of uneven addition of prompts. At the same time, the method also proposes to add virtual generated logic to the logic output by the classifier, so that the classifier has a better classification boundary, achieving the purpose of solving the confusion problem between tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 Flowchart of a continuous learning method based on prototype-like prompts and virtual logical values.
[0027] Figure 2 This is a model structure diagram of a continuous learning method based on prototype-like prompts and virtual logical values. DETAILED DESCRIPTION
[0028] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.
[0029] like Figure 1 As shown, a continuous learning method based on class prototype prompts and virtual logical values includes the following steps: S1: In the query function fine-tuning phase, the image of the current task and the introduced prompt are input into the pre-trained encoder for training, and the classifier parameters and prompts are updated through the cross-entropy loss backpropagation of the training samples; S2: Based on the updated hint and the hint in the previous task query function, the hint is updated using momentum and combined with the pre-trained encoder to obtain the query function of the current task; S3: Based on the query function of the current task and the image of the current task, the query features of the training samples are extracted, and a class prototype is calculated for each category sample of the current task through the query features, and the class prototype is stored in the prototype pool; The stored prototypes will be used as keys to query specific prompts, and will be used to find the prompts that need to be added to the input image during the testing phase; S4: In the prompt fine-tuning stage based on virtual logical values, the image and prompt of the current task are input into another pre-trained encoder, the cross entropy loss of the training sample is calculated by adding the virtual logical value, and the classifier and prompt are updated by backpropagation according to the cross entropy loss, and the updated prompt is stored in the prompt pool; Among them, the stored hints will be input into the model together with the image during the test phase to obtain more refined features to instruct the model to make predictions; S5: Repeat the above steps S1-S4 until the training of the current task is completed, and based on the stored class prototypes and prompts, use the test samples of the current task to test, obtain classification results, and complete continuous learning based on class prototype prompts and virtual logical values.
[0030] Figure 2 The diagram shows an overview of the training phase of the method of the present invention. We divide the entire training process into two phases: the query function fine-tuning phase and the prompt fine-tuning phase based on virtual logic values. Specifically, the following steps are included: The S1 includes the following sub-steps: S11: Initialize the model parameters and input the image of the current task and the introduced prompts into the pre-trained encoder to obtain image features; Model parameter initialization: Get the pre-trained ViT encoder and , randomly initialized prompt and , the initialized classifier and ,in represents the parameters of the model encoder (feature extractor), Represents the parameters of the classifier, and the subscript represents the task stage ( ), where 0 represents the initialization phase, and the overline represents the relevant parameters used for the query function fine-tuning phase, which is distinguished from the parameters of the second training phase. Number of tasks , training set , number of training rounds ; like Figure 2 As shown in the query function fine-tuning module in , from the training set Get a small batch , for each sample input in a small batch ,in For the sample, For the corresponding label, calculate the output obtained by forward propagation; S12: Input the image features into the classifier, and obtain the output obtained by forward propagation through the classifier. The formula is:
[0031] in, is the output obtained by forward propagation, are the initialized classifier parameters, For the current task The query function, For samples; S13: Based on the output obtained by forward propagation, calculate the first cross entropy loss of each sample , and update the classifier and prompt through back propagation, the formula is:
[0032] in, For sample The corresponding label, For the current task The model classifier parameters of , the superscript - distinguishes the query function fine-tuning stage from the prompt fine-tuning stage based on the virtual logical value, For the current task By back-propagating the updated hint, is the process of back-propagation update, is the query function of the previous task, is the model classifier of the previous task, For the training set.
[0033] In S2, based on the updated prompt and the prompt in the previous task query function, the momentum is used to update the prompt, and the formula is:
[0034] in, As a reminder of the momentum update, Query the prompt in the previous task function. For momentum.
[0035] when When directly taking . When you update, you will get the prompt After that, combined with the pre-trained ViT encoder , get the current task Query function (Right now Figure 2 The middle module (blue dashed line structure).
[0036] Based on these query functions, a class prototype is calculated for each category. Specifically, for a given category , using the query function Calculate the sample features of this category and take the mean of the features as the class prototype .
[0037] In S3, a class prototype is calculated for each class sample of the current task by querying the features, and the formula is:
[0038] in, For the current task No. The class prototype of the category, For Category The total number of samples in For the of the categories The samples correspond to the extracted features. For the current task The query function updated by momentum, For the of the categories Characteristics of a sample.
[0039] The S4 comprises the following sub-steps: S41: Input the image and prompt of the current task into another pre-trained encoder to obtain image features; S42: Input the image features into the classifier, and obtain the output logic value obtained by forward propagation through the classifier. The formula is:
[0040] in, is the output logic value obtained by forward propagation, For samples; The output logic value obtained by forward propagation , which can be further expressed as:
[0041] S43: Generate a virtual logic value using a virtual logic value generator , and the virtual logic value Add to the output logic value obtained by forward propagation to obtain the extended logic value , the formula is:
[0042] in, Indicates a connection operation. The sample corresponds to The output logical value of each category, is the total number of categories of the current task; S44: Using extended logic values Calculate the second cross entropy loss for each sample , and update the classifier and prompt through back propagation, the formula is:
[0043] in, is the hint updated by back-propagation, is the process of back-propagation update, Add a reminder for the previous task After the encoder, is the training set, is the second cross entropy loss; S45: Based on the update , store it in the prompt pool, the formula is:
[0044] in, A collection of hints for all tasks. Hints for all tasks.
[0045] The virtual logic value in S43 for:
[0046] in, is a virtual logic value generator, To get a random value, and is a hyperparameter.
[0047] Through this virtual logic value generator, it is possible to generate In this implementation case, the virtual logic generator can generate a range between These virtual logical values are close in size to the logical values generated by the classifier.
[0048] In S5, based on the stored class prototypes and prompts, the test samples of the current task are used for testing to obtain the classification results, including the following sub-steps: S51: Select a test sample from the test set , and the test sample Input to the query function updated by momentum Extract its query features; S52: Calculate the distance between the extracted query features and the class prototypes stored in the prototype pool, and select the task label corresponding to the nearest neighbor class prototype , the formula is:
[0049] in, represents the Euclidean distance, Indicates that the task is fixed first For Category Minimize and then re-assign the task Minimize, and finally get the task label corresponding to the nearest neighbor prototype ; S53: Based on task tags Select the corresponding hint stored in the hint pool , and will prompt With test samples Input into the model In the ; S54: Features Input into the classifier to obtain the classification result.
[0050] In the test phase of this embodiment, the test set ) , first input it into the formula The query function obtained The second step is to calculate the distance between the query feature and the stored class prototype and select the task label corresponding to the nearest neighbor class prototype:
[0051] The third step is to use the task label Select the corresponding prompt and compare it with the test sample Input them into the model together to get the features Finally, the features are input into the combined classifier to obtain the classification result.
[0052] when test set (to the current task After all tests are completed, the current task is finished. All training and testing processes. When , the training and testing of all tasks are completed.
[0053] In one embodiment of the present invention, the implementation examples of the present invention are implemented on four public commonly used data sets 10-SplitImageNet-R, 20-Split ImageNet-R, 10-Split CIFAR-100, and 10-Split DomainNet, using the ViT model pre-trained on ImageNet-21k, using a prompt length of 8, using 100 training rounds on ImageNet-R, 50 on CIFAR-100 and DomainNet, and a uniform number of mini-batches of 150. For the virtual outlier parameter, , .
[0054] The comparison with other methods on 10-Split ImageNet-R, 20-Split ImageNet-R, 10-Split CIFAR-100, and 10-SplitDomainNet is shown in Table 1, where n-split means that different datasets are divided into n consecutive category incremental learning tasks, and the evaluation indicators are the last accuracy and the last forgetting rate, that is, the average accuracy and forgetting rate after the last task is completed. The value after represents the standard deviation of multiple experiments. The baseline method in the table is a method that does not use momentum update fine-tuning query function and virtual outlier strategy. It can be seen from the table that the accuracy of the present invention is improved by 0.85%-4.02% compared with the baseline method, and the forgetting rate is reduced by 0.40%-1.17%. It also exceeds other advanced methods in terms of accuracy and achieves the best performance.
[0055] Table 1 Comparison with other methods on common datasets (%)
[0056] The present invention is compared with the baseline and other methods in the long-term (multi-task incremental learning) experiment. Table 2 shows the comparison results of the present invention with the baseline and other methods on 50 tasks. It can be seen from the table that the present invention still achieves the best performance on 50 tasks and the improvement is more obvious.
[0057] Table 2 Comparison with other methods on 50 tasks (%)
[0058] Table 3 shows the comparison results of the present invention with the baseline and other methods on 100 tasks. As can be seen from the table, when the number of tasks increases again, the present invention can still achieve good performance on the two data sets in the table, and has a more obvious improvement than other methods, while other methods have obvious catastrophic forgetting. This shows that the present invention has a more obvious advantage in long-term category incremental learning and has the potential for practical application.
[0059] Table 3 Comparison with other methods on 100 tasks (%)
[0060] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the invention.
Claims
1. A continuous learning method based on class prototype prompts and virtual logic values, characterized in that: The following steps are involved: S1: In the query function fine-tuning phase, the image of the current task and the introduced prompt are input into the pre-trained encoder for training, and the classifier parameters and prompts are updated through the cross-entropy loss backpropagation of the training samples; S2: Based on the updated hint and the hint in the previous task query function, the hint is updated using momentum and combined with the pre-trained encoder to obtain the query function of the current task; S3: Based on the query function of the current task and the image of the current task, the query features of the training samples are extracted, and a class prototype is calculated for each category sample of the current task through the query features, and the class prototype is stored in the prototype pool; S4: In the prompt fine-tuning stage based on virtual logical values, the image and prompt of the current task are input into another pre-trained encoder, the cross entropy loss of the training sample is calculated by adding the virtual logical value, and the classifier and prompt are updated by backpropagation according to the cross entropy loss, and the updated prompt is stored in the prompt pool; S5: Repeat the above steps S1-S4 until the training of the current task is completed, and based on the stored class prototypes and prompts, use the test samples of the current task to test, obtain classification results, and complete continuous learning based on class prototype prompts and virtual logical values.
2. A continuous learning method based on class prototype prompts and virtual logic values according to claim 1, characterized in that: The S1 includes the following sub-steps: S11: Initialize the model parameters and input the image of the current task and the introduced prompts into the pre-trained encoder to obtain image features; S12: Input the image features into the classifier, and obtain the output obtained by forward propagation through the classifier. The formula is: in, is the output obtained by forward propagation, are the initialized classifier parameters, For the current task The query function, For samples; S13: Based on the output obtained by forward propagation, calculate the first cross entropy loss of each sample , and update the classifier and prompt through back propagation, the formula is: in, For sample The corresponding label, For the current task The model classifier parameters of , the superscript - distinguishes the query function fine-tuning stage from the prompt fine-tuning stage based on the virtual logical value, For the current task By back-propagating the updated hint, is the process of back-propagation update, is the query function of the previous task, is the model classifier of the previous task, For the training set.
3. A continuous learning method based on class prototype prompts and virtual logic values according to claim 2, characterized in that: In S2, based on the updated prompt and the prompt in the previous task query function, the momentum is used to update the prompt, and the formula is: in, As a reminder of the momentum update, Query the prompt in the previous task function. For momentum.
4. A continuous learning method based on class prototype prompts and virtual logic values according to claim 3, characterized in that: In S3, a class prototype is calculated for each class sample of the current task by querying the features, and the formula is: in, For the current task No. The class prototype of the category, For Category The total number of samples in For the of the categories The samples correspond to the extracted features. For the current task The query function updated by momentum, For the of the categories Characteristics of a sample.
5. A continuous learning method based on class prototype prompts and virtual logic values according to claim 4, characterized in that: The S4 comprises the following sub-steps: S41: Input the image and prompt of the current task into another pre-trained encoder to obtain image features; S42: Input the image features into the classifier, and obtain the output logic value obtained by forward propagation through the classifier. The formula is: in, is the output logic value obtained by forward propagation, For samples; S43: Generate a virtual logic value using a virtual logic value generator , and the virtual logic value Add to the output logic value obtained by forward propagation to obtain the extended logic value , the formula is: in, Indicates a connection operation. The sample corresponds to The output logical value of each category, is the total number of categories of the current task; S44: Using extended logic values Calculate the second cross entropy loss for each sample , and update the classifier and prompt through back propagation, the formula is: in, is the hint updated by back-propagation, is the process of back-propagation update, Add a reminder for the previous task After the encoder, is the training set, is the second cross entropy loss; S45: Based on the update , store it in the prompt pool, the formula is: in, A collection of hints for all tasks. Hints for all tasks.
6. A continuous learning method based on class prototype prompts and virtual logic values according to claim 5, characterized in that: The virtual logic value in S43 for: in, is a virtual logic value generator, To get a random value, and is a hyperparameter.
7. A continuous learning method based on class prototype prompts and virtual logic values according to claim 6, characterized in that: In S5, based on the stored class prototypes and prompts, the test samples of the current task are used for testing to obtain the classification results, including the following sub-steps: S51: Select a test sample from the test set , and the test sample Input to the query function updated by momentum Extract its query features; S52: Calculate the distance between the extracted query features and the class prototypes stored in the prototype pool, and select the task label corresponding to the nearest neighbor class prototype , the formula is: in, represents the Euclidean distance, Indicates that the task is fixed first For Category Minimize and then re-assign the task Minimize, and finally get the task label corresponding to the nearest neighbor prototype ; S53: Based on task tags Select the corresponding hint stored in the hint pool , and will prompt With test samples Input into the model In the ; S54: Features Input into the classifier to obtain the classification result.
Citation Information
Patent Citations
Small sample image classification method based on memory mechanism and graph neural network
CN113688878A
Fault diagnosis method of wind turbine generator gearbox
CN115541228A
Class incremental learning method and system based on prototype recall and asymmetric knowledge aggregation
CN117274770A
Multi-source target detection method based on prototype network dynamic balance optimization strategy
CN118015342A
Persistent evolution learning method for prompting fine tuning in null space
CN118657989A