Feature recognition training method, device and equipment and readable storage medium
By extracting four-dimensional and two-dimensional feature tensors and vectors in feature recognition training, calculating multiple loss functions and optimizing student model parameters, the problem of insufficient model generalization ability in existing technologies is solved, and higher recognition accuracy and performance improvement are achieved.
Patent Information
- Application Number
- CN202510762138.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-09
- Publication Date
- 2025-09-09
AI Technical Summary
Existing feature recognition training methods have shortcomings in improving model generalization ability and recognition accuracy, especially when dealing with high-dimensional features, it is difficult to capture the complex dependencies between features.
By inputting the input data into the pre-trained teacher model and the student model to be trained respectively, four-dimensional and two-dimensional feature tensors and feature vectors are extracted, the mask mapping loss, similarity preservation loss and label classification loss are calculated, the total loss function is jointly constructed, and the student model parameters are optimized through backpropagation.
It significantly improves the generalization ability and recognition accuracy of the model, solves the problem that traditional methods have difficulty in capturing complex dependencies when dealing with high-dimensional features, and enhances the overall performance of the model.
Smart Images

Figure CN120611222A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of model training technology, and more specifically, to a feature recognition training method, apparatus, device and readable storage medium. Background Art
[0002] In the field of feature recognition, improving the recognition ability and generalization performance of the model is crucial. Traditional model training methods often rely on large amounts of labeled data and complex network structures, resulting in high training costs and low efficiency. In existing technologies, knowledge distillation methods are widely used. By transferring the knowledge of the teacher model to the student model, the performance of the student model can be improved to a certain extent. However, existing knowledge distillation methods usually only focus on the surface similarity of features, ignoring the structural relationships and semantic information within the features, resulting in insufficient generalization ability of the student model when faced with unseen samples. In addition, when dealing with high-dimensional features, traditional methods have difficulty effectively capturing the complex dependencies between features, further limiting the performance improvement of the model.
[0003] Therefore, a more effective feature recognition training method is needed to improve the generalization ability and recognition accuracy of the model. Summary of the Invention
[0004] This application provides a feature recognition training method, apparatus, device and readable storage medium, which significantly improves the recognition accuracy and generalization performance of the model while keeping the model lightweight.
[0005] A feature recognition training method, comprising:
[0006] Input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0007] Calculating a mask mapping loss through mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor;
[0008] Calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0009] Calculating label classification loss based on the two-dimensional student feature vector and the corresponding sample label;
[0010] Combining the mask mapping loss, the similarity preservation loss, and the label classification loss to construct a total loss function;
[0011] The student model parameters are optimized by back-propagation until the total loss function converges.
[0012] Optionally, based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, a mask mapping loss is calculated by mask generative mapping, including:
[0013] Performing channel dimension alignment on the four-dimensional student feature tensor to generate an aligned feature tensor with the same dimension as the four-dimensional teacher feature tensor;
[0014] generating a mask matrix according to the activation value of the aligned feature tensor, and multiplying the mask matrix by the aligned feature tensor element by element to obtain a masked feature tensor;
[0015] Performing a convolution mapping operation on the masked feature tensor to generate a mapped feature tensor with the same dimension as the four-dimensional teacher feature tensor;
[0016] The mean square error between the mapping feature tensor and the four-dimensional teacher feature tensor is calculated to obtain the mask mapping loss.
[0017] Optionally, the calculation formula of the mask mapping loss is:
[0018]
[0019] in, is the mask mapping loss, is the four-dimensional teacher feature tensor, is the mapping feature tensor, is the number of batch samples, is the teacher characteristic dimension, is the spatial dimension.
[0020] Optionally, calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector includes:
[0021] Performing L2 norm normalization processing on the two-dimensional teacher feature vector and the two-dimensional student feature vector respectively to generate teacher normalized features and student normalized features;
[0022] Calculating a corresponding teacher feature self-similarity matrix based on the teacher normalized features, and calculating a corresponding student feature self-similarity matrix based on the student normalized features;
[0023] The difference between the teacher feature self-similarity matrix and the student feature self-similarity matrix is calculated by mean square error to obtain the similarity preservation loss.
[0024] Optionally, the calculation formula for the similarity preservation loss is:
[0025]
[0026] ,
[0027] in, For similarity preservation loss, is the teacher feature self-similarity matrix, is the student feature self-similarity matrix, is the number of batch samples, is the teacher normalized feature, Normalize features for students.
[0028] Optionally, the calculation formula for the label classification loss is:
[0029]
[0030] in, is the label classification loss, is the scale factor, is the angle marginal parameter, For samples Corresponding to the angle of the true category, is the number of samples in the batch.
[0031] Optionally, the total loss function is:
[0032]
[0033] in, is the mask mapping loss, For similarity preservation loss, is the label classification loss, 、 、 is the weight coefficient.
[0034] A feature recognition training device, comprising:
[0035] A feature extraction unit is used to input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0036] A mask loss unit, configured to calculate a mask mapping loss by mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor;
[0037] A preservation loss unit, configured to calculate a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0038] A classification loss unit, configured to calculate a label classification loss based on the two-dimensional student feature vector and the corresponding sample label;
[0039] a joint loss unit, configured to jointly construct a total loss function by combining the mask mapping loss, the similarity preservation loss, and the label classification loss;
[0040] An optimization training unit is used to optimize the student model parameters by back propagation until the total loss function converges.
[0041] A feature recognition training device comprising a memory and a processor;
[0042] The memory is used to store programs;
[0043] The processor is used to execute the program to implement each step of the feature recognition training method as described in any one of the above items.
[0044] A readable storage medium stores a computer program thereon, wherein when the computer program is executed by a processor, the computer program implements each step of the feature recognition training method as described in any one of the above items.
[0045] It can be seen from the above technical solutions that the embodiment of the present application provides a feature recognition training method, device, equipment and readable storage medium. The method inputs the input data into the pre-trained teacher model and the student model to be trained respectively, and extracts the four-dimensional teacher feature tensor and the four-dimensional student feature tensor as well as the two-dimensional teacher feature vector and the two-dimensional student feature vector. The mask mapping loss is calculated based on the four-dimensional feature tensor through mask generative mapping, the similarity preservation loss is calculated based on the two-dimensional feature vector, and the label classification loss is calculated at the same time. The total loss function is jointly constructed and the student model parameters are optimized by back propagation. This solution can capture the structural relationship and semantic information inside the feature through mask generative mapping, solves the problem of ignoring the internal structure of the feature in the prior art, thereby improving the model's generalization ability for unseen samples. At the same time, by calculating the similarity preservation loss, it is ensured that the student model learns the feature expression of the teacher model, further enhancing the recognition ability of the model. In addition, by combining multiple loss functions for optimization, different aspects of the feature can be considered more comprehensively, effectively solving the defect that the traditional method is difficult to capture complex dependencies when processing high-dimensional features, thereby improving the overall performance and recognition accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0047] Figure 1This is a flow chart of a feature recognition training method disclosed in an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a feature recognition training method disclosed in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of a feature recognition training device disclosed in an embodiment of the present application;
[0050] Figure 4 This is a hardware structure block diagram of a feature recognition training device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0052] The present application can be used in a variety of general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, and distributed computing environments including any of the above devices or devices.
[0053] Next, we will introduce the application scheme. This application proposes the following technical scheme, please see below for details.
[0054] Figure 1 This is a flowchart of a feature recognition training method disclosed in an embodiment of the present application.
[0055] Figure 2 A schematic diagram of a feature recognition training method disclosed in an embodiment of the present application.
[0056] like Figure 1 and Figure 2 As shown, the method may include:
[0057] Step S1: Input the input data into the pre-trained teacher model and the student model to be trained respectively, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector.
[0058] Specifically, during the training process, the input data is processed in batches, and the number of batches is recorded as B. The input data of the same batch is simultaneously input to the pre-trained teacher model with fixed parameters and the student model to be trained. The teacher model first extracts a four-dimensional teacher feature tensor, whose shape is [B, , H, W], where Represents the dimension of teacher features, H and W are the height and width of the feature map respectively; at the same time, the teacher model further analyzes the input data to extract a two-dimensional teacher feature vector, the shape of [B, The student model synchronously extracts the four-dimensional student feature tensor with the shape of [B, ,H,W], is the student feature dimension, and extracts the two-dimensional student feature vector with the shape of [B, ]. If the dimensions of the teacher and student feature vectors are inconsistent (i.e., D1≠D2), the student feature vector needs to be dimensionally aligned through a projection layer such as a fully connected layer or a convolutional layer to make it consistent with the teacher feature vector dimension for subsequent calculations.
[0059] Step S2: Based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, calculate the mask mapping loss through mask generative mapping.
[0060] Specifically, after obtaining the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, the student feature tensor is first dimensionally aligned. Through a preset 1×1 convolution layer, the number of channels of the student feature tensor is adjusted to be consistent with the teacher feature tensor, and the aligned feature tensor is obtained. Next, a random mask tensor mask is generated, whose shape can be [B, , H, W], or by performing global average pooling of the spatial dimension on the aligned feature tensor. Specifically, the average pooling operation with a kernel size of (H, W) is used to pool the aligned feature tensor on the spatial dimension (H, W), resulting in a shape of [B, , 1, 1] mask tensor, this operation only aggregates spatial information and does not change the number of channels The element values of the mask tensor are generated according to a preset rule: if the activation value after pooling is lower than the threshold ε (such as 0.1-0.3), the corresponding position is set to a random number a (in the range [0, 0.1]), otherwise it is set to 1.
[0061] The mask tensor is multiplied element-by-element by the aligned feature tensor to obtain the masked feature tensor, thereby suppressing unimportant feature areas in the space or low activation value parts in the channel dimension.
[0062] Subsequently, the mask feature tensor is mapped through two layers of 1×1 convolutional networks with the same number of channels. The number of input channels of the first convolutional layer is , the number of output channels remains , and introduced the ReLU activation function to enhance the nonlinear expression ability; the second convolution layer also keeps the number of input and output channels as , further learning the complex interaction between features. After mapping, a mapping feature tensor with the same dimension as the teacher feature tensor is generated (the shape is [B, , H, W]).
[0063] Finally, the average squared difference between the mapped feature tensor and the teacher feature tensor across all batches, channels, and spatial positions is calculated as the mask mapping loss. This loss constrains the structural similarity between the student and teacher features, forcing the student model to learn richer feature representations and feature interactions, thereby improving the model's generalization performance.
[0064] Step S3: Calculate the similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector.
[0065] Specifically, to eliminate the influence of eigenvector amplitude on similarity calculations, the two-dimensional teacher eigenvector and the two-dimensional student eigenvector are first normalized using the L2 norm, so that the length of each vector is 1, retaining only directional information. Based on the normalized teacher eigenvector, a self-similarity matrix is calculated between all samples. Each element in the matrix is the dot product of the eigenvectors of the corresponding two samples, reflecting the degree of similarity between the samples. The same operation is performed on the student eigenvector to generate a student feature self-similarity matrix. By comparing the differences between the two self-similarity matrices and calculating the squared average of the corresponding element differences, a similarity preservation loss is obtained. This loss is used to constrain the student model to learn the feature correlation structure between samples in the teacher model, ensuring the consistency of feature distribution.
[0066] Step S4: Calculate the label classification loss based on the two-dimensional student feature vector and the corresponding sample label.
[0067] Specifically, the two-dimensional student feature vector is input into a classifier (such as a fully connected layer), which outputs a predicted score for each class. The predicted scores are converted to a probability distribution using the softmax function, and the cross-entropy loss function is used to calculate the difference between this probability distribution and the true sample label (in one-hot encoding). The cross-entropy loss measures the degree of mismatch between the predicted result and the true label. The closer the predicted probability is to the true label, the smaller the loss value. By minimizing this loss, the feature vector of the student model can effectively distinguish between different classes, improving classification accuracy.
[0068] The calculation formula for the label classification loss is:
[0069]
[0070] in, is the label classification loss, is the scale factor, is the angle marginal parameter, For samples Corresponding to the angle of the true category, is the number of samples in the batch.
[0071] Step S5: Combining the mask mapping loss, the similarity preservation loss, and the label classification loss to construct a total loss function.
[0072] Specifically, the mask mapping loss, similarity preservation loss, and label classification loss are combined into a total loss function through weighted summation. Adjustable weight coefficients (such as α, β, γ) are set before each loss term to balance the impact of different losses on model training. The weight coefficients need to be set according to specific task requirements. For example, in scenarios where feature structure learning is more critical, the weight of the mask mapping loss can be increased. The total loss function comprehensively reflects the overall performance of the student model in terms of feature tensor structure, feature vector similarity, and classification tasks. By optimizing the total loss function, multi-objective collaborative optimization is achieved to ensure that the model achieves good performance in multiple dimensions.
[0073] The total loss function is:
[0074]
[0075] in, is the mask mapping loss, For similarity preservation loss, is the label classification loss, 、 、 is the weight coefficient.
[0076] Step S6: Optimize the student model parameters by back propagation until the total loss function converges.
[0077] Specifically, after constructing the total loss function, the backpropagation algorithm is used to calculate the gradient of the total loss with respect to each parameter of the student model. Model parameters (such as convolutional layer weights and biases) are then updated based on the gradient direction. During the parameter update process, optimizers (such as Adam and SGD) are used to adjust the update step size to accelerate convergence and avoid falling into local optima. The value of the total loss function is continuously monitored during training. When the loss value no longer decreases significantly over multiple consecutive training batches or fluctuates below a preset threshold, the model is considered to have reached convergence. Training is then terminated, resulting in the optimized student model. Through iterative optimization, this process enables the student model to gradually learn the feature expression capabilities of the teacher model and improve its generalization performance on the target task.
[0078] It can be seen from the above technical solutions that the embodiment of the present application provides a feature recognition training method, device, equipment and readable storage medium. The method inputs the input data into the pre-trained teacher model and the student model to be trained respectively, and extracts the four-dimensional teacher feature tensor and the four-dimensional student feature tensor as well as the two-dimensional teacher feature vector and the two-dimensional student feature vector. The mask mapping loss is calculated based on the four-dimensional feature tensor through mask generative mapping, the similarity preservation loss is calculated based on the two-dimensional feature vector, and the label classification loss is calculated at the same time. The total loss function is jointly constructed and the student model parameters are optimized by back propagation. This solution can capture the structural relationship and semantic information inside the feature through mask generative mapping, solves the problem of ignoring the internal structure of the feature in the prior art, thereby improving the model's generalization ability for unseen samples. At the same time, by calculating the similarity preservation loss, it is ensured that the student model learns the feature expression of the teacher model, further enhancing the recognition ability of the model. In addition, by combining multiple loss functions for optimization, different aspects of the feature can be considered more comprehensively, effectively solving the defect that the traditional method is difficult to capture complex dependencies when processing high-dimensional features, thereby improving the overall performance and recognition accuracy of the model.
[0079] In some embodiments of the present application, the process of calculating the mask mapping loss by mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor in step S2 is introduced, which may specifically include:
[0080] Step S21: perform channel dimension alignment on the four-dimensional student feature tensor to generate an aligned feature tensor with the same dimension as the four-dimensional teacher feature tensor.
[0081] Specifically, when obtaining the four-dimensional student feature tensor (The shape is [B, , H, W]) and the four-dimensional teacher feature tensor (The shape is [B, , H, W]), since the number of feature channels of the student model and the teacher model is usually different, it is necessary to align the channel dimension of the student features. By designing a parameter-learnable 1×1 convolutional layer To achieve dimension conversion, the number of input channels is , the number of output channels is , the convolution kernel size is 1×1. This convolution operation changes the number of channels of the student feature tensor from Adjust to , while keeping the height and width of the feature map unchanged, we get an aligned feature tensor that is consistent with the dimension of the teacher feature tensor. The specific calculation formula is:
[0082]
[0083] in, Represents the aligned feature tensor (shape [B, , H, W]), and b is the bias term. This 1×1 convolution operation can efficiently map the student features to the same dimensional space as the teacher features while keeping the spatial size (H, W) of the feature map unchanged, providing a basis for subsequent feature comparison.
[0084] Step S22: Generate a mask matrix according to the activation value of the aligned feature tensor, and multiply the mask matrix by the aligned feature tensor element by element to obtain a masked feature tensor.
[0085] Specifically, in order to selectively focus on the important areas in the aligned feature tensor, a dynamic mask generation mechanism is designed in this step. First, the aligned feature tensor is globally average pooled in the spatial dimension (H, W), and the average pooling operation with the kernel size of (H, W) is used to obtain a shape of [B, , 1, 1] tensor, where each element represents the average activation value of the corresponding channel. Then, the average activation value of each channel is compared with the preset threshold. If it is lower than the threshold, the mask value corresponding to the channel is set to a small random number (for example, 0.05), otherwise it is set to 1, generating a mask matrix (shape [B, , 1, 1]). Finally, the mask matrix is multiplied element-wise with the aligned feature tensor to obtain the masked feature tensor for:
[0086] =mask⊙
[0087] This masking mechanism can suppress unimportant channels with low activation values, retain the most discriminative feature information for classification tasks, and enhance the pertinence of subsequent feature mapping.
[0088] Step S23: Perform a convolution mapping operation on the masked feature tensor to generate a mapping feature tensor with the same dimension as the four-dimensional teacher feature tensor.
[0089] Specifically, in order to map the masked student features to a representation space closer to the teacher features, a two-layer convolutional mapping network is designed in this step. The network first processes the masked feature tensor through a 1×1 convolutional layer. The number of input channels of this convolutional layer is , the number of output channels remains , and the ReLU activation function is applied to increase the nonlinear expression ability; then, it is processed by another 1×1 convolution layer, the number of input channels and the number of output channels of this convolution layer are , without using an activation function. In this way, the masked student features are converted into a mapping feature tensor with a similar distribution and structure to the teacher features , and the number of channels during the mapping process always remains .
[0090] Mapping feature tensors The calculation formula is:
[0091]
[0092]
[0093] Step S24: Calculate the mean square error between the mapping feature tensor and the four-dimensional teacher feature tensor to obtain the mask mapping loss.
[0094] Specifically, to measure the similarity between the mapped feature tensor and the four-dimensional teacher feature tensor, this step uses mean square error as the loss function. Specifically, the mapped feature tensor is compared with the teacher feature tensor element-by-element in each batch, channel, and spatial position, and the square of the difference between them is calculated. All these squared differences are then summed and averaged to obtain the mask mapping loss. By minimizing this loss function, the student model is forced to learn the feature expression patterns in the teacher model. Combined with the previous masking mechanism, it can focus on important feature areas, improving the generalization ability and feature extraction quality of the student model.
[0095] The mask map loss is calculated as:
[0096]
[0097] in, is the mask mapping loss, is the four-dimensional teacher feature tensor, is the mapping feature tensor, is the number of batch samples, is the teacher characteristic dimension, is the spatial dimension.
[0098] In some embodiments of the present application, the process of calculating the similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector in step S3 is introduced, which may specifically include:
[0099] Step S31: perform L2 norm normalization processing on the two-dimensional teacher feature vector and the two-dimensional student feature vector respectively to generate teacher normalized features and student normalized features.
[0100] Specifically, to eliminate the impact of feature vector amplitude differences on similarity calculations, the two-dimensional teacher feature vector and the two-dimensional student feature vector must be normalized. For each two-dimensional teacher feature vector, its L2 norm (the square root of the sum of the squares of its elements) is calculated sample by sample and each element is divided by this norm to obtain the unit-length normalized teacher feature. The same operation is performed on the two-dimensional student feature vector to obtain the normalized student feature. This process ensures that the feature vector retains only directional information, focusing on the similarity relationship between features rather than their magnitude.
[0101] Step S32: Calculate the corresponding teacher feature self-similarity matrix based on the teacher normalized features, and calculate the corresponding student feature self-similarity matrix based on the student normalized features.
[0102] Specifically, based on the normalized teacher features, the similarities between all samples in the sample set are calculated to form a teacher feature self-similarity matrix. Each element in the matrix is the dot product of the normalized teacher features of the corresponding two samples, reflecting the degree of feature similarity between the samples. Using the same method, the student feature self-similarity matrix is calculated based on the normalized student features, with the matrix elements being the dot products of the normalized student features. This method converts the feature vector similarity into a matrix form, facilitating subsequent quantitative analysis of the differences in feature correlation structures between the student and teacher models.
[0103] Step S33: Calculate the difference between the teacher feature self-similarity matrix and the student feature self-similarity matrix through mean square error to obtain similarity preservation loss.
[0104] Specifically, the corresponding elements of the teacher's feature self-similarity matrix and the student's feature self-similarity matrix are subtracted one by one, the square of the difference is calculated, and the squared differences of all matrix elements are averaged to obtain the similarity preservation loss. This loss function measures the overall difference between the two matrices, forcing the student model to learn the feature similarity relationships between samples in the teacher model, ensuring that the student model captures the same feature distribution and structure as the teacher model, thereby improving the accuracy and robustness of the student model's feature representation.
[0105] The calculation formula of the similarity preservation loss is:
[0106]
[0107] ,
[0108] in, For similarity preservation loss, is the teacher feature self-similarity matrix, is the student feature self-similarity matrix, is the number of batch samples, is the teacher normalized feature, Normalize features for students.
[0109] A feature recognition training device provided in an embodiment of the present application is described below. The feature recognition training device described below and the feature recognition training method described above can refer to each other.
[0110] See also Figure 3 , Figure 3 A schematic diagram of a feature recognition training device disclosed in an embodiment of the present application.
[0111] like Figure 3 As shown, the feature recognition training device may include:
[0112] A feature extraction unit 110 is configured to input the input data into the pre-trained teacher model and the student model to be trained, extract a four-dimensional teacher feature tensor and a four-dimensional student feature tensor, and further extract a two-dimensional teacher feature vector and a two-dimensional student feature vector;
[0113] a mask loss unit 120 for calculating a mask mapping loss by mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor;
[0114] A preservation loss unit 130, configured to calculate a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0115] A classification loss unit 140 is configured to calculate a label classification loss based on the two-dimensional student feature vector and the corresponding sample label;
[0116] a joint loss unit 150, configured to jointly construct a total loss function by combining the mask mapping loss, the similarity preservation loss, and the label classification loss;
[0117] The optimization training unit 160 is used to optimize the student model parameters by back propagation until the total loss function converges.
[0118] It can be seen from the above technical solutions that the embodiment of the present application provides a feature recognition training method, device, equipment and readable storage medium. The method inputs the input data into the pre-trained teacher model and the student model to be trained respectively, and extracts the four-dimensional teacher feature tensor and the four-dimensional student feature tensor as well as the two-dimensional teacher feature vector and the two-dimensional student feature vector. The mask mapping loss is calculated based on the four-dimensional feature tensor through mask generative mapping, the similarity preservation loss is calculated based on the two-dimensional feature vector, and the label classification loss is calculated at the same time. The total loss function is jointly constructed and the student model parameters are optimized by back propagation. This solution can capture the structural relationship and semantic information inside the feature through mask generative mapping, solves the problem of ignoring the internal structure of the feature in the prior art, thereby improving the model's generalization ability for unseen samples. At the same time, by calculating the similarity preservation loss, it is ensured that the student model learns the feature expression of the teacher model, further enhancing the recognition ability of the model. In addition, by combining multiple loss functions for optimization, different aspects of the feature can be considered more comprehensively, effectively solving the defect that the traditional method is difficult to capture complex dependencies when processing high-dimensional features, thereby improving the overall performance and recognition accuracy of the model. Optionally, based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, a mask mapping loss is calculated by mask generative mapping, including:
[0119] Performing channel dimension alignment on the four-dimensional student feature tensor to generate an aligned feature tensor with the same dimension as the four-dimensional teacher feature tensor;
[0120] generating a mask matrix according to the activation value of the aligned feature tensor, and multiplying the mask matrix by the aligned feature tensor element by element to obtain a masked feature tensor;
[0121] Performing a convolution mapping operation on the masked feature tensor to generate a mapped feature tensor with the same dimension as the four-dimensional teacher feature tensor;
[0122] The mean square error between the mapping feature tensor and the four-dimensional teacher feature tensor is calculated to obtain the mask mapping loss.
[0123] Optionally, the calculation formula of the mask mapping loss is:
[0124]
[0125] in, is the mask mapping loss, is the four-dimensional teacher feature tensor, is the mapping feature tensor, is the number of batch samples, is the teacher characteristic dimension, is the spatial dimension.
[0126] Optionally, calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector includes:
[0127] Performing L2 norm normalization processing on the two-dimensional teacher feature vector and the two-dimensional student feature vector respectively to generate teacher normalized features and student normalized features;
[0128] Calculating a corresponding teacher feature self-similarity matrix based on the teacher normalized features, and calculating a corresponding student feature self-similarity matrix based on the student normalized features;
[0129] The difference between the teacher feature self-similarity matrix and the student feature self-similarity matrix is calculated by mean square error to obtain the similarity preservation loss.
[0130] Optionally, the calculation formula for the similarity preservation loss is:
[0131]
[0132] ,
[0133] in, For similarity preservation loss, is the teacher feature self-similarity matrix, is the student feature self-similarity matrix, is the number of batch samples, is the teacher normalized feature, Normalize features for students.
[0134] Optionally, the calculation formula for the label classification loss is:
[0135]
[0136] in, is the label classification loss, is the scale factor, is the angle marginal parameter, For samples Corresponding to the angle of the true category, is the number of samples in the batch.
[0137] Optionally, the total loss function is:
[0138]
[0139] in, is the mask mapping loss, For similarity preservation loss, is the label classification loss, 、 、 is the weight coefficient.
[0140] The feature recognition training apparatus provided in the embodiment of the present application can be applied to feature recognition training equipment. Figure 4 The hardware structure diagram of the feature recognition training device is shown. Figure 4 ,The hardware structure of the feature recognition training device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0141] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0142] The processor 1 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0143] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory;
[0144] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:
[0145] Input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0146] Calculating a mask mapping loss through mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor;
[0147] Calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0148] Calculating label classification loss based on the two-dimensional student feature vector and the corresponding sample label;
[0149] Combining the mask mapping loss, the similarity preservation loss, and the label classification loss to construct a total loss function;
[0150] The student model parameters are optimized by back-propagation until the total loss function converges.
[0151] Optionally, the refined functions and extended functions of the program may refer to the above description.
[0152] The present application also provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0153] Input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0154] Calculating a mask mapping loss through mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor;
[0155] Calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector;
[0156] Calculating label classification loss based on the two-dimensional student feature vector and the corresponding sample label;
[0157] Combining the mask mapping loss, the similarity preservation loss, and the label classification loss to construct a total loss function;
[0158] The student model parameters are optimized by back-propagation until the total loss function converges.
[0159] Optionally, the refined functions and extended functions of the program may refer to the above description.
[0160] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0161] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0162] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A feature recognition training method, characterized in that: include: Input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector; Calculating a mask mapping loss through mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor; Calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector; Calculating label classification loss based on the two-dimensional student feature vector and the corresponding sample label; Combining the mask mapping loss, the similarity preservation loss, and the label classification loss to construct a total loss function; The student model parameters are optimized by back-propagation until the total loss function converges.
2. The method according to claim 1, characterized in that Based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, a mask mapping loss is calculated through mask generative mapping, including: Performing channel dimension alignment on the four-dimensional student feature tensor to generate an aligned feature tensor with the same dimension as the four-dimensional teacher feature tensor; generating a mask matrix according to the activation value of the aligned feature tensor, and multiplying the mask matrix by the aligned feature tensor element by element to obtain a masked feature tensor; Performing a convolution mapping operation on the masked feature tensor to generate a mapped feature tensor with the same dimension as the four-dimensional teacher feature tensor; The mean square error between the mapping feature tensor and the four-dimensional teacher feature tensor is calculated to obtain the mask mapping loss.
3. The method according to claim 2, characterized in that The calculation formula of the mask mapping loss is: in, is the mask mapping loss, is the four-dimensional teacher feature tensor, is the mapping feature tensor, is the number of batch samples, is the teacher characteristic dimension, is the spatial dimension.
4. The method according to claim 1, wherein Calculating a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector includes: Performing L2 norm normalization processing on the two-dimensional teacher feature vector and the two-dimensional student feature vector respectively to generate teacher normalized features and student normalized features; Calculating a corresponding teacher feature self-similarity matrix based on the teacher normalized features, and calculating a corresponding student feature self-similarity matrix based on the student normalized features; The difference between the teacher feature self-similarity matrix and the student feature self-similarity matrix is calculated by mean square error to obtain the similarity preservation loss.
5. The method according to claim 4, characterized in that The calculation formula of the similarity preservation loss is: , in, For similarity preservation loss, is the teacher feature self-similarity matrix, is the student feature self-similarity matrix, is the number of batch samples, is the teacher normalized feature, Normalize features for students.
6. The method according to claim 1, characterized in that The calculation formula for the label classification loss is: in, is the label classification loss, is the scale factor, is the angle marginal parameter, For samples Corresponding to the angle of the true category, is the number of samples in the batch.
7. The method according to claim 1, characterized in that The total loss function is: in, is the mask mapping loss, For similarity preservation loss, is the label classification loss, 、 、 is the weight coefficient.
8. A feature recognition training device, characterized in that: include: A feature extraction unit is used to input the input data into the pre-trained teacher model and the student model to be trained, extract the four-dimensional teacher feature tensor and the four-dimensional student feature tensor, and further extract the two-dimensional teacher feature vector and the two-dimensional student feature vector; A mask loss unit, configured to calculate a mask mapping loss by mask generative mapping based on the four-dimensional teacher feature tensor and the four-dimensional student feature tensor; A preservation loss unit, configured to calculate a similarity preservation loss based on the two-dimensional teacher feature vector and the two-dimensional student feature vector; A classification loss unit, configured to calculate a label classification loss based on the two-dimensional student feature vector and the corresponding sample label; a joint loss unit, configured to jointly construct a total loss function by combining the mask mapping loss, the similarity preservation loss, and the label classification loss; An optimization training unit is used to optimize the student model parameters by back propagation until the total loss function converges.
9. A feature recognition training device, characterized in that: including memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement each step of the feature recognition training method according to any one of claims 1 to 7.
10. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the feature recognition training method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Searcher model training method, and Burt-Hooger-Durob syndrome recognition method and system based on retrieval enhancement generation
CN121366329A
Retriever model training method, birt-hogg-dube syndrome identification method and system based on retrieval enhancement generation
CN121366329B