A class-incremental image classification method based on virtual feature generation and replay
Through the method of virtual feature generation and replay, the pre-trained CLIP model and Transformer architecture are used to solve the problem of low semantic space utilization and forgetting in the visual-language model, and significantly improve the accuracy of class incremental image classification, which is better than Performance of existing methods on ImageNet100 and CIFAR100 datasets.
Patent Information
- Application Number
- CN202410740618.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-09
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-06-09
AI Technical Summary
The existing incremental image classification methods based on visual-language models have low utilization of semantic space, serious forgetting problems, and classification accuracy needs to be improved.
A class-incremental image classification method based on virtual feature generation and replay is adopted. By constructing a text prompt building module, a text feature extraction module, an image feature extraction module, a virtual feature generation module and a virtual feature replay module, the pre-trained CLIP model is used and Transformer architecture, which generates and replays virtual features to enhance data diversity and prevent forgetting.
It significantly improves the accuracy of class incremental image classification, is suitable for most large model-based class incremental image classification tasks, and shows better performance than iCaRL, ContinualCLIP, and CoOp in experiments on ImageNet100 and CIFAR100 data sets.
Smart Images

Figure CN118506101B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of class incremental image classification, and in particular to a method for improving the accuracy of class incremental image classification. Background Art
[0002] With the rapid development of the Internet and big data technology, machine learning algorithms have been widely used in many fields. However, traditional machine learning algorithms often require a large amount of labeled data for training, which is unrealistic in some scenarios. For example, in some scenarios that require real-time updates, such as stock market analysis, network security detection, etc., traditional machine learning algorithms need to be retrained regularly to adapt to the new data distribution, which undoubtedly increases the computational cost and time cost. In order to solve this problem, Class-Incremental Image Classification came into being. Class-Incremental Image Classification aims to classify only the categories involved in the new data after obtaining new data, without retraining the original data. This method greatly reduces the amount of computation and time cost and improves the real-time update capability of the model.
[0003] Class-incremental image classification encounters a major challenge: the process of learning new categories often overwrites previously acquired knowledge, leading to catastrophic forgetting. Common class-incremental image classification methods can be roughly divided into three categories: regularization-based methods, architecture-based methods, and replay-based methods. Regularization-based methods use regularization terms to prevent the drift of key parameters during model updates, thereby retaining previous knowledge. Architecture-based methods focus on modifying the network architecture, such as expanding the network architecture, adopting different expert networks, and dynamically expanding network parameters to alleviate forgetting. Replay-based methods use an external memory buffer to retain a set of examples from previous tasks. During the learning of subsequent tasks, the model can review the stored samples to consolidate existing knowledge. Among these methods, replay-based methods have shown better performance.
[0004] An emerging trend in class-incremental image classification is to use pre-trained models, such as the Vision Transformer (ViT) pre-trained on the ImageNet dataset, to leverage the common features and knowledge that these models have learned to improve the ability to learn new tasks. Furthermore, vision-language large models are pre-trained with a large number of image-text pairs, and have strong zero-shot and inductive capabilities. CLIP (see the paper "Alec Radford, et al. Learning transferable visual models from natural language supervision. International conference on machine learning. PMLR, 2021." Alec Radford et al.'s paper: Learning transferable visual models from natural language supervision) is a classic vision-language large model that collects 400 million image-text pairs from the Internet as a training set and trains the model on the ResNet series and ViT (Vision Transformer) series neural networks to obtain a pre-trained model with strong zero-shot and inductive capabilities. Research on class-incremental image classification using CLIP has shown great potential.
[0005] Reference "Rebuffi, Sylvestre-Alvise, et al. iCaRL Incremental classifier and representation learning. Proceedings of the IEEE conference on Computer Vision and Pattern Recognition. 2017." Rebuffi, Sylvestre-Alvise et al.'s paper: iCaRL: Incremental classifier and representation learning builds a memory that can save previous category samples and uses replay to alleviate catastrophic forgetting. Reference "Thengane V, Khan S, Hayat M, et al. Clip model is an efficient continual learner [J]. arXiv preprint arXiv: 2210.03114, 2022." Thengane V et al.'s paper: The CLIP model is an efficient continuous learner (Continual CLIP) for the first time to apply CLIP to incremental learning without adding additional training parameters. The pre-trained CLIP has shown excellent incremental learning capabilities, but the accuracy of each incremental stage is not high enough, and the semantic space utilization is low and catastrophic forgetting is still serious. Literature "Runqi Wang etal.AttriCLIP:A Non-Incremental Learner for Incremental Knowledge Learning[A].2023IEEE / CVF Conference on Computer Vision and Pattern Recognition(CVPR)[C],2023" "The paper by Runqi Wang et al.: AttriCLIP: A Non-Incremental Learner for Incremental Knowledge Learning (AttriCLIP) fixes the image encoder and text encoder of CLIP to extract features from images and text. A module called attribute vocabulary is designed to store the attributes of images and their descriptive words. During training, AttriCLIP adds a set of learnable parameters to the text, which select the most similar attributes from the attribute vocabulary to prevent catastrophic forgetting.
[0006] The above two class-incremental image classification methods based on the vision-language large model both utilize the powerful feature extraction and generalization capabilities of the vision-language large model, but these methods simply add CLIP and the class-incremental image classification method, and cannot fully utilize the semantic space that CLIP has constructed. Therefore, there is still room for improvement in the accuracy of class-incremental image classification.
[0007] How to improve the accuracy of class incremental image classification remains a technical issue of great concern to those skilled in the art. Summary of the invention
[0008] The technical problem to be solved by the present invention is to propose a class incremental image classification method based on virtual feature generation and replay in view of the problems that the existing class incremental image classification method based on visual-language model has low utilization of semantic space, serious forgetting problem, and classification accuracy needs to be improved. By introducing virtual features and using feature generation and replay technology, the problems of low utilization of semantic space and serious catastrophic forgetting can be alleviated, and the accuracy of image classification can be improved.
[0009] In order to solve the above technical problems, the technical solution of the present invention is: construct a class incremental image classification system based on virtual feature generation and replay. The system consists of a text prompt construction module, a text feature extraction module, an image feature extraction module, a virtual feature generation module, a virtual feature replay module and a main task module. Prepare and construct the data set required for the class incremental image classification system, and divide the data set into a training set, a verification set and a test set. Use the training set to train the text prompt construction module in the class incremental image classification system to obtain a more robust trained class incremental image classification system. Use the verification set to verify the trained class incremental image classification system, assign the weight parameters containing the best text prompts to the trainable module (text prompt construction module) in the class incremental image classification system, and obtain the best trained class incremental image classification system; finally, use the best trained class incremental image classification system to classify the image input by the user to obtain the category of the image.
[0010] The present invention comprises the following steps:
[0011] The first step is to build a class-incremental image classification system based on virtual feature generation and replay. Figure 2 As shown, the class-incremental image classification system consists of a text prompt construction module, a text feature extraction module, an image feature extraction module, a virtual feature generation module, a virtual feature replay module and a main task module.
[0012] The text prompt construction module is connected to the text feature extraction module. The text prompt construction module uses a set of learnable vectors and category names to construct text prompts, obtains a text prompt list related to the category, and sends the constructed text prompt list to the text feature extraction module.
[0013] The text feature extraction module is connected to the text prompt construction module and the main task module. The text feature extraction module extracts features from the text prompt list received from the text prompt construction module, obtains text prompt features, and sends the text prompt features to the main task module. The text feature extraction module adopts the Transformer architecture, and its parameters adopt the parameters pre-trained in the Transformer architecture by CLIP (see the document "Alec Radford, et al. Learning transferable visual models from natural language supervision. International conference on machine learning. PMLR, 2021." Alec Radford et al.'s paper: Learning transferable visual models from natural language supervision). The Transformer architecture mainly consists of two parts: the encoder and the decoder. The encoder is used to understand the input text prompt and obtain context information, while the decoder is used to generate an output sequence based on the context information received from the encoder. Both the encoder and the decoder are stacked by multiple identical layers, usually 6 layers. Each layer contains two sub-layers: one is a multi-head self-attention module, which uses a self-attention mechanism to allow the model to simultaneously focus on other elements in the sequence when processing an element of a sequence, thereby capturing the dependencies between them. The other is the fully connected layer, and the multi-head self-attention module and the fully connected layer are connected through residual connections. The Transformer architecture can capture the dependencies between different positions in the text prompt and obtain global context information, making it particularly effective in semantic feature extraction. In addition, the multi-head self-attention module of the Transformer architecture allows the Transformer to perform attention calculations between inputs at different positions, which can be easily parallelized and improve computational efficiency.
[0014] The image feature extraction module is connected to the virtual feature generation module, the virtual feature replay module and the main task module. During training, the image feature extraction module extracts the image features of the training set and sends the image features of the training set to the virtual feature generation module to generate virtual features of new categories and enhance the diversity of existing data; at the same time, the image features of the training set are sent to the virtual feature replay module. During verification, the image feature extraction module extracts the image features of the verification set and sends the image features of the verification set to the main task module; when classifying the image to be classified input by the user, the image features to be classified input by the user are sent to the main task module. The image feature extraction module adopts ResNet (see the document "Kaiming He, et al. Deep Residual Learning for Image Recognition [J]. Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 770-778" Kaiming He et al.'s paper: Deep residual learning for image recognition) network or ViT (Vision Transformer) (see the document "Dosovitskiy Alexey, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv: 2010.11929 (2020)." Dosovitskiy Alexey et al.'s paper: An image is worth 16x16 words: Transformers for image recognition at scale) network, both of which can effectively extract image features. The ResNet network is constructed by stacking a series of residual blocks, which are composed of convolutional layers and normalization layers. Depending on the depth of the network, variants of the ResNet network (such as ResNet50, ResNet101, and other networks) are often used in specific applications; the core idea of the ViT network is to divide the image into a series of small patches, and then treat these small patches as sequence data and process them through the Transformer model. In specific applications, variants of the ViT network such as ViT-B / 32, ViT-B / 16, and ViT-L / 14 are often used. The ResNet network has smaller parameters, shorter training time, and better feature extraction capabilities; the ViT network has more parameters, longer training time, and better feature extraction capabilities.In the present invention, according to specific scenarios and requirements, any one of the networks including ResNet50, ResNet101, ViT-B / 32, ViT-B / 16 and ViT-L / 14 (variant models of ViT, ViT-B represents the base model, ViT-L represents the Large model; 16 represents that the input is a small block of 16×16 pixels) trained on 400 million image-text pairs can be used as an image feature extraction module.
[0015] The virtual feature generation module is connected to the image feature extraction module and the main task module. Its function is to use the training set image features received from the image feature extraction module to generate new types of virtual features, including virtual in-group values and virtual outliers, and send the new types of virtual features to the main task module.
[0016] The virtual feature replay module is connected to the image feature extraction module and the main task module. Its function is to receive the training set image features from the image feature extraction module and estimate the training set list D′ based on the training set image features. train The Gaussian distribution of each category in the feature level; for each category, the virtual feature generation module randomly samples an old category virtual feature from the feature-level Gaussian distribution (i.e., replays the virtual feature of the old category) and sends the old category virtual feature to the main task module. Sampling virtual features from the feature-level Gaussian distribution for replay can prevent catastrophic forgetting.
[0017] The main task module is connected to the text feature extraction module, the image feature extraction module, the virtual feature generation module and the virtual feature replay module. It receives the text prompt feature from the text feature extraction module. During training, it receives the training set image features from the image feature extraction module, receives the new class virtual features from the virtual feature generation module, and receives the old class virtual features from the virtual feature replay module. It uses the similarity between the above image features (training set image features, new class virtual features, old class virtual features) and the text prompt feature to complete the classification and obtain the category of the image. During verification, the text prompt feature is verified using the verification set image feature to obtain the optimal text prompt feature. When classifying the image to be classified input by the user, the features of the image to be classified input by the user are received from the image feature extraction module, and the image is classified using the optimal text prompt feature to obtain the classification result.
[0018] The second step is to construct the training set, validation set, and test set by:
[0019] 2.1 Collect class-incremental image classification scene images as class-incremental image classification scene dataset, the method is:
[0020] We use two datasets, ImageNet100 (a subset of ImageNet, see the paper "Jia Deng, et al. ImageNet: A Large-Scale Hierarchical Image Database [A]. 2009 IEEE Conference on Computer Vision and Pattern Recognition [C], 2009" Jia Deng et al.: ImageNet: A Large-Scale Hierarchical Image Database) and CIFAR100 (see the paper "Krizhevsky, Alex, and Geoffrey Hinton. Learning multiple layers of features from tiny images. (2009): 7." Krizhevsky, Alex et al.: Learning multiple layers of features from tiny images) as class-incremental image classification scene datasets. Each image in these two datasets is manually annotated, that is, each image is annotated with the category of the object and its corresponding true label.
[0021] 2.2 According to the dataset partition file commonly used by researchers (i.e., the partition file included in the dataset file), the incremental image classification dataset is divided into training set D train , test set D test , validation set D val , let the total number of categories in the data set be C, and each image has its corresponding category label (usually [1,2,…,C]). In the field of incremental image classification, the training process is divided into T (T is a positive integer, generally 10) training stages to simulate the process of increasing data. During training, usually only the training data of the current stage can be used, and a small amount of training data from the previous stage can be saved. Therefore, the training set D needs to be train Divide again according to the training stage to get the training set list is the sub-training set for the t-th training stage, and the method is:
[0022] 2.2.1 Let the number of elements in the training set of each category be N ptrain Zhang, the number of elements in the test set N ptest Zhang, for stage t(t∈[1,2,…,T]), the number of categories N contained in the tth stage t = C / T, the category label set I contained in the tth stage t =N t *(t-1)+1,…,N t *t](For example: for stage 1, the category label set I contained in stage 11 = [1, 2, ..., N t );
[0023] 2.2.2 Let the stage \(t = 1\);
[0024] 2.2.3 Find the images in the training set \(D\) train that belong to \(I\) t (i.e., find the images that are the same as \(I\) according to the labels in the training set), and add the images in the training set \(D\) t that belong to \(I\) traIn to t ; ;
[0025] 2.2.4 If \(t < T\), let \(t=t + 1\), and go to step 2.2.3; if \(t\geq T\), obtain the training set list \(D'\) traIn , and go to step 2.3;
[0026] 2.3 Let the number of elements in the test set for each category be \(N\) ptest sheets. In the field of class-incremental image classification, during testing, the test set for each stage should include the categories of the current and previous stages. Therefore, the test set \(D\) test needs to be re-partitioned according to the training stage to obtain the test set list as the sub-test set for the \(t\)-th training stage. The method is as follows:
[0027] 2.3.1 Let the stage \(t = 1\),
[0028] 2.3.2 Find the images in the test set \(D\) test that belong to \(I\) 1 \(\cup I\) 2 \(\cup\cdots\cup I\) t (i.e., find the images that are the same as \(I\) \(\cup I\) test \(\cup\cdots\cup I\) 1 \(\cup\cdots\cup I\) 2 \(\cup\cdots\cup I\) t in the test set \(D\) according to the labels), and add these images to ;
[0029] 2.3.3 If \(t < T\), let \(t=t + 1\), and go to step 2.3.2; if \(t\geq T\), obtain the final test set list \(D'\) test , and go to step 2.3.4;
[0030] 2.3.4 The validation set list \(D\) val adopts the same list as the test set, i.e., \(D\) val = \(D'\) test .
[0031] In the third step, the gradient back propagation method is used to train the class incremental image classification system based on virtual feature generation and replay constructed in the first step to obtain N m model parameters, N m is the number of training steps that need to be saved. The method is:
[0032] 3.1 Initialize the model parameters of each module in the incremental image classification system. Use the pre-trained model CLIP to initialize the parameters of the Transformer framework in the text feature extraction module and the parameters of ResNet or ViT in the image feature extraction module;
[0033] 3.2 Let stage t = 1;
[0034] 3.3 For stage t, the category label sequence of text prompts to be constructed is: [1,2,...,n,…,N t *t], the text prompt building module initializes the text prompt and obtains the text prompt list L of the tth stage t , n is the category label number, 1≤n≤N t *t, the method is:
[0035] 3.3.1 Let n = 1, initialize the text prompt list L of the tth stage t =[];
[0036] 3.3.2 Let m = 1;
[0037] 3.3.3 Use the prompt construction method in CoOp (see the literature "KaiyangZhou, et al. "Learning to prompt for vision-language models." International Journal of Computer Vision 130.9 (2022): 2337-2348." KaiyangZhou et al.'s paper: Learning prompt visual language model) to construct the text prompt P of the nth category n , as shown in formula (1):
[0038] P n =[V] 1 [V] 2 ...[V] m ...[V] M [CLASS] Formula (1)
[0039] Among them, [V] 1 [V] 2 …[V] m …[V] M As a trainable text hint parameter WP , [V] m is the m-th learnable vector, which is a vector with a dimension of 512; "[CLASS]" represents the class name. M is the number of learnable vectors (M is a positive integer, usually set to 16).
[0040] 3.3.4 For the m-th learnable vector "[V] m ", initialize each dimension of [V] m by using random initialization (mean is 0, standard deviation is 0.02);
[0041] 3.3.5 If m < M, let m = m + 1, and go to 3.3.3; if m ≥ M, for [V] 1 [V] 2 …[V] m …[V] M the initialization is completed, and go to 3.3.6;
[0042] 3.3.6 Replace "CLASS" in formula (1) with the class name class corresponding to n, and use the tokenize method of CLIP to convert class n into a sequence of tokens (a vector with a dimension of 512); at this time, the initialization of M learnable vectors is completed, and [V] n …[V] 1 [V] 2 …[V] m …[V] M are concatenated with the sequence of tokens to obtain the learnable text prompt P n for the n-th class, and add P n to L t .
[0043] 3.3.7 If n < N t *t (in incremental learning, all classes seen in the t-th stage need to be tested, so N t *t text prompts need to be constructed), let n = n + 1, and go to 3.3.2; if n ≥ N t *t, it means that the text prompts L t for all classes in the t-th stage have been constructed, and the text prompt list L t for the t-th stage is obtained, and go to 3.3.8;
[0044] 3.3.8 Send the text prompt list L t for the t-th stage to the text feature extraction module, and go to 3.4;
[0045] 3.3.9 The text prompt construction module loads the text prompt parameters W P saved in the t - 1 stage, that is, [V]1 [V] 2 …[V] m …[V] M , let n = 1, go to 3.3.6;
[0046] 3.4 Set the training parameters of the incremental image classification system. Set the initial learning rate learning_rate to 0.002, and set the learning rate adjustment function to the cosine annealing (Cosine Annealing) dynamic learning rate adjustment function. Select stochastic gradient descent (SGD) as the model training optimizer. Set the batch size (mini_batch_size) of network training to 100. The maximum training step (maxepoch) is 50.
[0047] 3.5 Text feature extraction module uses Transformer network to extract L t The text hint feature F T (is a two-dimensional matrix with dimension (N t *t,D), D is the feature dimension, which is a positive integer), T Send to the main task module;
[0048] 3.6 Let the number of training rounds epoch = 1;
[0049] 3.7 Let batch number b = 1, indicating the bth image batch, each batch has B = 256 images, and the total number of batches is N B , N train is the number of images in the training set;
[0050] 3.8 Image feature extraction module from the training set list D′ train Take out the training set of stage t from Read the B images of the b-th batch and record the B images of the b-th batch as matrix I train , I train It contains B H×W×3 images. H represents the height of the input image, W represents the width of the input image, and “3” represents the RGB channels of the image.
[0051] 3.9 Image feature extraction module uses ResNet or ViT to extract I train The image features f of B images in v (is a two-dimensional matrix with dimensions (B, D), where D is the feature dimension), and the image feature f v Send to the virtual feature generation module, the virtual feature replay module and the main task module;
[0052] 3.10 The virtual feature generation module receives the image feature f from the image feature extraction module v , according to the category label sequence [N t *(t-1)+1,…c,…,N t *t], for the feature space composed of features with category label c in stage t The k-nearest neighbor algorithm k-NN is used to select boundary samples. According to the boundary sample points, is the number of training sets for categories with category label c, generating virtual in-group points and virtual outliers, The method is:
[0053] 3.10.1 Let class label c = N t *(t-1)+1, initialize the virtual cluster point set F P = [], initialize the virtual outlier set F Q =[];
[0054] 3.10.2 Set variable i = 1, initialize k-NN distance list Dis = [];
[0055] 3.10.3 For The i-th image feature f i , use formula (2) to calculate the k-NN distance
[0056]
[0057] in,‖·‖ 2 Indicates calculating the Euclidean distance between two vectors, f (k) It is the feature space The kth hyperparameter in is set according to the number of training samples in each category (f (k) =N ptrain *0.1); Add to the k-NN distance list Dis c ;
[0058] 3.10.4 If Let i = i + 1, go to 3.10.3; if Explanation: For the same category of N ptrain The k-NN distance list Dis of samples c Calculation is complete, go to 3.10.5;
[0059] 3.10.5 Dis based on k-NN distance c , the virtual feature generation module selects B features with the largest k-NN distance from Dis as boundary samples, and uses represents the set of boundary samples, h(xb ) represents the b-th boundary sample, 1≤b≤B;
[0060] 3.10.6 Let b = 1;
[0061] 3.10.7 Virtual feature generation module from around h(x b ) is sampled from the multivariate Gaussian distribution to synthesize virtual in-group points and virtual outliers, where the virtual in-group points refer to the points f v Virtual features with consistent distribution, virtual outliers refer to f v The distribution of the virtual features is inconsistent, around h(x b ) is shown in formula (3):
[0062] v~N(h(x b ),σ 2 I) Formula (3)
[0063] Where v represents the sample h(x b ) generated virtual features, σ 2 is the adjustment variance;
[0064] 3.10.8 For boundary samples h(x b ), the variance σ 2 Set to 0.1, the virtual feature generation module uses formula (3) to sample p virtual features as boundary samples h(x b ) corresponds to the virtual point in the group As positive samples to enhance the diversity of existing data, Join to the virtual cluster point set F Q ; p is a hyperparameter, a positive integer, is a two-dimensional matrix with dimension (p,D);
[0065] 3.10.9 For boundary samples h(x b ), the variance σ 2 Set to 50, the virtual feature generation module uses formula (3) to sample q features, and a total of q virtual features are sampled as boundary samples h(x b ) corresponds to the virtual outlier point The virtual outliers with the highest k-NN distance are selected for filtering. As negative samples, to shrink the classification boundary, the virtual feature generation module will Add to the virtual outlier set F Q ; q is a hyperparameter, which is a positive integer, is a two-dimensional matrix with dimension (q,D);
[0066] 3.10.10 If b < B, let b = b + 1, and go to 3.10.7; if b ≥ B, it means that the virtual inliers and virtual outliers have been generated based on the B boundary points of the c-th category, and go to 3.10.11;
[0067] 3.10.11 If c < N t *t, let c = c + 1, and go to 3.10.2; if c ≥ N t *t, it means that the virtual inlier set F t corresponding to N P categories and the virtual outlier set F Q have been generated, and go to 3.10.12;
[0068] 3.10.12 The virtual feature module sends F P and F Q as the virtual features of the new class to the main task module;
[0069] 3.11 The virtual feature replay module receives the image feature f v from the image feature extraction module, and according to the class label sequence [N t *(t - 1) + 1,..., c,..., N t *t] in the t-th stage, statistically analyzes the features of the class with class label c in f v as a Gaussian distribution Each feature dimension is approximately independently distributed, where μ c represents the mean vector of the Gaussian distribution, represents the covariance matrix, is the covariance of the c-th class corresponding to dimension d. Formulas (4) and (5) are used to estimate μ c and
[0070]
[0071] f id is the feature value of the d-th dimension of the i-th image feature f i , saves the mean of each class to the mean list μ, and saves the covariance of the c-th class corresponding to dimension d to the covariance matrix corresponding to class c for sampling in subsequent stages. The method is as follows:
[0072] 3.11.1 Let the class c = N t *(t - 1) + 1, initialize the mean list μ = [], and initialize the covariance list σ 2 = [];
[0073] 3.11.2 Calculate the mean μ c corresponding to class c using formula (4), and add μc Add the mean list μ;
[0074] 3.11.3 Let the dimension d = 1; Initialize the covariance matrix corresponding to class c
[0075] 3.11.4 Calculate the covariance of the c-th class corresponding to dimension d using formula (5) Put into
[0076] 3.11.5 If d < D, let d = d + 1, go to 3.11.4; If d ≥ D, it means that the covariance matrix corresponding to class c has been calculated, go to 3.11.6;
[0077] 3.11.6 Put into the covariance list σ 2 ;
[0078] 3.11.7 If c < N t *t, let c = c + 1, go to 3.11.2; If c ≥ N t *t, it means that the means of all classes have been saved to μ, and the variances have been saved to go to 3.12;
[0079] 3.12 If t = 1, directly go to 3.13; If t > 1, the virtual feature replay module randomly selects O (hyperparameter, set to 8) classes from the classes before stage t (i.e., the classes whose class labels belong to [1,…,N t *(t - 1)]), and then randomly selects a virtual feature from the feature distributions of the O classes to obtain the old-class virtual feature list F o . is the mean vector of the Gaussian distribution corresponding to class o, is the covariance matrix corresponding to class o, and is used to replay the features of previous classes to reduce forgetting, as follows:
[0080] 3.12.1 Randomly select O labels from the class labels [1,N t *(t - 1)], denoted as the label set C O , C O = [c 1 ,…c o ,…c o ;
[0081] 3.12.2 Let o = 1, initialize the old-class virtual feature list F o = [];
[0082] 3.12.3 Find the feature distribution corresponding to the class label that is consistent with c among the class labels saved in step 3.11.7 o From Randomly select a virtual feature and add it to F ; ; o ;
[0083] 3.12.4 If o < O, let o = o + 1, and go to 3.13.3; if o ≥ O, it means that the old-class virtual feature list F o is constructed, and go to 3.13.5;
[0084] 3.12.5 Send F o to the main task module;
[0085] 3.13 The main task module receives the image feature f from the image feature extraction module v , receives F P and F Q from the virtual feature generation module, receives F o from the virtual feature replay module, and receives the text prompt feature F T from the text feature extraction module.
[0086] 3.14 The main task module constructs the loss function of the original image feature Construct the loss function of the virtual inlier image feature Construct the loss function of the virtual outlier image feature The loss function of the old-class virtual feature
[0087] 3.15 Construct the final loss function L as shown in formula (6):
[0088]
[0089] where λ in , λ out , λ o are the proportionality coefficients for adjusting the loss functions L in , L out , L o respectively, and are set to 0.1, 0.1, 2;
[0090] 3.16 Calculate formula (6) to obtain the final loss value Loss, and use the gradient backpropagation method to optimize the parameters of the text prompt construction module;
[0091] 3.17 If epoch ≤ maxepoch, go to 3.5; if epoch > maxepoch, it means that the training of the epoch-th round is over, and go to 3.18;
[0092] 3.18 Save the text prompt parameter weight W of the last epoch P If t < T, let t = t + 1, and go to 3.3.9; if t ≥ T, it means that the training of T stages has ended, and go to 3.19;
[0093] 3.19 Save the text prompt parameter weights of the last N m (Hyperparameter, set to 10) epochs.
[0094] In the fourth step, use the validation set to verify the detection accuracy of the class-incremental image classification system loaded with the text prompt parameter weights of the last N m epochs, retain the text prompt features with the best performance as the text prompt parameter weights of the class-incremental image classification system, and obtain the trained class-incremental image classification system based on virtual feature generation and replay. The method is as follows:
[0095] 4.1 Let the variable n m = 1, and let the total number of correctly classified total_correct = 0;
[0096] 4.2 The class-incremental image classification system loads the n m th network weight parameter among the network weight parameters of the last N m epochs; input the validation set D val into the class-incremental image classification system;
[0097] 4.3 Let v = 1;
[0098] 4.4 The image feature extraction module receives the vth validation set image D v , extracts the image feature f v of D val , and sends f val to the main task module;
[0099] 4.5 The text prompt feature extraction module loads the n m th network weight parameter, concatenates it with the sequence token of the class name corresponding to the test set, obtains the text prompt required for verification, and then the text prompt feature extraction module extracts the text prompt feature f m corresponding to the n t th epoch, and sends the text prompt feature f t to the main task module;
[0100] 4.6 The main task module uses f t and f val to calculate the similarity, and obtains N (for stage t, N = N tThe predicted probability logits of (*t) categories (a one-dimensional vector of dimension N) are shown in the following formula (7):
[0101] logits = <f val ·f t T > Formula (7)
[0102] <·> represents calculating the similarity between two vectors. The category corresponding to the maximum value in the second dimension of logits is the predicted result of the v-th image, and f t T represents the transpose of f t ;
[0103] 4.7 Determine whether the predicted result is the same as the true label when obtaining the dataset in step 2.1. If it is the same, the predicted result of the v-th image is a correct classification, and go to 4.8; if it is not the same, go to 4.9;
[0104] 4.8 Accumulate the correct number to the total number total_correct of correctly classified images in the validation set, as shown in the following formula (8):
[0105] total_correct = total_correct + 1 Formula (8)
[0106] 4.9 If v < V, where V is the number of images in the validation set, let v = v + 1 and go to 4.4; if v ≥ V, it means the validation is completed and go to 4.10;
[0107] 4.10 Calculate the classification accuracy acc, as shown in the following formula (9):
[0108]
[0109] 4.11 If n m < N m , let n m = n m + 1 and go to 4.2; if n m ≥ N m , it means all weight parameters have been verified and go to 4.12;
[0110] 4.12 Compare the accuracies of N m groups of weight parameters, and find the weight parameters with the highest accuracy. The corresponding text prompt features are the optimal text prompt features The weight parameter is used as the weight parameter selected by the class incremental image classification system based on virtual feature generation and replay, and the selected weight parameter is loaded into the class incremental image classification system based on virtual feature generation and replay. The class incremental image classification system based on text prompt weighted aggregation loaded with the selected weight parameter becomes the trained class incremental image classification system based on virtual feature generation and replay. The trained class incremental image classification system based on virtual feature generation and replay has the best performance because it has been fully trained with text prompts.
[0111] The fifth step is to use the trained incremental image classification system based on virtual feature generation and replay to classify the image to be classified input by the user to obtain the prediction result of the image to be classified. The method is:
[0112] 5.1 The image feature extraction module receives the image to be classified I input by the user test ;
[0113] 5.2 Image Feature Extraction Module Extraction I test The image feature f test ;
[0114] 5.3 The main task module loads the optimal text prompt features obtained in step 4.12 With the test set image features f test Perform similarity calculation to obtain the predicted probability logits_test of N categories (a one-dimensional vector with dimension N). The specific process is shown in formula (7):
[0115]
[0116] <·> represents the calculation of the similarity between two vectors. express The category corresponding to the maximum value of the second dimension in logits_test is the prediction result of the image to be classified, and the image classification is completed.
[0117] The following beneficial effects can be achieved by adopting the present invention:
[0118] 1. The present invention uses the semantic space constructed by the pre-trained CLIP model and its inductive generalization ability as the basis, uses virtual features of new categories to enhance data diversity, shrinks classification boundaries, and uses virtual features of old categories for replay, which can prevent catastrophic forgetting and achieve a significant improvement in accuracy. It is suitable for most class-incremental image classification based on large models.
[0119] 2. The present invention constructs a class-incremental image classification system that integrates a text prompt construction module, a text feature extraction module, an image feature extraction module, a virtual feature generation module, a virtual feature replay module and a main task module, introduces learnable text prompts, uses the visual-language large model to construct a semantic space and its inductive generalization ability, as well as the mutual supervision relationship between image and text prompt features in the feature space of the visual-language large model, designs a class-incremental image classification method based on virtual feature generation and replay, uses new categories of virtual features to enhance data diversity and shrink classification boundaries (see 3.10.6-3.10.8 for details), uses two data sets, ImageNet100 and CIFAR100, to conduct experiments on the present invention, compares the present invention with four methods, namely iCaRL, ContinualCLIP, CoOp and AttriCLIP, and the classification accuracy of the present invention is greatly improved compared with the above three methods.
[0120] 3. The virtual feature replay module of the present invention (see 3.11-3.12 for details) models each dimension of the features of the old category into a Gaussian distribution, while the replay method (iCaRL) described in the background technology requires a large memory to store some images or features of previous categories, and there is no diversity. The virtual feature replay of 3.12 of the present invention can reduce the memory occupancy, and at the same time, the virtual features have diversity, which greatly improves the classification accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0121] Figure 1 The logical structure diagram of the class-incremental image classification system constructed for the first step of the present invention.
[0122] Figure 2 It is the overall flow chart of the present invention. DETAILED DESCRIPTION
[0123] The following is a description of specific examples of the present invention in conjunction with the accompanying drawings. Figure 2 As shown, the present invention comprises the following steps:
[0124] The first step is to build a class-incremental image classification system based on virtual feature generation and replay. Figure 2 As shown, the class-incremental image classification system consists of a text prompt construction module, a text feature extraction module, an image feature extraction module, a virtual feature generation module, a virtual feature replay module and a main task module.
[0125] The text prompt construction module is connected to the text feature extraction module. The text prompt construction module uses a set of learnable vectors and category names to construct text prompts, obtains a text prompt list related to the category, and sends the constructed text prompt list to the text feature extraction module.
[0126] The text feature extraction module is connected to the text prompt construction module and the main task module. The text feature extraction module extracts features from the text prompt list received from the text prompt construction module, obtains text prompt features, and sends the text prompt features to the main task module. The text feature extraction module adopts the Transformer architecture, and its parameters adopt the parameters pre-trained in the Transformer architecture by CLIP (see the document "Alec Radford, et al. Learning transferable visual models from natural language supervision. International conference on machine learning. PMLR, 2021." Alec Radford et al.'s paper: Learning transferable visual models from natural language supervision). The Transformer architecture mainly consists of two parts: the encoder and the decoder. The encoder is used to understand the input text prompt and obtain context information, while the decoder is used to generate an output sequence based on the context information received from the encoder. Both the encoder and the decoder are stacked by multiple identical layers, usually 6 layers. Each layer contains two sub-layers: one is a multi-head self-attention module, which uses a self-attention mechanism to allow the model to simultaneously focus on other elements in the sequence when processing an element of a sequence, thereby capturing the dependencies between them. The other is the fully connected layer, and the multi-head self-attention module and the fully connected layer are connected through residual connections. The Transformer architecture can capture the dependencies between different positions in the text prompt and obtain global context information, making it particularly effective in semantic feature extraction. In addition, the multi-head self-attention module of the Transformer architecture allows the Transformer to perform attention calculations between inputs at different positions, which can be easily parallelized and improve computational efficiency.
[0127] The image feature extraction module is connected to the virtual feature generation module, the virtual feature replay module and the main task module. During training, the image feature extraction module extracts the image features of the training set and sends the image features of the training set to the virtual feature generation module to generate virtual features of new categories and enhance the diversity of existing data; at the same time, the image features of the training set are sent to the virtual feature replay module. During verification, the image feature extraction module extracts the image features of the verification set and sends the image features of the verification set to the main task module; when classifying the image to be classified input by the user, the image features to be classified input by the user are sent to the main task module. The image feature extraction module adopts ResNet (see the document "Kaiming He, et al. Deep Residual Learning for Image Recognition [J]. Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 770-778" Kaiming He et al.'s paper: Deep residual learning for image recognition) network or ViT (Vision Transformer) (see the document "Dosovitskiy Alexey, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv: 2010.11929 (2020)." Dosovitskiy Alexey et al.'s paper: An image is worth 16x16 words: Transformers for image recognition at scale) network, both of which can effectively extract image features. The ResNet network is constructed by stacking a series of residual blocks, which are composed of convolutional layers and normalization layers. Depending on the depth of the network, variants of the ResNet network (such as ResNet50, ResNet101, and other networks) are often used in specific applications; the core idea of the ViT network is to divide the image into a series of small patches, and then treat these small patches as sequence data and process them through the Transformer model. In specific applications, variants of the ViT network such as ViT-B / 32, ViT-B / 16, and ViT-L / 14 are often used. The ResNet network has smaller parameters, shorter training time, and better feature extraction capabilities; the ViT network has more parameters, longer training time, and better feature extraction capabilities.In the present invention, according to specific scenarios and requirements, any one of the networks including ResNet50, ResNet101, ViT-B / 32, ViT-B / 16 and ViT-L / 14 (variant models of ViT, ViT-B represents the base model, ViT-L represents the Large model; 16 represents that the input is a small block of 16×16 pixels) trained on 400 million image-text pairs can be used as an image feature extraction module.
[0128] The virtual feature generation module is connected to the image feature extraction module and the main task module. Its function is to use the training set image features received from the image feature extraction module to generate new types of virtual features, including virtual in-group values and virtual outliers, and send the new types of virtual features to the main task module.
[0129] The virtual feature replay module is connected to the image feature extraction module and the main task module. Its function is to receive the training set image features from the image feature extraction module and estimate the training set list D′ based on the training set image features. train The Gaussian distribution of each category in the feature level; for each category, the virtual feature generation module randomly samples an old category virtual feature from the feature-level Gaussian distribution (i.e., replays the virtual feature of the old category) and sends the old category virtual feature to the main task module. Sampling virtual features from the feature-level Gaussian distribution for replay can prevent catastrophic forgetting.
[0130] The main task module is connected to the text feature extraction module, the image feature extraction module, the virtual feature generation module and the virtual feature replay module. It receives the text prompt feature from the text feature extraction module. During training, it receives the training set image features from the image feature extraction module, receives the new class virtual features from the virtual feature generation module, and receives the old class virtual features from the virtual feature replay module. It uses the similarity between the above image features (training set image features, new class virtual features, old class virtual features) and the text prompt feature to complete the classification and obtain the category of the image. During verification, the text prompt feature is verified using the verification set image feature to obtain the optimal text prompt feature. When classifying the image to be classified input by the user, the features of the image to be classified input by the user are received from the image feature extraction module, and the image is classified using the optimal text prompt feature to obtain the classification result.
[0131] The second step is to construct the training set, validation set, and test set by:
[0132] 2.1 Collect class-incremental image classification scene images as class-incremental image classification scene dataset, the method is:
[0133] We use two datasets, ImageNet100 (a subset of ImageNet, see the paper "Jia Deng, et al. ImageNet: A Large-Scale Hierarchical Image Database [A]. 2009 IEEE Conference on Computer Vision and Pattern Recognition [C], 2009" Jia Deng et al.: ImageNet: A Large-Scale Hierarchical Image Database) and CIFAR100 (see the paper "Krizhevsky, Alex, and Geoffrey Hinton. Learning multiple layers of features from tiny images. (2009): 7." Krizhevsky, Alex et al.: Learning multiple layers of features from tiny images) as class-incremental image classification scene datasets. Each image in these two datasets is manually annotated, that is, each image is annotated with the category of the object and its corresponding true label.
[0134] 2.2 According to the dataset partition file commonly used by researchers (i.e., the partition file included in the dataset file), the incremental image classification dataset is divided into training set D train , test set D test , validation set D val , let the total number of categories in the data set be C, and each image has its corresponding category label (usually [1,2,…,C]). In the field of incremental image classification, the training process is divided into T (T is a positive integer, generally 10) training stages to simulate the process of increasing data. During training, usually only the training data of the current stage can be used, and a small amount of training data from the previous stage can be saved. Therefore, the training set D needs to be train Divide again according to the training stage to get the training set list is the sub-training set for the t-th training stage, and the method is:
[0135] 2.2.1 Let the number of elements in the training set of each category be N ptrain Zhang, the number of elements in the test set N ptest Zhang, for stage t(t∈[1,2,…,T]), the number of categories N contained in the tth stage t = C / T, the category label set I contained in the tth stage t =N t *(t-1)+1,…,N t *t](For example: for stage 1, the category label set I contained in stage 11 = [1, 2, ..., N t );
[0136] 2.2.2 Let the stage \(t = 1\);
[0137] 2.2.3 Find the images in the training set \(D\) train that belong to \(I\) t (that is, find the images identical to \(I\) according to the labels in the training set), and add the images in the training set \(D\) t that belong to \(I\) traIn to t ; ;
[0138] 2.2.4 If \(t < T\), let \(t=t + 1\), and go to step 2.2.3; if \(t\geq T\), obtain the training set list \(D'\) traIn , and go to step 2.3;
[0139] 2.3 Let the number of elements in the test set for each category be \(N\) ptest sheets. In the field of class-incremental image classification, during testing, the test set for each stage should include the categories of the current and previous stages. Therefore, the test set \(D\) test needs to be re-partitioned according to the training stage to obtain the test set list as the sub-test set for the \(t\)-th training stage. The method is as follows:
[0140] 2.3.1 Let the stage \(t = 1\),
[0141] 2.3.2 Find the images in the test set \(D\) test that belong to \(I\) 1 \(\cup I\) 2 \(\cup \cdots \cup I\) t (that is, find the images identical to \(I\) \(\cup I\) test \(\cup \cdots \cup I\) according to the labels in the test set \(D\)), and add these images to 1 \(\cup I\) 2 \(\cup \cdots \cup I\) t ; ;
[0142] 2.3.3 If \(t < T\), let \(t=t + 1\), and go to step 2.3.2; if \(t\geq T\), obtain the final test set list \(D'\) test , and go to step 2.3.4;
[0143] 2.3.4 The validation set list \(D\) val adopts the same list as the test set, that is, \(D\) val = \(D'\) test ;
[0144] In the third step, the gradient back propagation method is used to train the class incremental image classification system based on virtual feature generation and replay constructed in the first step to obtain N m model parameters, N m is the number of training steps that need to be saved. The method is:
[0145] 3.1 Initialize the model parameters of each module in the incremental image classification system. Use the pre-trained model CLIP to initialize the parameters of the Transformer framework in the text feature extraction module and the parameters of ResNet or ViT in the image feature extraction module;
[0146] 3.2 Let stage t = 1;
[0147] 3.3 For stage t, the category label sequence of text prompts to be constructed is: [1,2,...,n,…,N t *t], the text prompt building module initializes the text prompt and obtains the text prompt list L of the tth stage t , n is the category label number, 1≤n≤N t *t, the method is:
[0148] 3.3.1 Let n = 1, initialize the text prompt list L of the tth stage t =[];
[0149] 3.3.2 Let m = 1;
[0150] 3.3.3 Use the prompt construction method in CoOp (see the literature "KaiyangZhou, et al. "Learning to prompt for vision-language models." International Journal of Computer Vision 130.9 (2022): 2337-2348." KaiyangZhou et al.'s paper: Learning prompt visual language model) to construct the text prompt P of the nth category n , as shown in formula (1):
[0151] P n =[V] 1 [V] 2 ...[V] m …[V] M [CLASS] Formula (1)
[0152] Among them, [V] 1 [V] 2 …[V] m …[V] M As a trainable text hint parameter WP , [V] m is the m-th learnable vector, which is a vector with a dimension of 512; "[CLASS]" represents the class name. M is the number of learnable vectors (M is a positive integer, usually set to 16).
[0153] 3.3.4 For the m-th learnable vector "[V] n ", initialize each dimension of [V] m by using random initialization (mean is 0, standard deviation is 0.02);
[0154] 3.3.5 If m < M, let m = m + 1, and go to 3.3.3; if m ≥ M, for [V] 1 [V] 2 …[V] m …[V] M After initialization is complete, go to 3.3.6;
[0155] 3.3.6 Replace "CLASS" in formula (1) with the class name class corresponding to n, and use the tokenize method of CLIP to convert class n into a sequence of tokens (a vector with a dimension of 512); at this time, the initialization of M learnable vectors is complete, and [V] n [V] 1 [V] 2 …[V] m …[V] M is concatenated with the sequence of tokens to obtain the learnable text prompt P n for the n-th class, and add P n to L t .
[0156] 3.3.7 If n < N t *t (in incremental learning, all classes seen in the t-th stage need to be tested, so N t *t text prompts need to be constructed), let n = n + 1, and go to 3.3.2; if n ≥ N t *t, it means that the text prompts Lt for all classes in the t-th stage have been constructed, and the text prompt list L t for the t-th stage has been obtained, and go to 3.3.8;
[0157] 3.3.8 Send the text prompt list L t for the t-th stage to the text feature extraction module, and go to 3.4;
[0158] 3.3.9 The text prompt construction module loads the text prompt parameters W P saved in the (t - 1)-th stage, that is, [V] 1 [V]2 …[V] m …[V] M , let n = 1, go to 3.3.6;
[0159] 3.4 Set the training parameters of the incremental image classification system. Set the initial learning rate learning_rate to 0.002, and set the learning rate adjustment function to the cosine annealing (Cosine Annealing) dynamic learning rate adjustment function. Select stochastic gradient descent (SGD) as the model training optimizer. Set the batch size (mini_batch_size) of network training to 100. The maximum training step (maxepoch) is 50.
[0160] 3.5 Text feature extraction module uses Transformer network to extract L t The text hint feature F T (is a two-dimensional matrix with dimension (N t *t,D), D is the feature dimension, which is a positive integer), T Send to the main task module;
[0161] 3.6 Let the number of training rounds epoch = 1;
[0162] 3.7 Let batch number b = 1, indicating the bth image batch, each batch has B = 256 images, and the total number of batches is N B , N train is the number of images in the training set;
[0163] 3.8 Image feature extraction module from the training set list D′ train Take out the training set of stage t from Read the B images of the b-th batch and record the B images of the b-th batch as matrix I train , I train It contains B H×W×3 images. H represents the height of the input image, W represents the width of the input image, and “3” represents the RGB channels of the image.
[0164] 3.9 Image feature extraction module uses ResNet or ViT to extract I train The image features f of B images in v (is a two-dimensional matrix with dimensions (B, D), where D is the feature dimension), and the image feature f v Send to the virtual feature generation module, the virtual feature replay module and the main task module;
[0165] 3.10 The virtual feature generation module receives the image feature f from the image feature extraction module v, according to the category label sequence [N t *(t-1)+1,…c,…,N t *t], for the feature space composed of features with category label c in stage t The k-nearest neighbor algorithm k-NN is used to select boundary samples. According to the boundary sample points, is the number of training sets for categories with category label c, generating virtual in-group points and virtual outliers, The method is:
[0166] 3.10.1 Let class label c = N t *(t-1)+1, initialize the virtual cluster point set F P = [], initialize the virtual outlier set F Q =[];
[0167] 3.10.2 Set variable i = 1, initialize k-NN distance list Dis = [];
[0168] 3.10.3 For The i-th image feature f i , use formula (2) to calculate the k-NN distance
[0169]
[0170] in,‖·‖ 2 Indicates calculating the Euclidean distance between two vectors, f (k) It is the feature space The kth hyperparameter in is set according to the number of training samples in each category (f (k) =N ptrain *0.1); Add to the k-NN distance list Dis c ;
[0171] 3.10.4 If Let i = i + 1, go to 3.10.3; if Explanation: For the same category of N ptrain The k-NN distance list Dis of samples c Calculation is complete, go to 3.10.5;
[0172] 3.10.5 Dis based on k-NN distance c , the virtual feature generation module selects B features with the largest k-NN distance from Dis as boundary samples, and uses represents the set of boundary samples, h(x b ) represents the b-th boundary sample, 1≤b≤B;
[0173] 3.10.6 Let b = 1;
[0174] 3.10.7 The virtual feature generation module samples from the multivariate Gaussian distribution around h(x b ) to synthesize virtual inliers and virtual outliers. Virtual inliers refer to virtual features that are consistent with the f v distribution, and virtual outliers refer to virtual features that are inconsistent with the f v distribution. The multivariate Gaussian distribution around h(x b ) is shown in Equation (3):
[0175] v ∼ N(h(x b ), σ 2 I) Equation (3)
[0176] where v represents the virtual features generated around the boundary sample h(x b ), and σ 2 is the adjusted variance;
[0177] 3.10.8 For the boundary sample h(x b ), set the variance σ 2 to 0.1. The virtual feature generation module samples p virtual features using Equation (3) as the virtual inliers corresponding to the boundary sample h(x b ) As positive samples to enhance the diversity of the existing data, add to the virtual inlier set F Q ; p is a hyperparameter and a positive integer, is a two-dimensional matrix with dimensions (p, D);
[0178] 3.10.9 For the boundary sample h(x b ), set the variance σ 2 to 50. The virtual feature generation module samples q features, a total of q virtual features, using Equation (3) as the virtual outliers corresponding to the boundary sample h(x b ) Select the virtual outliers with the highest k-NN distance for filtering, and use as negative samples to shrink the classification boundary. The virtual feature generation module adds to the virtual outlier set F Q ; q is a hyperparameter and a positive integer, is a two-dimensional matrix with dimensions (q, D);
[0179] 3.10.10 If b < B, let b = b + 1 and go to 3.10.7; if b ≥ B, it means that virtual inliers and virtual outliers have been generated based on the B boundary points of the c-th category, go to 3.10.11;
[0180] 3.10.11 If c <N t *t, let c=c+1, go to 3.10.2; if c≥N t *t, indicating that N t The virtual cluster point set F corresponding to each category P and the virtual outlier set F Q , go to 3.10.12;
[0181] 3.10.12 Virtual Feature Module P and F Q Sent to the main task module as a new class of virtual features;
[0182] 3.11 The virtual feature replay module receives the image feature f from the image feature extraction module v , according to the category label sequence [N t *(t-1)+1,…c,…,N t *t], f v The characteristic statistics of the category with category label c are Gaussian distribution Each feature dimension is approximately independently distributed, where μ c represents the mean vector of the Gaussian distribution, represents the covariance matrix, is the covariance of the cth category corresponding to dimension d. Use formula (4) and formula (5) to estimate μ c and
[0183]
[0184] f id is the i-th image feature f i The eigenvalue of the dth dimension of , save the mean of each category to the mean list μ, and save the covariance of the cth category corresponding to dimension d to the covariance matrix corresponding to category c In preparation for sampling in the subsequent stage, the method is:
[0185] 3.11.1 Let category c = N t *(t-1)+1, initialize the mean list μ=[], initialize the covariance list σ 2 =[];
[0186] 3.11.2 Use formula (4) to calculate the mean μ corresponding to category c c , μ c Add the mean list μ;
[0187] 3.11.3 Let dimension d = 1; initialize the covariance matrix corresponding to category c
[0188] 3.11.4 Calculate the covariance of the c-th category corresponding to dimension d using formula (5). Add to
[0189] 3.11.5 If d < D, set d = d + 1 and go to 3.11.4; if d ≥ D, it means that the covariance matrix corresponding to category c has been calculated, go to 3.11.6; The calculation is completed, go to 3.11.6;
[0190] 3.11.6 Add to the covariance list σ 2 ;
[0191] 3.11.7 If c < N t *t, set c = c + 1 and go to 3.11.2; if c ≥ N t *t, it means that the means of all categories have been saved to μ, and the variances have been saved to Go to 3.12;
[0192] 3.12 If t = 1, directly go to 3.13; if t > 1, the virtual feature replay module randomly selects O (hyperparameter, set to 8) categories from the categories before stage t (i.e., the categories whose class labels belong to [1,…,N t *(t - 1)]), and then randomly selects a virtual feature from the feature distributions of the O categories to obtain the old-class virtual feature list F . o . is the mean vector of the Gaussian distribution corresponding to category o, is the covariance matrix corresponding to category o, and is used to replay the features of previous categories to reduce forgetting, as follows:
[0193] 3.12.1 Randomly select O labels from the class labels [1,N t *(t - 1)], and denote them as the label set C O , C O = [c 1 ,…c o ,…c o ;
[0194] 3.12.2 Set o = 1 and initialize the old-class virtual feature list F o = [];
[0195] 3.12.3 Find the feature distribution corresponding to the class label that is the same as c o among the class labels saved in step 3.11.7 From Randomly extract a virtual feature Add to F o ;
[0196] 3.12.4 If o < O, let o = o + 1, and go to 3.13.3; if o ≥ O, it means the virtual feature list F of the old class o is constructed, and go to 3.13.5;
[0197] 3.12.5 Send F o to the main task module;
[0198] 3.13 The main task module receives the image feature f v from the image feature extraction module, receives F P and F Q from the virtual feature generation module, receives F o from the virtual feature replay module, and receives the text prompt feature F T .
[0199] 3.14 The main task module constructs the loss function of the original image feature Constructs the loss function of the virtual inlier image feature Constructs the loss function of the virtual outlier image feature The loss function of the virtual features of the old class
[0200] 3.15 Construct the final loss function L as shown in formula (6):
[0201]
[0202] where λ in , λ out , λ o are the proportionality coefficients for adjusting the loss functions L in , L out , L o respectively, and are set to 0.1, 0.1, 2;
[0203] 3.16 Calculate formula (6) to obtain the final loss value Loss, and use the gradient backpropagation method to optimize the parameters of the text prompt construction module;
[0204] 3.17 If epoch ≤ maxepoch, go to 3.5; if epoch > maxepoch, it means the training of the epoch-th round is over, and go to 3.18;
[0205] 3.18 Save the text prompt parameter weight W of the last epoch P, if t < T, set t = t + 1 and go to 3.3.9; if t ≥ T, it means that the training of T stages has ended, go to 3.19;
[0206] 3.19 Save the text prompt parameter weights for the last N m (Hyperparameter, set to 10) epochs.
[0207] Step 4, use the validation set to verify the detection accuracy of the class-incremental image classification system with the text prompt parameter weights loaded for the last N m epochs, retain the text prompt features with the best performance as the text prompt parameter weights of the class-incremental image classification system, and obtain the trained class-incremental image classification system based on virtual feature generation and replay. The method is as follows:
[0208] 4.1 Let the variable n m = 1, and let the total number of correctly classified samples total_correct = 0;
[0209] 4.2 The class-incremental image classification system loads the nth m network weight parameter among the network weight parameters for the last N m epochs; input the validation set D val into the class-incremental image classification system;
[0210] 4.3 Let v = 1;
[0211] 4.4 The image feature extraction module receives the vth validation set image D v , extracts the image feature f v of D val , and sends f val to the main task module;
[0212] 4.5 The text prompt feature extraction module loads the nth m network weight parameter, concatenates it with the sequence token of the class name corresponding to the test set, obtains the text prompt required for verification, and then the text prompt feature extraction module extracts the text prompt feature f m corresponding to the nth t epoch, and sends the text prompt feature f t to the main task module;
[0213] 4.6 The main task module uses f t and f val to calculate the similarity, and obtains the predicted probabilities logits (a one-dimensional vector with a dimension of N) for N (for stage t, N = N t *t) classes. The specific process is shown in formula (7):
[0214] logits = <f val·f t T > Formula (7)
[0215] <·> represents calculating the similarity between two vectors. The category corresponding to the maximum value in the second dimension of logits is the prediction result of the v-th image, and f t T denotes f t 's transpose;
[0216] 4.7 Determine whether the prediction result is the same as the true label when obtaining the dataset in step 2.1. If they are the same, the prediction result of the v-th image is a correct classification, and go to 4.8; if they are not the same, go to 4.9;
[0217] 4.8 Accumulate the number of correct ones to the total number total_correct of correctly classified ones in the validation set. The specific process is shown in Formula (8):
[0218] total_correct = total_correct + 1 Formula (8)
[0219] 4.9 If v < V, where V is the number of images in the validation set, let v = v + 1 and go to 4.4; if v ≥ V, it means the validation is completed, and go to 4.10;
[0220] 4.10 Calculate the classification accuracy acc. The specific process is shown in Formula (9):
[0221]
[0222] 4.11 If n m < N m , let n m = n m + 1 and go to 4.2; if n m ≥ N m , it means that all weight parameters have been verified, and go to 4.12;
[0223] 4.12 Compare the accuracies of N m groups of weight parameters, find the weight parameter with the highest accuracy, and its corresponding text prompt feature is the optimal text prompt feature Take this weight parameter as the selected weight parameter of the class-incremental image classification system based on virtual feature generation and replay. Load this selected weight parameter into the class-incremental image classification system based on virtual feature generation and replay. The class-incremental image classification system based on text prompt weighted aggregation loaded with this selected weight parameter becomes the trained class-incremental image classification system based on virtual feature generation and replay. The trained class-incremental image classification system based on virtual feature generation and replay has been fully trained due to the text prompt, and its performance is the best.
[0224] The fifth step is to use the trained incremental image classification system based on virtual feature generation and replay to classify the image to be classified input by the user to obtain the prediction result of the image to be classified. The method is:
[0225] 5.1 The image feature extraction module receives the image to be classified I input by the user test ;
[0226] 5.2 Image Feature Extraction Module Extraction I test The image feature f test ;
[0227] 5.3 The main task module loads the optimal text prompt features obtained in step 4.12 With the test set image features f test Perform similarity calculation to obtain the predicted probability logits_test of N categories (a one-dimensional vector with dimension N). The specific process is shown in formula (7):
[0228]
[0229] <·> represents the calculation of the similarity between two vectors. express The category corresponding to the maximum value of the second dimension in logits_test is the prediction result of the image to be classified, and the image classification is completed.
[0230] In order to verify the effect of the present invention, the test set data of 2 data sets from ImageNet100 and CIFAR100 are selected to replace the user's input image, and the numerical test of the classification accuracy Acc is performed on each incremental stage of the present invention. The experimental environment is Ubuntu20.04 (a version of the Linux system), equipped with an Intel i9-10900K series CPU, with a processing frequency of 3.70GHz, and four NVIDIA RTX 2080Ti image processors, with a core frequency of 1635MHz and a video memory capacity of 12GB. The test set of the above 2 data sets is input into the class incremental image classification system of the present invention, the test set data is classified, and the classification accuracy Acc of each stage (i.e., stage 1-10) is counted and compared with other methods for comparing and measuring the effectiveness of the present invention.
[0231] First, define the target detection algorithm performance evaluation indicators. This experiment uses a standard accuracy evaluation method with three specific indicators: Acc, Avg, and PD. Acc represents accuracy, that is, the proportion of correct classifications. The larger the Acc value, the higher the classification accuracy; Avg (Average) represents average accuracy, that is, the average classification accuracy of all stages; PD represents performance drop, that is, the difference between the accuracy of the first stage and the last stage.
[0232] According to the experimental results of the present invention, the performance comparison of the class incremental image classification method of the present invention on the ImageNet100 dataset is shown in Table 1. The performance comparison of the present invention compared with the current SOTA class incremental image classification method AttriCLIP, the classic replay-based class incremental image classification method iCaRL, the CLIP-based class incremental image classification method Continual CLIP, and CoOp is shown. From the experimental results, it can be seen that the present invention can quickly and accurately perform image classification and achieve consistent accuracy improvement. The present invention has performed accuracy tests on the ImageNet100 dataset (a subset of the more authoritative image classification dataset of 1000 categories), and the test results are as follows:
[0233] Compared with the current SOTA incremental image classification method AttriCLIP, the accuracy of the present invention in the first stage is slightly lower by 0.4%, and the accuracy of each subsequent incremental stage is improved by 0.4%, 0.0%, 2.4%, 3.3%, 3.4%, 2.2%, 1.4%, 1.1%, and 0.5% respectively. The average accuracy Avg is improved by 1.46%, and the performance degradation PD is reduced by 0.9%.
[0234] Compared with the classic replay-based incremental image classification method iCaRL, the accuracy of the present invention in each incremental stage is improved by 15.3%, 13.8%, 15.5%, 19.8%, 19.9%, 20.1%, 22.0%, 22.0%, 22.1%, and 22.4% respectively, the average accuracy Avg is improved by 19.29%, and the performance degradation PD is reduced by 7.1%.
[0235] Compared with the CLIP-based class incremental image classification method Continual CLIP, the accuracy of the present invention in each incremental stage is improved by 0.7%, 2.2%, 5.0%, 9.5%, 8.5%, 10.1%, 11.5%, 11.9%, 13.0%, and 15.2% respectively, the average accuracy Avg is improved by 8.96%, and the performance degradation PD is reduced by 14.5%.
[0236] Compared with the CLIP-based incremental image classification method CoOp, the accuracy of the present invention in each incremental stage is improved by 1.6%, 3.7%, 5.8%, 6.5%, 7.2%, 10.1%, 9.8%, 11.6%, 11.5%, and 14.3% respectively, the average accuracy Avg is improved by 8.21%, and the performance degradation PD is reduced by 12.7%.
[0237] Table 1
[0238]
Claims
1. A class-incremental image classification method based on virtual feature generation and replay, characterized in that The following steps are involved: The first step is to build a class-incremental image classification system based on virtual feature generation and replay; the class-incremental image classification system consists of a text prompt construction module, a text feature extraction module, an image feature extraction module, a virtual feature generation module, a virtual feature replay module and a main task module; The text prompt construction module is connected to the text feature extraction module. The text prompt construction module uses a set of learnable vectors and category names to construct text prompts, obtains a text prompt list related to the category, and sends the constructed text prompt list to the text feature extraction module; The text feature extraction module is connected to the text prompt construction module and the main task module. The text feature extraction module extracts features from the text prompt list received from the text prompt construction module to obtain text prompt features, and sends the text prompt features to the main task module. The text feature extraction module adopts the Transformer architecture, and its parameters adopt the parameters pre-trained by CLIP in the Transformer architecture. The encoder in the Transformer architecture is used to understand the input text prompt and obtain context information, and the decoder in the Transformer architecture is used to generate an output sequence according to the context information received from the encoder. The image feature extraction module is connected with the virtual feature generation module, the virtual feature replay module and the main task module. During training, the image feature extraction module extracts the image features of the training set and sends the image features of the training set to the virtual feature generation module to generate virtual features of new categories to enhance the diversity of existing data; at the same time, the image features of the training set are sent to the virtual feature replay module; During verification, the image feature extraction module extracts the features of the verification set images and sends the features of the verification set images to the main task module; when classifying the images to be classified input by the user, the features of the images to be classified input by the user are sent to the main task module; the image feature extraction module uses a ResNet network or a ViT network; The virtual feature generation module is connected to the image feature extraction module and the main task module. Its function is to use the training set image features received from the image feature extraction module to generate new virtual features, including virtual in-group values and virtual outliers, and send the new virtual features to the main task module. The virtual feature replay module is connected to the image feature extraction module and the main task module. Its function is to receive the training set image features from the image feature extraction module and estimate the training set list D according to the training set image features. t ' rain The Gaussian distribution of the feature level of each category in the ; for each category, the virtual feature generation module randomly samples an old class virtual feature from the feature-level Gaussian distribution, that is, replays the virtual feature of the old category, and sends the old class virtual feature to the main task module; The main task module is connected to the text feature extraction module, the image feature extraction module, the virtual feature generation module, and the virtual feature replay module. It receives text prompt features from the text feature extraction module. During training, it receives training set image features from the image feature extraction module, new class virtual features from the virtual feature generation module, and old class virtual features from the virtual feature replay module. It uses the similarities among the training set image features, new class virtual features, old class virtual features, and text prompt features to complete classification and obtain the category of the picture. During validation, it uses the validation set image features to test the text prompt features and obtain the optimal text prompt features. When classifying the image to be classified input by the user, it receives the features of the image to be classified input by the user from the image feature extraction module and uses the optimal text prompt features to classify the image to obtain the classification result. Step 2: Construct the training set, validation set, and test set. The method is as follows: 2.1 Collect the images of the class-incremental image classification scenario as the class-incremental image classification scenario dataset. The method is as follows: Use 2 datasets, namely the general scenario datasets ImageNet100 and CIFAR100, as the class-incremental image classification scenario dataset. Each image in these 2 datasets has been manually annotated, that is, each image is annotated with the category of the object and its corresponding true label. 2.2 Divide the files according to the dataset and divide the class incremental image classification dataset into training set D train , test set D test , validation set D val , let the total number of categories in the dataset be C, and each image has its corresponding category label, denoted as [1,2,…,C]. In the field of class-incremental image classification, the training process is divided into T training stages to simulate the process of increasing data; for the training set D train Divide again according to the training stage to get the training set list is the sub-training set of the t-th training stage, t∈[1,2,…,T], T is a positive integer, and the number of categories contained in the t-th stage is N t = C / T, the category label list I contained in the tth stage t =N t *(t-1)+1,…,N t *t]; 2.3 Let the number of elements in the test set of each category be N ptest Zhang, for the test set D test Divide again according to the training stage to get the test set list is the sub-test set of the t-th training stage; 2.3.4 Validation set list D val Use a list consistent with the test set, namely D val =D t ' est ; In the third step, the gradient back propagation method is used to train the class incremental image classification system based on virtual feature generation and replay constructed in the first step to obtain N m model parameters, N m is the number of training steps that need to be saved; the method is: 3.1 Initialize the model parameters of each module in the class-incremental image classification system. Use the pre-trained model CLIP to initialize the parameters of the Transformer framework in the text feature extraction module and the parameters of ResNet or ViT in the image feature extraction module. 3.2 Let the stage t = 1; 3.3 For stage t, the category label sequence of text prompts to be constructed is: [1, 2, ..., n, ..., N t *t], the text prompt building module initializes the text prompt and obtains the text prompt list L of the tth stage t , n is the category label number, 1≤n≤N t *t, the method is: 3.3.1 Let category n = 1 and initialize the text prompt list L of the tth stage t =[]; 3.3.2 Let m = 1; 3.3.3 Use the prompt construction method in CoOp to construct the text prompt P of the nth category n , as shown in formula (1): P n = [V]1[V]2…[V] m …[V] M [CLASS] Formula (1) where a[V]1[V]2…[V] m …[V] M As a trainable text hint parameter W P , [V] m is the mth learnable vector, which is a vector with a dimension of 512; "[CLASS]" represents the class name; M is the number of learnable vectors, and M is a positive integer; 3.3.4 Initialization using random initialization [V] m Each dimension of 3.3.5 If m < M, let m = m + 1, and go to 3.3.3; if m ≥ M, for [V]1[V]2…[V] m …[V] M Initialization is completed, and go to 3.3.6; 3.3.6 Set the class name corresponding to n to class n Replace "CLASS" in formula (1) and use the tokenize method of CLIP to convert class n Convert to sequence token; at this time, M learnable vectors are initialized, and [V]1[V]2…[V] m …[V] M Concatenate with the sequence token to get the learnable text prompt P of the nth category n , P n Add to L t ; 3.3.7 If n <N t *t, let n=n+1, go to 3.3.2; if n≥N t *t, indicating the text prompts L of all categories in the tth stage t The construction has been completed, and the text prompt list L of the tth stage has been obtained t , go to 3.3.8; 3.3.8 List the text prompts of the tth stage L t Send to the text feature extraction module, go to 3.4; 3.3.9 Text prompt construction module loads the text prompt parameters W saved in stage t-1 P , that is, [y]1[V]2…[y]m…[V] M , let n = 1, go to 3.3.6; 3.4 Set the training parameters of the class-incremental image classification system, including the initial learning rate learning_rate, the batch size mini_batch_size of network training, the maximum training step maxepoch, and set the learning rate adjustment function. Select stochastic gradient descent as the model training optimizer. 3.5 Text feature extraction module uses Transformer network to extract L t The text hint feature F T , F T Sent to the main task module, F T is a two-dimensional matrix with dimension (N t *t, D), D is the feature dimension, which is a positive integer; 3.6 Let the number of training epochs epoch = 1; 3.7 Let batch number b = 1, indicating the bth image batch, each batch has B images, and the total number of batches is N B , N train is the number of images in the training set, and B is a positive integer; 3.8 Image feature extraction module from the training set list D′ train Take out the training set of stage t from Read the B images of the b-th batch and record the B images of the b-th batch as matrix I train , I train It contains B H×W×3 images, where H represents the height of the input image, W represents the width of the input image, and "3" represents the RGB channels of the image. 3.9 Image feature extraction module uses ResNet or ViT to extract I train The image features f of B images in v , the image feature f v Send to the virtual feature generation module, virtual feature replay module and main task module; f v is a two-dimensional matrix with dimensions (B,D); 3.10 The virtual feature generation module receives the image feature f from the image feature extraction module v , according to the category label sequence [N t *(t-1)+1,…c,…,N t *t], for the feature space F consisting of features with category label c in the tth stage c , the k-nearest neighbor algorithm k-NN is used to select boundary samples. According to the boundary sample points, is the number of training sets for categories with category label c, generating virtual in-group points and virtual outliers, The method is: 3.10.1 Let class label c = N t *(t-1)+1, initialize the virtual cluster point set F P = [], initialize the virtual outlier set F Q =[]; 3.10.2 Let the variable i = 1, and initialize the k-NN distance list Dis = []; 3.10.3 For The i-th image feature f i , use formula (2) to calculate the k-NN distance Among them, ‖·‖2 means calculating the Euclidean distance between two vectors, f (k) It is the feature space The kth hyperparameter in is set according to the number of training samples in each category (f (k) =N ptrain *0.1); Add to the k-NN distance list Dis c ; 3.10.4 If Let i = i + 1, go to 3.10.3; if Explanation: For the same category of N ptrain The k-NN distance list Dis of samples c Calculation is complete, go to 3.10.5; 3.10.5 Dis based on k-NN distance c , the virtual feature generation module selects B features with the largest k-NN distance from Dis as boundary samples, and uses represents the set of boundary samples, h(x b ) represents the b-th boundary sample, 1≤b≤B; 3.10.6 Let b = 1; 3.10.7 Virtual feature generation module from around h(x b ) is sampled from the multivariate Gaussian distribution to synthesize virtual in-group points and virtual outliers, where the virtual in-group points refer to the points f v Virtual features with consistent distribution, virtual outliers refer to f v The distribution of the virtual features is inconsistent, around h(x b ) is shown in formula (3): v~N(h(x b ),σ 2 I) Formula (3) where v represents the sample h(x) around the boundary b ) generated virtual features, σ 2 is the adjustment variance; 3.10.8 For boundary samples h(x b ), the variance σ 2 Set to 0.1, the virtual feature generation module uses formula (3) to sample p virtual features as boundary samples h(x b ) corresponds to the virtual point in the group As positive samples to enhance the diversity of existing data, Join the virtual cluster point set F Q ; p is a hyperparameter, a positive integer, is a two-dimensional matrix with dimension (p,D); 3.10.9 For boundary samples h(x b ), the variance σ 2 Set to 50, the virtual feature generation module uses formula (3) to sample q features, and a total of q virtual features are sampled as boundary samples h(x b ) corresponds to the virtual outlier point The virtual outliers with the highest k-NN distance are selected for filtering. As negative samples, to shrink the classification boundary, the virtual feature generation module will Add to the virtual outlier set F Q ; q is a hyperparameter, which is a positive integer, is a two-dimensional matrix with dimension (q,D); 3.10.10 If b < B, let b = b + 1, and go to 3.10.7; if b ≥ B, it means that the virtual inliers and virtual outliers have been generated according to the B boundary points of the c-th category, and go to 3.10.11; 3.10.11 If c <N t *t, let c=c+1, go to 3.10.2; if c≥N t *t, indicating that N t The virtual cluster point set F corresponding to each category P and the virtual outlier set F Q , go to 3.10.12; 3.10.12 Virtual Feature Module P and F Q Sent to the main task module as a new class of virtual features; 3.11 The virtual feature replay module receives the image feature f from the image feature extraction module v , according to the category label sequence [N t *(t-1)+1,…c,…,N t *t], f v The characteristic statistics of the category with category label c are Gaussian distribution Each feature dimension is approximately independently distributed, where μ c represents the mean vector of the Gaussian distribution, represents the covariance matrix, is the covariance of the cth category corresponding to dimension d, and equations (4) and (5) are used to estimate μ c and f id is the i-th image feature f i The eigenvalue of the dth dimension of , save the mean of each category to the mean list μ, and save the covariance of the cth category corresponding to dimension d to the covariance matrix corresponding to category c 3.12 If t = 1, go directly to 3.13; if t>1, the virtual feature replay module uses the category labels before stage t to belong to [1,…,N t *(t-1)] randomly select O categories, and then select the feature distribution of O categories Randomly extract a virtual feature from the old class to get the virtual feature list F o ; is the mean vector of the Gaussian distribution corresponding to category o, is the covariance matrix corresponding to category o, which is used to replay the characteristics of the previous category. O is a hyperparameter, which is a positive integer. The method is as follows: 3.12.1 From the category label [1, N t *(t-1)], randomly select O tags and record them as tag set C O , C O =[c1,…c o ,…c O ]; 3.12.2 Let o = 1, initialize the old class virtual feature list F o =[]; 3.12.3 Find the category labels saved in step 3.11.7 that match c o Feature distribution corresponding to consistent category labels from Randomly extract a dummy feature Will Join Fo ; 3.12.4 If o < O, let o = o + 1, and go to 3.12.3; if o ≥ O, it means that the old class virtual feature list F o is constructed, and go to 3.12.5; 3.12.5 Send F o to the main task module; 3.13 The main task module receives the image feature f v from the image feature extraction module, receives F P and F Q from the virtual feature generation module, receives F o from the virtual feature replay module, and receives the text prompt feature F T from the text feature extraction module; 3.14 The main task module constructs the loss function of the original image feature Constructs the loss function of the virtual in-group point image feature Constructs the loss function of the virtual outlier image feature The loss function of the old class virtual feature 3.15 Construct the final loss function L as shown in formula (6): where, λ in ,λ out ,λ o They are respectively adjusted loss function L in ,L out ,L o The proportional coefficients are set to 0.1, 0.1, and 2 respectively; 3.16 Calculate formula (6) to obtain the final loss value Loss, and use the gradient backpropagation method to optimize the parameters of the text prompt construction module. 3.17 If epoch ≤ maxepoch, go to 3.5; if epoch > maxepoch, it means that the training of the epoch-th round is over, and go to 3.18; 3.18 Save the text prompt parameter weight W of the last epoch P , if t<T, let t=t+1, go to 3.3.9; if t≥T, it means that the training of T stages has been completed, go to 3.19; 3.19 Save after N m The text prompt parameter weights for each epoch, N m is a positive integer; Step 4: Use the validation set to verify the loaded N m The detection accuracy of the incremental image classification system with the text prompt parameter weights of epochs is obtained, and the best performing text prompt feature is retained as the text prompt parameter weight of the incremental image classification system to obtain the trained incremental image classification system based on virtual feature generation and replay; the method is: 4.1 Let variable n m =1, let the total number of correct classifications total_correct = 0; 4.2 Class Incremental Image Classification System Loaded After N m The nth network weight parameter of the epoch m network weight parameters; the validation set D val Input class incremental image classification system; 4.3 Let v = 1; 4.4 The image feature extraction module receives the vth validation set image D v , extract D v The image feature f val , f val Send to the main task module; 4.5 Text prompt feature extraction module loading nth m The network weight parameters are concatenated with the sequence tokens of the category names corresponding to the test set to obtain the text prompts required for verification. Then the text prompt feature extraction module extracts the nth m The text prompt feature f corresponding to the epoch t , the text prompt feature f t Send to the main task module; 4.6 Main task module uses f t With f val Perform similarity calculation to obtain the predicted probabilities of N categories, logits, which is a one-dimensional vector with a dimension of N. For stage t, N = N t *t, the specific process is shown in formula (7): logits= <f val f t T > Official(7) <·> represents the calculation of the similarity between two vectors. The category corresponding to the maximum value of the second dimension in logits is the prediction result of the vth image. t T represents f t The transpose of 4.7 Judge whether the prediction result is the same as the true label when obtaining the dataset in step 2.
1. If they are the same, the prediction result of the v-th picture is a correct classification, and go to 4.8; if they are not the same, go to 4.9; 4.8 Add the correct number to the total number of correct classifications in the validation set. The specific process is shown in formula (8): total_correct=total_correct+1 formula (8) 4.9 If v < V, where V is the number of images in the validation set, let v = v + 1, and go to 4.4; if v ≥ V, it means that the validation is completed, and go to 4.10; 4.10 Calculate the classification accuracy acc. The specific process is shown in formula (9): 4.11 If n m <N m , let n m =n m +1, go to 4.2; if n m ≥N m , indicating that all weight parameters have been verified. Go to 4.12; 4.12 to N m The accuracy of the group weight parameters is compared, and the weight parameter with the highest accuracy is found. The corresponding text prompt feature is the optimal text prompt feature. The weight parameter is used as the weight parameter selected by the class incremental image classification system based on virtual feature generation and replay, and the selected weight parameter is loaded into the class incremental image classification system based on virtual feature generation and replay, and the class incremental image classification system based on text prompt weighted aggregation loaded with the selected weight parameter becomes the trained class incremental image classification system based on virtual feature generation and replay; The fifth step is to use the trained incremental image classification system based on virtual feature generation and replay to classify the image to be classified input by the user to obtain the prediction result of the image to be classified. The method is: 5.1 The image feature extraction module receives the image to be classified I input by the user test ; 5.2 Image Feature Extraction Module Extraction I test The image feature f test ; 5.3 The main task module loads the optimal text prompt features obtained in step 4.12 With the test set image features f test Perform similarity calculation to obtain the predicted probability logits_test of N categories. Logits_test is a one-dimensional vector with a dimension of N. The specific process is shown in formula (7): <·> represents the calculation of the similarity between two vectors. express The category corresponding to the maximum value of the second dimension in logits_test is the prediction result of the image to be classified, and the image classification is completed.
2. A class-incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that The parameters of the text feature extraction module adopt the parameters pre-trained by CLIP in the Transformer architecture; the encoder and decoder in the Transformer architecture are both composed of multiple identical layers stacked together, totaling 6 layers; each layer contains two sublayers: one is a multi-head self-attention module, which uses a self-attention mechanism to allow the model to focus on other elements in the sequence while processing an element of a sequence, thereby capturing the dependencies between them; the other is a fully connected layer, and the multi-head self-attention module and the fully connected layer are connected via a residual connection.
3. A class incremental image classification method based on virtual feature generation and replay as described in claim 1, characterized in that the ResNet network used in the image feature extraction module is constructed by stacking a series of residual modules, and the residual module consists of a convolutional layer and a normalization layer; depending on the depth of the network, the image feature extraction module uses a ResNet50 or ResNet101 network trained with 400 million image-text pairs.
4. A class incremental image classification method based on virtual feature generation and replay as described in claim 1, characterized in that the ViT network used in the image feature extraction module divides the image into a series of small blocks, and then regards these small blocks as sequence data and processes them through a Transformer model; depending on the specific application, the image feature extraction module uses any one of the networks ViT-B / 32, ViT-B / 16 or ViT-L / 14 trained on 400 million image-text pairs.
5. The class incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that the training set D is train Divide again according to the training stage to get the training set list D t ' rain The method is: 2.2.1 Let the number of elements in the training set of each category be N ptrain Zhang, the number of elements in the test set N ptest Zhang, the number of categories contained in the tth stage N t = C / T, the category label set I contained in the tth stage t =[N t *(t-1)+1,…,N t *t]; T is 10; 2.2.2 Let stage t = 1; 2.2.3 Find the training set D train I t The training set D train I t The image is added to middle; 2.2.4 If t < T, let t = t + 1, and go to step 2.2.3; if t ≥ T, obtain the training set list D′ train , 6. A class-incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that Step 2.3 for the test set D test Divide again according to the training stage to get the test set list The method is: 2.3.1 Let stage t = 1, 2.3.2 Find the test set D test I1∪I2∪…∪I t , add these images to middle, I t is the set of category labels contained in the tth stage; 2.3.3 If t < T, let t = t + 1 and go to step 2.3.2; if t ≥ T, obtain the final test set list D t ′ est , 7. A class-incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that 3.3: M is set to 16; the random initialization method is used to initialize [V] m For each dimension of , the mean is 0 and the standard deviation is 0.02; the sequence token is a vector with a dimension of 512.
8. A class-incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that The initial learning rate learning_rate in step 3.4 is set to 0.002, and the batch size mini_batch_size of the network training is set to 100; the learning rate adjustment function is set to the cosine annealing dynamic learning rate adjustment function; the maximum training step maxepoch is 50; B=256 in step 3.7; p is set to 10 in step 3.10.8; q is set to 10 in step 3.10.9; O is set to 8 in step 3.12; λ in step 3.15 in ,λ out ,λ o Set them to 0.1, 0.1, 2 respectively; N in step 3.19 m Set to 10.
9. A class-incremental image classification method based on virtual feature generation and replay as claimed in claim 1, characterized in that The method for saving the mean and covariance of each category in step 3.11 is: 3.11.1 Let c = N t *(t-1)+1, initialize the mean list μ=[], initialize the covariance list σ 2 =[]; 3.11.2 Use formula (4) to calculate the mean μ corresponding to category c c , μ c Add the mean list μ; 3.11.3 Let dimension d = 1; initialize the covariance matrix corresponding to category c 3.11.4 Calculate the covariance of the c-th category corresponding to dimension d using formula (5) Put into 3.11.5 If d < D, let d = d + 1, and go to 3.11.4; if d ≥ D, it means that the covariance matrix corresponding to category c has been calculated, go to 3.11.6; 3.11.6 Put into the covariance list σ 2 ; 3.11.7 If c < N t *t, let c = c + 1, and go to 3.11.2; if c ≥ N t *t, it means that the means of all categories have been saved to μ, and the variances have been saved to
