Deep fusion multi-cross-domain few-sample classification method based on knowledge distillation
By using a combination of knowledge distillation and meta-learning in multi-cross-domain, low-sample learning, the problems of data distribution differences and teacher network conflicts are solved, the generalization ability and classification accuracy of the model are improved, and efficient knowledge transfer and tasks are achieved. adapt.
Patent Information
- Application Number
- CN202411030578.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-10-18
AI Technical Summary
Existing multi-cross-domain few-shot learning methods have data distribution differences and teacher network conflicts in the process of model fusion and knowledge distillation, which affect the generalization ability and task coordination of the model, and make it difficult to effectively utilize knowledge from multiple source domains.
Adopt a deep fusion multi-domain few-sample classification method based on knowledge distillation, pre-train teacher and student networks, introduce meta-learning and task-oriented knowledge distillation strategies, use soft labels and attention mechanisms for knowledge transfer and feature fusion, and optimize students The training objective function of the network to improve model performance.
It significantly improves the classification accuracy and generalization ability of the student network in the target domain, enhances the rapid adaptability to few-sample tasks, and improves the efficiency of knowledge distillation and model performance through deep fusion and multi-teacher network collaboration.
Smart Images

Figure CN118799645A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to a deep fusion multi-cross-domain few-sample classification method based on knowledge distillation. Background Art
[0002] At present, deep learning has achieved great success in the field of computer vision, such as object classification, image retrieval, and action recognition. The success of deep learning depends largely on massive data and powerful computing resources. However, in many recognition and machine learning tasks, humans can often recognize new objects or visual concepts from very few examples. This ability to learn quickly is not available in current deep learning. Therefore, how to learn to recognize new categories with limited labeled data has attracted widespread attention, which is also the core problem that few-shot learning (Few-Shot Learning) aims to solve. In recent years, a large number of few-shot learning works have adopted the idea of meta-learning. The basic idea is to train a model that can quickly adapt to new tasks in the training phase, so that a small number of samples can be used efficiently to learn new tasks in the testing phase. However, most few-shot learning methods rely on auxiliary data with the same distribution as the target task domain. To solve this problem, researchers proposed multiple cross-domain few-shot learning (MCD-FSL), which aims to use data from multiple different source domains to improve model performance. Tseng et al. verified that this method can bring effective improvements by conducting experiments on multiple source domains. However, Triantafillou et al. also pointed out that simple cross-domain learning does not always achieve the desired results. This is because the data interference between multiple source domains leads to negative transfer. To solve this problem, some studies use knowledge distillation to capture the correct source domain information.
[0003] Knowledge distillation (KD) is a deep learning technique that aims to transfer knowledge from one or more complex teacher networks to a simpler student network. The student network is usually smaller, faster, and more resource-efficient. Despite the small size of the student network, it can maintain comparable performance to the teacher network and even improve its generalization ability. Traditional knowledge distillation methods mainly rely on a strong teacher network. Hinton et al. first proposed the concept of knowledge distillation, and they proved that a strong teacher network can effectively guide the training of the student network. However, recent studies have found that using multiple teacher networks for knowledge distillation can further improve the performance of the student network. For example, by averaging the outputs of multiple teacher networks, a more robust guidance signal can be obtained. However, simply averaging the outputs of multiple teacher networks may ignore the different contributions of each teacher network on different tasks, thereby misleading the learning of the student network. In order to better combine cross-domain few-shot learning and knowledge distillation methods, researchers have proposed some new strategies. For example, researchers introduced adaptive distillation temperature and loss weights to enable the student network to learn more effectively from multiple teacher networks. During the training process, the researchers first trained multiple teacher networks on multiple source domains, and then transferred the knowledge in these teacher networks to the student network through distillation. In order to ensure that the student network can learn useful information from different source domains, the researchers designed a cross-domain distillation loss function. This loss function can help the student network effectively transfer knowledge between multiple source domains, thereby improving its performance in the target domain.
[0004] Although these methods have shown certain effectiveness in experiments, there are still some problems and challenges in the current methods. First, the distribution differences between multi-source domain data may cause difficulties for the network model when fusing information from different source domains, affecting the generalization ability of the model. Even if the data from different source domains are integrated through the knowledge distillation method, it is still impossible to completely eliminate the negative impact of the distribution differences between source domains on model performance. In addition, there may be conflicts between the multiple teacher networks involved in the knowledge distillation process, resulting in the student network being unable to effectively learn the knowledge of all teacher networks. This requires the introduction of a more complex weight adjustment mechanism in the distillation process to balance the impact of different teacher networks on the student network. In cross-domain learning, the problem of multi-task learning is often involved, that is, the network model needs to learn and process multiple different tasks at the same time. How to effectively coordinate and optimize the relationship between these tasks to maximize the overall performance is also a question worth thinking about. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a deep fusion multi-cross-domain few-sample classification method based on knowledge distillation to achieve multi-cross-domain few-sample classification in view of the shortcomings of the above-mentioned prior art.
[0006] In order to solve the above technical problems, the technical solution adopted by the present invention is: a deep fusion multi-cross-domain few-sample classification method based on knowledge distillation, comprising the following steps:
[0007] Step 1: Pre-train teacher and student networks;
[0008] We use N training sets {Z1, Z2, …, Z N} to train N different teacher networks, each of which uses the same network structure, including a teacher feature encoder E t and a linear classifier C t , initialize N teacher network parameters, pre-train each teacher network using cross entropy loss in the traditional supervised training mode, and finally obtain N trained teacher networks; use a diverse dataset to pre-train the student network S p , the student network consists of a feature encoder E s_p and a classifier C based on a distance metric s , the student network is pre-trained using cross entropy loss in the traditional supervised training mode to obtain the pre-trained student network S p ;
[0009] Each teacher network and student network are pre-trained using the cross entropy loss function, including:
[0010] (1) From the nth source domain training set Z n Randomly select a certain amount of data As the input of the nth teacher feature encoder or student network, the visual features of the i-th sample image are obtained after encoding
[0011]
[0012] in, is the i-th sample image in the n-th source domain training set, E n is the nth feature encoder;
[0013] (2) The visual features of the i-th sample image Input the nth teacher classifier C n , get the category prediction probability of the i-th sample image in the n-th source domain training set:
[0014]
[0015] in, is the i-th sample image The predicted probability of belonging to the wth category;
[0016] (3) Set the objective function L of the teacher network and the student network n The formula is as follows:
[0017]
[0018] in, is the i-th sample image The true label of , W is the number of sample categories in the n-th source domain training set;
[0019] (4) According to formula (2), train the nth feature encoder E n and the nth classifier C n , retain the nth feature encoder E that minimizes the error value of formula (3) n and the nth classifier C n ;
[0020] (5) Repeat steps (1) to (4) to obtain N pre-trained teacher networks and one student network S p ;
[0021] Step 2: Use the pre-trained student network S p Build a student network S;
[0022] The student network S is a metric-based few-shot model, the prototype network, which contains a student feature encoder E s and a metric function d, through the pre-trained student network feature encoder E s_p Initialize the student feature encoder E s ;
[0023] Step 3: In the meta-training phase, a training set is randomly selected from the training sets of N different source domains as the current meta-training set D train According to the idea of meta-learning, M few-shot tasks are randomly sampled from the current meta-training set. Each task contains a support set S and a query set Q. The support set S contains sample image data of W categories, and each category has K samples; the query set Q contains sample images of W categories;
[0024] Step 4: Send different few-sample tasks to N teacher networks and student network S simultaneously;
[0025] Step 5: Take the kth sample image x in the support set S k Input to N teacher feature encoders and student feature encoder E sIn the above example, we obtain the corresponding visual features. and
[0026]
[0027]
[0028] Among them, x k is the kth sample image in the support set S, is the nth teacher feature encoder, n=1,2,…,N,E s For the student feature encoder, is the nth teacher feature encoder E n x k The visual features output after encoding, For the student feature encoder E s x k The visual features of the encoded output;
[0029] Step 6: In each source domain, average the visual features corresponding to the sample images of the same category in the support set, and obtain the prototype representation of each category as:
[0030]
[0031]
[0032] Where K is the total number of samples in the w-th category, w = 1, 2, ..., W, is the prototype representation of the wth category after being encoded by the nth teacher feature encoder, is the prototype representation of the wth category after being encoded by the student encoder;
[0033] Step 7: Take the sample images x in the query set Q in turn Q Input to N teacher feature encoders and student feature encoder E s In the above example, we obtain the corresponding visual features. and
[0034]
[0035]
[0036] Among them, x Q is a sample image in the query set Q, is the nth teacher feature encoder x Q The visual features output after encoding, For the student feature encoder Es x Q The visual features of the encoded output;
[0037] Step 8: Normalize the prototype representation of each category in the support set obtained by the teacher network and the student network S and the visual features corresponding to the sample images in the query set to obtain the corresponding normalized results:
[0038]
[0039]
[0040]
[0041]
[0042] in, is the normalized feature encoder of the nth teacher The prototype representation of the w-th category after encoding, is the normalized nth teacher feature encoder x Q The visual features output after encoding, is the normalized student encoder E s The prototype representation vector of the encoded w-th category, is the normalized student feature encoder E s x Q The visual features of the encoded output;
[0043] Step 9: Based on the normalized visual features corresponding to the query samples in the teacher network and the student network and the prototype representation of each category, the prediction probability matrix of each query sample belonging to each category in the teacher network and the student network is calculated based on the similarity. and S logits :
[0044]
[0045]
[0046] in, represents the similarity-based prediction probability matrix between the visual features corresponding to the query sample in the nth teacher network and the prototype representation, s logits represents the similarity-based prediction probability matrix between the visual features corresponding to the query sample in the student network and the prototype representation, For each prototype representation of the same teacher feature encoder, Each prototype representation for the student feature encoder;
[0047] Step 10: Set the true label of the sample in the query set Q to y query , according to the true label y of the query set query The similarity-based prediction probability matrix s between the visual features corresponding to the query sample in the student network and the prototype representation logits , calculate the classification loss of the student network, and set the classification objective function L of the student network cls as follows:
[0048]
[0049] Where q is the total number of samples in the query set, W is the total number of categories, is the predicted probability vector of the i-th query sample, is the true label of the i-th query sample, d(,) is the metric function based on Euclidean distance;
[0050] Step 11: Calculate the category prediction probability matrix based on the prototype representation encoded by the N teacher feature encoders and the student feature encoders and the visual features corresponding to the query set samples, so as to perform soft-label-based knowledge distillation between the N teacher networks and the student network, and obtain the soft-label-based objective function L of the student network KL ;
[0051] 1) Take the query set sample images x output by N teacher networks Q Deep fusion with the similarity-based prediction probability matrix between the prototype representations of each class is used as one of the goals of training the student network:
[0052]
[0053] where f fc represents a fully connected network, f mean represents the average function, represents the similarity-based prediction probability matrix between the query sample and the prototype representation of each class in the N teacher networks, ⊕, ⊙, || respectively represent point addition, point multiplication, cascade, t fusion Represents the query set sample image x after N teacher networks are fused Q A similarity-based prediction probability matrix between features and prototype representations of each class;
[0054] 2) In order to make the output of the student network consistent with that of the teacher network, the objective function L of the student network based on the prediction probability matrix is set KL as follows:
[0055]
[0056]
[0057] Among them, τ is the temperature coefficient of knowledge distillation, Q is the total number of samples in the query sample set, is the predicted probability vector based on similarity between the visual features corresponding to the i-th query sample extracted by the student network and the prototype representation of each class, Represents the predicted probability vector based on similarity between the visual features corresponding to the i-th query sample after the fusion of N teacher networks and the prototype representation of each class;
[0058] Step 12: Based on the prototype representation encoded by the N teacher feature encoders and the student feature encoders and the visual features corresponding to the query set samples, the spatial distribution of the feature map generated by the student network is aligned with the feature map generated by the teacher network, and the feature map of the teacher network is used as a reference for information transfer, thereby performing attention-based knowledge distillation between the N teacher networks and the student network, and obtaining the objective function L of the student network based on the feature map attention ;
[0059] S1: Based on the visual features corresponding to the support set samples and query set samples encoded by N teacher feature encoders and student feature encoders, obtain the visual features encoded by the same teacher or student encoder:
[0060]
[0061]
[0062] in, is the nth teacher feature encoder E n x Q The visual features output after encoding, For the student feature encoder E s x Q The visual features output after encoding, is the result of merging the visual features corresponding to the support set and query set samples encoded by the nth teacher feature encoder, v s It is the result of merging the visual features corresponding to the support set and the query set encoded by the student feature encoder;
[0063] S2: Deeply fuse the visual features encoded by N teacher feature encoders on the support set and query set samples as one of the goals of training the student network:
[0064]
[0065] Among them, v 1 ,…,v N represents the visual features of the support set and query set samples after N teacher feature encoders are combined, It represents the result of deep fusion of the visual features of the support set and query set samples after the N teacher feature encoders are merged;
[0066] S3: In order to make the output of the student network consistent with that of the teacher network, the attention-based objective function L of the student network is set by extracting the visual features of the support set and query set samples through the student network and the fused visual features extracted by multiple teacher networks. attention as follows:
[0067]
[0068]
[0069]
[0070] Among them, G is the total number of samples in the support set and query set, is the feature vector obtained by the student feature encoder for the i-th sample in the support set and query set sample set, is the visual feature vector of the fusion of the i-th sample in the support set and the query set, and p is the hyperparameter for the attention transfer function;
[0071] Step 13: According to the following total objective function formula of the student network, use the SGD algorithm to train the student feature encoder:
[0072] L=λ1×L cls +λ2×L KL +λ3×L attention (26)
[0073] Among them, L is the overall objective function of the student network, L cls is the classification objective function of the student network, L KL is the soft-label-based objective function of the student network, L attention is the objective function of the student network based on the feature graph, λ1,λ2,λ3 are weight coefficients;
[0074] Step 14: Repeat steps 3-13 until the total objective function value gradually converges and tends to be constant, and a trained student network is obtained;
[0075] Step 15: In the testing phase, given a dataset different from the N pre-trained source domains as the target domain, sample images from the support set and query set of the target domain test set are input into the trained student feature encoder E in turn. sIn the above formula, we obtain the corresponding visual features, calculate the prototype representation of each category in the support set according to formula (6) (7), and then calculate the probability that the sample image in the query set belongs to each category according to formula (14) (15). The category corresponding to the largest probability among the calculated probabilities is taken as the classification result of the sample image in the query set.
[0076] The beneficial effect produced by adopting the above technical solution is that: the present invention provides a deep fusion cross-domain few-sample classification method based on knowledge distillation, which uses the teacher-student network framework of knowledge distillation to achieve efficient knowledge transfer, thereby improving the generalization ability of the model. By integrating the training strategy of meta-learning into knowledge distillation, combining task-oriented knowledge distillation and the collaboration of multiple teacher networks, it not only provides rich and effective knowledge for the student network, but also enhances the student network's ability to quickly adapt to few-sample tasks. Supervision information is extracted from the output prediction and sample relationship of the teacher network, and the outputs of multiple teacher networks are fused using deep fusion to guide the training of the student network and improve the efficiency of knowledge distillation. Therefore, the present invention can better transfer the effective knowledge of multiple source domains to the target domain, and significantly improve the classification accuracy of the student network on the target few-sample task. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 A flowchart of a deep fusion multi-domain few-sample classification method based on knowledge distillation provided in an embodiment of the present invention;
[0078] Figure 2 A workflow diagram of the deep fusion method provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0079] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.
[0080] Multi-domain cross-domain few-shot learning uses training data from multiple source domains as auxiliary data sets to provide prior knowledge for the model, and ultimately achieves prediction of the test sample category in the target domain. This embodiment adopts a 5-way 5-shot setting. During the training phase, five training sets {Z1, Z2, …, Z5} from different source domains are given, corresponding to mini-ImageNet, CUB, Cars, Places, and Plantae datasets, respectively. Each source domain contains a large amount of labeled data. Where z is the total number of samples in the training set of the nth source domain, is the i-th sample image in the training set, is the category label corresponding to the i-th sample in the training set. In the test phase, the trained model is used to complete the few-shot classification task on the target domain. Each few-shot task contains a support set S and a query set Q. The support set contains W categories of data, and each category has K samples. The goal of the few-shot task is to use the training data of the W*K support sets to predict the category to which the samples in the query set belong.
[0081] The mini-ImageNet dataset contains 100 items with a wide diversity; the CUB dataset contains 200 bird species; the Cars dataset contains 196 car models; the Places dataset contains 365 scene categories; and the Plantae dataset contains more than 8,000 natural biological categories.
[0082] Figure 1 Describes the flowchart of the deep fusion multi-domain cross-domain few-shot classification method based on knowledge distillation. Data represents all images of a few-shot task, {E1, E2, …, E N} are N teacher feature encoders, E S is the student feature encoder, {l1,l2,…,l N} is the category probability distribution obtained by each teacher network, {f1,f2,…,f N} is the visual feature obtained by each teacher network, l S is the category probability distribution obtained by the student network, f S is the visual feature obtained by the student network. Deep is the deep fusion module. f is the category probability distribution after teacher network fusion, f f is the visual feature after fusion by the teacher network.
[0083] like Figure 1 , 2 As shown, a deep fusion multi-domain cross-domain few-sample classification method based on knowledge distillation of the present invention includes the following steps:
[0084] Step 1: Pre-train the teacher and student networks. Use the training sets {Z1, Z2, …, Z5} of 5 different source domains to train 5 different teacher networks. Each teacher network uses the same network structure, including a teacher feature encoder E t and a linear classifier C t , initialize the parameters of 5 teacher networks, pre-train each teacher network using cross entropy loss in the traditional supervised training method, and finally obtain 5 trained teacher networks; use a diverse dataset mini-ImageNet to pre-train the student network S p , Student Network S p Contains a feature encoder Es_p and a classifier C based on a distance metric s , the student network is pre-trained using cross entropy loss in the traditional supervised training mode to obtain the pre-trained student network S p . Specifically include:
[0085] Step 1.1: From the nth source domain training set Z n Randomly select a certain amount of data As the input of the nth teacher feature encoder or student network, the visual features of the i-th sample image are obtained after encoding
[0086]
[0087] in, is the i-th sample image in the n-th source domain training set, E n is the nth feature encoder;
[0088] Step 1.2: The visual features of the i-th sample image Input the nth teacher classifier C n , get the category prediction probability of the i-th sample image in the n-th source domain training set:
[0089]
[0090] in, is the visual feature of the i-th sample image, is the i-th sample image The predicted probability of belonging to the wth category;
[0091] Step 1.3: Set up the teacher network and student network S p The objective function L n The formula is as follows:
[0092]
[0093] in, is the i-th sample image The true label of , W is the number of sample categories in the n-th source domain training set, is the i-th sample image The predicted probability of belonging to the wth category;
[0094] Step 1.4: Train the nth feature encoder E according to formula (2) n and the nth classifier C n , retain the nth feature encoder E that minimizes the error value of formula (3) n and the nth classifier C n;
[0095] Step 1.5: Repeat steps 1.1 to 1.5 to obtain 5 pre-trained teacher networks and one student network S p .
[0096] Step 2: Construct the student network S, which is a metric-based few-shot model - the prototype network, which contains a student feature encoder E s and a metric function d, through the pre-trained student network feature encoder E s_p Initialize the student feature encoder E s .
[0097] Step 3: Meta-training stage: At the beginning of training, a test data set is selected. In this embodiment, the CUB data set is selected as the test set. Then, in each training, a training set is randomly selected from the remaining four training sets of different source domains as the current meta-training set D. train , and use the network pre-trained with the corresponding dataset in step 1 as the teacher network. According to the idea of meta-learning, a certain number of few-sample tasks are randomly sampled from the current meta-training set. Each task contains a support set S and a query set Q. The support set contains W categories of data, and each category has K samples.
[0098] Step 4: Send different few-sample tasks to the four teacher networks and the student network S at the same time;
[0099] Step 5: Take the kth sample image x in the support set S k Input into the selected 4 teacher feature encoders and student feature encoders to obtain the corresponding visual features and
[0100]
[0101]
[0102] Among them, x k is the kth sample image in the support set S, is the nth teacher feature encoder, E s For the student feature encoder, is the nth teacher feature encoder E n x k The visual features output after encoding, For the student feature encoder E s x k The visual features of the encoded output;
[0103] Step 6: In each source domain, the visual features of samples belonging to the same category in the support set are averaged to obtain the prototype representation of each category:
[0104]
[0105]
[0106] Among them, K is the total number of samples in the wth category, is the prototype representation of the wth category after being encoded by the nth teacher feature encoder, is the prototype representation of the wth category after being encoded by the student feature encoder;
[0107] Step 7: Sequentially take the sample images x of the query set Q Input into 4 teacher feature encoders and student feature encoders to obtain corresponding visual features and
[0108]
[0109]
[0110] Among them, x Q is a sample image in the query set Q, is the nth teacher feature encoder x Q The visual features output after encoding, For the student feature encoder E s x Q The visual features of the encoded output;
[0111] Step 8: Normalize the prototype representation and query set visual features obtained by the teacher network and the student network respectively to obtain the corresponding normalized results:
[0112]
[0113]
[0114]
[0115]
[0116] in, is the normalized feature encoder of the nth teacher The prototype representation of the w-th category after encoding, is the normalized nth teacher feature encoder x QThe visual features output after encoding, is the normalized student encoder E s The prototype representation vector of the encoded w-th category, is the normalized student feature encoder E s x Q The visual features of the encoded output;
[0117] Step 9: Based on the normalized visual features corresponding to the query samples in the teacher network and the student network and the prototype representation of each category, the prediction probability matrix of each query sample belonging to each category in the teacher network and the student network is calculated based on the similarity. and logits :
[0118]
[0119]
[0120] in, represents the similarity-based prediction probability matrix between the visual features corresponding to the query sample in the teacher network and the prototype representation, s logits represents the similarity-based prediction probability matrix between the visual features corresponding to the query sample in the student network and the prototype representation, For each prototype representation of the same teacher feature encoder, Each prototype representation for the student feature encoder;
[0121] Step 10: Set the true label of the sample in the query set Q to y query , according to the true label y of the query set query The similarity-based prediction probability matrix s between the visual features corresponding to the query sample in the student network and the prototype representation logits , calculate the classification loss of the student network, and set the classification objective function L of the student network cls as follows:
[0122]
[0123] Where q is the total number of samples in the query set, W is the total number of categories, is the predicted probability vector of the i-th query sample, is the true label of the i-th query sample, and d(,) is the metric function based on Euclidean distance.
[0124] Step 11: Calculate the category prediction probability matrix based on the prototype representation encoded by the four teacher feature encoders and the student feature encoder and the visual features corresponding to the query set samples, so as to perform soft-label-based knowledge distillation between the four teacher networks and the student network, and obtain the soft-label-based objective function L of the student network KL . The following steps are included:
[0125] (1) The query set samples x output by the four teacher networks Q Deep fusion with the similarity-based prediction probability matrix between the prototype representations of each class is used as one of the goals of training the student network:
[0126]
[0127] Among them, f fc represents a fully connected network, f mean represents the average function, represents the similarity-based prediction probability matrix between the query sample and the prototype representation of each class in the N teacher networks, ⊕, ⊙, || represent point addition, point multiplication and cascade respectively, t fusion Represents the query set sample x after the fusion of the four teacher networks Q The similarity-based prediction probability matrix between the corresponding visual features and the prototype representation of each class;
[0128] (2) In order to make the output of the student network consistent with that of the teacher network, the objective function L of the student network based on the prediction probability matrix is set KL as follows:
[0129]
[0130]
[0131] Where τ is the temperature coefficient, q is the total number of samples in the query sample set, is the predicted probability vector based on similarity between the visual features corresponding to the i-th query sample extracted by the student network and the prototype representation of each class, Represents the predicted probability vector based on similarity between the visual features corresponding to the i-th query sample after the fusion of the four teacher networks and the prototype representation of each class;
[0132] Step 12: Based on the prototype representation encoded by the four teacher feature encoders and the student feature encoder and the visual features corresponding to the query set samples, the spatial distribution of the feature map generated by the student network is aligned with the feature map generated by the teacher network, and the feature map of the teacher network is used as a reference for information transfer, thereby performing attention-based knowledge distillation between the four teacher networks and the student network, and obtaining the objective function L of the student network based on the feature map attention; including the following steps:
[0133] 1) According to the visual features corresponding to the support set samples and the query set samples encoded by the four teacher feature encoders and the student feature encoders, the visual features encoded by the same teacher encoder or student encoder are obtained:
[0134]
[0135]
[0136] in, is the nth teacher feature encoder E n x Q The visual features output after encoding, For the student feature encoder E s x Q The visual features output after encoding, is the result of merging the visual features of the support set and the query set encoded by the nth teacher feature encoder, v s It is the result of merging the visual features of the support set and the query set encoded by the student feature encoder;
[0137] 2) Deeply fuse the visual features encoded by the four teacher feature encoders on the support set and query set samples as one of the goals of training the student network:
[0138]
[0139] Among them, v 1 ,…,v 4 represents the visual features of the support set and query set samples after the four selected teacher feature encoders are combined, It represents the result of deep fusion of the visual features of the support set and query set samples after the four selected teacher feature encoders are combined;
[0140] 3) In order to make the output of the student network consistent with that of the teacher network, the attention-based objective function L of the student network is set by using the visual features extracted by the student network of the support set and query set samples and the visual features extracted by multiple teacher networks after fusion. attention as follows:
[0141]
[0142]
[0143]
[0144] Among them, G is the total number of samples in the support set and query set, is the feature vector obtained by the student feature encoder for the i-th sample in the support set and query set sample set, The visual feature vector of the ith sample in the support set and query set is fused, and p is the hyperparameter for the attention transfer function.
[0145] Step 13: According to the following total objective function formula of the student network, use the SGD algorithm to train the student feature encoder:
[0146] L=λ1×L cls +λ2×L KL +λ3×L attention (26)
[0147] Among them, L is the overall objective function of the student network, L cls is the classification objective function of the student network, L KL is the soft-label-based objective function of the student network, L attention is the objective function of the student network based on the feature graph, λ1,λ2,λ3 are weight coefficients;
[0148] Step 14: Repeat steps 3 to 13 until the total objective function value gradually converges and tends to be constant, and a trained student network is obtained;
[0149] Step 15: In the testing phase, the CUB dataset selected in step 3 is used as the target domain. Sample images from the support set and query set of the target domain test set are input into the trained student feature encoder E s In the above formula, we obtain the corresponding visual features, calculate the prototype representation of each category in the support set according to formula (6) (7), and then calculate the probability that the sample image in the query set belongs to each category according to formula (14) (15). The category corresponding to the largest probability among the calculated probabilities is taken as the classification result of the sample image in the query set.
[0150] In this embodiment, in a 5-way 5-shot experiment using the CUB dataset as a test set, the accuracy can reach 58.54±0.52%, which is more than 3% higher than the baseline model ProtoNet, proving the effectiveness of the model.
[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A deep fusion multi-domain few-shot classification method based on knowledge distillation, characterized by: The following steps are involved: Step 1: Pre-train N teacher networks and one student network S p ; Each teacher network adopts the same network structure, including a teacher feature encoder E t and a linear classifier C t , the student network contains a feature encoder E s_p and a classifier C based on a distance metric s ; Step 2: Use the pre-trained student network S p Build student network S; The student network S is a metric-based few-shot model that includes a student feature encoder E s and a metric function d, through the pre-trained student network feature encoder E s_p Initialize the student feature encoder E s ; Step 3: Meta-training stage, randomly select a training set from N training sets of different source domains as the current meta-training set D train According to the idea of meta-learning, M few-shot tasks are randomly sampled from the current meta-training set. Each task contains a support set S and a query set Q. The support set S contains sample image data of W categories, and each category has K samples; the query set Q contains sample images of W categories. Step 4: Send different few-shot tasks to N teacher networks and student network S simultaneously; Step 5: Input the sample images in the support set S into N teacher feature encoders and student feature encoders E in turn s In the , the corresponding visual features are obtained respectively; Step 6: In each source domain, the visual features corresponding to the sample images belonging to the same category in the support set obtained by the teacher network and the student network S in step 5 are averaged to obtain the prototype representation of each category after being encoded by the teacher feature encoder and the student feature encoder; Step 7: Input the sample images in the query set Q into N teacher feature encoders and student feature encoders E in turn s In the , the corresponding visual features are obtained respectively; Step 8: Normalize the prototype representation of each category in the support set obtained by the teacher network and the student network S and the visual features corresponding to the sample images in the query set in step 7 to obtain the corresponding normalized results; Step 9: Using the visual features corresponding to the query samples in the teacher network and the student network normalized in step 8 and the prototype representation of each category, calculate the prediction probability matrix of each query sample belonging to each category in the teacher network and the student network based on the similarity; Step 10: Calculate the classification loss of the student network based on the true labels of the samples in the query set Q and the predicted probability matrix based on the similarity between the visual features and prototype representations corresponding to the query samples in the student network in step 9, and set the classification objective function L of the student network cls ; Step 11: Calculate the category prediction probability matrix based on the prototype representation encoded by the N teacher feature encoders and the student feature encoders in step 9 and the visual features corresponding to the query set samples, thereby performing soft-label-based knowledge distillation between the N teacher networks and the student network to obtain the soft-label-based objective function L of the student network KL ; Step 12: Based on the prototype representation and the visual features corresponding to the query set samples encoded by the N teacher feature encoders and student feature encoders in steps 5 and 7, the spatial distribution of the feature map generated by the student network is aligned with the feature map generated by the teacher network. The feature map of the teacher network is used as a reference for information transfer, thereby performing attention-based knowledge distillation between the N teacher networks and the student network, and obtaining the objective function L of the student network based on the feature map. attention ; Step 13: Use the SGD algorithm to train the student feature encoder according to the following total objective function formula of the student network: L=λ1×L cls +λ2×L KL +λ3×L atention Among them, L is the total objective function of the student network, L cls is the classification objective function of the student network, L KL is the soft label-based objective function of the student network, L attention is the objective function of the student network based on the feature graph, λ1, λ2, λ3 are weight coefficients; Step 14: Repeat steps 3-13 until the total objective function value gradually converges and tends to be unchanged, and the trained student network is obtained; Step 15: In the testing phase, given a dataset different from the N pre-trained source domains as the target domain, the sample images of the support set and query set from the target domain test set are input into the trained student feature encoder E in turn. s In the , the corresponding visual features are obtained, the prototype representation of each category in the support set is calculated, the probability that the sample image of the query set belongs to each category is calculated, and the category corresponding to the largest probability among the calculated probabilities is taken as the classification result of the sample image of the query set.
2. The deep fusion multi-domain few-sample classification method based on knowledge distillation according to claim 1 is characterized by: The step 1 uses N training sets {Z1, Z2, ..., Z N } to train N different teacher networks, initialize N teacher network parameters, pre-train each teacher network using cross entropy loss in the traditional supervised training method, and finally obtain N trained teacher networks; use a diverse dataset to pre-train the student network S p , the student network is pre-trained using cross entropy loss in the traditional supervised training mode to obtain the pre-trained student network S p .
3. The deep fusion multi-domain few-sample classification method based on knowledge distillation according to claim 2 is characterized by: The step 1 uses the cross entropy loss function to pre-train each teacher network and student network, including: (1) From the nth source domain training set Z n Randomly select a certain amount of data As the input of the nth teacher feature encoder or student network, the visual features of the i-th sample image are obtained after encoding in, is the i-th sample image in the n-th source domain training set, E n is the nth feature encoder; (2) The visual features of the i-th sample image Input the nth teacher classifier C n , get the category prediction probability of the i-th sample image in the n-th source domain training set: in, is the i-th sample image The predicted probability of belonging to the w-th category; (3) Set the objective function L of the teacher network and the student network n The formula is as follows: in, is the i-th sample image The true label of , W is the number of sample categories in the n-th source domain training set; (4) According to formula (2), train the nth feature encoder E n and the nth classifier C n , retain the nth feature encoder E that minimizes the error value of formula (3) n and the nth classifier C n ; (5) Repeat steps (1) to (4) to obtain N pre-trained teacher networks and one student network S p .
4. The deep fusion multi-domain few-sample classification method based on knowledge distillation according to claim 3 is characterized by: The classification objective function L of the student network described in step 10 cls as follows: Where q is the total number of samples in the query set, W is the total number of categories, is the predicted probability vector of the i-th query sample, is the true label of the i-th query sample, and d(,) is the metric function based on Euclidean distance.
5. The deep fusion multi-domain few-sample classification method based on knowledge distillation according to claim 4 is characterized by: The step 11 comprises: 1) Take the query set sample images x output by N teacher networks Q Deep fusion with the similarity-based prediction probability matrix between the prototype representations of each class is used as one of the goals of training the student network: Among them, f fc represents a fully connected network, f mean represents the average function, represents the similarity-based prediction probability matrix between the query sample and the prototype representation of each class in the N teacher networks, ⊙,|| respectively represent point addition, point multiplication, cascade, t fusion Represents the query set sample image x after N teacher networks are fused Q A similarity-based prediction probability matrix between the features and the prototype representation of each class; 2) In order to make the output of the student network consistent with that of the teacher network, the objective function L of the student network based on the prediction probability matrix is set KL as follows: Among them, τ is the temperature coefficient of knowledge distillation, q is the total number of samples in the query sample set, is the predicted probability vector based on the similarity between the visual features corresponding to the i-th query sample extracted by the student network and the prototype representation of each class, Represents the predicted probability vector based on similarity between the visual features corresponding to the i-th query sample after the fusion of N teacher networks and the prototype representation of each class.
6. The deep fusion multi-domain cross-domain few-sample classification method based on knowledge distillation according to claim 5 is characterized by: The step 12 comprises: S1: Based on the visual features corresponding to the support set samples and query set samples encoded by N teacher feature encoders and student feature encoders, obtain the visual features encoded by the same teacher or student encoder: in, is the nth teacher feature encoder E n x k The visual features output after encoding, For the student feature encoder E s x k The visual features output after encoding, is the nth teacher feature encoder E n x Q The visual features output after encoding, For the student feature encoder E s x Q The visual features output after encoding, x k is the kth sample image in the support set S, x Q is a sample image in the query set Q, is the result of merging the visual features corresponding to the support set and query set samples encoded by the nth teacher feature encoder, v s It is the result of merging the visual features corresponding to the support set and query set encoded by the student feature encoder; S2: Deeply fuse the visual features encoded by N teacher feature encoders on the support set and query set samples as one of the goals of training the student network: Among them, v 1 ,…,v N represents the visual features of the support set and query set samples after the N teacher feature encoders are combined, It represents the result of deep fusion of the visual features of the support set and query set samples after the N teacher feature encoders are combined; S3: In order to make the output of the student network consistent with that of the teacher network, the attention-based objective function L of the student network is set by extracting the visual features of the support set and query set samples through the student network and the visual features extracted by multiple teacher networks after fusion. attention as follows: Among them, G is the total number of samples in the support set and query set, is the feature vector obtained by the student feature encoder for the i-th sample in the support set and query set sample set, is the visual feature vector of the fusion of the i-th sample in the support set and the query set, and p is the hyperparameter for the attention transfer function.
Citation Information
Cited By
Rare fundus disease OCT image classification method and system based on distillation element learning
CN119445645A
Knowledge distillation and parameter efficient fine tuning fused few-sample relationship classification method
CN120086374A
Emotion analysis system based on multi-teacher knowledge distillation
CN121561683A
A sentiment analysis system based on multi-teacher knowledge distillation
CN121561683B
3D-GAN small model incremental training and optimization method based on retrieval enhancement
CN121580796A
