A deep learning model compression method

CN118246507BActive Publication Date: 2024-10-29ZHUHAI RAYSHARP TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410149585.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-02
Publication Date
2024-10-29
Estimated Expiration
2044-02-02

AI Technical Summary

Technical Problem

但是小模型设定后,有些地方参数表达能力不强,会导致整个效果上不去,只能同个模型,相对蒸馏后会有一些提高,但是训练时,大模型,小模型需要一起训练,训练时间也是会加长

Benefits of technology

[0015] The beneficial effect of the deep learning model compression method provided by the present invention is that the deep learning model compression method can accurately and quickly determine whether parameters are useful or useless in the model, and remove useless parameters in different structures. In this way, most of the useless parameters in the model can be removed, which greatly reduces the size of the model. On the premise of ensuring the accuracy of the model, the application of memory is reduced, the amount of calculation is also greatly reduced, and the speed of model response is greatly improved, with a smaller size. The model achieves the effect of a large model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118246507B_ABST
    Figure CN118246507B_ABST
Patent Text Reader

Abstract

The present invention provides a deep learning model compression method, which specifically includes: S1, obtaining all batchnorm layers in the network; S2, merging the affected layers to generate a combination of relationship layers; S3, setting a threshold a, calculating the absolute value of the batchnorm layer in the combination and dividing it by its maximum value, setting the channels greater than the threshold a to be retained, and removing all other channels, if there are multiple batchnorm layers, taking any corresponding channel that meets the conditions; S4, processing the input convolution layer and output convolution layer of the batchnorm layer in the combination. This deep learning model compression method can automatically remove useless parameters for different model structures while ensuring the accuracy of the model, so as to achieve the purpose of reducing the model and achieve the effect of a large model with a smaller model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a deep learning model compression method. Background Art

[0002] Model training: The trained model is too small, and the effect after training cannot meet the requirements, and the accuracy is low. If a large model is selected, it cannot be used because the product performance, speed, and computing performance cannot be achieved. Usually, general pruning, distillation, nas and other methods can be adopted. Pruning requires training a large model, and then training again after pruning, and the training accuracy after pruning will be lower than the accuracy of the model before pruning. Distillation uses the method of guiding the small model with a large model. However, after the small model is set, the parameter expression ability in some places is not strong, which will lead to the overall effect not being able to go up. The same model can only be used. There will be some improvement after distillation, but during training, the large model and the small model need to be trained together, and the training time will also be longer. Compared with the computing power of the current gpu, nas has a slow training speed and a long training time. The model search time after training is also very long. The above model training methods all have their own defects, so it is necessary to develop a strategy for selecting a large model before training. By expanding the width of the model, the expressive ability of the model can be improved. After training, useless parameters can be removed, directly reducing the model size and calculation amount. The accuracy of the model does not change and does not need to be trained again. Summary of the invention

[0003] In view of the shortcomings of the prior art, the present invention proposes a deep learning model compression method, which can automatically remove useless parameters for different model structures while ensuring the accuracy of the model, thereby achieving the purpose of reducing the model and achieving the effect of a large model with a smaller model.

[0004] To implement the above technical solution, the present invention provides a deep learning model compression method, which specifically includes the following steps:

[0005] S1. Get all batchnorm layers in the network. If a convolutional layer, deconvolutional layer, or fully connected layer is encountered, the process ends. If an activation layer or pool layer is encountered, the process upsamples. If a concat layer, clip layer, or add layer is encountered, the process searches downward.

[0006] S2, merge the affected layers to generate a combination of relationship layers, retain key features and remove unimportant features;

[0007] S3. Set a threshold a, calculate its absolute value and divide it by its maximum value through the batchnorm layer in the combination, set the channels that are greater than the threshold a to be retained, and remove all other channels;

[0008] S4. Process the input convolution layer and the output convolution layer of the batchnorm layer in the combination. For the input convolution layer, directly remove the channel corresponding to the first dimension of the convolution kernel. For the output convolution layer, directly remove the channel corresponding to the second dimension of the convolution kernel.

[0009] Preferably, in step S1, obtaining all batchnorm layers in the network includes all batchnorm input layers and output layers corresponding to the batchnorm input layers.

[0010] Preferably, in step S3, threshold a≦0.001.

[0011] Preferably, in step S3, if there are multiple batchnorm layers, any corresponding channel that meets the conditions is selected.

[0012] Preferably, in step S3, the importance of the channel convolution kernel can be highlighted by regularizing the gmma parameter weights of the batchnorm layer.

[0013] Preferably, in step S4, the Dw layer is attributed to the output layer, and when processing the output convolution, the corresponding bias removes the corresponding channel at the same time.

[0014] Preferably, in step S1, a large bandwidth network is used in the process of acquiring all batchnorm layers in the network.

[0015] The beneficial effect of a deep learning model compression method provided by the present invention is that: the deep learning model compression method can accurately and quickly determine whether a parameter is useful or useless in the model, and remove useless parameters in different structures, thereby removing most of the useless parameters in the model, greatly reducing the size of the model, and reducing the use of memory while ensuring the accuracy of the model. The amount of calculation is also greatly reduced, greatly improving the speed of model response, and achieving the effect of a large model with a smaller model. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a flow chart of the steps of the present invention.

[0017] Figure 2 It is an application flow chart of an embodiment of the present invention. DETAILED DESCRIPTION

[0018] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary persons in the art without creative work are within the scope of protection of the present invention.

[0019] Embodiment: A deep learning model compression method.

[0020] This deep learning model compression method mainly includes: (1) how to determine whether the parameters in the convolution are useful or useless; (2) how to remove useless parameters in different structures. The detailed process is as follows:

[0021] S1. Get all batchnorm layers in the network; get all corresponding batchnorm input layers, which are usually the corresponding convolutional layers; get the corresponding output layers with them as input layers, and end if you encounter a convolutional layer, deconvolutional layer, or fully connected layer. If you encounter an activation layer, pool layer, upsample, concat layer, clip layer, or add layer, look down to Figure 2 Take the network in as an example, the specific method is as follows:

[0022] The bn1 layer, the input comes from conv1, passes through the activation layer and the Pooling layer as the input of conv2 and conv3.

[0023] For example, the above method finally generates:

[0024] [batchnorm layer: bn1, input layer: conv1, output layer conv2, conv3]

[0025] Assume the following combination:

[0026] [batchnorm layer: bn2, input layer conv4, output layer conv5]

[0027] [batchnorm layer: bn3, input layer conv6, output layer conv2].

[0028] Through operations such as pool layer, concat, clip, add, etc., we can know that the output result has no effect on the weight of the next convolution, fully connected layer, etc. Therefore, through the above sampling method of encountering the activation layer, the pool layer is up-sampled, and the concat layer, clip layer, and add layer are down-sampled, the output has been determined in the current convolution to determine whether its features are important or not. All batchnorm layers in the network can be fully obtained to determine which convolution weights are large and which are large, so as to obtain which features are more important and which features are insignificant.

[0029] S2. Merge the affected layers to generate a combination of relationship layers.

[0030] In the above example, we can see

[0031] [bn1, input layer: conv1, output layer conv2, conv3],

[0032] [bn3, input layer conv6, output layer conv2]

[0033] There is a common convolutional layer conv2, and at this time we need to merge these two into a combination. The combination is:

[0034] [batchnorm layer: bn1, bn3, input layer: conv1, conv6, output layer: conv2, conv3]

[0035] The final result is:

[0036] [batchnorm layer: bn1, bn3, input layer: conv1, conv6, output layer: conv2, conv3],

[0037] [batchnorm layer: bn2, input layer conv4, output layer conv5].

[0038] Defined by convolution It is known that the weight of the convolution of conv2, that is, the weight of the feature, is jointly determined by bn1 and bn3. If only one weight is used to distinguish, the features learned from a certain direction will be abandoned. Therefore, the importance of the conv2 feature is jointly determined by bn1 and bn3. Through the above-mentioned merging influence layer, we can accurately know whether the feature is important or not, and retain the key features to ensure the correctness of the final model. After merging, retain the features that bn1 and bn3 consider unimportant. Remove the features that are considered unimportant.

[0039] S3. Set the threshold a=0.001 (it is recommended to take 0.001 or less). Through the batchnorm layer in the combination, calculate its absolute value and divide it by its maximum value, set the channels that are greater than the threshold a to be retained, and remove all other channels. If there are multiple batchnorm layers, take any corresponding channel that meets the conditions.

[0040] For example, assuming that the gmma value of bn2 in the above is:

[0041] [2.295200314528234e-11,

[0042] -0.026561154052615166,

[0043] 1.7346097891390855e-8,

[0044] 0.21172288060188293,

[0045] 2.1014741596186992e-12,

[0046] 9.000307823244652e-14,

[0047] 0.000011705763427016791,

[0048] 3.882556439977619e-13];

[0049] Its absolute value / max = [1.08405870e-100.125452450.0000000819.92558836e-124.25098497e-135.52881360e-051.83379162e-12]

[0050] It can be seen that only 0.12545245 and 1 are greater than the threshold 0.001 set above, so the parameters of channels 0, 2, 4, 5, 6, and 7 can be removed. The parameters of the convolution finally become:

[0051] [-0.026561154052615166,0.21172288060188293], which can remove most of the useless parameters and greatly reduce the size of the parameters, thereby reducing the size of the model. During use, the use of memory is reduced and the amount of calculation is greatly reduced, thereby improving the speed without affecting the results.

[0052] The two-dimensional multi-group convolution is not intuitive. The following takes one-dimensional convolution as an example to illustrate its principle.

[0053] From the definition of convolution We can know the weight f(τ) before each feature to determine the importance of the feature at the τ position. Take one-dimensional discrete convolution as an example: f(τ) = (0, 1, 2, 3, 4), feature g(x) = (3, 2, 1, 0), and the convolution results are as follows:

[0054] t / x-t 0 3(*0=0) 2(*0=0) 1(*0=0) 0(*0=0) 1 3(*1=3) 2(*1=2) 1(*1=1) 0(*1=0) 2 3(*2=6) 2(*2=4) 1(*2=2) 0(*2=0) 3 3(*3=9) 2(*3=6) 1(*3=3) 0(*3=0) 4 3(*4=12) 2(*4=8) 1(*4=4) 0(*4=0) sum 0 3 8 14 20 11 4 0

[0055] Remove the feature of τ = 2, as follows

[0056] t / x-t 0 3(*0=0) 2(*0=0) 1(*0=0) 0(*0=0) 1 3(*1=3) 2(*1=2) 1(*1=1) 0(*1=0) 3 3(*3=9) 2(*3=6) 1(*3=3) 0(*3=0) 4 3(*4=12) 2(*4=8) 1(*4=4) 0(*4=0) sum 0 3 2 10 18 11 4 0

[0057] It can be found that the convolution results (0, 3, 8, 14, 20, 11, 4, 0) and (0, 3, 2, 10, 18, 11, 4, 0) are important for τ = 2 features. The difference in the results is obvious. When deconvolution is performed again, there is no way to equal the input result. The important part of the feature is removed in the middle.

[0058] When the weight before the feature is low, it means that this part of the feature is not important and can be removed, as follows:

[0059]

[0060] Remove the feature of τ = 2, as follows

[0061] t / x-t 0 3(*0=0) 2(*0=0) 1(*0=0) 0(*0=0) 1 3(*1=3) 2(*1=2) 1(*1=1) 0(*1=0) 3 3(*3=9) 2(*3=6) 1(*3=3) 0(*3=0) 4 3(*4=12) 2(*4=8) 1(*4=4) 0(*4=0) sum 0 3 2 10 18 11 4 0

[0062] Comparing the results after convolution (0,3,2.0003,10.0002,18.0001,11.0,4,0) and (0,3,2,10,18,11,4,0), the results are not much different. On the contrary, for the network, too much learning and some detailed features are not conducive to the generalization of the network. Removing some overly detailed features will better express the network.

[0063] S4. Process the input convolution layer and output convolution layer of the batchnorm layer in the above combination. For the input convolution layer, simply remove the channel corresponding to the first dimension of the convolution kernel. For the output convolution layer, simply remove the channel corresponding to the second dimension of the convolution kernel. The Dw layer belongs to the output layer. When processing the output convolution, the corresponding bias also removes the corresponding channel.

[0064] For example: if conv4.shape = (8,4,3,3), conv5.shape = (6,8,3,3), for conv4, only the 1 and 3 channels of the first dimension are retained, that is, the obtained weight = conv4[(1,3)], weight.shape = (2,4,3,3), the parameter amount is 2*4*3*3 = 72, and the value before removal is 8*4*3*3 = 288.

[0065] For conv5, as output, only channels 1 and 3 of the second dimension are retained, that is, weight = conv4[:, (1, 3)], weight.shape = (6, 2, 3, 3), the number of parameters is 6*2*3*3 = 108, and the number before removal is 6*8*3*3 = 432. For the depthwise layer, whether it is the input or output of batchnorm, it is used as the output, and the first dimension is removed in response. In this way, useless parameters can be automatically removed while ensuring the accuracy of the model, so as to achieve the purpose of reducing the model and achieve the effect of a large model with a smaller model.

[0066] 2. Some strategies to improve the effect during training:

[0067] (1) By regularizing the weights of the gmma parameters of the batchnorm layer, the importance of the channel convolution kernel is highlighted. This highlights the importance of some channel features. Do not restrict the importance of some channels during training. During training, the model will distinguish the importance of each channel by itself.

[0068] (2) During the training process, the width of the network can be expanded. After the training is completed, useful channels can be automatically selected to avoid the situation where the width is too small at the beginning, the network is small, the expression ability is insufficient, and the training results are not good. At this time, how many channels each layer of the network needs and which channels are important can be determined by the network itself during the training process without human intervention. The training results will be greatly improved.

[0069] 3. Effect

[0070] Based on yolov5, depth=0.65, width=0.75 as the basic network centernet, the model is trained to a size of 25M. After the above method, the size is 8.8M after removing useless parameters. The map does not change, and the model size is reduced by 65%.

[0071] The network size of the mobilenet-based face recognition model is 40M. After removing useless parameters using the above method, the size is reduced to 27M. The accuracy rate remains unchanged, and the model size is reduced by 33%.

[0072] Compared with the prior art, after the model is trained, the present invention does not need to be trained again, saving time and GPU computing power, and has basically no effect on the effect of the model, and sometimes even improves the generalization ability of the model.

[0073] This deep learning model compression method can accurately and quickly determine whether a parameter is useful or useless in the model, and remove useless parameters in different structures, thereby removing most of the useless parameters in the model, greatly reducing the size of the model. While ensuring the accuracy of the model, it reduces the use of memory, greatly reduces the amount of calculation, and greatly improves the speed of model response, achieving the effect of a large model with a smaller model.

[0074] The above description is only a preferred embodiment of the present invention, but the present invention should not be limited to the contents disclosed in the embodiment and the drawings, so any equivalent or modification completed without departing from the spirit disclosed in the present invention shall fall within the scope of protection of the present invention.

Claims

1. A deep learning model compression method, characterized in that: This deep learning model is based on the mobilenet face recognition model, which includes the following steps: S1. Get all batchnorm layers in the network. If a convolutional layer, deconvolutional layer, or fully connected layer is encountered, the process ends. If an activation layer or pool layer is encountered, the process upsamples. If a concat layer, clip layer, or add layer is encountered, the process searches downward. S2, merge the affected layers to generate a combination of relationship layers, retain key features and remove unimportant features; S3. Set a threshold a, calculate its absolute value and divide it by its maximum value through the batchnorm layer in the combination, set the channels that are greater than the threshold a to be retained, and remove all other channels; S4. Process the input convolution layer and the output convolution layer of the batchnorm layer in the combination. For the input convolution layer, directly remove the channel corresponding to the first dimension of the convolution kernel. For the output convolution layer, directly remove the channel corresponding to the second dimension of the convolution kernel.

2. The deep learning model compression method according to claim 1, characterized in that: In step S1, all batchnorm layers in the network are obtained, including all batchnorm input layers, and output layers corresponding to the batchnorm input layers.

3. The deep learning model compression method according to claim 1, characterized in that: In step S3, the threshold a≦0.

001.

4. The deep learning model compression method according to claim 1, characterized in that: In step S3, if there are multiple batchnorm layers, any corresponding channel that meets the conditions is selected.

5. The deep learning model compression method according to claim 1, characterized in that: In step S3, the importance of the channel convolution kernel is highlighted by regularizing the gmma parameter weights of the batchnorm layer.

6. The deep learning model compression method according to claim 1, characterized in that: In step S4, the Dw layer is attributed to the output layer, and when processing the output convolution, the corresponding bias removes the corresponding channel at the same time.

7. The deep learning model compression method according to claim 1, characterized in that: In step S1, a large bandwidth network is used in the process of acquiring all batchnorm layers in the network.

Citation Information

Patent Citations

  • Deep learning network model compression method based on network layer pruning

    CN111401523A

  • Feature extraction module compression method and device, image processing method and device, and medium

    CN112287950A