An image recognition method and device based on contrastive knowledge distillation
By fixing the embedded features of the first neural network model and performing comparative distillation training of positive and negative examples in the feature space, and combining comparative distillation loss and KL divergence loss, the problem of the teacher's knowledge representation not being effectively modeled and accurately transmitted in the existing technology is solved, and the image recognition accuracy of the second neural network model is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG LAB
- Filing Date
- 2023-11-15
- Publication Date
- 2026-04-17
AI Technical Summary
In existing image recognition methods based on a combination of contrastive learning and knowledge distillation, the embedded features of the first neural network model change dynamically in the feature space, which cannot effectively model the sample feature representation and cannot accurately transmit knowledge, resulting in limited improvement in the recognition accuracy of the second neural network model.
By fixing the embedded feature representation of the first neural network model and performing comparative distillation training on the similarity of positive and negative features in the first and second embedded feature spaces, and combining comparative distillation loss and KL divergence loss, the parameters of the second neural network model are updated to achieve effective modeling and accurate transmission of teacher knowledge.
The image recognition accuracy of the second neural network model was improved, specifically from 72.51% to 77.40% on the CIFAR100 dataset, significantly improving the recognition performance.
Smart Images

Figure CN117557847B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision, and more particularly to an image recognition method and apparatus based on contrastive knowledge distillation. Background Technology
[0002] Image recognition refers to the technology of using computers to process, analyze, and understand images in order to identify targets and objects of various patterns. It is a practical application of deep learning algorithms. Currently, image recognition technology is generally divided into facial recognition and product recognition. Facial recognition is mainly used in security checks, identity verification, and mobile payments; product recognition is mainly used in the process of commodity circulation, especially in unmanned retail fields such as unmanned shelves and smart retail cabinets.
[0003] Knowledge distillation is a technique that transfers knowledge from a highly accurate and complex neural network (teacher model) to a smaller neural network (student model), thereby improving the recognition accuracy of the smaller neural network and compressing the model size. Image recognition models built based on the student model in knowledge distillation are a technique widely used in various image recognition fields.
[0004] Contrastive learning refers to a technique that makes the feature representations of different views of the same image sample (positive examples) closer to and farther away from the feature representations of other samples (negative examples) in the feature space. Existing knowledge distillation work mostly focuses on how to better model knowledge representations, and few works combine contrastive learning with knowledge distillation.
[0005] Existing work combining contrastive learning and knowledge distillation (such as Tian et al. Contrastive Representation Distillation. ICLR 2020; Chen et al. Wasserstein Contrastive Representation Distillation. CVPR 2021) has the following drawbacks:
[0006] a. The embedding features of the first neural network model change dynamically in the feature space, making it impossible to effectively model the feature representation of the samples;
[0007] b. The dynamically changing embedding features of the first neural network model are easily affected by the embedding features of the second neural network model, making it impossible to accurately transmit knowledge representation;
[0008] c. Existing work only performs feature comparison in the feature space embedded in the first neural network model, ignoring the feature representation of other categories of samples in the second neural network model, which limits the improvement of the recognition accuracy of the second neural network model.
[0009] Based on the above shortcomings, the recognition accuracy of the second neural network model, which is constructed by combining contrastive learning and knowledge distillation, still needs to be improved when used for image recognition. Summary of the Invention
[0010] In view of the above, the purpose of this invention is to provide an image recognition method and apparatus based on comparative knowledge distillation to solve the technical problem that the teacher's knowledge representation is not effectively modeled and accurately transmitted, resulting in limited improvement in the accuracy of student models for image recognition.
[0011] To achieve the above-mentioned objectives, this invention provides an image recognition method based on comparative knowledge distillation, comprising the following steps:
[0012] Obtain training image samples with category labels;
[0013] The first neural network classification model is trained using training image samples with supervised learning based on category labels. The training image samples are then input into the trained first neural network classification model to obtain the first embedded feature expression and the corresponding first classification soft label.
[0014] The training image samples are input into the second neural network classification model to obtain the second embedded feature expression and the corresponding second classification soft label. The comparative distillation loss is calculated based on the first and second embedded feature expressions. The KL divergence loss is calculated based on the first and second classification soft labels. The parameters of the second neural network classification model are updated by comparing the distillation loss and the KL divergence loss and the image recognition task loss. The updated second neural network classification model is used as the image recognition model.
[0015] Preferably, the step of performing supervised learning training on the first neural network classification model using training image samples based on true labels includes:
[0016] The first neural network classification model includes a first neural network and a first classifier. The first neural network maps the input training image samples to a fixed-dimensional embedding feature space using a feature mapper to obtain a fixed-dimensional first embedding feature expression. The first classifier performs classification prediction on the first embedding feature expression and outputs the classification prediction result as a first classification soft label. The classification loss is calculated based on the first classification soft label and the category label, and the parameters of the first neural network classification model are updated using the classification loss.
[0017] Preferably, the step of inputting training image samples into a second neural network classification model to obtain a second embedded feature representation and a corresponding second classification soft label includes:
[0018] The second neural network classification model includes a second neural network and a second classifier. The second neural network maps the input training image samples to a fixed-dimensional embedding feature space using a feature mapper to obtain a fixed-dimensional pre-embedded feature expression. It then updates the pre-embedded feature expression using historical second-embedded feature expressions to obtain a second-embedded feature expression. The second classifier performs classification prediction on the second-embedded feature expression and outputs the classification prediction result as a second classification soft label.
[0019] Preferably, the second embedded feature representation is updated and saved using a momentum update method, which can be formally represented as follows:
[0020]
[0021] Where i represents the i-th iteration. This represents the updated second embedded feature representation. Let z represent the second embedded feature representation obtained in the (i-1)th iteration, m represent the updated momentum parameter, and z represent the second embedded feature representation obtained in the (i-1)th iteration. s This represents the second embedded feature expression obtained by the training image sample x through the second neural network classification model during the i-th iteration.
[0022] Preferably, the training method further includes:
[0023] Record and save the index numbers of training image samples of the same category to the category memory;
[0024] For each category label, other categories are treated as negative example categories. All training image samples corresponding to the negative example categories are recorded as negative example samples. The index number of the negative example samples is saved to the negative example storage.
[0025] The first embedded feature representation and the first classification soft label corresponding to the training image sample are stored in the first embedded feature representation memory;
[0026] The second embedding feature representation and the second classification soft label corresponding to the training image sample are stored in the second embedding feature representation memory.
[0027] Preferably, the calculation of the comparative distillation loss based on the first embedded feature representation and the second embedded feature representation includes:
[0028] Based on the index number of the training image samples, the first and second embedded feature expressions of the training image samples with the same index number are retrieved from the first and second embedded feature expression memories to form a pair of positive examples, and the feature similarity T between the positive examples is calculated.
[0029] Based on the category labels of the training image samples, the index numbers of all negative sample samples corresponding to each category label are obtained from the negative sample memory. The index numbers of the negative sample samples are used to obtain the first embedded feature expression and the second embedded feature expression from the first embedded feature expression memory and the second embedded feature expression memory respectively as negative examples, and the feature similarity N between positive and negative examples is calculated.
[0030] Comparative knowledge distillation is calculated based on feature similarity T and feature similarity N. for:
[0031]
[0032] Where G represents the number of negative examples.
[0033] Thirdly, embodiments of the present invention also provide an image recognition model training device based on comparative knowledge distillation, including an acquisition module, a first training module, and a second training module;
[0034] The acquisition module is used to acquire training image samples with category labels;
[0035] The first training module is used to perform supervised learning training of the first neural network classification model based on category labels using training image samples, and inputs the training image samples into the trained first neural network classification model to obtain the first embedded feature expression and the corresponding first classification soft label;
[0036] The second training module is used to input training image samples into the second neural network classification model to obtain the second embedded feature expression and the corresponding second classification soft label. It calculates the comparative distillation loss based on the first and second embedded feature expressions, calculates the KL divergence loss based on the first and second classification soft labels, and updates the parameters of the second neural network classification model by comparing the distillation loss and the KL divergence loss in conjunction with the image recognition task loss. The updated second neural network classification model is used as the image recognition model.
[0037] Thirdly, embodiments of the present invention also provide an image recognition method based on comparative knowledge distillation, comprising the following steps:
[0038] Obtain test image samples;
[0039] The test image sample is input into the image recognition model constructed using the above training method, and the second classification soft label is calculated as the image recognition result.
[0040] Output the image recognition results.
[0041] Fourthly, embodiments of the present invention also provide an image recognition device based on comparative knowledge distillation, including an input module, a recognition module, and an output module;
[0042] The input module is used to acquire test image samples;
[0043] The recognition module is used to input test image samples into the image recognition model constructed using the above training method, and calculate the second classification soft label as the image recognition result.
[0044] The output module is used to output the image recognition results.
[0045] Fifthly, embodiments of the present invention also provide a computing device, including a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the above-described image recognition model training method based on contrastive knowledge distillation and the above-described image recognition method based on contrastive knowledge distillation.
[0046] Compared with the prior art, the beneficial effects of the present invention include at least the following:
[0047] Based on training image samples, a contrastive distillation loss is constructed using the first and second embedded feature representations of the first and second neural network classification models. Simultaneously, a KL divergence loss is constructed based on the first and second classification soft labels. This method is used to train the second neural network classification model. This enables the effective modeling and accurate transmission of knowledge representation from the first neural network classification model (actually the teacher model), thereby improving the image recognition accuracy of the second neural network classification model (actually the student model). This method is simple, intuitive, and easy to operate. It is not limited to a specific teacher-student model combination and can be easily deployed to existing neural network models for image recognition. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 This is a comparative illustration of the technical solution of the present invention and existing work;
[0050] Figure 2 This is a flowchart of the image recognition model training method based on comparative knowledge distillation provided in the embodiment;
[0051] Figure 3 This is a flowchart illustrating the construction of a comparative distillation loss provided in the embodiments;
[0052] Figure 4 This is a schematic diagram of the structure of the image recognition model training device based on comparative knowledge distillation provided in the embodiment;
[0053] Figure 5 This is a flowchart of the image recognition method based on comparative knowledge distillation provided in the embodiment;
[0054] Figure 6 This is a schematic diagram of the image recognition device based on comparative knowledge distillation provided in the embodiment;
[0055] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiment. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the scope of protection of this invention.
[0057] To address the technical problem that existing technologies fail to effectively model and accurately transmit teacher knowledge representations while limiting the improvement in student model recognition accuracy, this invention provides an image recognition scheme based on comparative knowledge distillation. By effectively modeling and accurately transmitting teacher knowledge to student models, the image recognition accuracy of student models is improved.
[0058] Figure 1 This diagram shows the main differences between the technical solution of this invention and existing work (Tian et al. Contrastive Representation Distillation. ICLR 2020; Chen et al. Wasserstein Contrastive Representation Distillation. CVPR 2021). The dashed lines represent dynamically changing parts during training. The solution of this invention fixes the embedded feature representation of the first neural network model, keeping it unchanged during training; and performs similarity distillation training on positive and negative features in both the first and second embedded feature spaces.
[0059] Figure 2 This is a flowchart of the image recognition model training method based on comparative knowledge distillation provided in an embodiment of the present invention. Figure 2 As shown, the image recognition model training method provided in this embodiment includes the following steps:
[0060] S110, Obtain training image samples with category labels.
[0061] In this embodiment, the training image samples can be facial images or traffic scene images, and the category label refers to the category corresponding to the image sample classification task. These training image samples are used for learning and training the image recognition model.
[0062] S120, using training image samples to perform supervised learning training on the first neural network classification model based on category labels, and inputting the training image samples into the trained first neural network classification model to obtain the first embedded feature expression and the corresponding first classification soft label.
[0063] In this embodiment of the invention, the first neural network classification model includes a first neural network and a first classifier. The first neural network can be any existing neural network, including but not limited to ResNet, VGGnet, etc., or a newly designed convolutional neural network. The first classifier can be a fully connected network, SVM, etc.
[0064] In this embodiment of the invention, supervised learning training based on category labels is performed on a first neural network classification model using training image samples, including:
[0065] like Figure 1 As shown on the right, a certain number of training image samples x are input into the first neural network. The convolutional neural network within it and pooling operations Then, using the feature mapper ε proj Mapping to the fixed-dimensional D embedding feature space yields the fixed-dimensional first embedding feature representation z. T Formal representation:
[0066]
[0067] The first embedded feature expression z T Input to the first classifier First classifier For the first embedded feature expression z T Perform classification prediction and output the classification prediction result as the first category soft label p T Formal representation:
[0068]
[0069] Where C represents the number of categories;
[0070] Based on the first category soft label p T And the true category label p 0 Calculate the classification loss and use it to update the parameters of the first neural network classification model.
[0071] After obtaining the trained first neural network classification model, the training image samples are input into the trained first neural network classification model to obtain the first embedded feature expression and the corresponding first classification soft label. This first embedded feature expression and the first classification soft label are stored in the first embedded feature expression memory. In this context, B represents the number of training image samples. During storage, the training image samples are stored using their index x as the index, expressed as:
[0072] M T [x] = z T
[0073] S130, input the training image samples into the second neural network classification model to obtain the second embedded feature expression and the corresponding second classification soft label, calculate the comparative distillation loss based on the first embedded feature expression and the second embedded feature expression, calculate the KL divergence loss based on the first classification soft label and the second classification soft label, compare the distillation loss and the KL divergence loss and the image classification task loss to update the parameters of the second neural network classification model, and use the updated second neural network classification model as the image recognition model.
[0074] In this embodiment of the invention, to facilitate the training of the second neural network classification model, the index number h of the training image samples of the same category is recorded and saved to the category memory. In this context, C represents the number of categories, and H represents the number of samples in each category. The formal representation is as follows:
[0075] E c [c] = h
[0076] Simultaneously, other categories corresponding to each category label are also treated as negative example categories. All training image samples corresponding to the negative example categories are recorded as negative example samples, and the index number j of the negative example samples is saved to the negative example storage. In the above, J represents the number of samples from other categories, formally expressed as:
[0077] M n [c] = j
[0078] In this embodiment of the invention, the second neural network classification model includes a second neural network and a second classifier. The first neural network can be any existing neural network, including but not limited to ResNet, VGGnet, etc., or a newly designed convolutional neural network. The first classifier can be a fully connected network, SVM, etc.
[0079] The training image samples are input into the second neural network classification model to obtain the second embedded feature representation and the corresponding second classification soft label, including:
[0080] like Figure 1As shown on the right, the training image sample x is input into the second neural network. In, it passes through the convolutional neural network. and pooling operations Then, using the feature mapper ε proj Mapping to the embedding feature space of fixed dimension D yields a pre-defined second embedding feature representation z of fixed dimension D. S Formal representation:
[0081]
[0082] Simultaneously, a momentum update method is used to save the pre-embedded feature representation, formally represented as: (Formal representation follows)
[0083]
[0084] Where i represents the i-th iteration. This represents the updated second embedded feature representation. Let z represent the second embedded feature representation obtained in the (i-1)th iteration, m represent the updated momentum parameter, and z represent the second embedded feature representation obtained in the (i-1)th iteration. S This represents the pre-embedded feature representation obtained by the training image sample x through the second neural network classification model during the i-th iteration.
[0085] Second Embedded Feature Representation Input to the second classifier Second classifier Expression of the second embedding feature Perform classification prediction and output the classification prediction result as the second classification soft label p S Formal representation:
[0086]
[0087] In each iteration, the second embedded feature representation and the second classification soft label corresponding to the training image sample are stored in the second embedded feature representation memory. In this context, B represents the number of training image samples, formally expressed as:
[0088]
[0089] In each iteration, such as Figure 3 As shown, the comparative distillation loss is calculated based on the first and second embedded feature representations, including:
[0090] S210, based on the index number of the training image samples, simultaneously retrieve the first and second embedded feature expressions of training image samples with the same index number from the first and second embedded feature expression memories to form a pair of positive examples, and calculate the feature similarity T between the positive examples. The similarity calculation method includes, but is not limited to, cosine similarity. When cosine similarity is used, it is formally expressed as:
[0091]
[0092] in, Let represent the first and second embedded feature representations corresponding to the training image sample with index x, respectively; let cos represent the cosine distance; and let τ represent the temperature coefficient. G represents the number of negative examples.
[0093] S220: Based on the category labels of the training image samples, obtain the index numbers of all negative samples corresponding to each category label from the negative sample memory. Use the index numbers of the negative samples to obtain the first embedded feature expression and the second embedded feature expression from the first embedded feature expression memory and the second embedded feature expression memory, respectively, as negative examples. Calculate the feature similarity N between the positive and negative examples. The similarity calculation method includes, but is not limited to, cosine similarity. When cosine similarity is used, it is formally expressed as:
[0094]
[0095] Where j = M n [c] represents the index number of the negative sample. and This represents the first and second embedded feature representations corresponding to the negative example sample with index number j.
[0096] S230, Calculate comparative knowledge distillation based on feature similarity T and feature similarity N. for:
[0097]
[0098] Computational comparison of knowledge distillation Simultaneously, it also uses the first classification soft label p corresponding to the training image sample with index number x. T Second category soft label p S KL divergence loss between Simultaneously, the second classification soft label p of the second neural network classification model is also calculated. S Compared to the true category label p 0 Image recognition task loss between Should Cross-entropy loss can be used.
[0099] Finally, the total loss is formed by comparing the distillation loss, KL divergence loss, and image recognition task loss. The second neural network classification model is trained and updated, and the updated second neural network classification model is used as the image recognition model.
[0100] Based on the same inventive concept, such as Figure 4 As shown, this embodiment of the invention also provides an image recognition model training device based on contrastive knowledge distillation, including an acquisition module 310, a first training module 320, and a second training module 330; wherein, the acquisition module 310 is used to acquire training image samples with category labels; the first training module 320 is used to perform supervised learning training on a first neural network classification model based on category labels using the training image samples, inputting the training image samples into the trained first neural network classification model to obtain a first embedded feature expression and a corresponding first classification soft label; the second training module 330 is used to input the training image samples into a second neural network classification model to obtain a second embedded feature expression and a corresponding second classification soft label, calculate a contrastive distillation loss based on the first and second embedded feature expressions, calculate a KL divergence loss based on the first and second classification soft labels, update the parameters of the second neural network classification model by combining the contrastive distillation loss and the KL divergence loss with the image recognition task loss, and use the updated second neural network classification model as an image recognition model.
[0101] In the second training module 330, the second embedded feature representation is updated and saved using the momentum update method.
[0102] In the second training module 330, the comparative distillation loss is calculated based on the first embedded feature representation and the second embedded feature representation, including:
[0103] Based on the index number of the training image samples, the first and second embedded feature expressions of the training image samples with the same index number are retrieved from the first and second embedded feature expression memories to form a pair of positive examples, and the feature similarity T between the positive examples is calculated.
[0104] Based on the category labels of the training image samples, the index numbers of all negative sample samples corresponding to each category label are obtained from the negative sample memory. The index numbers of the negative sample samples are used to obtain the first embedded feature expression and the second embedded feature expression from the first embedded feature expression memory and the second embedded feature expression memory respectively as negative examples, and the feature similarity N between positive and negative examples is calculated.
[0105] Comparative knowledge distillation is calculated based on feature similarity T and feature similarity N.
[0106] It should be noted that the image recognition model training device provided in the above embodiments should be illustrated using the above-described division of functional modules when training the image recognition model. The functions can be assigned to different functional modules as needed, that is, the internal structure of the terminal or server can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the image recognition model training device and the image recognition model training method embodiments provided in the above embodiments belong to the same concept; their specific implementation process is detailed in the image recognition model training method embodiments, and will not be repeated here.
[0107] Based on the same inventive concept, such as Figure 5 As shown, the embodiment also provides an image recognition method based on comparative knowledge distillation, including the following steps:
[0108] S410, acquire test image samples;
[0109] S420, Input the test image sample into the image recognition model constructed using steps S110-S130, and calculate the second classification soft label as the image recognition result;
[0110] S430 outputs the image recognition results.
[0111] Based on the same inventive concept, such as Figure 6 As shown, the embodiment also provides an image recognition device based on comparative knowledge distillation, including an input module 510, a recognition module 520, and an output module 530; wherein, the input module 510 is used to acquire test image samples; the recognition module 530 is used to input the test image samples into the image recognition model constructed by steps S110-S130, and calculate the second classification soft label as the image recognition result; the output module 530 is used to output the image recognition result.
[0112] It should be noted that the image recognition device provided in the above embodiments should be illustrated using the above-described division of functional modules when performing image recognition. The functions can be assigned to different functional modules as needed, that is, the internal structure of the terminal or server can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the image recognition device and image recognition method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the image recognition method embodiments, which will not be repeated here.
[0113] Figure 7The diagram shows a structural schematic of a computing device provided by this invention. At the hardware level, in addition to a processor and memory, it also includes an internal bus, network interface, memory, and other hardware required for business operations. The memory is non-volatile memory. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the image recognition model training method based on contrastive knowledge distillation described in S110-S130 above, and also to implement the image recognition method described in S410-S430 above. Of course, besides software implementation, this invention does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0114] The image recognition scheme based on contrastive knowledge distillation provided in the above embodiments can significantly improve the image recognition accuracy of the second neural network model compared with the existing knowledge distillation technology based on contrastive learning. Using ResNet32x4 as the first neural network and ResNet8x4 as the second neural network, the method of the present invention can improve the image classification accuracy of the second neural network classification model from 72.51% to 77.40% on the CIFAR100 dataset, which is 1.5% higher than the existing contrastive distillation work (recognition accuracy 75.9%).
[0115] The specific embodiments described above illustrate the technical solution and beneficial effects of the present invention in detail. It should be understood that the above description is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, additions, and equivalent substitutions made within the scope of the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for training an image recognition model based on contrastive knowledge distillation, characterized in that, Includes the following steps: Obtain training image samples with category labels; Supervised learning training of a first neural network classification model based on category labels using training image samples includes: the first neural network classification model includes a first neural network and a first classifier; the first neural network maps the input training image samples to a fixed-dimensional embedding feature space using a feature mapper to obtain a fixed-dimensional first embedding feature expression; the first classifier performs classification prediction on the first embedding feature expression and outputs the classification prediction result as a first classification soft label; the classification loss is calculated based on the first classification soft label and the category label; and the parameters of the first neural network classification model are updated using the classification loss. The training image samples are input into the trained first neural network classification model to obtain the first embedded feature expression and the corresponding first classification soft label; The training image samples are input into the second neural network classification model to obtain the second embedded feature expression and the corresponding second classification soft label, including: the second neural network classification model includes a second neural network and a second classifier. The second neural network maps the input training image samples to a fixed-dimensional embedded feature space using a feature mapper to obtain a fixed-dimensional pre-embedded feature expression, and updates the pre-embedded feature expression using historical second embedded feature expressions to obtain the second embedded feature expression. The second classifier performs classification prediction on the second embedded feature expression and outputs the classification prediction result as the second classification soft label. The second embedded feature representation is updated and saved using a momentum update method, which can be formally represented as follows: in, i Indicates the first i iteration This represents the updated second embedded feature representation. Indicates the first i-1 The second embedded feature representation obtained in the next iteration This indicates an update to the momentum parameter. Indicates the first i Training image samples during the next iteration x The second embedded feature representation obtained through the second neural network classification model; The comparative distillation loss is calculated based on the first and second embedded feature representations, and the KL divergence loss is calculated based on the first and second classification soft labels. The parameters of the second neural network classification model are updated by comparing the distillation loss and the KL divergence loss in conjunction with the image recognition task loss. The updated second neural network classification model is then used as the image recognition model.
2. The image recognition model training method based on contrast knowledge distillation according to claim 1, characterized in that, Also includes: Record and save the index numbers of training image samples of the same category to the category memory; For each category label, other categories are treated as negative example categories. All training image samples corresponding to the negative example categories are recorded as negative example samples. The index number of the negative example samples is saved to the negative example storage. The first embedded feature representation and the first classification soft label corresponding to the training image sample are stored in the first embedded feature representation memory; The second embedding feature representation and the second classification soft label corresponding to the training image sample are stored in the second embedding feature representation memory.
3. The image recognition model training method based on contrast knowledge distillation according to claim 2, characterized in that, The calculation of the comparative distillation loss based on the first and second embedded feature representations includes: Based on the index number of the training image samples, the first and second embedded feature expressions of the training image samples with the same index number are retrieved from the first and second embedded feature expression memories to form a pair of positive examples, and the feature similarity T between the positive examples is calculated. Based on the category labels of the training image samples, the index numbers of all negative samples corresponding to each category label are obtained from the negative sample memory. Using the index numbers of the negative samples, the first embedded feature representation and the second embedded feature representation are obtained from the first embedded feature representation memory and the second embedded feature representation memory, respectively, as negative examples. The feature similarity between positive and negative examples is then calculated. ; Computing contrast knowledge distillation according to feature similarity T and feature similarity N are: wherein, represents the number of negative examples.
4. A training device for an image recognition model based on contrastive knowledge distillation, characterized in that, It includes an acquisition module, a first training module, and a second training module; The acquisition module is used to acquire training image samples with category labels; The first training module is used to perform supervised learning training on the first neural network classification model based on category labels using training image samples, including: the first neural network classification model includes a first neural network and a first classifier; the first neural network maps the input training image samples to a fixed-dimensional embedding feature space using a feature mapper to obtain a fixed-dimensional first embedding feature expression; the first classifier performs classification prediction on the first embedding feature expression and outputs the classification prediction result as a first classification soft label; the classification loss is calculated based on the first classification soft label and the category label; and the parameters of the first neural network classification model are updated using the classification loss. The first training module is further configured to input training image samples into the trained first neural network classification model to obtain a first embedded feature representation and a corresponding first classification soft label; The second training module is used to input training image samples into the second neural network classification model to obtain the second embedded feature expression and the corresponding second classification soft label. The second neural network classification model includes a second neural network and a second classifier. The second neural network maps the input training image samples to a fixed-dimensional embedded feature space using a feature mapper to obtain a fixed-dimensional pre-embedded feature expression, and updates the pre-embedded feature expression using historical second embedded feature expressions to obtain the second embedded feature expression. The second classifier performs classification prediction on the second embedded feature expression and outputs the classification prediction result as the second classification soft label. The second embedded feature representation is updated and saved using a momentum update method, which can be formally represented as follows: in, i Indicates the first i iteration This represents the updated second embedded feature representation. Indicates the first i-1 The second embedded feature representation obtained in the next iteration This indicates an update to the momentum parameter. Indicates the first i Training image samples during the next iteration x The second embedded feature representation obtained through the second neural network classification model; The second training module is also used to calculate the comparative distillation loss based on the first embedded feature expression and the second embedded feature expression, calculate the KL divergence loss based on the first classification soft label and the second classification soft label, update the parameters of the second neural network classification model by comparing the distillation loss and the KL divergence loss together with the image recognition task loss, and use the updated second neural network classification model as the image recognition model.
5. An image recognition method based on contrastive knowledge distillation, characterized in that, Includes the following steps: Obtain test image samples; The test image sample is input into the image recognition model constructed using the training method described in any one of claims 1-3, and the second classification soft label is calculated as the image recognition result. Output the image recognition results.
6. An image recognition device based on contrastive knowledge distillation, characterized in that, It includes an input module, a recognition module, and an output module; The input module is used to acquire test image samples; The recognition module is used to input test image samples into an image recognition model constructed using the training method described in any one of claims 1-3, and calculate a second classification soft label as the image recognition result. The output module is used to output the image recognition results.
7. A computing device, comprising: The method includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the image recognition model training method based on contrastive knowledge distillation as described in any one of claims 1-3 and the image recognition method based on contrastive knowledge distillation as described in claim 5.
Citation Information
Patent Citations
Image recognition method and device based on structural knowledge propagation
CN116071635A
Image recognition model training method and system and image processing method and system
CN116597245A