A knowledge distillation method based on multi-teacher model

By determining the primary and secondary relationships, feature alignment and mask processing in the multi-teacher model, the loss function of the student model is optimized, which solves the problem of limited knowledge distillation effect of the multi-teacher model and significantly improves the image recognition effect and the learning ability of the student model.

CN118379568BActive Publication Date: 2024-09-24ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410834565.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-24
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

Multi-teacher model knowledge distillation has limited effect in the field of image recognition, mainly because the feature dimension fails to fully utilize the information gain brought by the multi-teacher model, resulting in limited knowledge loss and limited improvement in recognition effect.

Method used

By determining the main model and auxiliary model in multiple teacher models, perform feature alignment and expansion, combine mask processing and feature mapping, optimize the student model to improve the knowledge distillation effect, and use the mask norm direction loss function for optimization.

Benefits of technology

It effectively improves the image recognition effect of multi-teacher model knowledge distillation, enhances the learning ability and generalization performance of the student model, and avoids knowledge loss. Compared with the student model distilled from a single-teacher model, it significantly improves the comprehensiveness of image recognition. .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118379568B
    Figure CN118379568B
Patent Text Reader

Abstract

The present invention provides a knowledge distillation method based on multiple teacher models, which relates to the field of image processing technology. The method comprises: determining a main model among multiple teacher models, and using other teacher models as auxiliary models; aligning the feature direction of the auxiliary model with that of the main model to obtain an aligned feature; superimposing the aligned feature with the feature of the main model along a second dimension to obtain an extended feature, wherein the feature dimension of the extended feature is higher than that of the main model or the auxiliary model; performing feature mapping on the middle layer of the student model to obtain a mapped feature; performing mask processing on the extended feature to obtain a first mask feature; performing mask processing on the mapped feature to obtain a second mask feature; determining a mask norm direction loss according to the first mask feature and the second mask feature; optimizing the student model according to a loss function, and classifying and identifying images through the optimized student model to ensure that the knowledge loss caused by the knowledge distillation of multiple teacher models is effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a knowledge distillation method based on a multi-teacher model. Background Art

[0002] In recent years, deep learning technology has demonstrated excellent performance in various task areas such as computer vision and natural language processing. However, its dependence on huge resources, especially in the data training and inference stages, involves the need for large-scale data sets and complex model parameters, which poses a major challenge. To address this challenge, researchers are actively exploring optimization strategies to improve the performance of lightweight models designed for resource-constrained environments. Knowledge distillation (KD) technology has emerged as an effective mechanism that can achieve knowledge transfer from large "teacher" models to small "student" models. Furthermore, the Multi-Teacher Distillation method aims to provide a richer and more diverse knowledge spectrum for student models by incorporating more teacher models, thereby broadening the learning horizon.

[0003] Knowledge distillation focuses on reducing the capability gap between teacher and student models. In the field of image recognition using knowledge distillation, the results obtained based on the multi-teacher distillation strategy have not significantly outperformed the single-teacher system in standard tests. The key is that the feature dimensions involved in the loss calculation during the integration process are often maintained at the same level as the single-teacher model, resulting in a significant loss of potential image feature knowledge, and failing to fully utilize the information gain potential brought by multiple teachers. A large amount of knowledge is lost, resulting in limited improvement in image recognition results when the student model obtained by the multi-teacher distillation strategy is used for image recognition, compared with the student model distilled from the single-teacher model. Summary of the invention

[0004] The problem solved by the present invention is how to effectively improve the image recognition effect of multi-teacher model knowledge distillation.

[0005] To solve the above problems, the present invention provides a knowledge distillation method based on a multi-teacher model, comprising:

[0006] Determine a main model among multiple teacher models, and use other teacher models as auxiliary models;

[0007] Aligning the feature direction of the auxiliary model with the main model to obtain an alignment feature;

[0008] Superimposing the alignment feature with the feature of the main model along the second dimension to obtain an extended feature, wherein the feature dimension of the extended feature is higher than the feature dimension of the main model or the auxiliary model;

[0009] Perform feature mapping on the middle layer of the student model to obtain mapping features;

[0010] Performing mask processing on the extended feature to obtain a first mask feature;

[0011] The mapping feature is subjected to mask processing to obtain a second mask feature;

[0012] Determining a mask norm direction loss according to the first mask feature and the second mask feature;

[0013] The student model is optimized according to the loss function to classify and identify the image through the optimized student model, wherein the loss function includes the mask norm direction loss.

[0014] Compared with the prior art, the present invention determines the main-sub relationship in multiple teacher models, and then determines the feature direction that the teacher model needs to align, so as to avoid the problem of feature direction mismatch of multiple teacher models. By superimposing the aligned features with the features of the main model along the second dimension, the extended features are obtained, so that the features include knowledge from different teacher models, so that the student model can learn from multiple teacher models at the same time, and obtain better knowledge distillation effect; by mapping the features of the middle layer of the student model, it is ensured that the student model can have the same dimension as the extended features after expansion, and obtain better knowledge distillation effect. The same dimension is also convenient for calculating the mask norm direction loss, so that the student model can be optimized according to the loss function, and the knowledge loss of the teacher model is avoided on the basis of realizing multi-teacher knowledge distillation. The optimized student model is used to classify and recognize pictures, and picture processing can be performed based on the knowledge from different teacher models, which improves the comprehensiveness of image recognition. Compared with the student model distilled from a single teacher model, the image recognition effect is effectively improved.

[0015] Optionally, performing mask processing on the extended feature to obtain a first mask feature includes:

[0016] Use the classifier of the preset teacher model as a filter;

[0017] Processing the extended feature through the filter to obtain a first result;

[0018] Compare the first result with the label, and construct a first mask matrix according to the comparison result;

[0019] The first mask feature is determined by the first mask matrix and the extended feature.

[0020] Optionally, the determining the first mask feature by using the first mask matrix and the extended feature includes:

[0021] The extended feature and the elements in the first mask matrix are multiplied item by item to set the elements at the positions of the error information to zero, and the feature after the elements are set to zero is used as the first mask feature.

[0022] Optionally, performing mask processing on the mapping feature to obtain a second mask feature includes:

[0023] Processing the mapping feature through the filter to obtain a second result;

[0024] Comparing the second result with the label, and constructing a second mask matrix according to the comparison result;

[0025] The mapped feature is multiplied item by item with the elements in the second mask matrix to set the elements at the positions of the error information to zero, and the feature after the elements are set to zero is used as the second mask feature.

[0026] Optionally, determining the mask norm direction loss according to the first mask feature and the second mask feature includes:

[0027] constructing a norm loss based on the second mask feature that is smaller than the first mask feature;

[0028] Calculating the cosine similarity between the first mask feature and the second mask feature, and constructing a directional loss based on the cosine similarity and the class mean of all teacher models;

[0029] The norm loss and the direction loss are weighted respectively to construct the mask norm direction loss.

[0030] Optionally, performing feature mapping on the intermediate layer of the student model to obtain mapping features includes:

[0031] Each intermediate layer of the student model is feature mapped through a projector to obtain the mapping feature, and the dimension of the mapping feature is the same as the dimension of the extended feature.

[0032] Optionally, the projector comprises at least three convolutional layers of sizes 1x1, 3x3 and 1x1 respectively, each of the convolutional layers being followed by a batch normalization layer and a ReLu activation function.

[0033] Optionally, aligning the feature direction of the auxiliary model with the main model to obtain the alignment feature includes:

[0034] The feature direction of the main model is aligned with the feature direction of the auxiliary model through a direction aligner to obtain the aligned feature, wherein the direction aligner includes a 1×1 convolution layer and a 3×3 convolution layer, each convolution layer is followed by a batch normalization layer and a ReLu activation function, and the number of the direction aligners is the same as the number of the auxiliary models.

[0035] Optionally, before aligning the feature direction of the primary model with the feature direction of the secondary model by a direction aligner to obtain the alignment feature, the method further includes:

[0036] Calculate the deviation between the class mean of each sample in the training set and the alignment feature by using the cosine similarity algorithm;

[0037] Using the deviation as a direction alignment loss function;

[0038] A direction aligner is trained based on the direction alignment loss function.

[0039] Optionally, determining a main model among multiple teacher models and using other teacher models as auxiliary models includes:

[0040] The teacher model with the highest recognition accuracy is used as the main model. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 Schematic diagram of a flow chart of a knowledge distillation method based on a multi-teacher model according to an embodiment of the present invention;

[0042] Figure 2 It is a schematic diagram of a detailed process of step S500 of the knowledge distillation method based on a multi-teacher model according to an embodiment of the present invention;

[0043] Figure 3 It is a flowchart diagram of a refinement of step S600 of the knowledge distillation method based on a multi-teacher model according to an embodiment of the present invention;

[0044] Figure 4 This is a flowchart of a refinement of step S700 of the knowledge distillation method based on a multi-teacher model in an embodiment of the present invention. DETAILED DESCRIPTION

[0045] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be interpreted as being limited to the embodiments described herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0046] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.

[0047] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments"; the term "optionally" means "optional embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0048] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0049] like Figure 1 As shown, an embodiment of the present invention provides a knowledge distillation method based on a multi-teacher model, including:

[0050] Step S100, determining a main model among multiple teacher models, and using other teacher models as auxiliary models.

[0051] Knowledge distillation is a model compression technology that aims to transfer large and complex (teacher model) knowledge to small and efficient (student model) while maintaining the highest possible performance. Multi-teacher knowledge distillation can integrate different features from different teachers into a more comprehensive feature. In theory, multi-teacher distillation can train a better student model, but in existing technical solutions, multi-teacher distillation not only ignores mismatched features from different teachers, but also only retains the same number of features as single-teacher distillation, resulting in a more obvious loss of knowledge, and the effect is not much different from that of single-teacher distillation.

[0052] In one embodiment, there are differences between multiple teacher models. For example, different teacher models have angular differences when using cosine similarity checks, and these angular differences will lead to divergence in model detection results, hindering the overall performance of the integrated model. After adding the features of multiple teacher models, the dimensions of the integrated features involved in the loss calculation are the same as those of a single teacher. For example, when three teachers are introduced, there are initially three teacher feature sets with the same dimensions for students to learn. However, after adding them, only one set of features remains, and the number of features is reduced to 1 / n, where n represents the number of teacher models. The additional knowledge that should have been provided to the student model is eliminated. Therefore, when performing knowledge distillation on multiple teacher models, it is necessary to minimize the lost knowledge and group the features. Therefore, in this embodiment, the directions of different teacher models are aligned by introducing direction-aware knowledge reorganization.

[0053] Optionally, determining a main model among multiple teacher models and using other teacher models as auxiliary models includes:

[0054] The teacher model with the highest recognition accuracy is used as the main model.

[0055] In one embodiment, the teacher model with the highest recognition accuracy is used as the main model, and the consistency problem of feature directions of multiple teacher models is solved by determining the main model and the auxiliary model.

[0056] Step S200, aligning the feature direction of the auxiliary model with the main model to obtain an alignment feature.

[0057] In one embodiment, direction perception, i.e., determining the feature direction of the primary model and aligning the feature direction of the secondary model with the primary model, has the same requirements as the projector, and is used to reduce the feature angle between teacher models while retaining as much abstract knowledge as possible from the teacher within each target class.

[0058] Generally speaking, when and When they are two vectors symmetric about point c, their cosine similarities with respect to point c can cancel each other out numerically.

[0059] ,

[0060] When we accumulate the cosine similarity between each vector and the class center, this not only strongly constrains the direction towards the class mean of the main teacher feature, but also relaxes the constraints on the directional differences between different features within the same class. This allows the overall direction to be adjusted while maintaining the local relationship between different features within the same class. This means that the model has more flexibility to optimize and adjust the direction of feature representation while maintaining the relative relationship between features within the class, thereby better capturing the essential characteristics and nuances of the class.

[0061] Step S300: Superimpose the alignment feature with the feature of the main model along the second dimension to obtain an extended feature, wherein the feature dimension of the extended feature is higher than the feature dimension of the main model or the auxiliary model.

[0062] In one embodiment, in order not to lose the dimension of the integrated features, these directionally aligned features are superimposed along the second dimension to become extended features. In this embodiment, the feature dimension of the extended features is equal to the sum of the feature dimensions of each classroom. In the superposition process, it is equivalent to combining the teacher features to maximize the knowledge retention of multiple teachers. Through direction alignment, the feature information provided by each teacher model is integrated into a high-dimensional feature vector while maintaining its unique directionality. Doing so not only brings together the advantages of each teacher model, but also potentially improves the effect of knowledge distillation by increasing the dimension and diversity of features, so that the student model can learn richer and more diverse feature representations. Such a design promotes the student model to comprehensively learn the collective knowledge of all teacher models without losing any important information of a single teacher model, thereby improving its learning ability and generalization performance. Feature superposition can be expressed as:

[0063] ,

[0064] in, Indicates extended features, represents the features after alignment of the i-th teacher model, n represents the number of teacher models, and i represents the i-th teacher model.

[0065] Step S400, performing feature mapping on the middle layer of the student model to obtain mapping features.

[0066] In one embodiment, not only the specific number of layers of the student model network needs to be paid attention to, but also feature mapping needs to be performed on each intermediate layer of the student model. By enhancing the distillation structure of the intermediate layer, the features of the student intermediate layer are mapped to the dimension consistent with the extended features, so that the student model can learn from multiple teacher models at the same time to better extract knowledge from the extended features. It is also helpful to calculate the mask norm loss and direction loss, thereby better optimizing the student model.

[0067] Step S500: performing mask processing on the extended feature to obtain a first mask feature.

[0068] Step S600: performing mask processing on the mapping feature to obtain a second mask feature.

[0069] In one embodiment, on the one hand, by masking the extended features, erroneous knowledge in the extended features is cleaned up, thereby improving the distillation effect and efficiency of the teacher model; on the other hand, by masking the mapping features, a larger loss is given to mapping features with larger differences, thereby improving the training effect and efficiency of the student model.

[0070] Step S700: determining a mask norm direction loss according to the first mask feature and the second mask feature.

[0071] In one embodiment, the norm loss and the directional loss are calculated according to the first mask feature and the second mask feature, respectively. The norm loss is used to characterize the size of the student model and the teacher model on the L2 norm, and the student model is optimized based on the size relationship. The directional loss is used to characterize the angle between the student model and all teacher models, and the student model is optimized based on the angle.

[0072] Step S800, optimizing the student model according to the loss function, and classifying and identifying the image using the optimized student model, wherein the loss function includes the mask norm direction loss.

[0073] Exemplarily, the image to be processed is input into the optimized student model, and the optimized student model extracts features from the image to be processed, and performs image recognition and classification based on the extracted features. The optimized student model can use the knowledge from different teacher models to extract features, and can extract more comprehensive and richer features, thereby effectively improving the image recognition effect for the image to be processed.

[0074] In one embodiment, the student model is optimized according to a loss function including a mask norm directional loss to achieve knowledge distillation from multiple teacher models to the student model.

[0075] A new knowledge reorganization multi-teacher distillation (KRMD) is introduced in the embodiment of the present application. Compared with the typical multi-teacher method, direction-aware knowledge reorganization is introduced in steps S100-S300, by aligning the feature directions of different teachers to alleviate the mismatch between their features. In order to maximize the amount of knowledge preserved for each teacher, instead of simply adding them, the features in the aligned directions are stacked to a higher dimension to obtain extended features. In addition, for parallel learning from multiple teachers, in step S400, feature mapping is performed on the intermediate layers of the student model to better cooperate with the mask norm direction (MND) loss of steps S500-S700. Among them, feature mapping can map the student's features to a higher dimension to better learn knowledge from multiple teacher models at the same time, and it is also convenient to calculate the loss brought about by the knowledge distillation process; the mask norm direction loss eliminates the erroneous features in the extended features composed of multiple teacher models by masking, thereby ensuring the improvement of the accuracy of the knowledge distillation process of multiple teacher models.

[0076] Specifically, by determining the main and secondary relationships in multiple teacher models, and then determining the feature directions that the teacher models need to align, the problem of feature direction mismatch of multiple teacher models is avoided. The extended features are obtained by superimposing the aligned features with the features of the main model along the second dimension, so that the features include knowledge from different teacher models, and the student model learns from multiple teacher models at the same time, and obtains better knowledge distillation effect; by mapping the features of the middle layer of the student model, it is ensured that the student model can have the same dimension as the extended features after expansion, and obtain better knowledge distillation effect. The same dimension is also convenient for calculating the mask norm direction loss, so that the student model can be optimized according to the loss function, and the knowledge loss of the teacher model is avoided on the basis of realizing multi-teacher knowledge distillation. The optimized student model is used to classify and recognize pictures, and can process pictures based on the knowledge from different teacher models, which improves the comprehensiveness of image recognition. Compared with the student model distilled from a single teacher model, the image recognition effect is effectively improved.

[0077] Optionally, the loss function also includes logit distillation loss and classification loss.

[0078] The total loss function can be expressed as:

[0079] ,

[0080] Among them, LOSS represents the loss function, α, β, and γ represent the weights of the loss. represents the classification loss, represents the logit distillation loss, represents the mask norm direction loss.

[0081] Alternatively, if Figure 2As shown, performing mask processing on the extended feature to obtain the first mask feature includes:

[0082] Step S510, using the classifier of the preset teacher model as a filter.

[0083] Step S520: Process the extended feature through the filter to obtain a first result.

[0084] Step S530: compare the first result with the label, and construct a first mask matrix according to the comparison result.

[0085] Step S540: determine the first mask feature through the first mask matrix and the extended feature.

[0086] In one embodiment, since the class mean of the auxiliary model is aligned to approximately the same position as the main model through the direction-aware knowledge rearrangement step of steps S100-S300, we choose to use the FC (fully connected layer) classifier of the preset teacher model as the filter. In this embodiment, the classifier of the first teacher model is used. As a filter, after the filter processes the extended features, an output result corresponding to the extended features is obtained as a first result. By comparing the first result with the corresponding previously marked true label, a first mask matrix can be obtained, wherein the construction of the first mask matrix can be expressed as:

[0087] ,

[0088] in, represents the i-th element in the first mask matrix, Indicates the classifier processing features The output result is, For extended features One of the features, represents the true label.

[0089] In the first mask matrix, each element has a value of 0 or 1, and the dimension of the first mask matrix is ​​the same as the extended feature Similarly, the first mask matrix and the extended features can remove the erroneous features and obtain the first mask features.

[0090] Optionally, the determining the first mask feature by using the first mask matrix and the extended feature includes:

[0091] The extended feature and the elements in the first mask matrix are multiplied item by item to set the elements at the positions of the error information to zero, and the feature after the elements are set to zero is used as the first mask feature.

[0092] In one embodiment, since the elements in the first mask matrix are 0 or 1, and the extended feature and the first mask matrix have the same dimension, after multiplying the extended feature and the elements in the first mask matrix item by item, it can be seen from the above formula that the error information is 0, then the element at the position of the error information after the multiplication is set to zero, and only the correct information is retained in the first mask feature.

[0093] The formula can be expressed as:

[0094] ,

[0095] in, represents the first mask feature, MASK represents the first mask matrix, Indicates an extended feature.

[0096] Alternatively, if Figure 3 As shown, the mapping feature is subjected to mask processing to obtain a second mask feature, including:

[0097] Step S610: Process the mapping feature through the filter to obtain a second result.

[0098] Step S620: compare the second result with the label, and construct a second mask matrix according to the comparison result.

[0099] Step S630: multiply the mapped features by the elements in the second mask matrix item by item to set the elements at the positions of the error information to zero, and use the features after the elements are set to zero as the second mask features.

[0100] In one embodiment, the mask operation is applied to the mapping features in a manner similar to steps S510-S540 to ensure that erroneous information does not affect the gradient during the calculation of the loss function.

[0101] The formula can be expressed as:

[0102] ,

[0103] in, represents the second mask feature, MASK represents the second mask matrix, Represents the mapping feature.

[0104] Alternatively, if Figure 4 As shown, determining the mask norm direction loss according to the first mask feature and the second mask feature includes:

[0105] Step S710: constructing a norm loss based on the second mask feature that is smaller than the first mask feature.

[0106] Step S720, calculating the cosine similarity between the first mask feature and the second mask feature, and constructing a directional loss based on the cosine similarity and the class mean of all teacher models.

[0107] Step S730, weighting the norm loss and the directional loss respectively to construct the mask norm directional loss.

[0108] In one embodiment, a better student model is obtained by constructing a norm loss and a direction loss respectively. On the one hand, by encouraging the mapping features of the intermediate layer of the student model to have a larger L2 norm, it specifically includes: penalizing the intermediate layer mapping features that are smaller than the teacher norm, and then calculating the norm loss of all intermediate layer mapping features. .

[0109] The formula can be expressed as:

[0110] ,

[0111] in, represents the norm loss, represents the first mask feature, Represents the second mask feature, N represents the number of intermediate layers of the student model, and i represents the i-th layer.

[0112] Secondly, the idea of ​​maximizing the directional consistency of the first mask feature and the second mask feature and trying to get close to the direction of the class center determined by the teacher model is used as the definition condition of the directional loss. The stronger the directional consistency, the smaller the loss; the closer to the direction of the class center, the smaller the loss. The directional loss of all intermediate layer mapping features is calculated.

[0113] The formula can be expressed as:

[0114] ,

[0115] in, represents the direction loss, n represents the number of teacher models, represents the first mask feature, Represents the second mask feature, N represents the number of intermediate layers of the student model, and i represents the i-th layer. represents the angle between the first mask feature and the second mask feature, and c represents the class mean of the kth class to which the input image belongs. The collection formed.

[0116] Furthermore, the norm loss and the direction loss are weighted respectively to construct the mask norm direction loss It can be expressed as:

[0117] ,

[0118] in, Represents an adjustable hyperparameter for balancing and The ratio between them.

[0119] Optionally, performing feature mapping on the intermediate layer of the student model to obtain mapping features includes:

[0120] Each intermediate layer of the student model is feature mapped through a projector to obtain the mapping feature, and the dimension of the mapping feature is the same as the dimension of the extended feature.

[0121] Optionally, the projector comprises at least three convolutional layers of sizes 1x1, 3x3 and 1x1 respectively, each of the convolutional layers being followed by a batch normalization layer and a ReLu activation function.

[0122] In one embodiment, projectors with the same structure correspond one-to-one with the intermediate layers, and feature mapping is performed, focusing not only on the penultimate layer but also on each layer of the intermediate layer for distillation. The dimension of the mapped features is the same as the dimension of the expanded features, which is used to better calculate the mask norm direction loss. For example, if the student model has five intermediate layers, it uses five identical convolutional layer structures with three layers (convolutional layers of size 1x1, 3x3, and 1x1), and each convolutional layer is followed by batch normalization and ReLu activation functions. This design aims to extract features through convolution operations. Batch normalization is used to accelerate the training process and improve the generalization ability of the model, while the ReLu activation function can introduce nonlinearity, allowing the network to learn more complex feature representations.

[0123] Optionally, aligning the feature direction of the auxiliary model with the main model to obtain the alignment feature includes:

[0124] The feature direction of the main model is aligned with the feature direction of the auxiliary model through a direction aligner to obtain the aligned feature, wherein the direction aligner includes a 1×1 convolution layer and a 3×3 convolution layer, each convolution layer is followed by a batch normalization layer and a ReLu activation function, and the number of the direction aligners is the same as the number of the auxiliary models.

[0125] After selecting the teacher model with the highest accuracy as the main model, the other teacher models are used as auxiliary models, and a direction aligner is designed for each auxiliary model. Through the direction aligner, the class means of the main model and the auxiliary model are made the same. The design of the direction aligner includes n-1 independent and identically structured alignment components. Each substructure It consists of a set of projectors with 1×1 and 3×3 convolutional layers, and uses batch normalization and ReLu activation function after each layer. Through the direction aligner, the original features can be Convert to a feature aligned with the main model .

[0126] Optionally, before aligning the feature direction of the primary model with the feature direction of the secondary model by a direction aligner to obtain the alignment feature, the method further includes:

[0127] Calculate the deviation between the class mean of each sample in the training set and the alignment feature by using the cosine similarity algorithm;

[0128] Using the deviation as a direction alignment loss function;

[0129] A direction aligner is trained based on the direction alignment loss function.

[0130] In one embodiment, the training direction aligner can be expressed as:

[0131] ,

[0132] in, represents the direction alignment loss function, n represents the number of teacher models, i represents the i-th teacher model, bsz represents the number of samples / batch size, j represents the j-th sample, represents the features of the jth sample after alignment with the main model, represents the class mean of the kth class to which the jth input image belongs. Each set Form a set C, which determines the target feature based on the center point of each category predicted by the main teacher model on the training dataset. As a loss function for aligning the feature directions of different teacher models, It aims to adjust the direction of the teacher model features while preserving as much abstract knowledge of each target category as possible in the aligned teacher model.

[0133] In an embodiment of the present application, a direction aligner is trained through a direction alignment loss function, and through independent direction aligners, the feature directions of the auxiliary models are adjusted one by one to align with the feature directions of the main model. The aligned features are stacked as high-order extended features, and the logits of the main model are used as the final logit for knowledge distillation. After the direction alignment is performed, the classifier of the preset teacher model is used as a filter to remove the erroneous features in the extended features to ensure that the erroneous features are not involved in the calculation of the mask norm direction loss. On the other hand, the distillation structure of the student model also changes accordingly, and the distillation structure of the middle layer of the student model is enhanced. Through the projector, feature mapping is performed on each middle layer, and the features are mapped to the same dimension as the extended features, which helps the student model to learn the knowledge of multiple teacher models at the same time and helps to calculate the loss.

[0134] Another embodiment of the present invention provides an electronic device, including a memory and a processor; the memory is used to store a computer program; the processor is used to implement the knowledge distillation method based on the multi-teacher model as described above when executing the computer program.

[0135] Another embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the knowledge distillation method based on the multi-teacher model as described above is implemented.

[0136] An electronic device that can be used as a server or client of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. Electronic devices are intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0137] The electronic device includes a computing unit, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) or a computer program loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for the operation of the device can also be stored. The computing unit, ROM, and RAM are connected to each other through a bus. An input / output (I / O) interface is also connected to the bus.

[0138] A computer system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on the respective computers and having a client-server relationship to each other.

[0139] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. In the present application, the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, which may be located in one place or distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present invention. In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0140] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will fall within the protection scope of the present invention.

Claims

1. A knowledge distillation method based on a multi-teacher model, characterized in that: include: Determine a main model among multiple teacher models, and use other teacher models as auxiliary models; Aligning the feature direction of the auxiliary model with the main model to obtain an alignment feature; Superimposing the alignment feature with the feature of the main model along the second dimension to obtain an extended feature, wherein the feature dimension of the extended feature is higher than the feature dimension of the main model or the auxiliary model; Perform feature mapping on the middle layer of the student model to obtain mapping features; Performing mask processing on the extended feature to obtain a first mask feature; The mapping feature is subjected to mask processing to obtain a second mask feature; Determining a mask norm direction loss according to the first mask feature and the second mask feature; The student model is optimized according to the loss function, and the image is classified and recognized by the optimized student model, wherein the loss function includes the mask norm direction loss.

2. The knowledge distillation method based on the multi-teacher model according to claim 1 is characterized in that: The performing mask processing on the extended feature to obtain a first mask feature comprises: Use the classifier of the preset teacher model as a filter; Processing the extended feature through the filter to obtain a first result; Compare the first result with the label, and construct a first mask matrix according to the comparison result; The first mask feature is determined by the first mask matrix and the extended feature.

3. The knowledge distillation method based on the multi-teacher model according to claim 2 is characterized in that: The determining the first mask feature by using the first mask matrix and the extended feature comprises: The extended feature and the elements in the first mask matrix are multiplied item by item to set the elements at the positions of the error information to zero, and the feature after the elements are set to zero is used as the first mask feature.

4. The knowledge distillation method based on the multi-teacher model according to claim 3 is characterized in that: The mapping feature is subjected to mask processing to obtain a second mask feature, comprising: Processing the mapping feature through the filter to obtain a second result; Comparing the second result with the label, and constructing a second mask matrix according to the comparison result; The mapped features are multiplied item by item with the elements in the second mask matrix to set the elements at the positions of the error information to zero, and the features after the elements are set to zero are used as the second mask features.

5. The knowledge distillation method based on a multi-teacher model according to any one of claims 1 to 4, characterized in that: The determining of the mask norm direction loss according to the first mask feature and the second mask feature comprises: constructing a norm loss based on the second mask feature that is smaller than the first mask feature; Calculating the cosine similarity between the first mask feature and the second mask feature, and constructing a directional loss based on the cosine similarity and the class mean of all teacher models; The norm loss and the direction loss are weighted respectively to construct the mask norm direction loss.

6. The knowledge distillation method based on the multi-teacher model according to claim 5, characterized in that: The feature mapping of the middle layer of the student model to obtain the mapping features includes: Each intermediate layer of the student model is feature mapped through a projector to obtain the mapping feature, and the dimension of the mapping feature is the same as the dimension of the extended feature.

7. The knowledge distillation method based on the multi-teacher model according to claim 6 is characterized in that: The projector includes at least three convolutional layers of sizes 1x1, 3x3 and 1x1, each of which is followed by a batch normalization layer and a ReLu activation function.

8. The knowledge distillation method based on the multi-teacher model according to claim 5, characterized in that: The step of aligning the feature direction of the auxiliary model with the main model to obtain the alignment feature comprises: The feature direction of the main model is aligned with the feature direction of the auxiliary model through a direction aligner to obtain the aligned feature, wherein the direction aligner includes a 1×1 convolution layer and a 3×3 convolution layer, each convolution layer is followed by a batch normalization layer and a ReLu activation function, and the number of the direction aligners is the same as the number of the auxiliary models.

9. The knowledge distillation method based on the multi-teacher model according to claim 8, characterized in that: Before aligning the feature direction of the main model with the feature direction of the auxiliary model by the direction aligner to obtain the alignment feature, the method further includes: Calculate the deviation between the class mean of each sample in the training set and the alignment feature by using a cosine similarity algorithm; Using the deviation as a direction alignment loss function; A direction aligner is trained based on the direction alignment loss function.

10. The knowledge distillation method based on the multi-teacher model according to claim 5, characterized in that: The determining of a main model among a plurality of teacher models and using other teacher models as auxiliary models comprises: The teacher model with the highest recognition accuracy is used as the main model.