A convolutional network channel pruning method and system based on reinforcement learning
By tailoring the filters in the deep learning model through the reinforcement learning algorithm, combined with fine-tuning the recovery accuracy, the problem of model deployment and inference speed improvement on edge devices is solved, and efficient model compression on edge devices is achieved.
Patent Information
- Application Number
- CN202210428600.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-22
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-04-22
AI Technical Summary
It is difficult to deploy existing deep learning models and increase the inference speed on edge devices with insufficient computing power, resulting in a mismatch between model complexity and resource consumption.
The convolutional network channel cutting method based on reinforcement learning is adopted, and the filters in the network model are gradually cut through the automatic depth compression algorithm and the absolute value importance index of the first-order Taylor expansion. Combined with fine-tuning the recovery accuracy, the model is lightweight.
The sensitivity of different layer parameters is effectively taken into account, and through loss function derivatives and threshold judgments, the model compression effect is improved while ensuring accuracy, and is suitable for lightweight deployment of edge devices.
Smart Images

Figure CN114757350B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence and model compression technology, and in particular to a convolutional network channel pruning method and system based on reinforcement learning. Background Art
[0002] Deep learning has brought artificial intelligence to an unprecedented level. It can be applied in all aspects of life, such as image, speech, driving, emotional computing, etc. The development of these different aspects has brought earth-shaking changes to people's lives and greatly improved people's efficiency in some fields. However, a deep learning model usually contains millions or even tens of millions of parameters.
[0003] The shortcoming of existing technologies is that, in order to improve the accuracy of models, models are becoming more and more complex and require huge computing power and memory resources. However, unlike the increasingly complex training models, how to deploy these networks on edge devices with insufficient computing power or increase the speed at which edge devices use these networks for reasoning has become a problem. Therefore, some methods are needed to help make complex models lightweight. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings of the prior art. To achieve the above purpose, a convolutional network channel pruning method and system based on reinforcement learning is adopted to solve the problems raised in the above background technology.
[0005] The technical solution of the first aspect adopted by the present invention is: a convolutional network channel pruning method based on reinforcement learning, the specific steps comprising:
[0006] S1. Obtain a network model to be compressed, wherein the network model is provided with a plurality of filters, and the filters are used to extract features of image data input to the network model;
[0007] S2. Use the automatic deep compression algorithm to perform reinforcement learning cropping ratio based on the focus direction of model accuracy and determine the cropping ratio;
[0008] S3. Based on the chain rule, the absolute value of the first-order Taylor expansion of the weights of all filters is obtained as the importance index of clipping to determine the importance of the parameters;
[0009] S4, for filters with low weight ranking within the cropping ratio range, use an algorithm to crop them to suit the network model, and save the network model before pruning;
[0010] S5, judging various status signs of the current network model, if it exceeds the cropping ratio or the preset limiting conditions, performing corresponding processing operations to obtain the final pruned network model;
[0011] S6. Restore the accuracy of the network model by fine-tuning.
[0012] As a further solution of the present invention: the specific steps of S2 are: by utilizing the automatic deep compression algorithm to design rewards for learning based on the direction of model accuracy, the optimal cropping ratio of each layer of filters is obtained.
[0013] As a further solution of the present invention: the specific steps of S4 are:
[0014] According to the determined cropping ratio of each layer filter, a step-by-step algorithm is designed to derive the target cropping ratio;
[0015] Each time, the algorithm obtains the current optimal cropping ratio, and continuously cooperates with other modules to iterate cropping and finally reaches the target cropping ratio;
[0016] At the same time, before each cropping, the uncropped network model is saved.
[0017] As a further solution of the present invention: the specific steps of the S5 network model judgment are:
[0018] If, in the current situation, the network model still does not meet the set accuracy threshold after pruning and fine-tuning, the last saved network is output;
[0019] If it has not been pruned, it is sent to the fine-tuning unit and the status is recorded;
[0020] If the cropping ratio obtained in step S2 is reached, the network model is output as the final compression result model.
[0021] The technical solution of the second aspect adopted by the present invention is: a system including a convolutional network channel pruning method based on reinforcement learning as described in any one of the above items, comprising:
[0022] The discretionary calculation module is used to obtain the sparse ratio of each layer of filters as the cropping ratio by using the automatic deep compression algorithm based on reinforcement learning;
[0023] The importance index module is used to calculate the absolute value of the first-order Taylor expansion of the loss function of each filter of the current unpruned or pruned network model as the importance index of pruning;
[0024] A trimming execution module is used to trim the filter to be trimmed within the minimum ratio index calculated by the index unit in the network model through a step-by-step pruning algorithm, and gradually reach the trimming ratio;
[0025] A fine-tuning module is used to fine-tune any pruned network model to improve the accuracy of the network model, and send the network model to the importance index module;
[0026] Judgment control output module: used to determine whether the pruned convolutional network meets the preset model accuracy threshold or reaches the cropping ratio. If it is less than the accuracy threshold, the pruning of the convolutional network is completed, and the previously pruned convolutional network model is output as the final compression result. If the cropping ratio is reached, the current cropping result is output as the compression result. In other cases, the fine-tuning module is input to restore the accuracy.
[0027] Compared with the prior art, the present invention has the following technical effects:
[0028] By adopting the above technical solution, the pruning ratio of each layer of the convolutional network is obtained through reinforcement learning, which effectively considers the sensitivity of the parameters of different layers. The absolute value of the first-order derivative of the filter channel weight of the loss function is used as the pruning indicator, and the network is pruned through automatic step-by-step pruning. The threshold of model accuracy is used to determine whether to perform the next iterative pruning or terminate the pruning and return to the previous result after pruning to obtain the final compression model. By combining multiple methods, the compression effect is effectively improved while ensuring the accuracy of the compression model. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings:
[0030] Figure 1 A schematic diagram of the steps of a convolutional network channel pruning method according to some embodiments disclosed in this application;
[0031] Figure 2 A flowchart of the steps of the convolutional network compression method of some embodiments disclosed in this application;
[0032] Figure 3 A flowchart of adjusting the cropping ratio in some embodiments disclosed in this application;
[0033] Figure 4 This is a schematic diagram of the modules of the system of some embodiments disclosed in this application.
[0034] In the figure: 301, discretion calculation module; 302, importance index module; 303, cutting execution module; 304, fine-tuning module; 305, judgment control output module. DETAILED DESCRIPTION
[0035] 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. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0036] Please refer to Figure 1 and Figure 2 In an embodiment of the present invention, a convolutional network channel pruning method based on reinforcement learning comprises the following specific steps:
[0037] S1. Obtain a network model to be compressed, wherein the network model is provided with a plurality of filters, and the filters are used to extract features of image data input to the network model;
[0038] S2. Use the automatic deep compression algorithm to perform reinforcement learning cropping ratio based on the emphasis of model accuracy and determine the cropping ratio; the specific steps are: by using the automatic deep compression algorithm to design rewards for learning based on the direction of model accuracy, the optimal cropping ratio of each layer of filters is obtained.
[0039] S3. Based on the chain rule, the absolute value of the first-order Taylor expansion of the weights of all filters is obtained as the importance index of clipping to determine the importance of the parameters;
[0040] S4, for filters with low weight ranking within the cropping ratio range, use an algorithm to crop them to suit the network model, and save the network model before pruning; the specific steps are:
[0041] According to the determined cropping ratio of each layer filter, a step-by-step algorithm is designed to derive the target cropping ratio;
[0042] Each time, the algorithm obtains the current optimal cropping ratio, and continuously cooperates with other modules to iterate cropping and finally reaches the target cropping ratio;
[0043] At the same time, before each cropping, the uncropped network model is saved.
[0044] S5. The various status flags of the current network model are judged. If the cropping ratio or the preset limiting conditions are exceeded, corresponding processing operations are performed to obtain the final pruned network model. The specific steps of network model judgment are:
[0045] If, in the current situation, the network model still does not meet the set accuracy threshold after pruning and fine-tuning, the last saved network is output;
[0046] If it has not been pruned, it is sent to the fine-tuning unit and the status is recorded;
[0047] If the cropping ratio obtained in step S2 is reached, the network model is output as the final compression result model.
[0048] S6. Restore the accuracy of the network model by fine-tuning.
[0049] In this embodiment, Figure 2As shown, the diagram shows a specific network model cutting embodiment, and the steps of the specific method are:
[0050] S101. For the input convolutional neural network N, an automatic deep compression enhancement algorithm is applied to the convolutional neural network through a branch focusing on accuracy, and the sparsity ratio of each layer is obtained, which is the cropping ratio;
[0051] In an actual embodiment, step S101 can pay more attention to the accuracy loss of the cropped model and the original model through reinforcement learning, and the reward function is as follows:
[0052]
[0053] Among them, Error is the error rate after compressing the model after a certain learning, FLOPS is the computing power required by the model, and Reward is the reward function of reinforcement learning. This reward fully considers the importance of both error rate and computing power, and makes a compromise between them. Its value function at convolution layer t is:
[0054]
[0055] S t =s means that the state at the tth layer is s. The function indicates that the value at the current state is and the expectation of the reward and discount rate for each subsequent step.
[0056] Agent from L t The layer receives the convolutional layer filter S t , output sparse ratio ratio, after compressing the layer, the agent moves to the next layer L t+1 . Evaluate the accuracy of the pruned model after all layers are compressed. Finally, the reward Reward is returned to the agent as a function of accuracy and computing power. Evaluate the accuracy of the pruned model after all layers are compressed. Finally, the reward R is returned to the agent as a function of accuracy and FLOPs. And because each layer is tested, the pruning ratio of each layer is different.
[0057] S102. For the weight of each layer of the filter of the current model, the absolute value of the first-order derivative of the loss function is used as the importance measure of clipping; the change of the loss function is:
[0058] |ΔC(hi)|=|C(D,hi=0)-C(D,hi)];
[0059] Among them, C(D,hi) is the value of the loss function without pruning, and C(D,hi=0) is the loss function after pruning when a certain weight of the convolution kernel of the filter is assumed to be 0. |ΔC(hi)| is the change in loss after pruning, which can reflect the importance of each weight of a filter. Expand the first-order derivative:
[0060]
[0061] Among them, R1(hi=0) is the remainder, which can be ignored during calculation. Assuming that there is a positive correlation between importance and the change of loss function, the importance formula of a certain weight can be obtained by combining them:
[0062]
[0063] Among them, hi is a simple symbolic representation of a certain weight. The following formula will use hij to represent the weight of the corresponding position in a channel of the convolution kernel. Then the importance formula of a channel of the convolution kernel of the filter can be recorded as:
[0064]
[0065] The importance of the convolution channel can be obtained according to this formula. The proportion of each channel in the convolution layer is the reciprocal of the total number of all convolution channels in the layer.
[0066] S103. Through the step-by-step pruning algorithm, the cropping ratio calculated in step S101 is gradually adjusted. The span of each step can be gradually adjusted by the algorithm first to a large extent, and then a small extent until the cropping ratio of each layer calculated in step S101 is finally reached. The cropping is performed and the network before the cropping is recorded as N1. N1 is updated each time the cropping is performed thereafter.
[0067] Specifically, in practical applications, in order to reduce the amount of calculation, a binary search variant method can be used to limit the increase ratio of each step of S103 by an algorithm. Figure 2 The steps of the algorithm flow chart shown are scaled.
[0068] S104, judging the network accuracy threshold of the current pruned network N0 to determine whether it has been fine-tuned. If it has been fine-tuned, proceed to the next judgment step S106; if it has not been fine-tuned, proceed to step S105;
[0069] S105, fine-tuning the current model to restore accuracy, and recording the fine-tuning status flag;
[0070] S106, judging whether the current model is smaller than the preset model accuracy threshold, if so, proceeding to step S107, judging whether the cropping ratio is reached, if so, also proceeding to step S107; if both are negative, proceeding to step S102;
[0071] S107. If the accuracy of the current model is less than the preset threshold accuracy, the convolutional network before pruning in the previous step saved in S103 is output. If the cropping ratio is reached, the current network compression model is output as the compression result.
[0072] In this embodiment, after obtaining the network model to be pruned, a stepwise adaptive pruning algorithm in the form of a binary transformation can be set to gradually approach the sparsity ratio, such as Figure 3 As shown, the diagram shows the specific steps of the step-by-step pruning algorithm:
[0073] S201: setting the cropping ratio to a range of sparsity ratio, i.e. L and R;
[0074] S202: Each step is adjusted to a step of 1,1 / 2 (RL);
[0075] S203-1: Compare the cropping results of 1 and 1 / 2 (RL) step lengths to see which one is better;
[0076] S203-2: If the cropping result when the step size is 1 is better than the cropping result less than 1 / 2(RL), then 1 / 2(RL) is set to L;
[0077] S203-3: If the step size is 1 / 2 (RL), R is set to 1 / 2 (RL);
[0078] S204: Compare whether 1 is equal to 1 / 2 (RL), if so, proceed to step S205;
[0079] S205: cropping is performed using the ratio at the 1 / 2 (L+R) position, and the steps after S103 may be performed;
[0080] S206: Reuse the original unpruned network, and then jump to step S202.
[0081] The above is a process of performing a better cropping ratio step. In the entire cropping method, such steps need to be performed multiple times to ultimately achieve the overall cropping ratio determined by the enhancement algorithm.
[0082] The technical solution of the second aspect: a system including a convolutional network channel pruning method based on reinforcement learning as described in any one of the above items, comprising:
[0083] like Figure 4 As shown, the figure is a schematic diagram of the system module of the convolutional network channel pruning method.
[0084] The discretionary calculation module 301 is used to obtain the sparse ratio of each layer of filters as the cropping ratio by using the automatic deep compression algorithm based on reinforcement learning; specifically, by processing the input convolutional neural network, the sparse ratio of each layer of filters of the current convolutional network is obtained through learning as the cropping ratio.
[0085] The importance index module 302 is used to calculate the absolute value of the first-order Taylor expansion of the loss function of each filter of the current unpruned or pruned network model as the importance index of pruning;
[0086] In a specific implementation, a certain importance index of each filter under the measurement method can be calculated in various ways, and by comparing the index, filters with lower importance can be selected for pruning;
[0087] The trimming execution module 303 is used to trim the filter to be trimmed within the minimum ratio index calculated by the index unit in the network model through a step-by-step adaptive step-size trimming algorithm, and gradually reach the trimming ratio;
[0088] A fine-tuning module 304 is used to fine-tune any pruned network model, i.e., retrain it, to improve the accuracy of the network model, and send the network model to the importance index module;
[0089] The specific implementation method is to fine-tune (retrain) the pruned convolutional network transmitted from the judgment control output module to restore the network accuracy, and output its N0 to the importance index unit to re-judge the importance index of the current network, and cycle the process shown in the figure until the judgment control output module finally determines that the compression is completed.
[0090] Determine the control output module 305: determine whether the state and the current cropped network meet the preset convolution network accuracy threshold:
[0091] If the accuracy is not met, the last convolutional network that meets the network accuracy threshold saved by the cropping execution unit is output as the final cropped network;
[0092] If the cropping ratio is reached, the current network is output as the final cropped network;
[0093] In other cases, the input fine-tuning module is used for the next iterative pruning.
[0094] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention. The scope of the present invention is defined by the appended claims and their equivalents, and all should be included within the scope of protection of the present invention.
Claims
1. A convolutional network channel pruning method based on reinforcement learning, It is characterized in that include: S1. Obtain a network model to be compressed, wherein the network model is provided with a plurality of filters, and the filters are used to extract features of image data input to the network model; S2. Using the automatic deep compression algorithm to perform reinforcement learning clipping ratio based on the emphasis direction of model accuracy, and determine the clipping ratio. The specific steps are: using the automatic deep compression algorithm to design rewards for learning based on the direction of model accuracy, and obtaining the optimal clipping ratio of each layer filter; S3. Based on the chain rule, the absolute value of the first-order Taylor expansion of the weights of all filters is obtained as the importance index of clipping to determine the importance of the parameters; S4. For filters with low importance ranking within the cropping ratio range, use an algorithm to crop them to suit the network model, and save the network model before pruning. The specific steps are as follows: According to the determined cropping ratio of each layer filter, a step-by-step algorithm is designed to derive the target cropping ratio; Each time, the algorithm obtains the current optimal cropping ratio, and continuously cooperates with other modules to iterate cropping and finally reaches the target cropping ratio; At the same time, before each cropping, save the uncropped network model; S5, judging various status signs of the current network model, if it exceeds the cropping ratio or the preset limiting conditions, performing corresponding processing operations to obtain the final pruned network model; S6, restore the accuracy of the network model by fine-tuning; The steps to determine the cropping ratio are: For the input convolutional neural network N, the automatic deep compression enhancement algorithm is applied to the convolutional neural network through the branch focusing on accuracy to obtain the sparsity ratio of each layer, which is the cropping ratio; Through reinforcement learning, we pay more attention to the accuracy loss of the cropped model and the original model. The reward function is as follows: ; Among them, Error is the error rate after compressing the model after a certain learning, FLOPs is the computing power required by the model, and Reward is the reward function of reinforcement learning; this reward fully considers the importance of both error rate and computing power, and balances them; its value function at convolution layer t is: ; S t =s means that the state at the tth layer is s. This function indicates that the value at the current state is , and the expected reward and discount rate of each subsequent step; Agent from L t The layer receives the convolutional layer filter S t , output sparse ratio ratio, after compressing the layer, the agent moves to the next layer L t+1 ; Evaluate the accuracy of the pruned model after all layers are compressed; Finally, the reward Reward is returned to the agent as a function of accuracy and computing power; Evaluate the accuracy of the pruned model after all layers are compressed; Finally, the reward R is returned to the Agent as a function of accuracy and FLOPs; and because each layer is tested, the pruning ratio of each layer is different.
2. According to the convolutional network channel pruning method based on reinforcement learning as described in claim 1, It is characterized in that The specific steps of determining the S5 network model are as follows: If, in the current situation, the network model still does not meet the set accuracy threshold after pruning and fine-tuning, the last saved network is output; If it has not been pruned, it is sent to the fine-tuning unit and the status is recorded; If the cropping ratio obtained in step S2 is reached, the network model is output as the final compression result model.
3. A system comprising a convolutional network channel pruning method based on reinforcement learning as described in any one of claims 1-2, It is characterized in that include: The discretionary calculation module is used to obtain the sparse ratio of each layer of filters as the cropping ratio by using the automatic deep compression algorithm based on reinforcement learning; The importance index module is used to calculate the absolute value of the first-order Taylor expansion of the loss function of each filter of the current unpruned or pruned network model as the importance index of pruning; A trimming execution module is used to trim the filter to be trimmed within the minimum ratio index calculated by the index unit in the network model through a step-by-step pruning algorithm, and gradually reach the trimming ratio; A fine-tuning module is used to fine-tune any pruned network model to improve the accuracy of the network model, and send the network model to the importance index module; Judgment control output module: used to determine whether the pruned convolutional network meets the preset model accuracy threshold or reaches the cropping ratio. If it is less than the accuracy threshold, the pruning of the convolutional network is completed, and the previously pruned convolutional network model is output as the final compression result. If the cropping ratio is reached, the current cropping result is output as the compression result. In other cases, the fine-tuning module is input to restore the accuracy.
