Network model training method, image target recognition method, device and electronic device
By deleting the samples that have been learned by the student network during the model distillation process, making them focus on learning poor samples, and updating parameters through the total loss function value, the problem of conveying negative knowledge by the teacher model is solved, and the accuracy and training of the student model is improved efficiency.
Patent Information
- Application Number
- CN202010950541.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-10
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2040-09-10
AI Technical Summary
During the model distillation process, negative knowledge of the teacher model is passed on to the student model, affecting the accuracy of the student model.
By deleting the samples that have been learned by the second network model, it will focus on learning those samples that are worse than the first network model, and update the parameters through the total loss function value until the loss function value converges to the preset value, and get trained The second network model.
It improves the accuracy and training efficiency of the student model, ensures the performance of the trained second network model, and makes it more accurate in target recognition and detection.
Smart Images

Figure CN112232506B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a network model training method, an image target recognition method, a device and an electronic device. Background Art
[0002] In the process of deploying deep neural networks on some edge computing devices, since edge devices cannot have the computing power and memory resources comparable to server devices, higher requirements are placed on model miniaturization technology. A more complete technology is needed to obtain a small model from a large model, and the model distillation method came into being. The model distillation method uses a large model with high accuracy as a teacher to guide the small model, namely the student model. By transferring the knowledge of the teacher model to the student model, the student model can also have a high accuracy on the edge computing device.
[0003] During the model distillation process, the knowledge of the teacher model will be directly transferred to the student model. This will cause some "negative knowledge" of the teacher model to be transferred to the student network, which will affect the accuracy of the student model to a certain extent. Summary of the invention
[0004] In view of this, the object of the present invention is to provide a network model training method, an image target recognition method, a device and an electronic device to improve the accuracy of the student model.
[0005] In the first aspect, an embodiment of the present invention provides a network model training method, wherein the method is applied to a server, comprising: applying the same sample pair set as the first network model to train a second network model, wherein the computational amount of the first network model is greater than the computational amount of the second network model; when the second network model completes this round of iterative training, obtaining a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair; if the second prediction result is better than the first prediction result, deleting the first sample pair from the sample pair set to obtain an updated sample pair set; determining a total loss function value of the second network model based on the updated sample pair set; if the total loss function value is greater than a preset value, applying the total loss function value to update the parameters of the second network model, and applying the sample pair set to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0006] In combination with the first aspect, an embodiment of the present invention provides a first possible implementation of the first aspect, wherein the step of obtaining a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair includes: calculating the first feature distance of the first network model for the first sample pair, and calculating the second feature distance of the second network model for the first sample pair; calculating the mean of the first feature distance of the sample class to which the first sample pair belongs based on the first network model, and calculating the mean of the second feature distance of the sample class to which the first sample pair belongs based on the second network model; wherein the sample class includes samples of the same class or samples of different classes; applying the mean of the first feature distance to normalize the first feature distance, and using the normalized result of the first feature distance as the first prediction result of the first network model for the first sample pair; applying the mean of the second feature distance to normalize the second feature distance, and using the normalized result of the second feature distance as the second prediction result of the second network model for the first sample pair.
[0007] In combination with the first possible implementation of the first aspect, the embodiment of the present invention provides a second possible implementation of the first aspect, wherein the feature distance is the Euclidean distance or cosine similarity corresponding to the features of the first sample pair.
[0008] In combination with the first possible implementation of the first aspect, an embodiment of the present invention provides a third possible implementation of the first aspect, wherein the above method also includes: based on the sample class to which the first sample pair belongs, by comparing the first prediction result and the second prediction result, determining whether the second prediction result is better than the first prediction result.
[0009] In combination with the third possible implementation of the first aspect, an embodiment of the present invention provides a fourth possible implementation of the first aspect, wherein the feature distance is the Euclidean distance corresponding to the feature of the first sample pair; based on the sample class to which the first sample pair belongs, by comparing the first prediction result and the second prediction result, the step of judging whether the second prediction result is better than the first prediction result includes: if the sample class to which the first sample pair belongs is a similar sample, subtracting the second prediction result from the first prediction result to obtain a first difference; if the first difference is greater than 0 or greater than a preset first positive value, determining that the second prediction result is better than the first prediction result.
[0010] In combination with the third possible implementation of the first aspect, an embodiment of the present invention provides a fifth possible implementation of the first aspect, wherein the feature distance is the Euclidean distance corresponding to the feature of the first sample pair; based on the sample class to which the first sample pair belongs, by comparing the first prediction result and the second prediction result, the step of judging whether the second prediction result is better than the first prediction result includes: if the sample class to which the first sample pair belongs is a heterogeneous sample, calculating the first prediction result minus the second prediction result to obtain a second difference; if the second difference is less than 0 or less than a preset second negative value, determining that the second prediction result is better than the first prediction result.
[0011] In combination with the first aspect, an embodiment of the present invention provides a sixth possible implementation of the first aspect, wherein the step of determining the total loss function value of the second network model based on the sample pair update set includes: determining the same sample distillation loss value and the heterogeneous sample distillation loss value of the second network model based on the sample pair update set; determining the total loss function value of the second network model based on the same sample distillation loss value and the heterogeneous sample distillation loss value.
[0012] In combination with the sixth possible implementation of the first aspect, an embodiment of the present invention provides a seventh possible implementation of the first aspect, wherein the step of determining the same sample distillation loss value and the heterogeneous sample distillation loss value of the second network model based on the sample pair update set includes: calculating the sum of squares of effective same-class distance differences between the first network model and the second network model based on the same sample pairs in the sample pair update set; dividing the sum of squares of effective same-class distance differences by the number of same-class sample pairs to obtain the same-class sample distillation loss value; calculating the sum of squares of effective heterogeneous distance differences between the first network model and the second network model based on the heterogeneous sample pairs in the sample pair update set; dividing the sum of squares of effective heterogeneous distance differences by the number of heterogeneous sample pairs to obtain the heterogeneous sample distillation loss value.
[0013] In combination with the seventh possible implementation of the first aspect, the embodiment of the present invention provides an eighth possible implementation of the first aspect, wherein the step of calculating the sum of squares of effective similar distance differences between the first network model and the second network model includes: calculating the sum of squares of effective similar distance differences between the first network model and the second network model W intra =∑((D intra_student [i]-D intra_teacher [i])×mask[i]) 2 ; Among them, D intra_student [i] represents the vector of sample distances corresponding to the same sample pairs of the second network model, D intra_teacher [i] represents the vector consisting of sample distances corresponding to the same sample pairs of the first network model; 1≤i≤N intra , N intrais the number of similar sample pairs; mask[i] is the mask of the similar sample pairs.
[0014] In combination with the seventh possible implementation of the first aspect, the embodiment of the present invention provides a ninth possible implementation of the first aspect, wherein the step of calculating the sum of squares of effective heterogeneous distance differences between the first network model and the second network model includes: calculating the sum of squares of effective heterogeneous distance differences between the first network model and the second network model W inter =∑((D intra_student [j]-D intra_teacher [j])×mask[j]) 2 ; Among them, D intra_student [j] represents the vector of sample distances corresponding to heterogeneous sample pairs of the second network model, D intra_teacher [j] represents the vector consisting of sample distances corresponding to heterogeneous sample pairs of the first network model; 1≤j≤N inter , N inter is the number of heterogeneous sample pairs; mask[j] is the mask of homogeneous sample pairs.
[0015] In a second aspect, an embodiment of the present invention further provides an image target recognition method, which is applied to an electronic device, and comprises: receiving an image to be recognized; processing the image to be recognized using a second network model, and outputting a target recognition result; wherein the second network model is a second network model pre-trained by the above-mentioned network model training method.
[0016] In a third aspect, an embodiment of the present invention further provides a network model training device, wherein the above-mentioned device is applied to a server, comprising: a training module, used to apply the same sample pair set as the first network model to train the second network model, wherein the computational amount of the first network model is greater than the computational amount of the second network model; an acquisition module, used to obtain a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair when the second network model completes this round of iterative training; a deletion module, used to delete the first sample pair from the sample pair set if the second prediction result is better than the first prediction result, and obtain a sample pair update set; a determination module, used to determine the total loss function value of the second network model based on the sample pair update set; an iteration module, used to apply the total loss function value to update the parameters of the second network model if the total loss function value is greater than a preset value, and apply the sample pair set to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0017] In a fourth aspect, an embodiment of the present invention further provides an image target recognition device, which is applied to an electronic device, and comprises: an image receiving module, for receiving an image to be recognized; an image processing module, for processing the image to be recognized using a second network model, and outputting a target recognition result; wherein the second network model is a second network model pre-trained by the above-mentioned network model training method.
[0018] In a fifth aspect, an embodiment of the present invention further provides an electronic device, which includes a processor and a memory, the memory storing computer executable instructions that can be executed by the processor, and the processor executing the computer executable instructions to implement the above-mentioned network model training method or to implement the above-mentioned image target recognition method.
[0019] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned network model training method or to implement the above-mentioned image target recognition method.
[0020] The embodiments of the present invention bring the following beneficial effects:
[0021] The embodiment of the present application provides a network model training method, an image target recognition method, a device and an electronic device, wherein the same sample pair set as the first network model is used to train the second network model, and when the second network model completes this round of iterative training, the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair are obtained; if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain a sample pair update set; the total loss function value of the first network model is determined based on the sample pair update set; if the total loss function value is greater than a preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model. This method deletes the samples that the second network model has learned well, so that the second network model can focus on learning samples that are worse than the first network model, and the samples that have learned well will not be biased, which not only improves the training efficiency, but also ensures the performance of the trained second network model, so that the accuracy of target recognition and detection using the second network model is higher.
[0022] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.
[0023] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention;
[0026] Figure 2 A flowchart of a network model training method provided by an embodiment of the present invention;
[0027] Figure 3 A flowchart of another network model training method provided by an embodiment of the present invention;
[0028] Figure 4 A flowchart of another network model training method provided by an embodiment of the present invention;
[0029] Figure 5 A flowchart of another network model training method provided by an embodiment of the present invention;
[0030] Figure 6 A schematic diagram of the structure of a network model training device provided by an embodiment of the present invention;
[0031] Figure 7 A schematic diagram of the structure of another network model training device provided by an embodiment of the present invention;
[0032] Figure 8 A flow chart of an image target recognition method provided by an embodiment of the present invention;
[0033] Fig. 9 A schematic diagram of the structure of an image target recognition device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] For example, for the prediction results of some samples, the prediction effect of the student network may be better than that of the teacher network. However, if the prediction results of the student network and the teacher network are still close, the prediction accuracy of the student network on these samples will decrease. Current research lacks a distillation method based on knowledge filtering, that is, in the distillation process, the teacher network transfers "positive knowledge" to the student network. The present invention mainly solves the problem that the teacher network transfers "negative knowledge" to the student network during the model distillation process.
[0036] The purpose of scale learning is to shorten the distance between similar samples and to increase the distance between heterogeneous samples. Therefore, in the model distillation process, for the same input sample, the prediction result of the teacher network can be passed as knowledge to the student network, that is, to shorten the prediction results of the student network and the teacher network for the same pair of samples. This distillation method is not limited by the sample feature dimensions of the teacher network and the student network, and has been widely used. However, in the distillation process, the teacher network will output some "negative knowledge". For example, for some samples, the prediction results of the student network may be more accurate. If the prediction results of the student network and the teacher network are forcibly shortened, the prediction accuracy of the student network on these samples will decrease. Based on this, a network model training method, device and electronic device provided by an embodiment of the present invention deletes the samples that the second network model (student network) has learned well, so that the second network model can focus on learning those samples that are worse than the first network model (teacher network), and the samples that have learned well will not be biased, thereby improving the accuracy of the second network model to a certain extent. The following is described by an embodiment.
[0037] The second network model in the embodiment of the present invention can be applied to various application scenarios such as target detection and target recognition, for example, applying the second network model to identify pedestrians or vehicles, applying the second network model to track pedestrians or vehicles, applying the second network model to identify human body parts or vehicle parts (such as license plates or logos), etc.
[0038] like Figure 1The electronic device 100 includes one or more processors 102, one or more memories 104, an input device 106, an output device 108, and one or more image acquisition devices 110. These components are interconnected via a bus system 112 and / or other forms of connection mechanisms (not shown). It should be noted that Figure 1 The components and structures of the electronic device 100 shown are merely exemplary and non-limiting. The electronic device may also have other components and structures as required.
[0039] The processor 102 can be a server, a smart terminal, or a device that includes a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities. It can process data of other components in the electronic device 100 and can also control other components in the electronic device 100 to perform network model training functions.
[0040] The memory 104 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on a computer-readable storage medium, and the processor 102 may run the program instructions to implement the functions (implemented by the processing device) in the following embodiments of the present invention and / or other desired functions. Various applications and various data, such as visible light video sequences and infrared video sequences, and various data used and / or generated by the application, etc. may also be stored in the computer-readable storage medium.
[0041] The input device 106 may be a device used by a user to input instructions, and may include one or more of a keyboard, a mouse, a microphone, a touch screen, and the like.
[0042] The output device 108 may output various information (eg, images or sounds) to the outside (eg, a user), and may include one or more of a display, a speaker, and the like.
[0043] The image acquisition device 110 may acquire a set of sample pairs and store the acquired video sequence in the memory 104 for use by other components.
[0044] Exemplarily, the components in the electronic device for implementing the network model training method, image target recognition method and device according to the embodiments of the present invention can be integrated or dispersed, such as integrating the processor 102, memory 104, input device 106 and output device 108 into one, and setting the image acquisition device 110 at a specified position where the video frame can be acquired. When the components in the above electronic device are integrated, the electronic device can be implemented as an intelligent terminal such as a camera, a smart phone, a tablet computer, a computer, a vehicle-mounted terminal, etc.
[0045] This embodiment provides a network model training method, wherein the method is applied to a server, see Figure 2 A flowchart of a network model training method is shown, and the method specifically includes the following steps:
[0046] Step S202, applying the same sample pair set as the first network model to train the second network model, wherein the computational complexity of the first network model is greater than that of the second network model; wherein the first network model is the above-mentioned teacher network, and the second network model is the above-mentioned student network.
[0047] The samples in the above sample pair set all appear in pairs. For example, (a 1 , b 1 ) is a sample pair, (a 2 , b 2 ) is a sample pair. In this embodiment, the number of sample pairs included in the sample pair set is not limited.
[0048] Step S204, when the second network model completes this round of iterative training, obtaining a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair;
[0049] When the training of the second network model reaches a preset time or a preset number of times, this round of iterative training is completed. The preset time or the preset number of times can be set according to actual needs and are not limited here.
[0050] Generally, the samples in the sample pair set can be divided into two categories, one is the same sample and the other is the different sample. For example, the picture sample including only men is regarded as the same sample, and the picture sample including both men and women is regarded as the different sample. In order to train the network model with more picture features, the above-mentioned same sample or different sample can also be divided into multiple small category samples. For example, the picture sample of the man wearing a hat in the above-mentioned same sample is regarded as a small category sample, the picture sample of the man wearing a suit is regarded as a small category sample, the picture sample of the man with a backpack is regarded as a small category sample, etc. The division of the above-mentioned same sample and different sample can be set according to the actual application scenario and is not limited here.
[0051] The above-mentioned first sample pairs can be samples of the same type including at least one sample pair, or samples of different types including at least one sample pair. The first sample pairs are predicted respectively using the second network model trained in this round and the first network model trained in advance using the above-mentioned sample pair set to obtain a first prediction result predicted by the first network model and a second prediction result predicted by the second network model.
[0052] Step S206, if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain an updated sample pair set;
[0053] If the second prediction result is better than the first prediction result, it means that the first sample pair is a good sample for the second network model. In the process of knowledge distillation, in order to avoid the problem of poor training effect caused by repeatedly using the first sample to train the second network model, in this embodiment, the first sample pair or the same sample to which the first sample pair belongs can be deleted from the sample set to obtain an updated set of sample pairs. For example, the first sample pair includes 10 sample pairs of men wearing hats. If the prediction results of the 10 sample pairs using the second network model are better than the prediction results of the 10 sample pairs using the first network model, the 10 sample pairs or all sample pairs of men wearing hats (20 sample pairs) can be deleted from the sample pair set.
[0054] If the second prediction result is worse than the first prediction result, it means that the prediction ability of the second network model for the first sample pair is worse than that of the first network model. Therefore, the knowledge of the first sample pair is exactly what the second network model needs. Therefore, the first sample pair is retained to train the second network model.
[0055] Step S208, determining the total loss function value of the second network model based on the sample pair update set;
[0056] The total loss function value determined above is the convergence parameter for the second network model to achieve the final training purpose.
[0057] Step S210, if the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to update the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0058] When the determined total loss function value is greater than the preset value, it means that the trained second network model has not reached the preset convergence. After applying the total loss function value to update the parameters of the second network model to obtain the updated second network model, a first sample pair can be selected from the sample pair set again, and steps S204 to S210 are re-executed until the determined total loss function value is not greater than the preset value, indicating that the updated second network model has achieved the preset convergence effect, so that the output of the trained second network model can be close to the output of the first network model.
[0059] When conducting the next round of training, the original sample pair set can still be used, so that the sample pair set used by the second network model and the first network model is always the same. In controlling the number of training times of the second network model, the total loss function value of the second network model is determined based on the sample pair update set of this round to ensure the rationality of the number of training times, thereby making the performance of the trained second network model basically consistent with that of the first network model.
[0060] An embodiment of the present application provides a network model training method, wherein the same sample pair set as the first network model is used to train the second network model, and when the second network model completes this round of iterative training, a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair are obtained; if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain an updated sample pair set; based on the updated sample pair set, a total loss function value of the first network model is determined; if the total loss function value is greater than a preset value, the total loss function value is used to update the parameters of the second network model so that the prediction result of the second network model approaches the prediction result of the first network model; and the sample pair set is used to continue the next round of iterative training for the updated second network model until the total loss function value converges to the preset value, thereby obtaining a trained second network model. This method deletes the samples that have been learned well by the second network model, so that the second network model can focus on learning samples that perform worse than the first network model, and the samples that have been learned well will not be biased. This not only improves the training efficiency, but also ensures the performance of the trained second network model, making the target recognition and detection using the second network model more accurate.
[0061] This embodiment provides another network model training method, which is implemented on the basis of the above embodiment; this embodiment focuses on the specific implementation method of obtaining the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair. Figure 3 The flowchart of another network model training method shown in FIG. 1 is a flowchart of another network model training method. The network model training method in this embodiment includes the following steps:
[0062] Step S302, using the same sample pair set as the first network model to train the second network model;
[0063] Step S304, when the second network model completes this round of iterative training, the first characteristic distance of the first network model for the first sample pair is calculated, and the second characteristic distance of the second network model for the first sample pair is calculated;
[0064] The first feature distance and the second feature distance are Euclidean distance or cosine similarity corresponding to the features of the first sample pair, or other metrics, which are not limited here.
[0065] In this embodiment, the feature distance is taken as the Euclidean distance corresponding to the feature of the first sample pair as an example for explanation. If the first sample pair belongs to the same type of samples, the first feature distance of the first sample pair calculated by the first network model is:
[0066] D intra1 [i] = Euclidean_Distance(a[i], b[i]), where (a[i], b[i]) represents the i-th first sample pair, and Euclidean_Distance(a[i], b[i]) represents the Euclidean distance of the i-th first sample pair.
[0067] If the first sample pair is a heterogeneous sample, the first characteristic distance of the first sample pair calculated by the first network model is:
[0068] D inter1 a[j]=Euclidean_Distance(a[j],b[j]), where Euclidean_Distance(a[j],b[j]) represents the Euclidean distance of the jth first sample pair.
[0069] If the first sample pair belongs to the same type of samples, the second characteristic distance of the first sample pair calculated by the second network model is: D intra2 [i]=Euclidean_Distance(a[i],b[i]).
[0070] If the first sample pair belongs to heterogeneous samples, the second characteristic distance of the first sample pair calculated by the second network model is: D inter2 [j]=Euclidean_Distance(a[j],b[j]).
[0071] In the embodiment of the present invention, the method for calculating the Euclidean distance is similar to the existing method for calculating the Euclidean distance, and will not be described in detail here.
[0072] Step S306, calculating the first feature distance mean of the sample class to which the first sample pair belongs based on the first network model, and calculating the second feature distance mean of the sample class to which the first sample pair belongs based on the second network model; wherein the sample class includes samples of the same class or samples of different classes;
[0073] In actual use, in order to facilitate the distinction of the sample class to which the sample pair belongs, each sample pair in the sample pair set and sample pair can be labeled with a sample class, wherein the sample pairs belonging to the same class can be labeled as 1, and the samples of different classes can be labeled as 0. Therefore, when the first sample pair is obtained, the sample class to which it belongs can be determined based on its label.
[0074] The above-mentioned feature distance mean refers to the mean of the feature distances of all sample pairs in the sample class to which the first sample pair belongs. The first feature distance mean and the second feature distance mean of the sample class to which the first sample belongs can be calculated using the first network model and the second network model respectively.
[0075] The specific calculation method of the first feature distance mean is as follows: all sample pairs of the sample class to which the first sample pair belongs are input into the first network model one by one to obtain the feature distance of each sample pair, and then the feature distance of each sample pair is summed up, and finally the calculated sum is divided by the total number of sample pairs of the sample class to which the first sample pair belongs. The result value is the first feature distance mean1 (D intra ) or mean1(D inter ), where mean1(D intra ) represents the mean of the first characteristic distance between the first sample and the samples of the same type, mean1(D inter ) represents the mean of the first characteristic distances of the first sample to its heterogeneous samples.
[0076] The second feature distance mean calculated based on the second network model is mean2(D intra ) or mean2(D inter ), where mean2(D intra ) represents the mean of the second characteristic distance between the first sample and the samples of the same type, mean2(D inter) represents the mean second feature distance of the first sample to its heterogeneous samples. Since the process of calculating the mean second feature distance based on the second network model is the same as the process of calculating the mean first feature distance based on the first network model, it will not be described in detail here.
[0077] Step S308, applying the first feature distance mean to normalize the first feature distance, and using the first feature distance normalization result as the first prediction result of the first network model for the first sample pair;
[0078] The purpose of applying the first feature distance mean to normalize the first feature distance is to ensure the stability of network model training; in this embodiment, the normalization method is to divide the first feature distance by the first feature distance mean, and the normalized result obtained can be regarded as the first prediction result of the first network model for the first sample pair.
[0079] If the normalized result of the first characteristic distance obtained by the first sample to its similar samples is:
[0080] If the normalized result of the first characteristic distance obtained by the first sample to its heterogeneous sample is:
[0081]
[0082] Step S310, applying the second feature distance mean to normalize the second feature distance, and using the second feature distance normalization result as the second prediction result of the second network model for the first sample pair;
[0083] The purpose and method of normalizing the second characteristic distance are the same as those of the above step S308, and will not be described in detail here.
[0084] If the normalized result of the second characteristic distance obtained by the first sample to the same type of sample is:
[0085] If the normalized result of the second characteristic distance obtained by the first sample to its heterogeneous sample is:
[0086] Step S312, based on the sample class to which the first sample pair belongs, by comparing the first prediction result with the second prediction result, determining whether the second prediction result is better than the first prediction result;
[0087] The process of step S312 above can be implemented by steps A1 and A2:
[0088] Step A1: if the sample class to which the first sample pair belongs is the same type of sample, subtract the second prediction result from the first prediction result to obtain a first difference; if the first difference is greater than 0 or greater than a preset first positive value, it is determined that the second prediction result is better than the first prediction result;
[0089] If the first difference is greater than 0 or greater than the preset first positive value, it means that the first prediction result is greater than the second prediction result. Continuing to use the Euclidean distance corresponding to the feature distance of the first sample pair as an example, for the same sample, if the second prediction result of the second network model is less than the first prediction result of the first network model, it means that on the first sample pair, the prediction ability of the second network model is better than that of the first network model. Therefore, in the distillation process, the knowledge of this part of the sample is filtered out.
[0090] If the second prediction result of the second network model is greater than or equal to the first prediction result of the first network model, it means that the prediction ability of the second network model for this part is worse than that of the first network model. Therefore, the knowledge of this part of the samples is exactly what the second network model needs to train.
[0091] Step A2: if the sample class to which the first sample pair belongs is a heterogeneous sample, the first prediction result is subtracted from the second prediction result to obtain a second difference; if the second difference is less than 0 or less than a preset second negative value, it is determined that the second prediction result is better than the first prediction result.
[0092] If the second difference is less than 0 or less than the preset second negative value, it means that the first prediction result is not greater than the second prediction result. Taking Euclidean distance as a measure of feature distance as an example, for heterogeneous samples, if the second prediction result of the second network model is greater than the first prediction result of the first network model, it means that the prediction ability of the second network model is better than that of the first network model on this part of the samples. Therefore, in the distillation process, the knowledge of this part of the samples is "negative knowledge" for the student network and should not be learned.
[0093] If the second prediction result of the second network model is less than or equal to the first prediction result of the first network model, it means that on this part of the samples, the second network model still has room for optimization compared with the first network model. Therefore, in the distillation process, the learning of this part of the samples is strengthened, that is, the first samples are used to train the second network model.
[0094] Step S314, if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain an updated sample pair set;
[0095] Regardless of whether it is a similar sample or a heterogeneous sample, as long as the second prediction result of the second network model is better than the first prediction result of the first network model, it means that the knowledge of the partial sample does not need to be learned and it can be deleted from the sample pair set.
[0096] Step S316, determining the total loss function value of the second network model based on the sample pair update set;
[0097] Step S318, if the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0098] The above-mentioned network model training method provided by the embodiment of the present invention can obtain a first prediction result based on the first feature distance mean and the first feature distance calculated by the first network model according to the first sample pair, and obtain a second prediction result based on the second feature distance mean and the second feature distance calculated by the second network model according to the first sample pair. When it is judged that the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set, and the total loss function value of the second network model is determined by using the sample pair update set. If the total loss function value is greater than a preset value, the total loss function value is applied to update the parameters of the second network model so that the prediction result of the second network model approaches the prediction result of the first network model; and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model; this method deletes the samples that the second network model has learned well, so that the second network model can focus on learning the samples that are worse than the first network model in prediction. Strengthening the training of the poorly learned samples can improve the accuracy of the second network model to a certain extent.
[0099] This embodiment provides another network model training method, which is implemented on the basis of the above embodiment; this embodiment focuses on describing a specific implementation method for determining the total loss function value of the second network model based on the sample pair update set. Figure 4 The flowchart of another network model training method shown in FIG. 1 is a flowchart of another network model training method. The network model training method in this embodiment includes the following steps:
[0100] Step S402, using the same sample pair set as the first network model to train the second network model;
[0101] Step S404, when the second network model completes this round of iterative training, obtaining a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair;
[0102] Step S406, if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain an updated sample pair set;
[0103] Step S408, determining a distillation loss value of similar samples and a distillation loss value of heterogeneous samples of the second network model based on the sample pair update set;
[0104] The process of step S408 can be implemented by steps B1-B4:
[0105] Step B1, based on the sample pairs of the same type in the sample pair update set, calculate the sum of squares of the effective distance differences of the same type between the first network model and the second network model;
[0106] In this embodiment, the sum of squares of effective distance differences of similar sample pairs can be calculated using the following formula: intra =∑((D intra_student [i]-D intra_teacher [i])×mask[i]) 2 Among them, D intra_student [i] represents the vector of sample distances corresponding to the same sample pairs of the second network model, D intra_teacher [i] represents the vector consisting of sample distances corresponding to the same sample pairs of the first network model; 1≤i≤N intra , N intra is the number of similar sample pairs; mask[i] is the mask of the similar sample pairs.
[0107] Step B2, dividing the sum of squares of effective similar distance differences by the number of similar sample pairs to obtain the similar sample distillation loss value;
[0108] The distillation loss value of the above-mentioned similar samples is:
[0109] Step B3, based on the heterogeneous sample pairs in the sample pair update set, calculating the sum of squares of effective heterogeneous distance differences between the first network model and the second network model;
[0110] In this embodiment, the sum of squares of effective same-class distance differences of heterogeneous sample pairs can be calculated using the following formula: inter =∑((D intra_student [j]-D intra_teacher [j])×mask[j]) 2 Among them, D intra_student [j] represents the vector of sample distances corresponding to heterogeneous sample pairs of the second network model, D intra_teacher [j] represents the vector consisting of sample distances corresponding to heterogeneous sample pairs of the first network model; 1≤j≤N inter , N inter is the number of heterogeneous sample pairs; mask[j] is the mask of homogeneous sample pairs.
[0111] Step B4: Divide the sum of squares of effective heterogeneous distance differences by the number of heterogeneous sample pairs to obtain the heterogeneous sample distillation loss value.
[0112] The distillation loss value of the above heterogeneous samples is:
[0113] Step S410, determining a total loss function value of the second network model based on the distillation loss value of the same type of samples and the distillation loss value of the different type of samples;
[0114] The above total loss function value can be expressed by the following formula:
[0115] L distill =αL intra +βL inter ; Among them, α represents the weight value corresponding to the distillation loss value of the same sample, and β represents the weight value corresponding to the distillation loss value of the different sample. The above two weight values can be adjusted according to actual needs to highlight the importance of the distillation loss value of the same sample and the distillation loss value of the different sample to the total loss function value.
[0116] Step S412: If the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0117] The network model training method provided by the embodiment of the present invention can obtain the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair, and when the second prediction result is better than the first prediction result, update the sample pair set and delete the first sample pair to obtain the sample pair update set; based on the same sample pairs and different sample pairs in the sample pair update set, respectively calculate the square sum of the effective same distance difference and the square sum of the effective different distance difference between the first network model and the second network model, and obtain the same sample distillation loss value and the different sample distillation loss value according to the number of the same sample pairs and the number of different sample pairs, thereby determining the total loss function value of the second network model, and in the training process, when the total loss function value obtained converges to a preset value, stop the training of the second network model. This method filters out the sample pairs that the second network model has learned well, so that the second network model can focus on the sample pairs that need to be poorly learned, and can make the output result of the trained second network model close to the output result of the first network model, thereby achieving a better training effect.
[0118] Furthermore, in order to fully understand the above network model training method, Figure 5 A flowchart of another network model training method is shown, such as Figure 5As shown, the network model training method includes the following steps:
[0119] Step S500, extracting a first sample feature of a first similar sample pair using a first network model; extracting a second sample feature of the first similar sample using a second network model;
[0120] Step S501, calculating the Euclidean distance of the first similar sample based on the first sample feature and performing normalization processing to obtain a first prediction result;
[0121] Step S502, calculating the Euclidean distance of the first similar sample based on the second sample feature and performing normalization processing to obtain a second prediction result;
[0122] Step S503: if the second prediction result is better than the first prediction result, filter similar samples in the sample pair set to obtain an updated sample pair set;
[0123] Step S504, determining the distillation loss value of the same type of samples based on the sample pair update set;
[0124] Step S505, extracting the third sample feature of the first heterogeneous sample pair using the first network model; extracting the fourth sample feature of the first heterogeneous sample pair using the second network model;
[0125] Step S506, calculating the Euclidean distance of the first heterogeneous sample pair based on the third sample feature and performing normalization processing to obtain a first prediction result;
[0126] Step S507, calculating the Euclidean distance of the first heterogeneous sample pair based on the fourth sample feature and performing normalization processing to obtain a second prediction result;
[0127] Step S508, if the second prediction result is better than the first prediction result, filter the heterogeneous samples in the sample pair set to obtain an updated sample pair set;
[0128] Step S509, determining the heterogeneous sample distillation loss value based on the sample pair update set;
[0129] Step S510, determining a total loss function value of the second network model based on the distillation loss value of the same type of samples and the distillation loss value of the different type of samples;
[0130] Step S511, if the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0131] The above steps S500-S504 are the update and loss value calculation process of the homogeneous sample set, and steps S505-S509 are the update and loss value calculation process of the heterogeneous sample set. Therefore, the execution order of the above two processes can be swapped or executed in parallel, which is not limited here.
[0132] The above-mentioned network model training method provided by the embodiment of the present invention can filter out the partially predicted sample pairs from the sample pair set when the second prediction result of the second network model is worse than the first prediction result of the first network model, regardless of whether the first sample pair is the first similar sample or the first heterogeneous sample, and continue to train the second network model for the remaining sample pairs whose second network model prediction results are not as good as the first network model prediction results, until the total loss function value converges to a preset value, and then stop the iterative training of the second network model. This method of filtering out "negative knowledge" can enable the second network model to better learn and predict samples that are worse than the first network model, so as to improve the accuracy of the second network model.
[0133] The second network model can be used for processing such as target recognition and detection in an image. The trained second network model improves the accuracy of target recognition and detection of the second network model to a certain extent. Based on this, an embodiment of the present invention also provides an image target recognition method, which is applied to the above electronic device, see Figure 8 The image target recognition method flow chart shown in the figure comprises the following steps:
[0134] Step S802, receiving an image to be recognized;
[0135] The image to be identified in this embodiment may come from an image captured by an image acquisition device (such as a camera). The image acquisition device may be a camera or other device set up in a public place, or a camera or other device set up in a specific place.
[0136] In addition to being obtained through an image acquisition device, the above-mentioned image to be identified can also be obtained from a third-party device. The third-party device can provide the acquired original image to the above-mentioned electronic device, or provide the image to the above-mentioned electronic device after filtering or screening the image.
[0137] Step S804, using the second network model to process the image to be recognized, and outputting a target recognition result; wherein the second network model is a second network model pre-trained by the network model training method provided in the above embodiment.
[0138] In the above-mentioned image target recognition method, the second network model obtained through training in the above embodiment is applied to target recognition, thereby obtaining the target recognition result. Because the second network model is trained with the same sample pair set as the first network model during the training process, and when the second network model completes each round of iterative training, the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair are obtained; if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain a sample pair update set; the total loss function value of the first network model is determined based on the sample pair update set; if the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model. This method deletes the samples that have been learned well by the second network model, so that the second network model can focus on learning samples that perform worse than the first network model, and the samples that have been learned well will not be biased. Therefore, the performance of the trained second network model is guaranteed, and the accuracy of target recognition and detection using the second network model is higher.
[0139] Corresponding to the above network model training method embodiment, the embodiment of the present invention provides a network model training device, wherein the above device is applied to a server, Figure 6 A schematic diagram of the structure of a network model training is shown, such as Figure 6 As shown, the device comprises:
[0140] A training module 602 is used to train a second network model using the same sample pair set as the first network model, wherein the computational complexity of the first network model is greater than that of the second network model;
[0141] An acquisition module 604 is used to acquire a first prediction result of the first network model for the first sample pair and a second prediction result of the second network model for the first sample pair when the second network model completes this round of iterative training;
[0142] A deletion module 606, configured to delete the first sample pair from the sample pair set if the second prediction result is better than the first prediction result, to obtain an updated sample pair set;
[0143] A determination module 608, configured to determine a total loss function value of a second network model based on the sample pair update set;
[0144] Iteration module 610 is used to apply the total loss function value to update the parameters of the second network model if the total loss function value is greater than the preset value, and apply the sample pair set to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
[0145] The embodiment of the present application provides a network model training device, wherein the same sample pair set as the first network model is used to train the second network model, and when the second network model completes this round of iterative training, the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair are obtained; if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain a sample pair update set; the total loss function value of the first network model is determined based on the sample pair update set; if the total loss function value is greater than a preset value, the total loss function value is used to update the parameters of the second network model, and the sample pair set is used to continue the next round of iterative training for the updated second network model until the total loss function value converges to the preset value, thereby obtaining a trained second network model. This method deletes the samples that the second network model has learned well, so that the second network model can focus more on learning those samples that are worse than the first network model, and the samples that have learned well will not be biased, thereby improving the accuracy of the second network model to a certain extent.
[0146] The acquisition module 604 is also used to calculate the first feature distance of the first network model for the first sample pair, and calculate the second feature distance of the second network model for the first sample pair; calculate the mean of the first feature distance of the sample class to which the first sample pair belongs based on the first network model, and calculate the mean of the second feature distance of the sample class to which the first sample pair belongs based on the second network model; wherein the sample class includes samples of the same class or samples of different classes; apply the mean of the first feature distance to normalize the first feature distance, and use the normalized result of the first feature distance as the first prediction result of the first network model for the first sample pair; apply the mean of the second feature distance to normalize the second feature distance, and use the normalized result of the second feature distance as the second prediction result of the second network model for the first sample pair.
[0147] The feature distance is the Euclidean distance or cosine similarity corresponding to the features of the first sample pair.
[0148] Based on the above network model training device, the embodiment of the present invention also provides another network model training device, see Figure 7 The schematic diagram of the structure of the network model training device shown in FIG. Figure 6In addition to the structure shown, a comparison module 702 connected to both the acquisition module 604 and the deletion module 606 is also included, which is used to determine whether the second prediction result is better than the first prediction result by comparing the first prediction result and the second prediction result based on the sample class to which the first sample pair belongs.
[0149] The comparison module 702 is also used to, if the sample class to which the first sample pair belongs is the same type of sample, subtract the second prediction result from the first prediction result to obtain a first difference; if the first difference is greater than 0 or greater than a preset first positive value, determine that the second prediction result is better than the first prediction result.
[0150] The comparison module 702 is also used to, if the sample class to which the first sample pair belongs is a heterogeneous sample, calculate the first prediction result minus the second prediction result to obtain a second difference; if the second difference is less than 0 or less than a preset second negative value, determine that the second prediction result is better than the first prediction result.
[0151] The above-mentioned determination module 608 is also used to determine the same-class sample distillation loss value and the heterogeneous sample distillation loss value of the second network model based on the sample pair update set; based on the same-class sample distillation loss value and the heterogeneous sample distillation loss value, determine the total loss function value of the second network model.
[0152] The above-mentioned determination module 608 is also used to calculate the sum of squares of effective similar distance differences between the first network model and the second network model based on similar sample pairs in the sample pair update set; divide the sum of squares of effective similar distance differences by the number of similar sample pairs to obtain the similar sample distillation loss value; calculate the sum of squares of effective heterogeneous distance differences between the first network model and the second network model based on heterogeneous sample pairs in the sample pair update set; divide the sum of squares of effective heterogeneous distance differences by the number of heterogeneous sample pairs to obtain the heterogeneous sample distillation loss value.
[0153] The determination module 608 is also used to calculate the square sum W of the effective similar distance differences between the first network model and the second network model. intra =∑((D intra_student [i]-D intra_teacher [i])×mask[i]) 2 ; Among them, D intra_student [i] represents the vector of sample distances corresponding to the same sample pairs of the second network model, D intra_teacher [i] represents the vector consisting of sample distances corresponding to the same sample pairs of the first network model; 1≤i≤N intra , N intra is the number of similar sample pairs; mask[i] is the mask of the similar sample pairs.
[0154] The determination module 608 is also used to calculate the square sum W of the effective heterogeneous distance differences between the first network model and the second network model. inter =∑((D intra_student [j]-D intra_teacher [j])×mask[j]) 2 ; Among them, D intra_student [j] represents the vector of sample distances corresponding to heterogeneous sample pairs of the second network model, D intra_teacher [j] represents the vector consisting of sample distances corresponding to heterogeneous sample pairs of the first network model; 1≤j≤N inter , N inter is the number of heterogeneous sample pairs; mask[j] is the mask of homogeneous sample pairs.
[0155] The network model training device provided in the embodiment of the present invention has the same technical features as the network model training method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.
[0156] Corresponding to the above-mentioned image target recognition method, an embodiment of the present invention further provides an image target recognition device, which is applied to an electronic device, see Fig. 9 The schematic diagram of the structure of the image target recognition device shown in the figure comprises: an image receiving module 92 for receiving an image to be recognized; an image processing module 94 for processing the image to be recognized using a second network model and outputting a target recognition result; wherein the second network model is a second network model pre-trained by the above-mentioned network model training method.
[0157] In the above-mentioned image target recognition device, the second network model trained by the above embodiment is applied to target recognition, thereby obtaining the target recognition result. Because the second network model is trained by the same sample pair set as the first network model during the training process, and when the second network model completes each round of iterative training, the first prediction result of the first network model for the first sample pair and the second prediction result of the second network model for the first sample pair are obtained; if the second prediction result is better than the first prediction result, the first sample pair is deleted from the sample pair set to obtain a sample pair update set; the total loss function value of the first network model is determined based on the sample pair update set; if the total loss function value is greater than the preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model. This method deletes the samples that have been learned well by the second network model, so that the second network model can focus on learning samples that perform worse than the first network model, and the samples that have been learned well will not be biased. Therefore, the performance of the trained second network model is guaranteed, and the accuracy of target recognition and detection using the second network model is higher.
[0158] This embodiment also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processing device, the above-mentioned network model training method or the steps of the above-mentioned image target recognition method are executed.
[0159] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the electronic devices, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0160] The embodiments of the present invention provide a network model training method, an image target recognition method, an apparatus, and a computer program product for an electronic device, including a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. The specific implementation can be found in the method embodiments, which will not be repeated here.
[0161] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0162] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0164] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0165] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A network model training method, characterized in that: The method is applied to a server and includes: Using the same sample pair set as the first network model to train the second network model, wherein the computational complexity of the first network model is greater than that of the second network model, and the second network model is used to process the image to be recognized to output a target recognition result; When the second network model completes this round of iterative training, the first sample pair is predicted by using the second network model and the first network model trained in this round, respectively, to obtain a first prediction result predicted by the first network model and a second prediction result predicted by the second network model; wherein the first sample pair is a homogeneous sample including at least one sample pair, or is a heterogeneous sample including at least one sample pair; If the second prediction result is better than the first prediction result, deleting the first sample pair from the sample pair set to obtain an updated sample pair set; Determine a total loss function value of the second network model based on the sample pair update set; If the total loss function value is greater than a preset value, the total loss function value is applied to update the parameters of the second network model, and the sample pair set is applied to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
2. The method according to claim 1, characterized in that The step of using the second network model and the first network model trained in this round to predict the first sample pair respectively to obtain a first prediction result predicted by the first network model and a second prediction result predicted by the second network model includes: Calculating a first characteristic distance of the first network model with respect to the first sample pair, and calculating a second characteristic distance of the second network model with respect to the first sample pair; Calculating a first feature distance mean of a sample class to which the first sample pair belongs based on the first network model, and calculating a second feature distance mean of a sample class to which the first sample pair belongs based on the second network model; wherein the sample class includes samples of the same class or samples of different classes; applying the first feature distance mean to normalize the first feature distance, and using the first feature distance normalization result as the first prediction result of the first network model for the first sample pair; The second feature distance is normalized by applying the second feature distance mean, and a normalized result of the second feature distance is used as a second prediction result of the second network model for the first sample pair.
3. The method according to claim 2, characterized in that The feature distance is the Euclidean distance or cosine similarity corresponding to the features of the first sample pair.
4. The method according to claim 2, characterized in that: The method further comprises: Based on the sample class to which the first sample pair belongs, by comparing the first prediction result with the second prediction result, it is determined whether the second prediction result is better than the first prediction result.
5. The method according to claim 4, characterized in that The feature distance is the Euclidean distance corresponding to the feature of the first sample pair; The step of comparing the first prediction result with the second prediction result based on the sample class to which the first sample pair belongs, and determining whether the second prediction result is better than the first prediction result, comprises: If the sample class to which the first sample pair belongs is the same type of sample, subtract the second prediction result from the first prediction result to obtain a first difference; If the first difference is greater than 0 or greater than a preset first positive value, it is determined that the second prediction result is better than the first prediction result.
6. The method according to claim 4, characterized in that The feature distance is the Euclidean distance corresponding to the feature of the first sample pair; The step of comparing the first prediction result with the second prediction result based on the sample class to which the first sample pair belongs, and determining whether the second prediction result is better than the first prediction result, comprises: If the sample class to which the first sample pair belongs is a heterogeneous sample, subtract the second prediction result from the first prediction result to obtain a second difference; If the second difference is less than 0 or less than a preset second negative value, it is determined that the second prediction result is better than the first prediction result.
7. The method according to claim 1, characterized in that The step of determining the total loss function value of the second network model based on the sample pair update set includes: Determine a similar sample distillation loss value and a heterogeneous sample distillation loss value of the second network model based on the sample pair update set; Based on the distillation loss value of the same type of samples and the distillation loss value of the different type of samples, a total loss function value of the second network model is determined.
8. The method according to claim 7, characterized in that The step of determining the distillation loss value of the same type of samples and the distillation loss value of the different type of samples of the second network model based on the sample pair update set includes: Based on the similar sample pairs in the sample pair update set, calculating the sum of squares of effective similar distance differences between the first network model and the second network model; dividing the sum of squares of effective similar distance differences by the number of similar sample pairs to obtain a similar sample distillation loss value; Based on the heterogeneous sample pairs in the sample pair update set, the sum of squares of effective heterogeneous distance differences between the first network model and the second network model is calculated; and the sum of squares of the effective heterogeneous distance differences is divided by the number of the heterogeneous sample pairs to obtain a heterogeneous sample distillation loss value.
9. The method according to claim 8, characterized in that The step of calculating the sum of squares of effective similar distance differences between the first network model and the second network model comprises: Calculate the sum of squares of effective similar distance differences between the first network model and the second network model ;in, A vector representing the sample distances corresponding to the pairs of samples of the same type in the second network model, A vector representing sample distances corresponding to the pairs of samples of the same type in the first network model; ; , is the number of similar sample pairs; is the mask for similar sample pairs.
10. The method according to claim 8, characterized in that The step of calculating the sum of squares of effective heterogeneous distance differences between the first network model and the second network model comprises: Calculate the sum of squares of effective heterogeneous distance differences between the first network model and the second network model ;in, A vector representing sample distances corresponding to the heterogeneous sample pairs of the second network model, A vector representing sample distances corresponding to the heterogeneous sample pairs of the first network model; ; , is the number of heterogeneous sample pairs; is the mask of heterogeneous sample pairs.
11. A method for image target recognition, characterized in that: The method is applied to an electronic device, and the method comprises: Receiving an image to be recognized; The image to be identified is processed using a second network model to output a target recognition result; wherein the second network model is a second network model pre-trained by the method described in any one of claims 1-10.
12. A network model training device, characterized in that: The device is applied to a server and includes: A training module, used for training a second network model using the same sample pair set as the first network model, wherein the computational complexity of the first network model is greater than that of the second network model, and the second network model is used for processing the image to be recognized to output a target recognition result; an acquisition module, configured to, when the second network model completes this round of iterative training, use the second network model trained in this round and the first network model to respectively predict the first sample pair, and obtain a first prediction result predicted by the first network model and a second prediction result predicted by the second network model; wherein the first sample pair is a homogeneous sample including at least one sample pair, or is a heterogeneous sample including at least one sample pair; a deleting module, configured to delete the first sample pair from the sample pair set if the second prediction result is better than the first prediction result, so as to obtain an updated sample pair set; A determination module, configured to determine a total loss function value of the second network model based on the sample pair update set; An iterative module is used to apply the total loss function value to update the parameters of the second network model if the total loss function value is greater than a preset value, and apply the sample pair set to the updated second network model to continue the next round of iterative training until the total loss function value converges to the preset value, thereby obtaining a trained second network model.
13. An image target recognition device, characterized in that: The device is applied to electronic equipment, and the device comprises: An image receiving module, used for receiving an image to be identified; An image processing module is used to process the image to be identified using a second network model and output a target recognition result; wherein the second network model is a second network model pre-trained by the method described in any one of claims 1-10.
14. An electronic device, characterized in that: It includes a processor and a memory, the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the network model training method described in any one of claims 1 to 10 or to implement the image target recognition method described in claim 11.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by the processor, the computer-executable instructions prompt the processor to implement the network model training method described in any one of claims 1 to 10 or to implement the image target recognition method described in claim 11.
Citation Information
Patent Citations
Neural network training method and device
CN107247989A
Neural network systems
CN108734283A