Active-class increment image classification method and device for realizing class balance sampling
By extracting features through the deep learning model and using clustering and improved greedy sampling algorithms, the problem of unbalanced sample selection categories in the class incremental image classification model is solved, the classification ability of the model is improved, and it is suitable for unlabeled data sets.
Patent Information
- Application Number
- CN202411064927.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-08-05
AI Technical Summary
Existing unlabeled image collections suffer from serious category imbalance when selecting samples in class incremental image classification models, which affects model performance.
A deep learning model is used to extract features, a clustering algorithm is used to cluster the samples, and an improved greedy sampling algorithm is used to select samples to ensure that the KL divergence between the distribution of the selected samples and the distribution of all samples in the cluster is minimized to achieve category balance.
By improving the greedy sampling algorithm to select class-balanced samples, the classification ability of the model is improved, and it is suitable for unlabeled data sets, especially for class incremental learning methods based on Vision Transformer and visual cue word fine-tuning.
Smart Images

Figure CN118762230A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image classification for incremental tasks. Background Art
[0002] The incremental image classification problem is a machine learning problem that aims to solve the problem of how to effectively classify all known categories when the model continuously receives new category data. In this problem, the training and test data are divided into several "incremental tasks" in an orderly manner, and the model learns on each task in turn. Each task contains training images of several categories, and the category space of the training images of any two tasks does not overlap. When the model is trained on task t, the training data of tasks 1 to task t-1 cannot be used. After the model is trained on task t, it is hoped that the model has the ability to classify images of all categories contained in tasks 1 to t.
[0003] In the prior art, in each task of the class-incremental image classification problem, the training data is a large number of labeled images. See application number 202311772256.X for details. The subject name is "Small sample class-incremental image classification method based on prompt word fine-tuning and feature replay". In order to reduce the annotation cost of the training data for each task, the active-class incremental image classification problem is proposed. In this problem, the training image of each task is initially unlabeled. It aims to screen out the most valuable training images through the model and feed them back to humans for annotation. Then, the model is trained using the images annotated by humans.
[0004] When the existing class-incremental image classification model is used to screen samples for unlabeled image collections, the mainstream active learning methods (Entropy, CoreSet, etc.) are applied to the class-incremental image classification model based on deep learning models and fine-tuning of visual prompt words, which will cause the samples selected by the class-incremental image classification model to show serious class imbalance. The class-incremental image classification model can be specifically an L2P model or a DualPromp model. Furthermore, using these class-imbalanced samples to train the classification model will damage the model performance, and the above problems need to be solved urgently. Summary of the invention
[0005] The purpose of the present invention is to solve the problem that the existing unlabeled image collection presents serious class imbalance when selecting samples in a class-incremental image classification model based on active learning; the present invention provides an active-class-incremental image classification method and device for achieving class-balanced sampling.
[0006] An active-class incremental image classification method for implementing class-balanced sampling comprises the following steps:
[0007] S1. Obtain unlabeled training sets for all tasks. The unlabeled training sets corresponding to each task include unlabeled images of multiple categories. Each image is used as a sample, and the image categories of different tasks do not overlap.
[0008] S2, the class incremental image classification model loads the given model parameters and locks them. The initial value of t is 1. At this time, the prompt word parameters of the class incremental image classification model are randomly initialized under the current t-th task;
[0009] The class incremental image classification model is composed of a deep learning model and a visual cue word fine-tuning unit, and the model parameters are used to constrain the deep learning model, and the cue word parameters are used to constrain the visual cue word fine-tuning unit;
[0010] S3, using a deep learning model to extract visual features of each sample in the unlabeled training set corresponding to the current task, to obtain a feature set;
[0011] S4. Use the clustering algorithm to cluster the samples in the feature set into several clusters, and use the improved greedy sampling algorithm to select valuable samples from each cluster until all clusters are traversed. The selection principle of the improved greedy sampling algorithm is: Determine the number of samples K to be selected in each cluster c , and ensure that the selected K c The Gaussian distribution of the samples is related to the K c The KL divergence between the Gaussian distributions of all samples in the cluster where the sample is located is the smallest; among them, the selected K c samples are all regarded as valuable samples; K c is the number of samples selected from the cth cluster;
[0012] S5. Determine whether the total number of selected valuable samples corresponding to the current t-th task exceeds the preset total number of samples B. If yes, randomly retain B valuable samples, and after the B valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6; if no, after all the selected valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6;
[0013] S6, let t=t+1, determine whether t is the last task, if yes, complete the training of the class incremental image classification model, and execute step S7, if no, use the prompt word parameters of the class incremental image classification model of the previous task to initialize the prompt word parameters of the current task, and execute step S3;
[0014] S7. Use the trained class-increment image classification model to classify the image to be classified.
[0015] Preferably, in step S4, the number of samples K selected from each cluster is determined c The implementation is:
[0016]
[0017] Among them, M c is the cth cluster G c The total number of samples contained in , N t is the total number of samples in the unlabeled training set corresponding to the t-th task, This is a round-up operation.
[0018] Preferably, in step S4, K is selected c The implementation of the sample is:
[0019] Step S41: Assume that the cth cluster G c All samples in the
[0020] Among them, μ c Cluster G c The mean vector of is a real number space of dimension D×1, Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ;
[0021] i is cluster G c The eigenvector corresponding to the i-th sample in , D is an integer, M c Cluster G c The total number of samples included in ;
[0022] Step S42: From cluster G c The implementation method of selecting the first sample is:
[0023]
[0024] in, Cluster G c The corresponding set of valuable samples, The initial state is an empty set, f selected1 for The first sample in ; ∪ means taking the union;
[0025] Step S43: From cluster G c After selecting the mth sample from in, until The number of samples reaches K c ; m=2,3……K c ;
[0026] The implementation method of selecting the mth sample is:
[0027]
[0028] Among them, f j Difference The feature vector of the jth sample in ;
[0029] for The Gaussian distribution that all samples in the constructed set obey;
[0030] D KL (·|·) means calculating two distributions and The KL divergence between selectedm for The mth sample in .
[0031] Preferably, in step S41,
[0032]
[0033] in, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, f id and μ cd f i and μ c The d-th row element in .
[0034] Preferably,
[0035]
[0036] in,
[0037] Gaussian distribution The mean vector of Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ;
[0038] Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row element of the mean vector, μ cd Gaussian distribution The d-th row element of the mean vector.
[0039] Preferably, the clustering algorithm is implemented using a K-means algorithm.
[0040] Preferably, the class-incremental image classification model is an L2P model or a DualPrompt model.
[0041] Preferably, the deep learning model is a deep learning model based on an attention mechanism.
[0042] Preferably, the given model parameters are parameters that have been trained for the deep learning model.
[0043] An active-class incremental image classification apparatus for implementing class-balanced sampling includes a storage device, a processor, and a computer program stored in the storage device and executable on the processor. The processor executes the computer program to implement the active-class incremental image classification method for implementing class-balanced sampling.
[0044] The beneficial effects brought by the present invention are:
[0045] In a given task, firstly, a deep learning model under given model parameters is used to extract features for each unlabeled sample. Secondly, a clustering algorithm is used to cluster these features into several clusters, each cluster including feature vectors of multiple samples. For each cluster, an improved greedy sampling algorithm designed by the present invention is used to select a batch of samples. The improved greedy sampling algorithm determines whether each sample is worthy of being selected by calculating the distribution of the selected samples and the similarity of the distribution of all samples in the cluster. After the samples of each group are selected, the selected samples of each group are collected as the final set of selected samples. And they are manually annotated with category labels, and the visual cue word fine-tuning unit in the class incremental image classification model is trained under the condition of locking the model parameters to determine the cue word parameters.
[0046] The present invention ensures that the KL divergence between the Gaussian distribution obeyed by the selected samples and the Gaussian distribution obeyed by all samples in the cluster is minimized by improving the greedy sampling algorithm, so that the distribution obeyed by the selected samples is close to the distribution of all samples, thereby achieving category balance in sampling.
[0047] The class balance of training samples will affect the performance of the trained model. The more balanced the training samples are, the higher the performance of the trained model is, and vice versa. The improved greedy sampling algorithm can effectively select class-balanced samples for model training, thereby improving the classification ability of the model. This method is suitable for incremental learning methods such as pre-training Vision Transformer (ViT) and visual prompt tuning, and is suitable for situations where the unlabeled dataset is overall class-balanced. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a flow chart of the active-class incremental image classification method for realizing class balanced sampling described in the present invention. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0051] The present invention is conceived in the process of proposing an active-class incremental image classification method for class-balanced sampling. This method can effectively select class-balanced samples for model training in each task, thereby improving the classification ability of the model. This method is applicable to the class-incremental learning method of the deep learning model (Transformer, ViT for short) based on the attention mechanism and visual prompt word fine-tuning (Viusal Prompt Tuning), and is applicable to the situation where the unlabeled data set presents class balance as a whole.
[0052] Specifically, in a given task, first use the deep learning model in the pre-trained class-incremental image classification model to extract features for each unlabeled sample. Secondly, use the K-means algorithm to cluster these features into several "groups", namely: clusters. For each group, the improved greedy sampling algorithm designed by the present invention is used to select a batch of samples. The greedy sampling algorithm determines whether each sample is worth selecting by calculating the distribution of the selected samples and the similarity of the distribution of all samples in the group. After the samples of each group are selected, the selected samples of each group are collected as the final set of selected samples.
[0053] Based on the above inventive concept, the specific implementation methods provided by the present invention are as follows:
[0054] Specific implementation method 1. Figure 1 The present embodiment is described. The active-class incremental image classification method for realizing class balanced sampling described in the present embodiment comprises the following steps:
[0055] S1. Obtain unlabeled training sets for all tasks. The unlabeled training sets corresponding to each task include unlabeled images of multiple categories. Each image is used as a sample, and the image categories of different tasks do not overlap.
[0056] Specifically, the samples in the unlabeled training set corresponding to each task can be real scene data or business data in the production environment, or public images;
[0057] S2, the class incremental image classification model loads the given model parameters and locks them. The initial value of t is 1. At this time, the prompt word parameters of the class incremental image classification model are randomly initialized under the current t-th task;
[0058] The class incremental image classification model is a deep learning model based on learnable visual cue words; specifically, it is composed of a deep learning model and visual cue word fine-tuning, and the model parameters are used to constrain the deep learning model, and the cue word parameters are used to constrain the visual cue word fine-tuning;
[0059] In specific applications, the incremental image classification model can be an L2P model or a DualPrompt model.
[0060] As an example, the deep learning model may be an attention mechanism-based deep learning model (ViT).
[0061] S3, using a deep learning model to extract visual features of each sample in the unlabeled training set corresponding to the current task, to obtain a feature set;
[0062] S4. Use the clustering algorithm to cluster the samples in the feature set into several clusters, and use the improved greedy sampling algorithm to select valuable samples from each cluster until all clusters are traversed. The selection principle of the improved greedy sampling algorithm is: Determine the number of samples K to be selected in each cluster c , and ensure that the selected K c The Gaussian distribution of the samples is related to the K c The KL divergence between the Gaussian distributions of all samples in the cluster where the sample is located is the smallest; among them, the selected K c samples are all regarded as valuable samples; K c is the number of samples selected from the cth cluster;
[0063] The clustering algorithm clusters samples into several clusters. The number of categories in each cluster is unknown, so it provides an effective data basis for improving the greedy sampling algorithm to balance the selection of valuable samples.
[0064] In the above steps, the number of samples K selected in each cluster is first determined c , and then use the improved greedy sampling algorithm to determine whether each sample is worth selecting by calculating the distribution of the selected samples and the similarity of the distribution of all samples in this cluster.
[0065] Empirically, K c The value of G c The ratio of the number of samples in the training set to the number of samples in the current task is determined by the ratio of the number of samples in the training set to the number of samples in the current task. Specifically, the number of samples K selected in each cluster is determined as the optimal method. c The implementation is:
[0066]
[0067] Among them, M c is the cth cluster G c The total number of samples contained in , N t is the total number of samples in the unlabeled training set corresponding to the t-th task, This is a round-up operation.
[0068] Furthermore, as a preferred method, in step S4, K is selected c The implementation of the sample is:
[0069] Step S41: Assume that the cth cluster G c All samples in the
[0070] Among them, μ c Cluster G c The mean vector of is a real number space of dimension D×1, Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ;
[0071] f i Cluster G c The eigenvector corresponding to the i-th sample in , D is an integer, M c Cluster G c The total number of samples included in ;
[0072] Furthermore, μ is given c and The specific expression of
[0073]
[0074] in, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, f id and μ cd f i and μ c The d-th row element in .
[0075] In this preferred method, μ c and The specific expression of effectively describes the distribution of samples with less computation.
[0076] Step S42: From cluster G c The implementation method of selecting the first sample is:
[0077]
[0078] in, Cluster G c The corresponding set of valuable samples, The initial state is an empty set, F selected1 for The first sample in ; ∪ means taking the union;
[0079] Step S43: From cluster G c After selecting the mth sample from In, until The number of samples reaches K c ; m=2,3……K c ;
[0080] The implementation method of selecting the mth sample is:
[0081]
[0082] Among them, f j Difference The feature vector of the jth sample in j} is due to f j The set of components;
[0083] for The Gaussian distribution that all samples in the constructed set obey;
[0084] D KL (·|·) means calculating two distributions and The KL divergence between selectedm for The mth sample in .
[0085] Whether each sample is worthy of being selected is determined by calculating the similarity between the distribution of the selected samples and the distribution of all samples in the cluster.
[0086] By ensuring that the KL divergence between the Gaussian distribution obeyed by the selected sample and the Gaussian distribution obeyed by the overall sample in the cluster is minimized, the distribution obeyed by the selected sample can be made close to the distribution of the overall sample, thereby achieving a balanced sampling category. The present invention is applicable to the case where the unlabeled data set presents a balanced category as a whole.
[0087] More specific Defined as a Gaussian distribution And gives a Gaussian distribution The specific expression of:
[0088]
[0089] Among them, Gaussian distribution Likewise The Gaussian distribution that all samples in the constructed set obey;
[0090] Gaussian distribution The mean vector of Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ;
[0091] Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row element of the mean vector, μ cd Gaussian distribution The d-th row element of the mean vector.
[0092] The above process specifically gives two distributions and The specific expression of the KL divergence between , accurately calculates the difference between the two distributions.
[0093] S5. Determine whether the total number of selected valuable samples corresponding to the current t-th task exceeds the preset total number of samples B. If yes, randomly retain B valuable samples, and after the B valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6; if no, after all the selected valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6;
[0094] Specifically, the process of labeling the categories of all the selected valuable samples is to manually label them and then return them to the model;
[0095] S6, let t=t+1, determine whether t is the last task, if yes, complete the training of the class incremental image classification model, and execute step S7, if no, use the prompt word parameters of the class incremental image classification model of the previous task to initialize the prompt word parameters of the current task, and execute step S3;
[0096] S7. Use the trained class-increment image classification model to classify the image to be classified.
[0097] In specific applications, the clustering algorithm is implemented using the K-means algorithm, and the given model parameters are the parameters trained for the deep learning model.
[0098] The process of training the class-incremental image classification model using the labeled samples can be achieved through existing technologies, and the given model parameters are locked during the training process, wherein the given model parameters are parameters that have been trained for the deep learning model. The process of training the class-incremental image classification model using the labeled samples is mainly to train the visual cue word fine-tuning unit in the class-incremental image classification model. Since the given model parameters have been locked, they are mainly trained to determine the cue word parameters of the deep learning model.
[0099] The active-class incremental image classification method for achieving class-balanced sampling described in this embodiment can effectively select class-balanced samples for model training through an improved greedy sampling algorithm, thereby improving the classification ability of the model. This method is applicable to the class-incremental learning method of deep learning models and visual prompt word fine-tuning (Viusal Prompt Tuning) after training, and is applicable to the situation where the unlabeled data set presents a class balance as a whole. An improved greedy sampling algorithm is used to select a batch of samples. The improved greedy sampling algorithm determines whether each sample is worth selecting by calculating the distribution of the selected samples and the similarity of the distribution of all samples in the cluster. It avoids the phenomenon that the samples selected by the model present serious class imbalance.
[0100] Specific implementation method 2: An active-class incremental image classification device that implements class-balanced sampling includes a storage device, a processor, and a computer program stored in the storage device and executable on the processor. The processor executes the computer program to implement the active-class incremental image classification method that implements class-balanced sampling as described above.
[0101] Although the present invention is described herein with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the present invention. It should therefore be understood that many modifications may be made to the exemplary embodiments and that other arrangements may be devised without departing from the spirit and scope of the present invention as defined by the appended claims. It should be understood that the various dependent claims and features described herein may be combined in a manner different from that described in the original claims. It should also be understood that features described in conjunction with individual embodiments may be used in other described embodiments.
Claims
1. An active-class incremental image classification method for achieving class-balanced sampling, characterized in that: The method comprises the following steps: S1. Obtain unlabeled training sets for all tasks. The unlabeled training sets corresponding to each task include unlabeled images of multiple categories. Each image is used as a sample, and the image categories of different tasks do not overlap. S2, the class incremental image classification model loads the given model parameters and locks them. The initial value of t is 1. At this time, the prompt word parameters of the class incremental image classification model are randomly initialized under the current t-th task; The class incremental image classification model is composed of a deep learning model and a visual cue word fine-tuning unit, and the model parameters are used to constrain the deep learning model, and the cue word parameters are used to constrain the visual cue word fine-tuning unit; S3, using a deep learning model to extract visual features of each sample in the unlabeled training set corresponding to the current task, to obtain a feature set; S4. Use the clustering algorithm to cluster the samples in the feature set into several clusters, and use the improved greedy sampling algorithm to select valuable samples from each cluster until all clusters are traversed. The selection principle of the improved greedy sampling algorithm is: Determine the number of samples K to be selected in each cluster c , and ensure that the selected K c The Gaussian distribution of the samples is related to the K c The KL divergence between the Gaussian distributions of all samples in the cluster where the sample is located is the smallest; among them, the selected K c samples are all regarded as valuable samples; K c is the number of samples selected from the cth cluster; S5. Determine whether the total number of selected valuable samples corresponding to the current t-th task exceeds the preset total number of samples B. If yes, randomly retain B valuable samples, and after the B valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6; if no, after all the selected valuable samples are labeled by category, continue to lock the given model parameters, and use the labeled samples to train the visual cue word fine-tuning unit in the class incremental image classification model, so as to determine the cue word parameters of the class incremental image classification model, and execute step S6; S6, let t=t+1, determine whether t is the last task, if yes, complete the training of the class incremental image classification model, and execute step S7, if no, use the prompt word parameters of the class incremental image classification model of the previous task to initialize the prompt word parameters of the current task, and execute step S3; S7. Use the trained class-increment image classification model to classify the image to be classified.
2. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: In step S4, the number of samples K selected from each cluster is determined c The implementation is: Among them, M c is the cth cluster G c The total number of samples contained in , N t is the total number of samples in the unlabeled training set corresponding to the t-th task, This is a round-up operation.
3. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: In step S4, K is selected c The implementation of the sample is: Step S41: Assume that the cth cluster G c All samples in the Among them, μ c Cluster G c The mean vector of is a real number space of dimension D×1, Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ; f i Cluster G c The eigenvector corresponding to the i-th sample in , D is an integer, M c Cluster G c The total number of samples included in ; Step S42: From cluster G c The implementation method of selecting the first sample is: in, Cluster G c The corresponding set of valuable samples, The initial state is an empty set, f selected1 for The first sample in ; ∪ means taking the union; Step S43: From cluster G c After selecting the mth sample from In, until The number of samples reaches K c ; m=2,3……K c ; The implementation method of selecting the mth sample is: Among them, f j Difference The feature vector of the jth sample in ; for The Gaussian distribution that all samples in the constructed set obey; D KL (·|·) means calculating two distributions and The KL divergence between selectedm for The mth sample in .
4. The active-class incremental image classification method for achieving class balanced sampling according to claim 3, characterized in that: In step S41, in, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, f id and μ cd f i and μ c The d-th row element in .
5. The active-class incremental image classification method for achieving class balanced sampling according to claim 3, characterized in that: in, Gaussian distribution The mean vector of Gaussian distribution The vector of diagonal elements of the covariance diagonal matrix of ; Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row and d-th column element on the diagonal of the covariance diagonal matrix, Gaussian distribution The d-th row element of the mean vector, μ cd Gaussian distribution The d-th row element of the mean vector.
6. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: The clustering algorithm is implemented using the K-means algorithm.
7. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: The class-incremental image classification model is either the L2P model or the DualPrompt model.
8. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: The deep learning model is a deep learning model based on the attention mechanism.
9. The active-class incremental image classification method for achieving class balanced sampling according to claim 1, characterized in that: The given model parameters are the parameters that have been trained for the deep learning model.
10. An active-class incremental image classification device for class-balanced sampling, comprising a storage device, a processor, and a computer program stored in the storage device and executable on the processor, characterized in that: The processor executes the computer program to implement the active-class incremental image classification method for class balanced sampling as claimed in any one of claims 1 to 9.
Citation Information
Patent Citations
Class increment image classification method based on unbalanced modeling
CN116229186A
Semi-supervised learning active method based on image key data extraction
CN116863195A
Small sample class increment image classification method based on cue word fine tuning and feature playback
CN117746140A
