Compression method, system and computing device of detection model based on knowledge distillation
Through knowledge distillation technology, the problem of insufficient knowledge transmission of the YOLO v3 network model in small networks is solved, the detection accuracy is improved, and the efficient compression and accuracy of the detection model are achieved.
Patent Information
- Application Number
- CN202111008937.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-08-31
AI Technical Summary
When the YOLO v3 network model is transplanted into a small network, knowledge transfer is insufficient, resulting in a decrease in detection accuracy.
The detection model compression method based on knowledge distillation is used to calculate the target image through the teacher network, obtain the image weight information and feature values, and use the loss function to perform knowledge distillation to obtain the compressed detection model.
The detection accuracy of the detection model is improved, allowing it to fully obtain the knowledge of the teacher network while maintaining a small model, and improve the accuracy and efficiency of knowledge distillation.
Smart Images

Figure CN113658173B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of artificial intelligence technology. More specifically, embodiments of the present invention relate to a compression method, system and computing device for a detection model based on knowledge distillation. Background Art
[0002] This section is intended to provide a background or context to embodiments of the invention that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] With the rapid development of artificial intelligence technology, deep learning technology in artificial intelligence technology is widely used in the field of target detection, especially the detection of small targets with small volume has become a research hotspot in the field of target detection. At present, the YOLO v3 network model is usually used to detect small targets, which can obtain relatively accurate detection results. However, in practice, it is found that due to the large size of the YOLO v3 network model, the knowledge transfer in the YOLO v3 network model may be insufficient when transplanting the YOLO v3 network model to a small network model. Summary of the invention
[0004] In this context, embodiments of the present invention are intended to provide a compression method, system, and computing device for a detection model based on knowledge distillation.
[0005] In a first aspect of an embodiment of the present invention, a method for compressing a detection model based on knowledge distillation is provided, comprising:
[0006] Calculating the acquired target image based on the teacher network to obtain image weight information corresponding to the target image;
[0007] Calculating the target image based on the detection model to obtain a feature value corresponding to the target image;
[0008] The detection model is subjected to knowledge distillation based on the loss function, the image weight information and the eigenvalues to obtain a compressed detection model.
[0009] In one embodiment of this implementation, the acquired target image is calculated based on the teacher network to obtain image weight information corresponding to the target image, including:
[0010] Calculating the acquired target image based on the teacher network to obtain a mask image corresponding to the target image;
[0011] Obtaining the confidence of the foreground area in the target image output by the teacher network;
[0012] The mask image is calculated based on the confidence level to obtain image weight information.
[0013] In one embodiment of this implementation, the acquired target image is calculated based on the teacher network to obtain a mask image corresponding to the target image, including:
[0014] Recognize the acquired target image based on the teacher network to obtain prediction box information in the target image;
[0015] Calculating the predicted frame information based on the real label information in the target image to determine a foreground area of the target image containing the detection target and a background area other than the foreground area;
[0016] A first preset value corresponding to a foreground area of the target image is determined, and a second preset value corresponding to a background area of the target image is determined, so as to obtain a mask image corresponding to the target image that includes the first preset value and the second preset value.
[0017] In one embodiment of this implementation, the detection model includes but is not limited to a feature extraction layer, a feature fusion layer, and an adaptive layer. The target image is calculated based on the detection model to obtain a feature value corresponding to the target image, including:
[0018] Calculating the target image based on the feature extraction layer to obtain a first eigenvalue output by the feature extraction layer;
[0019] Calculating the first eigenvalue based on the feature fusion layer to obtain a second eigenvalue output by the feature fusion layer;
[0020] The dimension of the first eigenvalue and the dimension of the second eigenvalue are respectively adjusted by the adaptive layer to obtain adjusted first eigenvalues and second eigenvalues, wherein the dimension of the adjusted first eigenvalue is the same as the dimension of the image weight information, and the dimension of the adjusted second eigenvalue is the same as the dimension of the image weight information.
[0021] In one embodiment of this implementation, knowledge distillation is performed on the detection model based on the loss function, the image weight information, and the eigenvalue to obtain a compressed detection model, including:
[0022] Calculating the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue;
[0023] Based on the total loss, a back-propagation algorithm is used to perform knowledge distillation on the detection model to obtain a compressed detection model.
[0024] In one embodiment of this implementation, the detection model further includes a target detection layer, and the image weight information and the eigenvalue are calculated based on a loss function to obtain a total loss corresponding to the eigenvalue, including:
[0025] Calculating the image weight information and the first eigenvalue based on a loss function to obtain a first distillation loss corresponding to the feature extraction layer;
[0026] Calculating the image weight information and the second eigenvalue based on a loss function to obtain a second distillation loss corresponding to the feature fusion layer;
[0027] Calculating the detection result output by the target detection layer based on the loss function to obtain a true loss;
[0028] The first distillation loss, the second distillation loss, and the true loss are calculated to obtain a total loss.
[0029] In one embodiment of this implementation, based on the total loss, the detection model is subjected to knowledge distillation using a back propagation algorithm to obtain a compressed detection model, including:
[0030] Based on the total loss, a back propagation algorithm is used to derive the model parameters of each layer in the detection model to obtain new model parameters corresponding to each layer;
[0031] The detection model is updated based on the new model parameters corresponding to each layer to obtain an updated detection model, so as to achieve knowledge distillation of the detection model.
[0032] In a second aspect of the embodiments of the present invention, a compression system for a detection model based on knowledge distillation is provided, comprising:
[0033] A calculation unit, used to calculate the acquired target image based on the teacher network to obtain image weight information corresponding to the target image;
[0034] The calculation unit is further used to calculate the target image based on the detection model to obtain the characteristic value corresponding to the target image;
[0035] A compression unit is used to perform knowledge distillation on the detection model based on the loss function, the image weight information and the eigenvalue to obtain a compressed detection model.
[0036] In a third aspect of the embodiments of the present invention, a storage medium storing a program is provided, wherein the storage medium stores a computer program, and the computer program can implement any one of the methods in the first aspect when executed by a processor.
[0037] In a fourth aspect of the embodiments of the present invention, a computing device is provided, comprising the storage medium described in the third aspect.
[0038] According to the compression method, system and computing device of the detection model based on knowledge distillation of the embodiment of the present invention, it is possible to calculate the target image based on the teacher network to obtain the image weight information corresponding to the target image, and it is also possible to calculate the target image based on the detection model to obtain the eigenvalues corresponding to the target image. Since the teacher network is a mature neural network, the image weight information and loss function obtained by the teacher network can be used to perform knowledge distillation on the detection model, so that the detection model can fully obtain the knowledge of the teacher network while also improving the detection accuracy of the detection model. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, in which:
[0040] Figure 1 A schematic diagram of a flow chart of a method for compressing a detection model based on knowledge distillation according to an embodiment of the present invention;
[0041] Figure 2 A schematic diagram of a flow chart of a method for compressing a detection model based on knowledge distillation according to another embodiment of the present invention;
[0042] Figure 3 A schematic diagram of the structure of a detection model based on knowledge distillation in a compression method of a detection model based on knowledge distillation provided in an embodiment of the present invention;
[0043] Figure 4 A schematic diagram of the structure of a compression system for a detection model based on knowledge distillation provided in one embodiment of the present invention;
[0044] Figure 5 A schematic diagram of the structure of a medium according to an embodiment of the present invention is schematically shown;
[0045] Figure 6 A schematic diagram of the structure of a computing device according to an embodiment of the present invention is schematically shown.
[0046] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0047] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0048] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0049] According to an embodiment of the present invention, a compression method, system and computing device for a detection model based on knowledge distillation are proposed.
[0050] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.
[0051] The principle and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.
[0052] Exemplary Methods
[0053] Reference below Figure 1 , Figure 1 A schematic diagram of a flow chart of a method for compressing a detection model based on knowledge distillation provided in an embodiment of the present invention. It should be noted that the embodiments of the present invention can be applied to any applicable scenario.
[0054] Figure 1 The process of the compression method of the detection model based on knowledge distillation provided by an embodiment of the present invention includes:
[0055] Step S101, calculating the acquired target image based on the teacher network to obtain image weight information corresponding to the target image;
[0056] Step S102, calculating the target image based on the detection model to obtain a feature value corresponding to the target image;
[0057] Step S103, performing knowledge distillation on the detection model based on the loss function, the image weight information and the eigenvalues to obtain a compressed detection model.
[0058] The compression method of the detection model based on knowledge distillation proposed in this application is aimed at the detection model constructed based on artificial intelligence represented by machine learning, especially deep learning, including but not limited to image segmentation, target detection, face recognition and other detection models suitable for different application scenarios, especially for application scenarios of small target detection.
[0059] In the present invention, the target image can be calculated based on the teacher network to obtain the image weight information corresponding to the target image, and the target image can also be calculated based on the detection model to obtain the eigenvalues corresponding to the target image. Since the teacher network is a mature neural network, the image weight information and loss function obtained by the teacher network can be used to perform knowledge distillation on the detection model, so that the detection model can fully obtain the knowledge of the teacher network while also improving the detection accuracy of the detection model.
[0060] The following is a diagram showing how to enable the detection model to fully acquire the knowledge of the teacher network while also improving the detection accuracy of the detection model:
[0061] In an embodiment of the present invention, knowledge distillation can be an algorithm in transfer learning, which introduces a soft-target related to the teacher network as part of the total loss to induce the training of the student network, thereby achieving the goal of knowledge transfer (Knowledge Transfer) of transferring the knowledge of the teacher network to the student network, wherein the characteristics of the teacher network are usually: complex but excellent reasoning performance, and the characteristics of the student network are usually: concise and low complexity.
[0062] In an embodiment of the present invention, the student network can be a detection model and can be constructed through the YOLO v3 network model. The knowledge in the teacher network can be migrated to the detection model through knowledge distillation, so that the detection network can fully obtain the knowledge of the teacher network while maintaining a small model, thereby improving the detection accuracy of the detection model.
[0063] In an embodiment of the present invention, the target image may include targets to be identified. The targets to be identified in the target image may be calculated through the teacher network to obtain image weight information corresponding to the target image. The targets to be identified in the target image may also be calculated through the detection model to obtain eigenvalues corresponding to the target image. Finally, the detection model may be subjected to knowledge distillation based on the loss function, image weight information and eigenvalues, so as to achieve the transfer of knowledge in the teacher network to the detection model through knowledge distillation, thereby improving the detection accuracy of the detection model.
[0064] Among them, the calculation method of image weight information can be: identify the target to be identified in the target image through the teacher network, determine the area where the identified target is located in the target image, and the area can be determined as the foreground area, and the confidence of each position in the target image and the position of the target can be determined based on the foreground area. The greater the confidence of any position, the closer the position is to the target in the target image, and vice versa, the farther away from the target in the target image, and the image weight information corresponding to the target image can be determined based on the confidence at each position in the target image. It can be seen that the image weight information can include the confidence of each position in the target image relative to the position of the target in the target image.
[0065] In addition, the eigenvalue can be calculated by calculating the target to be identified in the target image through the detection model, and the eigenvalue corresponding to the target image can be obtained. Since the dimensions of the eigenvalue output by the current detection model and the image weight information output by the teacher network are different, the eigenvalue can be input into an adaptive layer composed of 1×1 convolution. The adaptive layer can adjust the dimension of the eigenvalue so that the dimension of the adjusted eigenvalue output by the adaptive layer is the same as the dimension of the image weight information, so that the eigenvalue and the image weight information can be better compared and analyzed, thereby improving the accuracy of knowledge distillation.
[0066] In addition, the loss function used in knowledge distillation may be a square error loss function or a mean square error loss function, etc., which is not limited in the embodiments of the present invention; the purpose of using the loss function is to provide a basis for subsequent parameter updates of the detection model.
[0067] See also Figure 2 , Figure 2 A schematic diagram of a flow chart of a method for compressing a detection model based on knowledge distillation provided in another embodiment of the present invention, Figure 2 The process of the compression method of the detection model based on knowledge distillation provided by another embodiment of the present invention includes:
[0068] Step S201, calculating the acquired target image based on the teacher network to obtain a mask image corresponding to the target image;
[0069] Step S202, obtaining the confidence of the foreground area in the target image output by the teacher network;
[0070] Step S203: Calculate the mask image based on the confidence level to obtain image weight information.
[0071] By implementing the above-mentioned steps S201 to S203, the target image can be calculated through the teacher network to obtain a mask map corresponding to the target image, and the confidence of the foreground area in the target image can be calculated, and the confidence can be combined with the mask map to obtain image weight information containing the confidence, so that the content contained in the obtained image weight information is richer.
[0072] As an optional implementation, step S201 calculates the acquired target image based on the teacher network, and the method of obtaining the mask image corresponding to the target image may specifically include the following steps:
[0073] Recognize the acquired target image based on the teacher network to obtain prediction box information in the target image;
[0074] Calculating the predicted frame information based on the real label information in the target image to determine a foreground area of the target image containing the detection target and a background area other than the foreground area;
[0075] A first preset value corresponding to a foreground area of the target image is determined, and a second preset value corresponding to a background area of the target image is determined, so as to obtain a mask image corresponding to the target image that includes the first preset value and the second preset value.
[0076] Among them, by implementing this implementation method, the prediction box information in the acquired target image can be analyzed and calculated based on the real label information, the foreground area and the background area in the target image can be determined, and then the foreground area and the background area can be assigned values respectively to obtain the final mask map, thereby improving the accuracy of the generated mask map.
[0077] In an embodiment of the present invention, a target image can be recognized through a teacher network to recognize one or more targets contained in the target image, and a prediction box can be generated based on the recognized one or more targets, and the prediction box can contain any recognized target; when a target is recognized, a prediction box corresponding to the target can be generated, and position information of the prediction box in the target image can be determined, and the position information of the determined prediction box can be determined as the prediction box information in the target image; when multiple targets are recognized, multiple prediction boxes corresponding to the multiple targets can be generated, wherein one target corresponds to one prediction box, and the position information of the determined multiple prediction boxes can be determined as the prediction box information in the target image;
[0078] Since the teacher network also identifies the target in the target image to determine the prediction box information, the prediction box information obtained by the teacher network can be corrected by the real label information in the target image to make the final mask map more accurate.
[0079] The real label information can be determined by: determining the target contained in the target image, generating a bounding box corresponding to the target, and determining the position information of the bounding box in the target image and the category information of the target together as the real label information of the target image, so that the target category of the target contained in the target image and the position information of the target in the target image can be obtained from the real label information. The target contained in the target image can be determined manually, and the target contained in the target image can be marked manually, so that the bounding box corresponding to the target in the target image can be determined based on the mark.
[0080] Therefore, the real label information in the target image and the prediction box information corresponding to the target image can be calculated (for example, the real label information and the prediction box information can be multiplied), that is, the position information of the target to be identified in the target image can be determined based on the real label information, and the identified prediction box information can be adjusted according to the position information, so that the adjusted prediction box information can accurately identify the target in the target image. Therefore, the area identified by the adjusted prediction box information can be determined in the target image, and the area can be determined as the foreground area, that is, the foreground area contains the target in the target image. It can be seen that the area other than the foreground area in the target image can be determined as the background area, that is, the background area does not contain the target in the target image.
[0081] Furthermore, in order to distinguish the foreground area and the background area in the target image, the foreground area and the background area in the target image can be assigned values respectively, and the numerical value assigned to the foreground area and the numerical value assigned to the background area are different. For example, a first preset value corresponding to the foreground area can be determined (such as the first preset value can be 1), and a second preset value corresponding to the background area can be determined (such as the second preset value can be 1). Therefore, the first preset value can be assigned to the foreground area in the target image, and the second preset value can be assigned to the background area in the target image, thereby obtaining a mask image containing the first preset value and the second preset value.
[0082] In the embodiment of the present invention, since only two values are used in the mask image to distinguish the foreground area containing the target and the background area not containing the target, it is impossible to distinguish the importance of information at different positions in the foreground information. Therefore, in order to distinguish the importance of information at different positions in the foreground information relative to the target core, the confidence at any position in the foreground information can be determined according to the distance of the information at the position relative to the target core position. It can be seen that the closer the information in the foreground area is to the target core position, the greater the confidence, and the farther the information is from the target core position, the smaller the confidence.
[0083] And, based on the confidence of the determined foreground area, the mask map can be calculated to obtain image weight information, and the image weight information can include the confidence between any position in the target image and the target, wherein the image weight information (Information-map) can be calculated as follows:
[0084] Information-map=confidence(teacher)_feature-map*mask-map
[0085] Among them, confidence(teacher)_feature-map can be the confidence output by the teacher network.
[0086] Step S204, the detection model includes but is not limited to a feature extraction layer, a feature fusion layer, and an adaptive layer, and the target image is calculated based on the feature extraction layer to obtain a first feature value output by the feature extraction layer;
[0087] Step S205, calculating the first eigenvalue based on the feature fusion layer to obtain a second eigenvalue output by the feature fusion layer;
[0088] Step S206, adjusting the dimension of the first eigenvalue and the dimension of the second eigenvalue respectively through the adaptive layer to obtain adjusted first eigenvalue and second eigenvalue, the dimension of the adjusted first eigenvalue is the same as the dimension of the image weight information, and the dimension of the adjusted second eigenvalue is the same as the dimension of the image weight information.
[0089] By implementing the above steps S204 to S206, the target image can be calculated through the feature extraction layer, feature fusion layer and adaptive layer included in the detection model, so that the feature value finally obtained is more accurate.
[0090] In an embodiment of the present invention, the detection model may include a feature extraction layer, a feature fusion layer and an adaptive layer. The first eigenvalue may be extracted from the target image through the feature extraction layer, and then the first eigenvalue may be fused and calculated through the feature fusion layer to obtain the second eigenvalue. Since the information dimensions output by the detection model and the teacher model may be different, in order to better train the detection model with the information output by the teacher model, the first eigenvalue and the second eigenvalue may be dimensionally adjusted respectively through the adaptive layer to obtain the adjusted first eigenvalue and the second eigenvalue, and the dimension of the first eigenvalue is the same as the dimension of the image weight information, and the dimension of the second eigenvalue is also the same as the dimension of the image weight information.
[0091] Step S207, calculating the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue;
[0092] Step S208: Based on the total loss, a back propagation algorithm is used to perform knowledge distillation on the detection model to obtain a compressed detection model.
[0093] By implementing the above steps S207 to S208, the total loss corresponding to the eigenvalue can be calculated first, and then the detection model can be knowledge distilled based on the total loss to obtain the final compressed detection model, thereby improving the effectiveness of the detection model knowledge distillation.
[0094] In the embodiment of the present invention, the loss function may be a square error loss function or a mean square error loss function, and the formula of the loss function may be:
[0095]
[0096] Among them, Y i It can be understood as the true label. It can be understood as a prediction result.
[0097] As an optional implementation, the detection model further includes a target detection layer, and step S207 calculates the image weight information and the eigenvalue based on a loss function, and a method of obtaining a total loss corresponding to the eigenvalue may specifically include the following steps:
[0098] Calculating the image weight information and the first eigenvalue based on a loss function to obtain a first distillation loss corresponding to the feature extraction layer;
[0099] Calculating the image weight information and the second eigenvalue based on a loss function to obtain a second distillation loss corresponding to the feature fusion layer;
[0100] Calculating the detection result output by the target detection layer based on the loss function to obtain a true loss;
[0101] The first distillation loss, the second distillation loss, and the true loss are calculated to obtain a total loss.
[0102] Among them, by implementing this implementation method, different distillation losses of the feature extraction layer and the feature fusion layer can be calculated respectively, and the final total loss can be calculated based on the obtained true loss and the different distillation losses of the feature extraction layer and the feature fusion layer to make the obtained total loss more accurate.
[0103] In the embodiment of the present invention, the first distillation loss L of the feature extraction layer is backbone The calculation formula can be:
[0104]
[0105] Where N is the sum of the number of pixels in the target image whose confidence is not 0 in the image weight information, W, H and C represent the size of the first eigenvalue output by the feature extraction layer, H xy Indicates the value of the mask map, conf t is the confidence of the teacher network output, f backbone_adap (s) xyz is the first eigenvalue output by the feature extraction layer of the student network after being processed by the adaptive layer, t xyz Image weight information output by the teacher network.
[0106] In the embodiment of the present invention, the second distillation loss L of the feature fusion layer is neck The calculation formula can be
[0107]
[0108] Among them, f neck_adap(s)xyz It can be the second eigenvalue output by the feature fusion layer of the student network after being processed by the adaptive layer.
[0109] In addition, the final detection result output by the student network through the target detection layer can be obtained. The final detection result can be calculated through the loss function and the true label information to obtain the final true loss L hard .
[0110] In the embodiment of the present invention, the total loss L loss The calculation method can be:
[0111] L loss =L hard (s, T)+αL baCkbone (s,t)+PL neCk (s, t)
[0112] Among them, a and β can be used to balance the first distillation loss L backbone , the second distillation loss L neck And the real loss L hard The weight between them is set to 1 at this time.
[0113] As an optional implementation, step S208 performs knowledge distillation on the detection model based on the total loss using a back propagation algorithm to obtain a compressed detection model, which may specifically include the following steps:
[0114] Based on the total loss, a back propagation algorithm is used to derive the model parameters of each layer in the detection model to obtain new model parameters corresponding to each layer;
[0115] The detection model is updated based on the new model parameters corresponding to each layer to obtain an updated detection model, so as to achieve knowledge distillation of the detection model.
[0116] Among them, by implementing this implementation method, the model parameters of each layer in the detection model can be derived based on the total loss to obtain new model parameters corresponding to each layer, and then the detection model can be updated based on the new model parameters corresponding to each layer to achieve knowledge distillation of the detection model and improve the efficiency of knowledge distillation of the detection model.
[0117] Please also read Figure 3 , Figure 3 A schematic diagram of the structure of a detection model based on knowledge distillation in a compression method of a detection model based on knowledge distillation provided in an embodiment of the present invention. Figure 3 It includes Teacher model (teacher network) and Student model (detection model), and both the teacher network and the detection model include Backbone (feature extraction layer), Neck (feature fusion layer) and Detection (target detection layer). The input image can be the target image input into the teacher network and the detection model. The teacher network can recognize the input target image to obtain a mask-map (mask map) and confidence (teacher) (confidence), and obtain the Information-map (image weight information) through the mask map and confidence calculation.
[0118] And, the detection model can also recognize the input target image:
[0119] First, the first eigenvalue can be output through the feature extraction layer, and the dimension of the first eigenvalue can be adjusted through the Adaptation layer so that the dimension of the adjusted first eigenvalue is the same as the dimension of the image weight information output by the teacher network, and the first eigenvalue and the image weight information are calculated through the L2 loss function to obtain the first distillation loss of the feature extraction layer in the detection model; and the feature extraction layer in the detection model can be distilled through the obtained first distillation loss.
[0120] Secondly, the first eigenvalue can be calculated through the feature fusion layer to output the second eigenvalue, and the dimension of the second eigenvalue can be adjusted through the Adaptation layer so that the dimension of the adjusted second eigenvalue is the same as the dimension of the image weight information output by the teacher network, and the second eigenvalue and the image weight information are calculated through the L2 loss function to obtain the second distillation loss of the feature fusion layer in the detection model; and the feature fusion layer in the detection model can be subjected to knowledge distillation through the obtained second distillation loss.
[0121] In addition, the second eigenvalue can be calculated through the target detection layer to output the final detection result, and the detection result and the Ground Truth Label (real label information) can be calculated through the Detection Loss (loss function) to obtain the real loss; and the target detection layer in the detection model can be used for knowledge distillation through the obtained real loss.
[0122] Finally, the first distillation loss, the second distillation loss and the true loss can be calculated to obtain the total loss, and the total loss can be used to perform knowledge distillation on all detection models to obtain the final compressed detection model.
[0123] The present invention enables the detection model to fully obtain the knowledge of the teacher network while also improving the detection accuracy of the detection model. In addition, the present invention can also make the content contained in the obtained image weight information richer. In addition, the present invention can also improve the accuracy of the generated mask map. In addition, the present invention can also make the final feature value more accurate. In addition, the present invention can also improve the effectiveness of the knowledge distillation of the detection model. In addition, the present invention can also make the total loss obtained more accurate. In addition, the present invention can also improve the efficiency of knowledge distillation of the detection model.
[0124] Exemplary Systems
[0125] After introducing the method of the exemplary embodiment of the present invention, next, refer to Figure 4 A compression system of a detection model based on knowledge distillation according to an exemplary embodiment of the present invention is described, and the system includes:
[0126] A calculation unit 401 is used to calculate the acquired target image based on the teacher network to obtain image weight information corresponding to the target image;
[0127] The calculation unit 401 is further used to calculate the target image based on the detection model to obtain the feature value corresponding to the target image;
[0128] The compression unit 402 is used to perform knowledge distillation on the detection model based on the loss function, the image weight information obtained by the calculation unit 401, and the eigenvalue to obtain a compressed detection model.
[0129] As an optional implementation, the calculation unit 401 calculates the acquired target image based on the teacher network, and obtains the image weight information corresponding to the target image in the following manner:
[0130] Calculating the acquired target image based on the teacher network to obtain a mask image corresponding to the target image;
[0131] Obtaining the confidence of the foreground area in the target image output by the teacher network;
[0132] The mask image is calculated based on the confidence level to obtain image weight information.
[0133] Among them, by implementing this implementation method, the target image can be calculated through the teacher network to obtain a mask map corresponding to the target image, and the confidence of the foreground area in the target image can be calculated, and the confidence can be combined with the mask map to obtain image weight information containing the confidence, so that the content contained in the obtained image weight information is richer.
[0134] As an optional implementation, the calculation unit 401 calculates the acquired target image based on the teacher network to obtain the mask image corresponding to the target image in the following manner:
[0135] Recognize the acquired target image based on the teacher network to obtain prediction box information in the target image;
[0136] Calculating the predicted frame information based on the real label information in the target image to determine a foreground area of the target image containing the detection target and a background area other than the foreground area;
[0137] A first preset value corresponding to a foreground area of the target image is determined, and a second preset value corresponding to a background area of the target image is determined, so as to obtain a mask image corresponding to the target image that includes the first preset value and the second preset value.
[0138] Among them, by implementing this implementation method, the prediction box information in the acquired target image can be analyzed and calculated based on the real label information, the foreground area and the background area in the target image can be determined, and then the foreground area and the background area can be assigned values respectively to obtain the final mask map, thereby improving the accuracy of the generated mask map.
[0139] As an optional implementation, the detection model includes but is not limited to a feature extraction layer, a feature fusion layer, and an adaptive layer. The calculation unit 401 calculates the target image based on the detection model to obtain the characteristic value corresponding to the target image in the following manner:
[0140] Calculating the target image based on the feature extraction layer to obtain a first eigenvalue output by the feature extraction layer;
[0141] Calculating the first eigenvalue based on the feature fusion layer to obtain a second eigenvalue output by the feature fusion layer;
[0142] The dimension of the first eigenvalue and the dimension of the second eigenvalue are respectively adjusted by the adaptive layer to obtain adjusted first eigenvalues and second eigenvalues, wherein the dimension of the adjusted first eigenvalue is the same as the dimension of the image weight information, and the dimension of the adjusted second eigenvalue is the same as the dimension of the image weight information.
[0143] Among them, by implementing this implementation method, the target image can be calculated through the feature extraction layer, feature fusion layer and adaptive layer included in the detection model, so that the final feature value is more accurate.
[0144] As an optional implementation manner, the compression unit 402 performs knowledge distillation on the detection model based on the loss function, the image weight information, and the eigenvalue to obtain the compressed detection model in the following manner:
[0145] Calculating the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue;
[0146] Based on the total loss, a back-propagation algorithm is used to perform knowledge distillation on the detection model to obtain a compressed detection model.
[0147] Among them, by implementing this implementation method, the total loss corresponding to the eigenvalue can be calculated first, and then the detection model can be knowledge distilled based on the total loss to obtain the final compressed detection model, thereby improving the effectiveness of the detection model knowledge distillation.
[0148] As an optional implementation, the detection model further includes a target detection layer, and the compression unit 402 calculates the image weight information and the eigenvalue based on the loss function, and obtains the total loss corresponding to the eigenvalue in the following manner:
[0149] Calculating the image weight information and the first eigenvalue based on a loss function to obtain a first distillation loss corresponding to the feature extraction layer;
[0150] Calculating the image weight information and the second eigenvalue based on a loss function to obtain a second distillation loss corresponding to the feature fusion layer;
[0151] Calculating the detection result output by the target detection layer based on the loss function to obtain a true loss;
[0152] The first distillation loss, the second distillation loss, and the true loss are calculated to obtain a total loss.
[0153] Among them, by implementing this implementation method, different distillation losses of the feature extraction layer and the feature fusion layer can be calculated respectively, and the final total loss can be calculated based on the obtained true loss and the different distillation losses of the feature extraction layer and the feature fusion layer to make the obtained total loss more accurate.
[0154] As an optional implementation manner, the compression unit 402 performs knowledge distillation on the detection model based on the total loss using a back propagation algorithm to obtain the compressed detection model in the following specific manner:
[0155] Based on the total loss, a back propagation algorithm is used to derive the model parameters of each layer in the detection model to obtain new model parameters corresponding to each layer;
[0156] The detection model is updated based on the new model parameters corresponding to each layer to obtain an updated detection model, so as to achieve knowledge distillation of the detection model.
[0157] Among them, by implementing this implementation method, the model parameters of each layer in the detection model can be derived based on the total loss to obtain new model parameters corresponding to each layer, and then the detection model can be updated based on the new model parameters corresponding to each layer to achieve knowledge distillation of the detection model and improve the efficiency of knowledge distillation of the detection model.
[0158] Exemplary Media
[0159] After introducing the method and system of the exemplary embodiment of the present invention, next, reference is made to Figure 5 For a description of a computer-readable storage medium according to an exemplary embodiment of the present invention, please refer to Figure 5, the computer-readable storage medium shown is a CD 50, on which a computer program (i.e., a program product) is stored. When the computer program is executed by the processor, the steps described in the above method implementation are implemented, for example, the acquired target image is calculated based on the teacher network to obtain the image weight information corresponding to the target image; the target image is calculated based on the detection model to obtain the eigenvalue corresponding to the target image; the detection model is knowledge distilled based on the loss function, the image weight information and the eigenvalue to obtain a compressed detection model; the specific implementation method of each step is not repeated here.
[0160] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0161] Exemplary Computing Devices
[0162] After introducing the method, medium and apparatus of the exemplary embodiments of the present invention, next, reference is made to Figure 6 A computing device for compression of a detection model based on knowledge distillation according to an exemplary embodiment of the present invention.
[0163] Figure 6 A block diagram of an exemplary computing device 60, which may be a computer system or a server, is shown that is suitable for use in implementing embodiments of the present invention. Figure 6 The computing device 60 shown is only an example and should not bring any limitation to the functionality and scope of use of the embodiments of the present invention.
[0164] like Figure 6 As shown, the components of the computing device 60 may include, but are not limited to: one or more processors or processing units 601, a system memory 602, and a bus 603 connecting different system components (including the system memory 602 and the processing unit 601).
[0165] The computing device 60 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computing device 60, including volatile and non-volatile media, removable and non-removable media.
[0166] The system memory 602 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 6021 and / or cache memory 6022. The computing device 60 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the ROM 6023 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 is not shown in the Figure 6 As shown in FIG. 6 , a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 603 via one or more data medium interfaces. System memory 602 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of various embodiments of the present invention.
[0167] A program / utility 6025 having a set (at least one) of program modules 6024 may be stored, for example, in system memory 602, and such program modules 6024 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 6024 generally perform the functions and / or methods of the embodiments described herein.
[0168] The computing device 60 may also communicate with one or more external devices 604 (e.g., a keyboard, a pointing device, a display, etc.). Such communication may be performed via an input / output (I / O) interface 605. Furthermore, the computing device 60 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 606. Figure 6 As shown, the network adapter 606 communicates with other modules (such as the processing unit 601, etc.) of the computing device 60 via the bus 603. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with computing device 60 .
[0169] The processing unit 601 executes various functional applications and data processing by running the program stored in the system memory 602, for example, calculating the acquired target image based on the teacher network to obtain the image weight information corresponding to the target image; calculating the target image based on the detection model to obtain the eigenvalue corresponding to the target image; performing knowledge distillation on the detection model based on the loss function, the image weight information and the eigenvalue to obtain the compressed detection model. The specific implementation method of each step is not repeated here. It should be noted that although several units / modules or sub-units / sub-modules of the compression system of the detection model based on knowledge distillation are mentioned in the above detailed description, this division is only exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more units / modules described above can be concretized in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be concretized.
[0170] In the description of the present invention, it should be noted that the terms “first”, “second” and “third” are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0171] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0172] 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.
[0173] 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.
[0174] 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.
[0175] 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.
[0176] 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-described 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-described 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 subject to the protection scope of the claims.
[0177] In addition, although the operations of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
Claims
1. A compression method for a detection model based on knowledge distillation, comprising: Calculating the acquired target image based on the teacher network to obtain image weight information corresponding to the target image; Calculating the target image based on the detection model to obtain a feature value corresponding to the target image; Performing knowledge distillation on the detection model based on the loss function, the image weight information, and the eigenvalues to obtain a compressed detection model; The obtained target image is calculated based on the teacher network to obtain image weight information corresponding to the target image, including: Calculating the acquired target image based on the teacher network to obtain a mask image corresponding to the target image; Obtaining the confidence of the foreground area in the target image output by the teacher network; Calculating the mask image based on the confidence level to obtain image weight information; The detection model includes but is not limited to a feature extraction layer, a feature fusion layer, and an adaptive layer. The target image is calculated based on the detection model to obtain a feature value corresponding to the target image, including: Calculating the target image based on the feature extraction layer to obtain a first eigenvalue output by the feature extraction layer; Calculating the first eigenvalue based on the feature fusion layer to obtain a second eigenvalue output by the feature fusion layer; The dimension of the first eigenvalue and the dimension of the second eigenvalue are respectively adjusted by the adaptive layer to obtain adjusted first eigenvalues and second eigenvalues, wherein the dimension of the adjusted first eigenvalues is the same as the dimension of the image weight information, and the dimension of the adjusted second eigenvalues is the same as the dimension of the image weight information; The performing knowledge distillation on the detection model based on the loss function, the image weight information and the eigenvalue to obtain a compressed detection model includes: Calculating the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue; Based on the total loss, using a back propagation algorithm to perform knowledge distillation on the detection model to obtain a compressed detection model; The detection model further includes a target detection layer, which calculates the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue, including: Calculating the image weight information and the first eigenvalue based on a loss function to obtain a first distillation loss corresponding to the feature extraction layer; Calculating the image weight information and the second eigenvalue based on a loss function to obtain a second distillation loss corresponding to the feature fusion layer; Calculating the detection result output by the target detection layer based on the loss function to obtain a true loss; The first distillation loss, the second distillation loss, and the true loss are calculated to obtain a total loss.
2. According to the compression method of the detection model based on knowledge distillation in claim 1, the obtained target image is calculated based on the teacher network to obtain a mask image corresponding to the target image, including: Recognize the acquired target image based on the teacher network to obtain prediction box information in the target image; Calculating the predicted frame information based on the real label information in the target image to determine a foreground area of the target image containing the detection target and a background area other than the foreground area; A first preset value corresponding to a foreground area of the target image is determined, and a second preset value corresponding to a background area of the target image is determined, so as to obtain a mask image corresponding to the target image that includes the first preset value and the second preset value.
3. According to the method for compressing a detection model based on knowledge distillation in claim 1, based on the total loss, the detection model is subjected to knowledge distillation using a back propagation algorithm to obtain a compressed detection model, comprising: Based on the total loss, a back propagation algorithm is used to derive the model parameters of each layer in the detection model to obtain new model parameters corresponding to each layer; The detection model is updated based on the new model parameters corresponding to each layer to obtain an updated detection model, so as to achieve knowledge distillation of the detection model.
4. A compression system for a detection model based on knowledge distillation, comprising: A calculation unit, used to calculate the acquired target image based on the teacher network to obtain image weight information corresponding to the target image; The calculation unit is further used to calculate the target image based on the detection model to obtain the characteristic value corresponding to the target image; A compression unit, used for performing knowledge distillation on the detection model based on the loss function, the image weight information and the eigenvalue to obtain a compressed detection model; The calculation unit calculates the acquired target image based on the teacher network to obtain the image weight information corresponding to the target image in the following manner: Calculating the acquired target image based on the teacher network to obtain a mask image corresponding to the target image; Obtaining the confidence of the foreground area in the target image output by the teacher network; Calculating the mask image based on the confidence level to obtain image weight information; The detection model includes but is not limited to a feature extraction layer, a feature fusion layer, and an adaptive layer. The calculation unit calculates the target image based on the detection model to obtain the feature value corresponding to the target image in the following manner: Calculating the target image based on the feature extraction layer to obtain a first eigenvalue output by the feature extraction layer; Calculating the first eigenvalue based on the feature fusion layer to obtain a second eigenvalue output by the feature fusion layer; The dimension of the first eigenvalue and the dimension of the second eigenvalue are respectively adjusted by the adaptive layer to obtain adjusted first eigenvalues and second eigenvalues, wherein the dimension of the adjusted first eigenvalues is the same as the dimension of the image weight information, and the dimension of the adjusted second eigenvalues is the same as the dimension of the image weight information; The compression unit performs knowledge distillation on the detection model based on the loss function, the image weight information, and the eigenvalue to obtain the compressed detection model in the following manner: Calculating the image weight information and the eigenvalue based on a loss function to obtain a total loss corresponding to the eigenvalue; Based on the total loss, using a back propagation algorithm to perform knowledge distillation on the detection model to obtain a compressed detection model; The detection model further includes a target detection layer, and the compression unit calculates the image weight information and the eigenvalue based on the loss function, and obtains the total loss corresponding to the eigenvalue in the following manner: Calculating the image weight information and the first eigenvalue based on a loss function to obtain a first distillation loss corresponding to the feature extraction layer; Calculating the image weight information and the second eigenvalue based on a loss function to obtain a second distillation loss corresponding to the feature fusion layer; Calculating the detection result output by the target detection layer based on the loss function to obtain a true loss; The first distillation loss, the second distillation loss, and the true loss are calculated to obtain a total loss.
5. A storage medium storing a program, wherein: The storage medium stores a computer program, and when the computer program is executed by a processor, the compression method of the detection model based on knowledge distillation as described in any one of claims 1 to 3 is implemented.
6. A computing device comprising the storage medium as claimed in claim 5.
Citation Information
Patent Citations
Student model training method and device and electronic equipment
CN111639744A
Pedestrian re-identification model compression method and evaluation method based on knowledge distillation
CN113297906A
