A method, device, computer equipment and storage medium for generating a neural network
By passing the differences in distribution characteristics between teachers and students' neural networks and adjusting student neural network parameters, the problem of difficulty in deploying large-scale neural networks in embedded devices is solved, and the training efficiency and image classification accuracy of small-scale neural networks are improved.
Patent Information
- Application Number
- CN202210262181.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-16
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-03-16
AI Technical Summary
In the prior art, large-scale neural networks are difficult to deploy in embedded devices with limited computing resources, and the hardware and time overhead of the knowledge distillation method is large, resulting in difficulty in training neural networks for small-scale students and unsatisfactory image classification accuracy.
By utilizing the distribution characteristics difference between the image classification results of the teacher neural network and the image classification results of the student neural network, the network parameters of the student neural network are adjusted, and the intrinsic distribution characteristics of the teacher network are transmitted, rather than precisely matching the classification results, reducing training difficulty and overhead.
While reducing training time and hardware overhead, the student neural network achieves image classification performance similar to that of the teacher network, improving the training efficiency and accuracy of small-scale neural networks.
Smart Images

Figure CN114612724B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of deep learning technology, and more specifically, to a method, apparatus, computer device, and storage medium for generating a neural network. Background Art
[0002] In the field of deep learning, large-scale neural networks typically feature complex network structures and large network sizes, while also exhibiting excellent performance and generalization capabilities. For image classification problems, they can more quickly extract and analyze large amounts of image information, while also delivering high output accuracy. However, small-scale neural networks, due to their small size and limited feature extraction capabilities, suffer from relatively weak performance and generalization capabilities. This results in slow image analysis and suboptimal classification accuracy when faced with large numbers of images. To improve image classification accuracy, neural networks used for image classification are often designed to be larger and deeper. However, due to computational resource constraints in practical applications, such large-scale neural networks are difficult to deploy in real-world scenarios. For example, in embedded devices, the computing resources are insufficient to support the computational processing of large-scale neural networks. Therefore, knowledge distillation methods have been proposed and are often used to use large-scale neural networks as teacher networks, guiding the training of smaller student networks, thereby improving the training accuracy of the smaller student networks. Currently, the process of using teacher networks to guide the training of student networks to obtain the target neural network for image classification requires significant hardware and time overhead. Summary of the Invention
[0003] The present disclosure provides at least one method, device, computer equipment, and storage medium for generating a neural network.
[0004] In a first aspect, an embodiment of the present disclosure provides a method for generating a neural network, comprising:
[0005] Using a teacher neural network to classify the image data to obtain a first image classification result, and using a student neural network to classify the image data to obtain a second image classification result;
[0006] Determining a first loss based on the first image classification result and the second image classification result, wherein the first loss is used to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result;
[0007] Based on the first loss, network parameters of the student neural network are adjusted to obtain a target neural network for image classification.
[0008] In an optional embodiment, the first image classification result includes: a first probability that the image data belongs to each first preset category among multiple first preset categories that can be predicted by the teacher neural network; the second image classification result includes: a second probability that the image data belongs to each second preset category among multiple second preset categories that can be predicted by the student neural network.
[0009] In an optional embodiment, the first loss includes: inter-classification loss and / or intra-classification loss;
[0010] In the case where the first loss includes an inter-class loss, the first distribution feature includes a first probability distribution feature, and the second distribution feature includes a second probability distribution feature; the inter-class loss characterizes the difference between the first probability distribution feature and the second probability distribution feature; wherein the first probability distribution feature includes: a distribution feature of a first probability that a single image data item belongs to each of the first preset classes, as determined by the teacher neural network, in the plurality of first preset classes; and the second probability distribution feature includes: a distribution feature of a second probability that the single image data item belongs to each of the second preset classes, as determined by the student network, in the plurality of second preset classes;
[0011] In the case where the first loss includes intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, the distribution feature of the first probability that the multiple image data determined by the teacher neural network belong to the first preset classification; the fourth probability distribution feature includes: for each first preset classification, the distribution feature of the second probability that the multiple image data determined by the student network belong to the second preset classification corresponding to the first preset classification.
[0012] In an optional implementation, determining the first loss based on the first image classification result and the second image classification result includes:
[0013] When the first loss includes an inter-class loss, determining, for each of the plurality of image data, a first similarity or a first difference between first probability distribution features of the image data corresponding to the plurality of first preset classes and second probability distribution features corresponding to the plurality of second preset classes based on first probabilities that the image data corresponds to the plurality of first preset classes, and second probabilities that the image data corresponds to the plurality of second preset classes;
[0014] The inter-classification loss is determined based on first similarities or first differences respectively corresponding to the plurality of image data.
[0015] In an optional implementation, determining the first loss based on the first image classification result and the second image classification result further includes:
[0016] In a case where the first loss includes an intra-class loss, for each of the plurality of second preset classes, determining, based on a first probability that the plurality of image data respectively belongs to the first preset class corresponding to the second preset class and a second probability that the plurality of image data belongs to the second preset class, a second similarity or a second difference between a third probability distribution feature corresponding to the first preset class and a fourth probability distribution feature corresponding to the second preset class of the plurality of image data;
[0017] The intra-class loss is determined based on the second similarities or second differences respectively corresponding to a plurality of the second preset classes.
[0018] In an optional implementation, the similarity includes: Pearson correlation coefficient and / or cosine similarity.
[0019] In an optional embodiment, the method further includes:
[0020] Determining a second loss of the student neural network based on the second image classification result and the labeling information of the image data;
[0021] The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes:
[0022] Based on the first loss and the second loss, the network parameters of the student neural network are adjusted to obtain a target neural network.
[0023] In an optional embodiment, the network parameters of the student neural network are adjusted based on the first loss and the second loss to obtain a target neural network, and the method further includes:
[0024] Determine the total training loss of the student neural network by weighting the first loss and the second loss;
[0025] Based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
[0026] In an optional embodiment, the classifying the image data using the student neural network to be trained to obtain a second image classification result includes:
[0027] The following process is performed in each of the multiple iteration cycles:
[0028] Determining a first neural network for a current iteration cycle; wherein the neural network to be trained for the current iteration cycle includes: an original student neural network, or a second neural network obtained in a previous iteration cycle; using the first neural network for the current iteration cycle, classifying the image data to obtain a second image classification result for the image data in the current iteration cycle;
[0029] The determining a first loss based on the first image classification result and the second image classification result includes:
[0030] Determining a first loss for a current iteration cycle based on the first image classification result and a second image classification result of the image data in a current iteration cycle;
[0031] The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes:
[0032] In response to the first loss of the current iteration cycle satisfying a preset iteration stop condition, determining the first neural network of the current iteration cycle as the target neural network;
[0033] In response to the first loss of the current iteration cycle not meeting the preset iteration stop condition, the network parameters of the first neural network of the current iteration cycle are adjusted to obtain the second neural network of the current iteration cycle, and enter the next iteration cycle.
[0034] In a second aspect, the present disclosure further provides a neural network generation device, including:
[0035] An image classification module is configured to classify the image data using a teacher neural network to obtain a first image classification result, and to classify the image data using a student neural network to obtain a second image classification result;
[0036] a feature analysis module, configured to determine a first loss based on the first image classification result and the second image classification result, wherein the first loss is used to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result;
[0037] A target generation module is used to adjust the network parameters of the student neural network based on the first loss to obtain a target neural network for image classification.
[0038] In an optional implementation, the first image classification result includes:
[0039] The image data has a first probability of belonging to each first preset category among multiple first preset categories that can be predicted by the teacher neural network; the second image classification result includes: the image data has a second probability of belonging to each second preset category among multiple second preset categories that can be predicted by the student neural network.
[0040] In an optional embodiment, the first loss includes: inter-classification loss and / or intra-classification loss;
[0041] In the case where the first loss includes an inter-class loss, the first distribution feature includes a first probability distribution feature, and the second distribution feature includes a second probability distribution feature; the inter-class loss characterizes the difference between the first probability distribution feature and the second probability distribution feature; wherein the first probability distribution feature includes: a distribution feature of a first probability that a single image data item belongs to each of the first preset classes, as determined by the teacher neural network, in the plurality of first preset classes; and the second probability distribution feature includes: a distribution feature of a second probability that the single image data item belongs to each of the second preset classes, as determined by the student network, in the plurality of first preset classes;
[0042] In the case where the first loss includes intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, the distribution feature of the first probability that the multiple image data determined by the teacher neural network belong to the first preset classification; the fourth probability distribution feature includes: for each first preset classification, the distribution feature of the second probability that the multiple image data determined by the student network belong to the second preset classification corresponding to the first preset classification.
[0043] In an optional implementation, the feature analysis module is further configured to:
[0044] When the first loss includes an inter-class loss, determining, for each of the plurality of image data, a first similarity or a first difference between first probability distribution features of the image data corresponding to the plurality of first preset classes and second probability distribution features corresponding to the plurality of second preset classes based on first probabilities that the image data corresponds to the plurality of first preset classes, and second probabilities that the image data corresponds to the plurality of second preset classes;
[0045] The inter-classification loss is determined based on first similarities or first differences respectively corresponding to the plurality of image data.
[0046] In an optional implementation, the feature analysis module is further configured to:
[0047] In a case where the first loss includes an intra-class loss, for each of the plurality of second preset classes, determining, based on a first probability that the plurality of image data respectively belongs to the first preset class corresponding to the second preset class and a second probability that the plurality of image data belongs to the second preset class, a second similarity or a second difference between a third probability distribution feature corresponding to the first preset class and a fourth probability distribution feature corresponding to the second preset class of the plurality of image data;
[0048] The intra-class loss is determined based on the second similarities or second differences respectively corresponding to a plurality of the second preset classes.
[0049] In an optional implementation, the similarity includes: Pearson correlation coefficient and / or cosine similarity.
[0050] In an optional implementation manner, the target generation module is further configured to:
[0051] Determining a second loss of the student neural network based on the second image classification result and the labeling information of the image data;
[0052] The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes:
[0053] Based on the first loss and the second loss, the network parameters of the student neural network are adjusted to obtain a target neural network.
[0054] In an optional implementation manner, the target generation module is further configured to:
[0055] Determine the total training loss of the student neural network by weighting the first loss and the second loss;
[0056] Based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
[0057] In an optional embodiment, the classifying the image data using the student neural network to be trained to obtain the second image classification result includes:
[0058] Determining a first neural network for a current iteration cycle; wherein the neural network to be trained for the current iteration cycle includes: an original student neural network, or a second neural network obtained in a previous iteration cycle; using the first neural network for the current iteration cycle, classifying the image data to obtain a second image classification result for the image data in the current iteration cycle;
[0059] The feature analysis module, when determining the first loss based on the first image classification result and the second image classification result, is configured to:
[0060] Determining a first loss for a current iteration cycle based on the first image classification result and a second image classification result of the image data in a current iteration cycle;
[0061] The target generation module, when adjusting the network parameters of the student neural network based on the first loss to obtain the target neural network, is used to:
[0062] In response to the first loss of the current iteration cycle satisfying a preset iteration stop condition, determining the first neural network of the current iteration cycle as the target neural network;
[0063] In response to the first loss of the current iteration cycle not meeting the preset iteration stop condition, the network parameters of the first neural network of the current iteration cycle are adjusted to obtain the second neural network of the current iteration cycle, and enter the next iteration cycle.
[0064] In a third aspect, an optional implementation of the present disclosure further provides a computer device, a processor, and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the processor is used to execute the machine-readable instructions stored in the memory. When the machine-readable instructions are executed by the processor, the machine-readable instructions perform the steps of the above-mentioned first aspect, or any possible implementation of the first aspect.
[0065] In a fourth aspect, an optional implementation of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed, it executes the steps of the above-mentioned first aspect or any possible implementation of the first aspect.
[0066] The neural network method, apparatus, computer equipment and storage medium provided by the embodiments of the present disclosure determine a first loss based on a first image classification result of image data by a teacher neural network and a second image classification result of image data by a student neural network, and then use the first loss to adjust the network parameters of the student neural network to obtain a target neural network. In this process, the first loss is used to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result. The difference can reflect the intrinsic distribution characteristics of the first image classification result and the second image classification result. Therefore, when transferring knowledge from the teacher neural network to the student neural network, the intrinsic distribution characteristics of the result of data classification processing by the teacher neural network are transferred to the student neural network, rather than requiring the student neural network to accurately match the classification processing result of the teacher neural network on the image data. The training process of the student neural network can more easily achieve this goal, so the training difficulty of the student neural network is relatively small, reducing the time and hardware overhead required for training the student neural network, and the student network after training can achieve image classification performance similar to that of the teacher network.
[0067] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and, together with the specification, are used to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without inventive effort.
[0069] Figure 1 A flowchart of a method for generating a neural network provided by an embodiment of the present disclosure is shown;
[0070] Figure 2 An example diagram of the generation process in the method for generating a neural network provided by an embodiment of the present disclosure is shown;
[0071] Figure 3 A flowchart of an iterative process in the method for generating a neural network provided by an embodiment of the present disclosure is shown;
[0072] Figure 4 A schematic diagram of a neural network generation device provided by an embodiment of the present disclosure is shown;
[0073] Figure 5 A schematic diagram of a computer device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0074] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present disclosure.
[0075] Research has found that knowledge distillation methods have been proposed and are often used to train student neural networks using knowledge learned by a teacher neural network. The teacher neural network, with its strong learning ability, can transfer its learned knowledge to the weaker student neural network, thereby improving the training accuracy of the student neural network. In related technologies, the information gain (Kullback–Leibler, KL) divergence is used to match the probabilities of multiple image classification results when the teacher and student models are able to classify image data. KL divergence is a method for accurately matching probability values. Application of this method ensures that the student neural network's classification results for image data are as close as possible to those of the teacher neural network. However, due to the significant structural differences between the student and teacher neural networks, achieving a student neural network's classification results close to those of the teacher neural network is difficult, requiring significant time and hardware overhead to achieve the desired training results.
[0076] Based on the above research, the present disclosure provides a method for generating a neural network. When training a student neural network to obtain a target neural network for image classification, the intrinsic distribution characteristics of the classification results of the teacher neural network for classifying image data are passed to the student neural network, rather than requiring the student neural network to accurately match the classification results of the teacher neural network for image data. The training process of the student neural network can more easily achieve this goal, so the training difficulty of the student neural network is less, reducing the time and hardware overhead required for training the student neural network, and the student network after training can achieve image classification performance similar to that of the teacher network.
[0077] The defects in the above solutions are the results obtained by the inventors after practice and careful research. Therefore, the process of discovering the above problems and the solutions proposed by this disclosure for the above problems below should be the contributions made by the inventors to this disclosure during the disclosure process.
[0078] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0079] To facilitate understanding of this embodiment, a method for generating a neural network disclosed in an embodiment of the present disclosure is first introduced in detail. The execution subject of the method for generating a neural network provided in the embodiment of the present disclosure is generally a computer device with a certain computing capability. The computer device includes, for example: a terminal device or a server or other processing device. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the method for generating a neural network can be implemented by a processor calling computer-readable instructions stored in a memory. The method for generating a neural network provided in an embodiment of the present disclosure is described below.
[0080] See also Figure 1 FIG. 1 is a flow chart of a method for generating a neural network according to an embodiment of the present disclosure, wherein the method includes steps S101 to S103, wherein:
[0081] S101: using a pre-trained teacher neural network to classify image data to obtain a first image classification result, and using a student neural network to be trained to classify the image data to obtain a second image classification result;
[0082] S102: Determine a first loss based on the first image classification result and the second image classification result, wherein the first loss is used to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result;
[0083] S103: Based on the first loss, adjust the network parameters of the student neural network to obtain a target neural network for image classification.
[0084] In the process of generating a neural network in the embodiment of the present disclosure, a first loss is determined based on the first image classification result of the teacher neural network on the image data and the second image classification result of the student neural network on the image data. Then, the network parameters of the student neural network are adjusted using the first loss to obtain a target neural network. In this process, the first loss is used to characterize the difference between the first distribution feature of the first image classification result and the second distribution feature of the second image classification result. The difference can reflect the intrinsic distribution characteristics of the first image classification result and the second image classification result. Therefore, when transferring knowledge from the teacher neural network to the student neural network, the intrinsic distribution characteristics of the result of the teacher neural network's classification processing of the data are transferred to the student neural network, rather than requiring the student neural network to accurately match the teacher neural network's classification processing result of the image data. The training process of the student neural network can more easily achieve this goal. Therefore, the training difficulty of the student neural network is relatively small, reducing the time and hardware overhead required for training the student neural network. After the training is completed, the student network can achieve image classification performance similar to that of the teacher network.
[0085] The above S101 to S103 are described in detail below.
[0086] Regarding S101 above, the image data type may be a data type related to the scene type or the content contained therein, such as an image reflecting the interior environment of a vehicle, an image of a human face, etc. Image classification processing refers to the processing of classifying at least one of the local or overall color, style, scene, content object, etc. contained in the image, including, for example, the classification processing of objects or pixels in the image.
[0087] The teacher neural network is a pre-trained neural network that can predict data for at least two classifications, obtaining the probability that the data belongs to each of the at least two classifications. The function of the teacher neural network can be determined based on the needs. For example, if the need is to classify objects in an image, the teacher network can classify the image and obtain the probability that the image belongs to each of multiple different categories. If the need is to detect key points in facial images, the teacher network can detect key points in facial images and obtain the probability that each pixel in the image belongs to a specific facial key point.
[0088] The student neural network is a neural network with the same function as the teacher neural network, but different in structure and size. It can classify data in the same predictive classification process as the teacher neural network, and predict the probability of the data belonging to each classification under at least two classifications.
[0089] Before training the student neural network to obtain the target neural network, the teacher neural network can be trained using image data to obtain a pre-trained teacher neural network. During the process of using the teacher neural network to guide the training of the student neural network, the network parameters of the teacher neural network no longer change. The first image classification result includes: a first probability that the image data belongs to each of the multiple first preset categories that can be predicted by the teacher neural network; the second image classification result includes: a first probability that the image data belongs to each of the multiple second preset categories that can be predicted by the student neural network.
[0090] The multiple first preset categories and the multiple second preset categories may be completely the same, or the multiple second preset categories may be subsets of the multiple first preset categories.
[0091] The classification described in the embodiment of the present disclosure includes a first preset classification and a second preset classification. In the following text, the classification mentioned is the first preset classification if it corresponds to the teacher neural network; and is the second preset classification if it corresponds to the student neural network.
[0092] The first probability represents the probability that the image data belongs to the first preset category or the second preset category among the multiple categories. The size of the probability can be expressed as a percentage. For example, the preset categories that can be predicted by the teacher neural network and the student neural network include: category A, category B, category C, category D, and category E, a total of five categories. Then the first image classification result includes: the first probability that the image data P belongs to category A, category B, category C, category D, and category E. The second image classification result includes: the second probability that the image data P belongs to category A, category B, category C, category D, and category E.
[0093] like Figure 2 In the example shown, the image data includes P1, P2, and P3, and the categories that can be recognized by the neural network include: category A, category B, category C, category D, and category E.
[0094] The first result data and the second result data corresponding to P1, P2, and P3 are respectively obtained as follows: Figure 2 For example, for image data P1, after classification using the teacher neural network, the first probabilities of P1 in the five categories A to E are 0.4, 0.1, 0.2, 0.2, and 0.1, respectively. Using the student neural network, the second probabilities of P1 in the five categories A to E are 0.5, 0.1, 0.1, 0.2, and 0.1, respectively.
[0095] Regarding the above S102, the first loss includes: inter-class loss and / or intra-class loss. The following A to B describe the inter-class loss and the intra-class loss respectively:
[0096] A: When the first loss includes inter-class loss, the first distribution feature includes a first probability distribution feature, and the second distribution feature includes a second probability distribution feature; the inter-class loss characterizes the difference between the first probability distribution feature and the second probability distribution feature; wherein the first probability distribution feature includes: the distribution feature of the first probability that the single image data determined by the teacher neural network belongs to each first preset class in multiple first preset classes; the second probability distribution feature includes: the distribution feature of the second probability that the single image data determined by the student network belongs to each second preset class in multiple second preset classes.
[0097] Here, the first probability distribution feature includes, for example, features represented by a sorting result obtained by sorting the first probabilities corresponding to the image data under multiple categories in descending order.
[0098] The second probability distribution feature includes, for example, features represented by a ranking result obtained by sorting the second probabilities corresponding to the image data under multiple categories in descending order.
[0099] In response to the first loss including the inter-classification loss, when determining the first loss based on the first image classification result and the second image classification result, for example, the following method can be used:
[0100] For each of the plurality of image data, determining, based on first probabilities that the image data corresponds to the plurality of first preset categories and second probabilities that the image data corresponds to the plurality of second preset categories, a first similarity or a first difference between first probability distribution features of the image data corresponding to the plurality of first preset categories and second probability distribution features corresponding to the plurality of second preset categories;
[0101] Based on the first similarities or first differences respectively corresponding to the plurality of image data, an inter-classification loss is determined.
[0102] In a specific implementation, the similarity includes: Pearson correlation coefficient and / or cosine similarity.
[0103] The difference may be calculated using distance or a mathematical method that has a negative correlation with the similarity. Optionally, the difference=1-similarity.
[0104] For example, during the prediction process, this method only considers the relationship between the teacher neural network and the student neural network, as described in the following formula (1):
[0105]
[0106] Where a represents a first prediction vector formed by first probabilities corresponding to each of the plurality of image data and the plurality of classes; b represents a second prediction vector formed by second probabilities corresponding to each of the plurality of image data and the plurality of classes. φ represents a mapping to a; ψ represents a mapping to b.
[0107] For the first prediction vector a and the second prediction vector b of any image data, if a=b, then d(a, b)=0, indicating that the loss is minimized when and only when the outputs of the teacher neural network and the student neural network are completely consistent. However, the difference between the actual student neural network and the teacher neural network may be quite large. Therefore, in the embodiment of the present disclosure, it is not necessarily required that a and b are exactly the same, but rather that the first similarity of the outputs of a and b is obtained. The mappings φ and ψ should be equivalent and do not affect the output result of the classification of the image data finally determined based on a and b. Therefore, the above equation (1) is subjected to a positive linear transformation to obtain the following equation (2):
[0108] d(m1a+n1,m2b+n2)=d(a,b) (2)
[0109] Where m1, m2, n1, and n2 are constants, and m1×m2>0. In fact, in order to satisfy the property of formula (2), the embodiment of the present disclosure can use the Pearson correlation coefficient to represent the first similarity between the output of the teacher neural network and the output of the student neural network, as described in the following formula (3):
[0110] d P (a,b):=1-ρ P (a,b) (3)
[0111] With ρ P For example, (a, b) represents the Pearson correlation coefficient between the output of the teacher neural network and the output of the student neural network. The larger the absolute value of the Pearson correlation coefficient, the stronger the correlation. That is, the closer the correlation coefficient is to 1 or -1, the stronger the correlation is, and the closer the correlation coefficient is to 0, the weaker the correlation is. A stronger correlation indicates a greater first similarity between a and b and a smaller difference. A weaker correlation indicates a smaller first similarity between a and b and a greater difference.
[0112] If the similarity is determined using the Pearson correlation coefficient, the similarity satisfies the following formula (4):
[0113]
[0114] Where Cov(a,b) represents the covariance between the first prediction vector a formed by the first image classification result and the second prediction vector b formed by the second image classification result, std(a) represents the standard deviation of the first prediction vector a; std(b) represents the standard deviation of the second prediction vector b. C represents the number of classifications; a i Represents the first probability corresponding to the i-th classification; represents the mean of the first probabilities in the first prediction vector a; b i Represents the second probability corresponding to the i-th classification; represents the mean of the second probabilities in the second prediction vector b.
[0115] In this way, the first similarity between the output of the teacher neural network and the output of the student neural network can be defined more specifically.
[0116] When determining the inter-classification loss based on the first similarities corresponding to the plurality of image data, the inter-classification loss For example, the following formula (5) is satisfied:
[0117]
[0118] Where B represents the amount of image data, Represents the first image classification result of the teacher neural network and the student neural network for the i-th image data And the second image classification result Here, Equivalent to a in the above formula (4), Equivalent to b in the above formula (4).
[0119] B: In the case where the first loss includes intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, the distribution feature of the first probability that the multiple image data determined by the teacher neural network belong to the first preset classification; the fourth probability distribution feature includes: for each first preset classification, the distribution feature of the second probability that the multiple image data determined by the student network belong to the second preset classification corresponding to the first preset classification.
[0120] Here, the third probability distribution feature includes, for example, a feature represented by a ranking result obtained by ranking the first probabilities corresponding to each category under a plurality of image data in descending order.
[0121] The fourth probability distribution feature, for example, includes: a feature represented by a sorting result obtained by sorting the second probabilities corresponding to each category under multiple image data in descending order.
[0122] In response to the first loss including the intra-classification loss, when determining the first loss based on the first image classification result and the second image classification result, for example, the following method can be used:
[0123] For each of the plurality of second preset categories, determining, based on a first probability that the plurality of image data respectively belongs to the first preset category corresponding to the second preset category and a second probability that the plurality of image data belongs to the second preset category, a second similarity or a second difference between a third probability distribution feature corresponding to the corresponding first preset category and a fourth probability distribution feature corresponding to the second preset category of the plurality of image data;
[0124] The intra-classification loss is determined based on the second similarities or second differences respectively corresponding to the plurality of second preset classes.
[0125] For each category, the prediction scores of different samples may also be correlated. For example, assume there are three image samples, including "airplane," "dog," and "cat." For the prediction results of the "cat" class, the probability value of "airplane" should be the smallest, the probability value of "dog" should be moderate, and the probability value of "cat" should be the highest. The intra-class loss is determined by extracting the second similarity of the intra-class prediction results output by the teacher neural network and the student neural network.
[0126] Specifically, it represents the intra-classification loss, as shown in formula (6):
[0127]
[0128] Among them, C represents the number of categories, Represents the first image classification result of the teacher neural network and the student neural network for the jth category And the second image classification result The second degree of difference between.
[0129] For S103, when adjusting the network parameters of the student neural network based on the first loss, for example, gradient descent can be performed based on the first loss and fed back to determine the gradient information of each network layer in the student neural network, and then the gradient information is used to determine the adjustment amount of the network parameters of each network layer in the student neural network and make adjustments.
[0130] In another embodiment of the present disclosure, in addition to the first loss, a second loss of the student neural network may be determined based on the second image classification result and the labeling information of the image data;
[0131] Among them, the second loss is expressed as classification loss, which is used to characterize the error between the second image classification result output by the student neural network for the image data and the true value labeled by the image data.
[0132] Adjusting the network parameters of the student neural network based on the first loss to obtain the target neural network includes: adjusting the network parameters of the student neural network based on the first loss and the second loss to obtain the target neural network, including:
[0133] Based on the first loss and the second loss, the total training loss of the student neural network is determined; based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
[0134] Among them, the first loss and the second loss are weighted to determine the total training loss of the student neural network;
[0135] Based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
[0136] For example, when the first loss includes inter-classification loss and intra-classification loss, the total training loss For example, the following formula (7) is satisfied:
[0137]
[0138] Total training loss By the second loss Inter-class loss and intra-class loss where α, β, and γ are the weight coefficients of the balance loss.
[0139] It is foreseeable that the total training loss can also be obtained by adding the classification loss to the inter-class loss or the intra-class loss, which depends on the actual application.
[0140] See also Figure 3 As shown, the present disclosure provides a specific neural network generation example, including:
[0141] S301: Use a pre-trained teacher neural network to classify the image data to obtain a first image classification result.
[0142] S302: Execute the following process in each of the multiple iteration cycles:
[0143] S3021: Determine the first neural network of the current iteration cycle; wherein the neural network to be trained in the current iteration cycle includes: the original student neural network, or the second neural network obtained in the previous iteration cycle; wherein, in response to the current iteration cycle being the first iteration cycle, the first neural network includes the original student neural network; in response to the current iteration cycle being not the first iteration cycle, the first neural network includes the second neural network obtained in the previous iteration cycle.
[0144] S3022: Using the first neural network of the current iteration cycle, classify the image data to obtain a second image classification result of the image data in the current iteration cycle;
[0145] S3023: Determine a first loss for the current iteration cycle based on the first image classification result and the second image classification result of the image data in the current iteration cycle;
[0146] S3024: Determine whether the first loss of the current iteration cycle meets the preset iteration stop condition. If not, jump to S3025; if yes, jump to 303.
[0147] Here, the iteration stopping conditions include, for example: the iteration cycle reaches a preset iteration cycle threshold; the first loss is less than a preset first loss threshold; the total loss determined based on the first loss is less than a preset second loss threshold, etc. The specific conditions can be determined based on actual training requirements.
[0148] S3025: Adjust the network parameters of the first neural network of the current iteration cycle to obtain the second neural network of the current iteration cycle, enter the next iteration cycle, and jump to S3021;
[0149] S303: Determine the first neural network in the current iteration cycle as the target neural network.
[0150] Regarding the above process, in a specific embodiment, as Figure 2 As shown, the original student neural network and the teacher neural network classify and process the three groups of image data respectively. The teacher neural network outputs the first image classification result, and the original student neural network outputs the second image classification result of the current iteration cycle.
[0151] Among them, the classification processing results can be expressed in the form of a numerical matrix, the number of rows of the matrix represents the number of image data P1, P2 and P3, and the number of columns of the matrix represents the predicted classification A, classification B, classification C, classification D and classification E corresponding to each sample. It can be foreseen that the information represented by the rows and columns of the matrix can also be that the number of rows represents the predicted classification corresponding to each sample, and the number of columns represents the number of image data, and there is no restriction here.
[0152] Taking inter-class loss as an example, extract the first row of data from the numerical matrix output of the first image classification result, representing the prediction results for the five classes corresponding to the first image data: 0.4, 0.1, 0.2, 0.2, and 0.1, respectively. Here, the numerical values represent the prediction scores for each class prediction result. A higher score indicates a greater similarity between the prediction result and the class attribute. Based on the prediction results, the probability distribution features corresponding to the first row of data in the numerical matrix output of the first image classification result are obtained. Extract the first row of data from the numerical matrix output of the second image classification result, representing the prediction results for the five classes corresponding to image data P1: 0.5, 0.1, 0.1, 0.2, and 0.1, respectively. Based on the prediction results, the probability distribution features corresponding to the first row of data in the numerical matrix output of the second image classification result are obtained.
[0153] Based on the probability distribution characteristics, the following analysis can be made: the first image classification result shows that the prediction score of category A for the first data sample is the highest, the prediction scores of category C and category D are second, and the prediction scores of category B and category E are the lowest; the second image classification result shows that the prediction score of category A for the first data sample is the highest, the prediction score of category D is second, and the prediction scores of category B, category C and category E are the lowest.
[0154] According to the feature distribution of the teacher neural network and the student neural network for different classification prediction results of the same image data, the inter-classification loss is calculated using the above formula (5).
[0155] Taking the intra-class loss as an example, extracting the fifth column of data from the numerical matrix output of the first image classification result indicates the prediction results of a class corresponding to the three image data, which are 0.1, 0.2, and 0.4 respectively; extracting the fifth column of data from the numerical matrix output of the second image classification result indicates the prediction results of a class corresponding to the three image data, which are 0.1, 0.1, and 0.3 respectively.
[0156] According to the probability distribution characteristics, the following analysis can be made: the first image classification result shows that the prediction score of data sample P1 for category E is the lowest, the prediction score of data sample P2 is second, and the prediction score of data sample P3 is the highest; the result of the original student neural network prediction shows that the prediction scores of data sample P1 and data sample P2 for category E are the lowest, and the prediction score of data sample P3 is the highest.
[0157] According to the characteristic distribution of the prediction results of the teacher neural network and the student neural network for different data samples of the same category, the intra-class loss is calculated using the above formula (6).
[0158] According to the inter-classification loss and intra-classification loss, the first loss is obtained to determine whether the output of the current student neural network matching the teacher neural network according to the first loss meets the accuracy required by knowledge distillation. If so, the training is stopped and the current student neural network that meets the conditions is determined as the target neural network; if not, the current student neural network is adjusted to obtain the second student neural network and enter the next iteration cycle.
[0159] Those skilled in the art will understand that in the above-mentioned method of the specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0160] Based on the same inventive concept, the embodiments of the present disclosure also provide a neural network generation device corresponding to the neural network generation method. Since the principle of solving the problem by the device in the embodiments of the present disclosure is similar to the above-mentioned neural network generation method in the embodiments of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0161] Reference Figure 4 FIG. 4 is a schematic diagram of a neural network generation device provided by an embodiment of the present disclosure, wherein the device includes: an image classification module 41, a feature analysis module 42, and a target generation module 43; wherein,
[0162] An image classification module 41 is configured to classify the image data using a teacher neural network to obtain a first image classification result, and to classify the image data using a student neural network to obtain a second image classification result;
[0163] a feature analysis module 42 configured to determine a first loss based on the first image classification result and the second image classification result, wherein the first loss is configured to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result;
[0164] The target generation module 43 is used to adjust the network parameters of the student neural network based on the first loss to obtain a target neural network for image classification.
[0165] In an optional embodiment, the first image classification result includes: a first probability that the image data belongs to each first preset category among multiple first preset categories that can be predicted by the teacher neural network; the second image classification result includes: a second probability that the image data belongs to each second preset category among multiple second preset categories that can be predicted by the student neural network.
[0166] In an optional embodiment, the first loss includes: inter-classification loss and / or intra-classification loss;
[0167] In the case where the first loss includes an inter-class loss, the first distribution feature includes a first probability distribution feature, and the second distribution feature includes a second probability distribution feature; the inter-class loss characterizes the difference between the first probability distribution feature and the second probability distribution feature; wherein the first probability distribution feature includes: a distribution feature of a first probability that a single image data item belongs to each of the first preset classes, as determined by the teacher neural network, in the plurality of first preset classes; and the second probability distribution feature includes: a distribution feature of a second probability that the single image data item belongs to each of the second preset classes, as determined by the student network, in the plurality of second preset classes;
[0168] In the case where the first loss includes intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, the distribution feature of the first probability that the multiple image data determined by the teacher neural network belong to the first preset classification; for each first preset classification, the fourth probability distribution feature includes: the distribution feature of the second probability that the multiple image data determined by the student network belong to the second preset classification corresponding to the first preset classification.
[0169] In an optional implementation, the feature analysis module 42 is further configured to:
[0170] When the first loss includes an inter-class loss, determining, for each of the plurality of image data, a first similarity or a first difference between first probability distribution features of the image data corresponding to the plurality of first preset classes and second probability distribution features corresponding to the plurality of second preset classes based on first probabilities that the image data corresponds to the plurality of first preset classes, and second probabilities that the image data corresponds to the plurality of second preset classes;
[0171] The inter-classification loss is determined based on first similarities or first differences respectively corresponding to the plurality of image data.
[0172] In an optional implementation, the feature analysis module 42 is further configured to:
[0173] In a case where the first loss includes an intra-class loss, for each of the plurality of second preset classes, determining, based on a first probability that the plurality of image data respectively belongs to the first preset class corresponding to the second preset class and a second probability that the plurality of image data belongs to the second preset class, a second similarity or a second difference between a third probability distribution feature corresponding to the first preset class and a fourth probability distribution feature corresponding to the second preset class of the plurality of image data;
[0174] The intra-class loss is determined based on the second similarities or second differences respectively corresponding to a plurality of the second preset classes.
[0175] In an optional implementation, the similarity includes: Pearson correlation coefficient and / or cosine similarity.
[0176] In an optional implementation, the target generation module 43 is further configured to:
[0177] Determining a second loss of the student neural network based on the second image classification result and the labeling information of the image data;
[0178] The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes:
[0179] Based on the first loss and the second loss, the network parameters of the student neural network are adjusted to obtain a target neural network.
[0180] In an optional implementation, the target generation module 43 is further configured to:
[0181] Determine the total training loss of the student neural network by weighting the first loss and the second loss;
[0182] Based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
[0183] In an optional embodiment, the classifying the image data using the student neural network to be trained to obtain the second image classification result includes:
[0184] Determining a first neural network for a current iteration cycle; wherein the neural network to be trained for the current iteration cycle includes: an original student neural network, or a second neural network obtained in a previous iteration cycle; using the first neural network for the current iteration cycle, classifying the image data to obtain a second image classification result for the image data in the current iteration cycle;
[0185] The feature analysis module 42, when determining the first loss based on the first image classification result and the second image classification result, is configured to:
[0186] Determining a first loss for a current iteration cycle based on the first image classification result and a second image classification result of the image data in a current iteration cycle;
[0187] The target generation module 43 is configured to adjust the network parameters of the student neural network based on the first loss to obtain a target neural network:
[0188] In response to the first loss of the current iteration cycle satisfying a preset iteration stop condition, determining the first neural network of the current iteration cycle as the target neural network;
[0189] In response to the first loss of the current iteration cycle not meeting the preset iteration stop condition, the network parameters of the first neural network of the current iteration cycle are adjusted to obtain the second neural network of the current iteration cycle, and enter the next iteration cycle.
[0190] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference can be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0191] The present disclosure also provides a computer device, such as Figure 5 FIG. 1 is a schematic diagram of a computer device structure provided by an embodiment of the present disclosure, including:
[0192] A processor 51 and a memory 52; the memory 52 stores machine-readable instructions executable by the processor 51, and the processor 51 is configured to execute the machine-readable instructions stored in the memory 52. When the machine-readable instructions are executed by the processor 51, the processor 51 performs the following steps:
[0193] Using a pre-trained teacher neural network to classify the image data to obtain a first image classification result, and using a student neural network to be trained to classify the image data to obtain a second image classification result;
[0194] Determining a first loss based on the first image classification result and the second image classification result, wherein the first loss is used to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result;
[0195] Based on the first loss, network parameters of the student neural network are adjusted to obtain a target neural network for image classification.
[0196] The above-mentioned memory 52 includes internal memory 521 and external memory 522; the memory 521 here is also called internal memory, which is used to temporarily store the calculation data in the processor 51 and the data exchanged with the external memory 522 such as the hard disk. The processor 51 exchanges data with the external memory 522 through the internal memory 521.
[0197] The specific execution process of the above instructions can refer to the steps of the neural network generation method described in the embodiment of the present disclosure, and will not be repeated here.
[0198] The present disclosure also provides a computer-readable storage medium having a computer program stored thereon. When executed by a processor, the computer program executes the steps of the method for generating a neural network described in the above method embodiment. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0199] The embodiments of the present disclosure further provide a computer program product, which carries program code. The instructions included in the program code can be used to execute the steps of the method for generating a neural network described in the above method embodiment. For details, please refer to the above method embodiment and will not be repeated here.
[0200] The computer program product may be implemented in hardware, software, or a combination thereof. In one embodiment, the computer program product is implemented as a computer storage medium. In another embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0201] The present disclosure relates to the field of augmented reality. By acquiring image information of a target object in a real-world environment, the relevant features, states, and attributes of the target object are detected or identified using various vision-related algorithms, thereby achieving an AR effect that combines virtual and real life and matches the specific application. For example, the target object may be a face, limbs, gestures, movements, etc. related to the human body, or an identifier or marker related to an object, or a sandbox, display area, or display items related to a venue or location. Vision-related algorithms may involve visual positioning, SLAM, 3D reconstruction, image registration, background segmentation, key point extraction and tracking of objects, and object pose or depth detection. Specific applications can involve not only interactive scenarios such as guided tours, navigation, explanations, reconstruction, and virtual effect overlay displays related to real scenes or objects, but also special effects processing related to people, such as makeup beautification, body beautification, special effects display, and virtual model display. Detection or identification of the relevant features, states, and attributes of the target object can be achieved using a convolutional neural network. The above-mentioned convolutional neural network is a network model obtained by model training based on a deep learning framework.
[0202] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems and devices described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely 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, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0203] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0204] In addition, each functional unit in each embodiment of the present disclosure 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.
[0205] 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 disclosure, 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, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present disclosure. 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.
[0206] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The scope of protection of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present disclosure, or replace some of the technical features therein with equivalents. Such modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure shall be subject to the scope of protection of the claims.
Claims
1. A method for generating a neural network, characterized in that: include: Using a teacher neural network to classify the image data to obtain a first image classification result, and using a student neural network to classify the image data to obtain a second image classification result; The first image classification result includes: a first probability that the image data belongs to each of the first preset categories among the multiple first preset categories that can be predicted by the teacher neural network; the second image classification result includes: a second probability that the image data belongs to each of the multiple second preset categories that can be predicted by the student neural network; Based on the first image classification result and the second image classification result, a first loss is determined; the first loss is used to characterize the difference between the first distribution feature of the first image classification result and the second distribution feature of the second image classification result; the first loss includes intra-class loss; in the case where the first loss includes intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, the distribution feature of the first probability that the multiple image data determined by the teacher neural network belong to the first preset classification; the fourth probability distribution feature includes: for each first preset classification, the distribution feature of the second probability that the multiple image data determined by the student neural network belong to the second preset classification corresponding to the first preset classification; Based on the first loss, network parameters of the student neural network are adjusted to obtain a target neural network for image classification.
2. The generation method according to claim 1, characterized in that The first loss also includes inter-classification loss; In a case where the first loss includes an inter-classification loss, the first distribution feature includes a first probability distribution feature, and the second distribution feature includes a second probability distribution feature; The inter-classification loss characterizes the difference between the first probability distribution feature and the second probability distribution feature; wherein, the first probability distribution feature includes: the distribution feature of the first probability that the single image data belongs to each of the first preset categories determined by the teacher neural network in the multiple first preset categories; the second probability distribution feature includes: the distribution feature of the second probability that the single image data belongs to each of the second preset categories determined by the student neural network in the multiple second preset categories.
3. The generation method according to claim 2, characterized in that The determining a first loss based on the first image classification result and the second image classification result includes: When the first loss includes an inter-class loss, determining, for each of the plurality of image data, a first similarity or a first difference between first probability distribution features of the image data corresponding to the plurality of first preset classes and second probability distribution features corresponding to the plurality of second preset classes based on first probabilities that the image data corresponds to the plurality of first preset classes, and second probabilities that the image data corresponds to the plurality of second preset classes; The inter-classification loss is determined based on first similarities or first differences respectively corresponding to the plurality of image data.
4. The generation method according to claim 1, characterized in that The determining of a first loss based on the first image classification result and the second image classification result further includes: In a case where the first loss includes an intra-class loss, for each of the plurality of second preset classes, determining, based on a first probability that the plurality of image data respectively belongs to the first preset class corresponding to the second preset class and a second probability that the plurality of image data belongs to the second preset class, a second similarity or a second difference between a third probability distribution feature corresponding to the first preset class and a fourth probability distribution feature corresponding to the second preset class of the plurality of image data; The intra-class loss is determined based on the second similarities or second differences respectively corresponding to a plurality of the second preset classes.
5. The generation method according to claim 3 or 4, characterized in that: The similarity includes: Pearson correlation coefficient and / or cosine similarity.
6. The generation method according to any one of claims 1 to 4, characterized in that: Also includes: Determining a second loss of the student neural network based on the second image classification result and the labeling information of the image data; The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes: Based on the first loss and the second loss, the network parameters of the student neural network are adjusted to obtain a target neural network.
7. The generation method according to claim 6, characterized in that The method further comprises adjusting the network parameters of the student neural network based on the first loss and the second loss to obtain a target neural network. Determine the total training loss of the student neural network by weighting the first loss and the second loss; Based on the total training loss, the network parameters of the student neural network are adjusted to obtain the target neural network.
8. The generation method according to any one of claims 1 to 4, characterized in that: The classifying process of the image data using the student neural network to obtain a second image classification result includes: The following process is performed in each of the multiple iteration cycles: Determining a first neural network for a current iteration cycle; wherein the neural network to be trained for the current iteration cycle includes: an original student neural network or a second neural network obtained in a previous iteration cycle; using the first neural network for the current iteration cycle, classifying the image data to obtain a second image classification result for the image data in the current iteration cycle; The determining a first loss based on the first image classification result and the second image classification result includes: Determining a first loss for a current iteration cycle based on the first image classification result and a second image classification result of the image data in a current iteration cycle; The adjusting the network parameters of the student neural network based on the first loss to obtain a target neural network includes: In response to the first loss of the current iteration cycle satisfying a preset iteration stop condition, determining the first neural network of the current iteration cycle as the target neural network; In response to the first loss of the current iteration cycle not meeting the preset iteration stop condition, the network parameters of the first neural network of the current iteration cycle are adjusted to obtain the second neural network of the current iteration cycle, and enter the next iteration cycle.
9. A device for generating a neural network, characterized in that: The device comprises: An image classification module is configured to classify image data using a teacher neural network to obtain a first image classification result, and to classify the image data using a student neural network to obtain a second image classification result; the first image classification result includes: a first probability that the image data belongs to each of a plurality of first preset categories that can be predicted by the teacher neural network; and the second image classification result includes: a second probability that the image data belongs to each of a plurality of second preset categories that can be predicted by the student neural network; A feature analysis module is configured to determine a first loss based on the first image classification result and the second image classification result; the first loss is configured to characterize the difference between a first distribution feature of the first image classification result and a second distribution feature of the second image classification result; the first loss includes an intra-class loss; when the first loss includes an intra-class loss, the first distribution feature includes a third probability distribution feature, and the second distribution feature includes a fourth probability distribution feature; the intra-class loss characterizes the difference between the third probability distribution feature and the fourth probability distribution feature; wherein the third probability distribution feature includes: for each first preset classification, a distribution feature of a first probability that the plurality of image data determined by the teacher neural network belong to the first preset classification; the fourth probability distribution feature includes: for each first preset classification, a distribution feature of a second probability that the plurality of image data determined by the student neural network belong to the second preset classification corresponding to the first preset classification; A target generation module is used to adjust the network parameters of the student neural network based on the first loss to obtain a target neural network for image classification.
10. A computer device, characterized in that: include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the processor is configured to execute the machine-readable instructions stored in the memory. When the machine-readable instructions are executed by the processor, the processor performs the steps of the method for generating a neural network according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program. When the computer program is executed by a computer device, the computer device performs the steps of the method for generating a neural network according to any one of claims 1 to 8.
Citation Information
Patent Citations
Neural network training method and device, image processing method and device and electronic equipment
CN110909815A
Neural network training method and device and computer equipment
CN112288086A