Model pruning method and computer readable storage medium
By calculating the sensitivity and importance scores of filter channels and combining them with a global grouping pruning strategy, the network acceleration and accuracy problems caused by excessively fine or coarse granularity in existing pruning methods are solved, achieving efficient model pruning and accuracy improvement.
Patent Information
- Application Number
- CN202410904785.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-11-01
AI Technical Summary
Existing unstructured pruning methods make sparse networks difficult to accelerate and require custom software or libraries for deployment, while structured pruning methods may lead to decreased model accuracy and training instability.
By calculating the pruning sensitivity and relative importance of each filter channel, an importance score is constructed as a pruning evaluation criterion. Convolutional layers with the same number of filters are grouped together for global group pruning, balancing the number of floating-point operations and parameters during pruning to avoid over-pruning.
This approach achieves a pruning granularity between unstructured and structured models, improving pruning efficiency, avoiding the problems of sparse networks being difficult to accelerate and losing model accuracy, and enhancing the model's generalization ability and accuracy.
Smart Images

Figure CN118886468A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of model lightweighting, and in particular to a model pruning method and a computer-readable storage medium. Background Art
[0002] At present, deep convolutional neural networks (DCNNs) have achieved great success in the field of computer vision, such as image classification, object detection, and semantic segmentation. The success of convolutional neural networks is usually accompanied by a sharp increase in network complexity and an exponential increase in network parameters and operations. For example, SENet has a 1.2×10 8 parameters, more than 2×10 are needed when reasoning about images with a resolution of 224×224. 10 This causes the model's resource consumption to rise sharply, the inference time to grow rapidly, and it is difficult to deploy on resource-constrained devices, such as embedded devices. For this reason, the compression and acceleration of deep convolutional neural networks have received widespread attention and has become a research hotspot.
[0003] The compression and acceleration technologies of deep convolutional neural networks mainly include network pruning, knowledge distillation, network quantization and low-rank decomposition. Network pruning reduces the computational and storage overhead of the network by removing unimportant parameters and connections while maintaining network performance as much as possible. Knowledge distillation uses a model with good performance as a teacher model to guide the training of a lightweight model, namely the student model, and improves the performance of the student model through the rich knowledge and information of the teacher model, thereby achieving the purpose of model compression and acceleration. Network quantization converts the parameters and activation values in the deep convolutional neural network from floating-point representation to fixed-point representation with fewer bits, such as 8-bit integers, thereby significantly reducing the storage space and computation of the network, achieving network compression and acceleration, and usually includes 8-bit quantization, 4-bit quantization and binary quantization. Low-rank decomposition decomposes the parameter matrix of the convolution kernel into a low-rank approximate matrix, thereby greatly reducing the computational amount and storage space of the convolution operation, achieving network compression and acceleration. Low-rank decomposition usually includes singular value decomposition, SVD, tensor decomposition, etc.
[0004] Network pruning can be divided into two categories: unstructured pruning and structured pruning. Unstructured pruning is a fine-grained pruning method that prunes individual weights within the network; for example, pruning weights close to 0, this method ultimately results in an unstructured sparse network without sacrificing network performance; however, since the positions of pruned weights are random, the resulting sparse network is usually unstructured, which makes it difficult to apply the model obtained by unstructured pruning on hardware devices and difficult to achieve hardware acceleration. Structured pruning is a coarse-grained pruning method, and the pruned network is still structured, which makes the structured pruned network applicable to hardware devices, making it easier to achieve hardware acceleration. Existing structured pruning can be divided into filter pruning and layer pruning; filter pruning prunes by deleting the filter parameters of the convolutional layer, and layer pruning reduces the depth of the network model by deleting the entire convolutional layer. Compared with filter pruning, layer pruning can significantly reduce runtime memory. In addition, since various operations within a layer are usually performed in parallel, deleting the entire layer can also significantly reduce the model prediction time. However, layer pruning discards the entire layer, which may destroy the correlation between layers, resulting in severe accuracy loss. Although filter pruning does not reduce the depth of the network, it ignores the differences in filter channels, and removing the entire filter may still remove weight elements that are important to the final accuracy.
[0005] Although unstructured pruning can effectively reduce the number of model parameters and achieve the purpose of model compression, its shortcomings in hardware acceleration, implementation complexity and training stability limit its widespread application. In practical applications, the models obtained by unstructured pruning require customized software or libraries to be deployed on edge devices, which is relatively complicated to use. Although structured pruning does not require customized software or hardware in actual deployment, the pruning granularity of structured pruning is large. This coarse-grained pruning may remove a large number of useful features, resulting in a significant decrease in model performance, such as accuracy and precision. In addition, pruning entire filters or layers may cause the model to be unable to learn important features originally extracted by these structures; large-scale parameter removal during pruning may also lead to instability during model training, requiring more adjustments to training parameters and strategies.
[0006] In summary, the existing unstructured pruning has too fine a pruning granularity, resulting in a sparse network that is not convenient for network acceleration. It requires customized software or libraries to be deployed on edge devices, which is more complicated to use. The existing structured pruning has too coarse a pruning granularity. Discarding the entire convolutional layer will destroy the correlation between layers, resulting in a decrease in model accuracy, network performance loss, and difficulty in recovering network performance. Summary of the invention
[0007] To this end, the technical problem to be solved by the present invention is to overcome the problem in the prior art that the pruned network becomes complex or has reduced accuracy due to the pruning granularity being too fine or too coarse.
[0008] In order to solve the above technical problems, the present invention provides a model pruning method, comprising:
[0009] Obtain a deep convolutional neural network containing multiple convolutional layers as a model to be pruned;
[0010] Based on the training set, the model network loss after each filter channel of each filter in each convolutional layer of the to-be-pruned model is calculated, and the difference between the initial network loss of the model when no filter channel is pruned is calculated, and the change in the model network loss after each filter channel is pruned is obtained as the pruning sensitivity of each filter channel;
[0011] Obtaining the channel weight of each filter channel in each filter of each convolutional layer in the to-be-pruned model; calculating the L2 norm of the channel weight of each filter channel, and normalizing it to obtain the normalized L2 norm of each filter channel as the relative importance of each filter channel;
[0012] For each filter channel in each filter of each convolutional layer in the model to be pruned, the pruning sensitivity and relative importance of each filter channel are weighted summed based on the preset hyperparameters to obtain the importance score of each filter channel;
[0013] Divide the convolutional layers with the same number of filters in the to-be-pruned model into a group, and obtain a plurality of groups of convolutional layer sets;
[0014] For each set of convolutional layers, all filter channels are sorted in ascending order according to their importance scores, and based on the preset global pruning rate, the filter channels of the first preset number in the sorting of each set of convolutional layers are pruned respectively;
[0015] The model to be pruned is obtained after pruning each set of convolutional layers, and the target model is obtained.
[0016] Preferably, the deep convolutional neural network comprising multiple convolutional layers includes any one of VGG16, Resnet56, Resnet110, Resnet18 and Resnet50.
[0017] Preferably, the pruning sensitivity of each filter channel is expressed as:
[0018]
[0019] Among them, the pruning sensitivity of the k-th filter channel of the j-th filter in the i-th convolutional layer is Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; It represents the feature map of the k-th filter channel output of the j-th filter of the i-th convolutional layer, expressed as C i Represents the number of input channels of the i-th convolutional layer, 1≤k≤C i , X i,k Represents the output feature map of the kth filter of the i-th convolutional layer;
[0020] L(X,Y;W) represents the initial network loss of the model when no filter channel is pruned, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the k-th filter channel of the j-th filter in the i-th convolutional layer; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K , R represents a real number set; X represents the model input data, Y represents the model output value, and W represents the model weight matrix.
[0021] Preferably, the model network loss is expressed as:
[0022]
[0023] Where n represents the number of prediction categories. Represents the predicted probability of the tth class, expressed as Function f() represents a network flow.
[0024] Preferably, after obtaining the pruning sensitivity of each filter channel, the method further includes:
[0025] Get the model initial network loss of each filter channel before pruning the filter channel, and construct the loss function weight matrix;
[0026] Performing Taylor expansion on the loss function weight matrix and omitting high-order terms to obtain a Taylor expansion of the loss function;
[0027] The Relu activation function is used to activate the channel weight of each filter channel in the Taylor expansion of the loss function, and the updated channel weight of each filter channel is obtained, which is updated to the pruning sensitivity of each filter.
[0028] Preferably, the loss function weight matrix is subjected to Taylor formula expansion, and high-order terms are omitted to obtain the loss function Taylor expansion, which is expressed as:
[0029]
[0030] in, Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; represents the feature map of the kth filter channel output of the jth filter of the i-th convolutional layer; L(X,Y;W) represents the initial network loss of the model before pruning the filter channel, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the kth filter channel of the jth filter of the i-th convolutional layer, W i,j,k←0 represents the kth filter channel in the jth filter of the ith convolutional layer; X represents the model input data, Y represents the model output value, and W represents the model weight matrix; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the set of real numbers; It means partial derivative.
[0031] Preferably, the Relu activation function is used to activate the channel weight of each filter channel in the Taylor expansion of the loss function to obtain the updated channel weight of each filter channel, which is expressed as:
[0032]
[0033] Among them, Relu() represents the Rel u activation function.
[0034] Preferably, the relative importance of each filter channel is expressed as:
[0035]
[0036] Among them, I i,j,k represents the relative importance of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the real number set; || ||2 represents the L2 norm; C i With C i+1 Respectively represent the number of input channels and output channels of the i-th convolutional layer, 1≤j≤C i+1 , 1≤k≤C i .
[0037] Preferably, the importance score of each filter channel is expressed as:
[0038]
[0039] Among them, S i,j,k represents the importance score of the kth filter channel in the jth filter of the i-th convolutional layer, and β is a preset hyperparameter; represents the pruning sensitivity of the kth filter channel in the jth filter of the i-th convolutional layer after pruning, I i,j,k represents the relative importance of the k-th filter channel in the j-th filter of the i-th convolutional layer.
[0040] This embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the model pruning method described above are implemented.
[0041] The above technical solution of the present invention has the following beneficial effects compared with the prior art:
[0042] The model pruning method described in the present invention takes into account the differences between different filter channels in the same filter, takes the filter channel as the pruning unit, calculates the change in model network loss after each filter channel is pruned, and the normalized L2 norm of each filter channel as the pruning sensitivity and relative importance of each filter channel; constructs an importance score based on the pruning sensitivity and relative importance as a pruning judgment standard for the filter channel, so that the pruning granularity is between unstructured pruning and structured pruning, that is, avoids the problem of sparse network caused by unstructured pruning granularity being too fine and inconvenient for network acceleration, and avoids the problem of pruning network performance loss caused by existing structured pruning granularity being too coarse.
[0043] The present invention divides convolutional layers with the same number of filters into a group, obtains multiple groups of convolutional layer sets, sorts all the filter channels in each group of convolutional layer sets in order of importance scores from small to large, and prunes the filter channels of the first preset number in the sorting of each group of convolutional layer sets based on a preset pruning rate; by performing global group pruning on the pruned model, the number of pruning floating-point operations Flops and the amount of pruning parameters are balanced, so that the pruned network will not have the phenomenon of excessive pruning of a certain layer, and the adaptive pruning rate calculation within the group is realized under the condition of the preset pruning rate, thereby improving the pruning efficiency.
[0044] The present invention constructs a loss function weight matrix based on the model initial network loss of each filter channel before pruning the filter channel; Taylor formula expansion is performed on the loss function weight matrix, and the channel weight of each filter channel in the Taylor expansion of the loss function is activated by using a Relu activation function, and the pruning sensitivity of each filter is updated; negative values in an input feature map are processed by the Relu activation function, and activation values corresponding to negative weights are set to zero, that is, the sensitivity of the filter channel is calculated by using the Relu activation function, so that when the weights of the filter channel are all negative values, the pruning sensitivity thereof is also 0, so that the convolutional neural network model can better learn features and improve the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein
[0046] Figure 1 is a flow chart of the steps of the model pruning method provided by the present invention;
[0047] Figure 2 It is a process schematic diagram of the filter channel pruning method provided by the present invention;
[0048] Figure 3 This is a schematic diagram of the L1 norm of each filter channel in the VGG16 model;
[0049] Figure 4 This is a schematic diagram of pruning grouping based on the VGG16 model provided by the present invention. DETAILED DESCRIPTION
[0050] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0051] Reference Figure 1 As shown, the step flow chart of the model pruning method provided by the present invention; the specific steps include:
[0052] S101: Obtain a deep convolutional neural network including multiple convolutional layers as a model to be pruned;
[0053] S102: Based on the training set, the model network loss after each filter channel of each filter in each convolutional layer of the to-be-pruned model is calculated, and the difference between the initial network loss of the model when no filter channel is pruned is calculated, and the change in the model network loss after each filter channel is pruned is obtained as the pruning sensitivity of each filter channel, which is expressed as:
[0054]
[0055] Among them, the pruning sensitivity of the k-th filter channel of the j-th filter in the i-th convolutional layer is Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; It represents the feature map of the k-th filter channel output of the j-th filter of the i-th convolutional layer, expressed as C i Represents the number of input channels of the i-th convolutional layer, 1≤k≤C i , X i,k represents the output feature map of the kth filter of the i-th convolutional layer; L(X,Y;W) represents the initial network loss of the model when no filter channel is pruned, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the k-th filter channel of the j-th filter in the i-th convolutional layer; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K , R represents a real number set; X represents the model input data, Y represents the model output value, and W represents the model weight matrix;
[0056] The model network loss is expressed as Where n represents the number of prediction categories. Represents the predicted probability of the tth class, expressed as Function f() represents the network flow. In this embodiment, n=3, and the three categories are seaweed, seaweed and coral.
[0057] S103: Obtain the channel weight of each filter channel in each filter of each convolutional layer in the to-be-pruned model; calculate the L2 norm of the channel weight of each filter channel, and normalize it to obtain the normalized L2 norm of each filter channel as the relative importance of each filter channel, expressed as:
[0058]
[0059] Among them, I i,j,k represents the relative importance of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the set of real numbers;||||2 represents the L2 norm; C i With C i+1 Respectively represent the number of input channels and output channels of the i-th convolutional layer, 1≤j≤Ci+1 , 1≤k≤C i .
[0060] S104: For each filter channel in each filter of each convolutional layer in the to-be-pruned model, the pruning sensitivity and relative importance of each filter channel are weighted summed based on preset hyperparameters to obtain an importance score of each filter channel, which is expressed as:
[0061]
[0062] Among them, S i,j,k represents the importance score of the kth filter channel in the jth filter of the i-th convolutional layer, and β is a preset hyperparameter; represents the pruning sensitivity of the kth filter channel in the jth filter of the i-th convolutional layer after pruning, I i,j,k represents the relative importance of the k-th filter channel in the j-th filter of the i-th convolutional layer.
[0063] S105: Divide the convolutional layers with the same number of filters in the to-be-pruned model into one group, and obtain multiple groups of convolutional layer sets;
[0064] S106: for each set of convolutional layers, sort all filter channels therein in ascending order according to the importance score, and prune the first preset number of filter channels in the sorting of each set of convolutional layers based on a preset global pruning rate;
[0065] S107: Obtain the model to be pruned after pruning each set of convolutional layers, and obtain the target model.
[0066] The model pruning method described in the present invention takes into account the differences between different filter channels in the same filter, takes the filter channel as the pruning unit, calculates the change in model network loss after each filter channel is pruned, and the normalized L2 norm of each filter channel as the pruning sensitivity and relative importance of each filter channel; constructs an importance score based on the pruning sensitivity and relative importance as a pruning judgment standard for the filter channel, so that the pruning granularity is between unstructured pruning and structured pruning, that is, avoids the problem of sparse network caused by unstructured pruning granularity being too fine and inconvenient for network acceleration, and avoids the problem of pruning network performance loss caused by existing structured pruning granularity being too coarse. The present invention divides convolutional layers with the same number of filters into a group, obtains multiple groups of convolutional layer sets, sorts all the filter channels in each group of convolutional layer sets in order of importance scores from small to large, and prunes the filter channels of the first preset number in the sorting of each group of convolutional layer sets based on a preset pruning rate; by performing global group pruning on the pruned model, the number of pruning floating-point operations Flops and the amount of pruning parameters are balanced, so that the pruned network will not have the phenomenon of excessive pruning of a certain layer, and the adaptive pruning rate calculation within the group is realized under the condition of the preset pruning rate, thereby improving the pruning efficiency.
[0067] In an embodiment of the present invention, the model to be pruned is a deep convolutional neural network comprising multiple convolutional layers, including any one of VGG16, Resnet56, Resnet110, Resnet18 and Resnet50.
[0068] Specifically, in step S102, after obtaining the pruning sensitivity of each filter channel, the method further includes:
[0069] Get the model initial network loss of each filter channel before pruning the filter channel, and construct the loss function weight matrix;
[0070] The loss function weight matrix is expanded by Taylor formula, and the high-order terms are omitted to obtain the loss function Taylor expansion, which is expressed as:
[0071]
[0072] The Relu activation function is used to activate the channel weight of each filter channel in the Taylor expansion of the loss function, and the updated channel weight of each filter channel is obtained, which is updated to the pruning sensitivity of each filter, expressed as:
[0073]
[0074] in, Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; represents the feature map of the kth filter channel output of the jth filter of the i-th convolutional layer; L(X,Y;W) represents the initial network loss of the model before pruning the filter channel, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the kth filter channel of the jth filter of the i-th convolutional layer, W i,j,k←0 represents the kth filter channel in the jth filter of the ith convolutional layer; X represents the model input data, Y represents the model output value, and W represents the model weight matrix; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the set of real numbers; Relu() represents the Relu activation function.
[0075] The present invention constructs a loss function weight matrix based on the model initial network loss of each filter channel before pruning the filter channel; Taylor formula expansion is performed on the loss function weight matrix, and the channel weight of each filter channel in the Taylor expansion of the loss function is activated by using a Relu activation function, and the pruning sensitivity of each filter is updated; negative values in an input feature map are processed by the Relu activation function, and activation values corresponding to negative weights are set to zero, that is, the sensitivity of the filter channel is calculated by using the Relu activation function, so that when the weights of the filter channel are all negative values, the pruning sensitivity thereof is also 0, so that the convolutional neural network model can better learn features and improve the generalization ability of the model.
[0076] Specifically, based on the above embodiment, in an embodiment of the present invention, the model pruning method provided by the present invention is applied to an image classification model, and image classification is performed after the image classification model is pruned. The specific steps include:
[0077] S201: Obtain a dataset of images to be classified, train an image classification model, and obtain the trained image classification model as a model to be pruned;
[0078] The image classification model includes any one of VGG and ResNet;
[0079] S202: Based on the training set, calculate the model network loss after each filter channel of each filter in each convolutional layer of the to-be-pruned model is pruned, and the difference between the initial network loss of the model when no filter channel is pruned, and obtain the change in the model network loss after each filter channel is pruned as the pruning sensitivity of each filter channel;
[0080] S203: Obtain the channel weight of each filter channel in each filter of each convolutional layer in the to-be-pruned model; calculate the L2 norm of the channel weight of each filter channel, and normalize it to obtain the normalized L2 norm of each filter channel as the relative importance of each filter channel;
[0081] S204: For each filter channel in each filter of each convolutional layer in the to-be-pruned model, weighted sum the pruning sensitivity and relative importance of each filter channel based on a preset hyperparameter to obtain an importance score of each filter channel;
[0082] S205: Divide the convolutional layers with the same number of filters in the to-be-pruned model into one group, and obtain multiple groups of convolutional layer sets;
[0083] S206: for each set of convolutional layers, sort all filter channels therein in ascending order according to the importance score, and prune the first preset number of filter channels in the sorting of each set of convolutional layers based on a preset global pruning rate;
[0084] S207: Obtain the to-be-pruned model after pruning each set of convolutional layers, and obtain the target model;
[0085] S208: Input the current image to be classified into the target model to obtain an image classification result.
[0086] Specifically, the number of channels of the filter (or convolution kernel) usually matches the number of channels of the input data, but increases in subsequent convolutional layers as the number of channels of the input feature map increases, and the number of channels of the filter of the subsequent convolutional layer is the same as the number of filters of the previous layer. For example, in the VGG16 model, since RGB images are processed, the number of channels of the input data is 3 (representing the three color channels of red, green, and blue). In the first convolutional layer, the number of channels of the filter is also 3 to match the number of channels of the input image. However, in subsequent convolutional layers, since the number of channels of the input feature map increases with the increase of convolutional layers, its number of channels is equal to the number of filters of the previous convolutional layer, so the number of channels of the filter will also increase accordingly. Specifically, in the first block, the number of channels of the filter of the second convolutional layer is 64, the same as the number of filters of the first convolutional layer; in the second block, the number of channels of the filter increases to 128; and so on, until the number of channels of the filter reaches 512 in the last block.
[0087] The present embodiment proposes a filter channel-oriented model pruning method, which does not prune the filter as a whole, but takes the filter channel as the pruning object, thereby performing finer-grained pruning on the deep convolutional neural network while maintaining the structure of the pruned model, better retaining important channels, and improving the accuracy of the pruned model. And its pruning granularity is between unstructured pruning and structured pruning, which avoids the problem of sparse network caused by unstructured pruning granularity being too fine, which is not convenient for network acceleration, and avoids the problem of pruning network performance loss caused by existing structured pruning granularity being too coarse. For the pruning evaluation criteria, the present embodiment proposes a filter channel importance scoring calculation method combining pruning sensitivity and weight norm, using the weight normalized norm of the filter channel to represent the importance of the channel, using Taylor expansion to estimate the pruning sensitivity of the filter channel, and then combining the channel importance and pruning sensitivity to evaluate the importance of the filter channel. Based on the filter channel evaluation criteria that combines pruning sensitivity and importance, global group pruning is used to balance the pruning Flops and pruning parameters, so that the pruned network will not have excessive pruning of a certain layer, thereby improving the accuracy of the pruned model and thus improving the accuracy of image classification.
[0088] Based on the above embodiments, in an embodiment of the present invention, the model pruning method provided by the present invention is used, the filter channel is used as the pruning unit, and VGG16 is used as the model to be pruned; the filter channels of all convolutional layers in the pruned model are scored for global importance, and then the filter channels with lower scores are pruned according to the set pruning rate to obtain a pruned network model; a filter channel pruning method FCoNP (Filter channel-oriented network pruning) with a pruning granularity between unstructured pruning and structured pruning provided in this embodiment is referred to Figure 2 As shown, it is a schematic diagram of the process of the filter channel pruning method, and the specific steps include:
[0089] S301: Given a deep convolutional neural network with L convolutional layers;
[0090] Among them, the convolutional layer weight of the i-th convolutional layer is The filter weight of the jth filter in the i-th layer is The channel weight of the kth channel of the jth filter in the i-th layer is W i,j,k ∈R K ×K ; C i With C i+1 Represent the number of input channels and the number of input channels of the i-th convolutional layer respectively, and K represents the convolution kernel size of the i-th convolutional layer. The output feature map of the j-th filter output of the i-th convolutional layer is expressed as:
[0091] Reference Figure 2 It can be seen that the left sub-graph is the calculation process of the unpruned model, which is used to select the pruning object. The right sub-graph is the calculation process of the pruned model. When a filter channel is pruned, the input feature map channel corresponding to the filter channel is no longer convolved. i,j is the jth channel of the input feature map of the i-th layer, 1≤j≤C i+1 .
[0092] S302: In the training process of the neural network, the loss function is an indicator to measure the difference between the model prediction output and the true label. The change of the loss function directly reflects the change of the network accuracy. Therefore, this embodiment uses the loss change of the network after pruning the filter channel to evaluate the pruning sensitivity of the filter channel, which is expressed as:
[0093]
[0094] in, represents the change in the model network loss after pruning the kth channel of the jth filter of the i-th convolutional layer, X represents the input data of the model, Y represents the output value of the model, L(X,Y,W) represents the initial network loss of the model before pruning the filter channel, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the k-th channel of the j-th filter of the i-th convolutional layer.
[0095] When any filter channel is pruned, the smaller the change in model network loss is, the lower the contribution of the filter channel to the network model performance is, and the smaller the impact on the network after pruning is.
[0096] The Taylor formula expansion of the weight matrix of the filter channel with respect to the loss function is performed to obtain the Taylor expansion of the loss function, which is expressed as:
[0097]
[0098] In order to simplify the calculation, the high-order terms in the Taylor expansion of the loss function that have little impact on the loss value calculation are omitted, and only the first-order terms are retained to obtain the change in the loss function value after the filter channel is pruned, which is expressed as:
[0099]
[0100] The pruning sensitivity of each filter channel is determined by the product of its weight and gradient. The larger the value, the greater the change in the loss function after pruning and the higher the pruning sensitivity.
[0101] In the forward reasoning process of the convolutional neural network, a larger positive value in the input feature map indicates that the specific part of the learning feature is more obvious, while a negative value will inhibit the learning of the feature. Therefore, existing convolutional neural network models usually use the Relu activation function to process negative values in the input feature map. By setting the activation value corresponding to the negative weight to 0, the convolutional neural network model can better learn features and improve the generalization ability of the model.
[0102] This embodiment calculates the sensitivity of the filter channel after the Relu activation function, so that when the weights of the filter channel are all negative, its pruning sensitivity level is 0. Therefore, the calculation formula of the pruning sensitivity of the filter channel is expressed as:
[0103]
[0104] S303: Relative importance calculation;
[0105] The norm has been used to evaluate the importance of filters. Figure 3 As shown in the figure, it is a schematic diagram of the L1 norm of each filter channel in the VGG16 model. It can be seen that there are differences in the order of magnitude of the weights in different convolutional layers. If the weight norm is directly used as the pruning judgment standard, it is easy for the entire layer to be pruned. Therefore, the embodiment of the present invention adopts relative importance as the judgment standard. First, the L2 norm of the filter channel is normalized to obtain the normalized L2 norm; the relative importance of each filter channel in all channels in the same layer is calculated according to the normalized L2 norm, which is expressed as:
[0106]
[0107] S304: pruning strategy;
[0108] According to the pruning sensitivity and relative importance of each filter channel, the importance score of each filter channel is calculated, which is expressed as:
[0109]
[0110] Among them, β is a preset hyperparameter used to adjust the relative weight of pruning sensitivity and relative importance.
[0111] Since the number of floating-point operations Flops is positively correlated with the size of the feature map, and as the network depth increases, the size of the feature map output by the convolutional layer usually decreases. When pruning in a deep network, although a large number of parameters can be reduced, the reduction in Flops may be relatively limited. In order to balance the amount of pruned parameters and pruned Flops, the embodiment of the present invention uses filter group pruning to group convolutional layers with the same number of filters. Each group is pruned according to the predefined pruning rate and the calculated importance score; refer to Figure 4 As shown, this is a schematic diagram of pruning grouping based on the VGG16 model.
[0112] The filter channel importance score-based pruning strategy (FCoNP) proposed in the embodiment of the present invention achieves finer-grained pruning than traditional structured pruning, and avoids the disadvantage of unstructured pruning that is limited in hardware device deployment. In addition, this embodiment also designs a group-wide global pruning strategy based on the sensitivity and relative importance of the filter channel, and realizes the adaptive pruning rate calculation within the group under the condition of setting the global pruning rate. Experimental results show that FCoNP has better performance, achieves a balance between a higher pruning rate and maintaining model accuracy through a finer-grained pruning method, and is better than most current pruning algorithms.
[0113] Based on the above embodiments, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the model pruning method described above are implemented.
[0114] Based on the above embodiments, the embodiments of the present invention use the model pruning method provided by the present invention to perform pruning comparison experiments on VGG16, ResNet56, and ResNet110 in the CI FAR-10 dataset; Referring to Table 1, the experimental results of the model pruning method FCoNP provided by the present invention and the traditional method on the VGG16, Resnet56, and Resnet110 models are compared;
[0115] Table 1 Experimental results on CI FAR-10
[0116]
[0117]
[0118] Among them, "Model" represents the model used in the experiment, "Method" represents the different traditional pruning methods compared, "Baseline" represents the accuracy of the unpruned model, "Top-1" represents the accuracy of the pruned model, "Acc.↓" represents the accuracy loss of the model after pruning, "Flpos.↓" represents the amount of floating-point calculations reduced by the model, and "Params.↓" represents the number of parameters reduced by the model.
[0119] For VGG16, it can be seen from Table 1 that the FCoNP provided by the present invention is significantly better than other pruning methods. Although the parameter pruning rates of Hrank, CHIP and CSHE are higher than those of FCP (65.00% vs 82.10% vs 78.20% vs 66.30%), the former reduces the classification accuracy after pruning, while FCP improves the classification accuracy by 0.61% after pruning, and the Flops pruning rate of FCoNP is slightly higher than that of the former (67.90% vs 65.30% vs 40.70% vs 65.70%). In addition, compared with the two latest pruning methods ASTER and AFpruner, the FCP provided by the embodiment of the present invention not only achieves a higher classification accuracy improvement (0.61% vs 0.31% vs 0.53%), but also achieves a higher Flops pruning rate (67.90% vs 67.75% vs 63.70%).
[0120] For Resnet56, it can be seen from Table 1 that most methods reduce the classification accuracy after pruning, while FCoNP significantly improves the classification accuracy based on the baseline. Compared with CHIP, although the improvement in classification accuracy after FCoNP pruning is lower (0.46% vs 0.9%), the Flops pruning rate (54.75% vs 47.40%) and parameter pruning rate (51.59% vs 40.80%) are higher. In addition, compared with the latest pruning methods ASTER, AFpruner, He et al. and Lee et al., FCoNP has a higher improvement in classification accuracy after pruning when the pruning rate is basically the same.
[0121] For Resnet110, even after pruning 55.34% of the Flops and 52.59% of the parameters, the classification accuracy after FCoNP pruning is improved by 0.9% on the basis of the baseline. FCoNP is superior to most of the current methods in terms of both pruning rate and loss of classification accuracy after pruning. Among the methods compared in the embodiments of the present invention, although the pruning rates of Hrank and ABCPruner are higher than those of FCoNP, the improvement of classification accuracy after FCoNP pruning is slightly higher (0.90% vs -0.14% vs 0.08%). Regarding the improvement of classification accuracy, although CHIP and ASTER are slightly higher than FCoNP, the Flops pruning rate of FCoNP is slightly higher (55.34% vs 52.10% vs 52.30%).
[0122] Based on the above embodiments, the embodiments of the present invention use the model pruning method provided by the present invention to perform pruning comparison experiments on Resnet18 and Resnet50 in ILSVRC-2012 respectively; referring to Table 2, the experimental results of the model pruning method FCoNP provided by the present invention and the traditional method on the Resnet18 and Resnet50 models are compared;
[0123] Table 2 Experimental results on ILSVRC-2012
[0124]
[0125] For ResNet18, FCoNP achieved the best results in both Top-1 and Top-5 accuracy after pruning. For methods with lower FCoNP pruning rates than FCoNP, such as Azadeh, SFP, ASFP, etc., FCoNP is undoubtedly superior to them in all aspects. For ABCPruner, although the Flops pruning rate is 0.48% higher than FCP, when the Baseline is higher than FCoNP, the Top-1 and Top-5 accuracy of FCoNP after pruning are 1.08% and 0.7% higher than ABCPruner, respectively. For AFpruner, although its Flops pruning rate is 3.82% higher than FCP, FCoNP has a lower accuracy drop after pruning, whether it is Top-1 accuracy or Top-5 accuracy.
[0126] For ResNet50, FCoNP still outperforms most existing methods in terms of pruning rate and accuracy. For methods with slightly higher FCoNP pruning rates than FCoNP, such as FPGM, CSHE, Heetal., and ABCPruner, the Top-1 and Top-5 accuracy losses after FCoNP pruning are much lower than them. Although ASTER has a higher FCoNP pruning rate than FCoNP and a slightly lower Top-5 accuracy loss than this embodiment, the Top-1 loss of FCoNP after pruning is much lower than the former.
[0127] The model pruning method and computer-readable storage medium described in the present invention take into account the differences between different filter channels in the same filter, take the filter channel as the pruning unit, calculate the change in model network loss after each filter channel is pruned, and the normalized L2 norm of each filter channel as the pruning sensitivity and relative importance of each filter channel; construct an importance score based on the pruning sensitivity and relative importance as a pruning judgment standard for the filter channel, so that the pruning granularity is between unstructured pruning and structured pruning, that is, avoids the problem of sparse network caused by unstructured pruning granularity being too fine and not convenient for network acceleration, and avoids the problem of pruning network performance loss caused by existing structured pruning granularity being too coarse. The present invention divides convolutional layers with the same number of filters into a group, obtains multiple groups of convolutional layer sets, sorts all the filter channels in each group of convolutional layer sets in order of importance scores from small to large, and prunes the filter channels of the first preset number in the sorting of each group of convolutional layer sets based on a preset pruning rate; by performing global group pruning on the pruned model, the number of pruning floating-point operations Flops and the amount of pruning parameters are balanced, so that the pruned network will not have the phenomenon of excessive pruning of a certain layer, and the adaptive pruning rate calculation within the group is realized under the condition of the preset pruning rate, thereby improving the pruning efficiency. The present invention constructs a loss function weight matrix based on the model initial network loss of each filter channel before pruning the filter channel; Taylor formula expansion is performed on the loss function weight matrix, and the channel weight of each filter channel in the Taylor expansion of the loss function is activated by using a Relu activation function, and the pruning sensitivity of each filter is updated; negative values in an input feature map are processed by the Relu activation function, and activation values corresponding to negative weights are set to zero, that is, the sensitivity of the filter channel is calculated by using the Relu activation function, so that when the weights of the filter channel are all negative values, the pruning sensitivity thereof is also 0, so that the convolutional neural network model can better learn features and improve the generalization ability of the model.
[0128] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0129] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0130] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0131] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0132] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.
Claims
1. A model pruning method, characterized in that: include: Obtain a deep convolutional neural network containing multiple convolutional layers as a model to be pruned; Based on the training set, the model network loss after each filter channel of each filter in each convolutional layer of the to-be-pruned model is calculated, and the difference between the initial network loss of the model when no filter channel is pruned is calculated, and the change in the model network loss after each filter channel is pruned is obtained as the pruning sensitivity of each filter channel; Obtaining the channel weight of each filter channel in each filter of each convolutional layer in the model to be pruned; Calculate the L2 norm of the channel weight of each filter channel and normalize it to obtain the normalized L2 norm of each filter channel as the relative importance of each filter channel; For each filter channel in each filter of each convolutional layer in the model to be pruned, the pruning sensitivity and relative importance of each filter channel are weighted summed based on the preset hyperparameters to obtain the importance score of each filter channel; Divide the convolutional layers with the same number of filters in the to-be-pruned model into a group to obtain a plurality of groups of convolutional layer sets; For each set of convolutional layers, all filter channels are sorted in ascending order according to their importance scores, and based on the preset global pruning rate, the filter channels of the first preset number in the sorting of each set of convolutional layers are pruned respectively; The model to be pruned is obtained after pruning each set of convolutional layers, and the target model is obtained.
2. The model pruning method according to claim 1, characterized in that: The deep convolutional neural network comprising multiple convolutional layers includes any one of VGG16, Resnet56, Resnet110, Resnet18 and Resnet50.
3. The model pruning method according to claim 1, characterized in that: The pruning sensitivity of each filter channel is expressed as: Among them, the pruning sensitivity of the k-th filter channel of the j-th filter in the i-th convolutional layer is Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; It represents the feature map of the k-th filter channel output of the j-th filter of the i-th convolutional layer, expressed as C i Represents the number of input channels of the i-th convolutional layer, 1≤k≤C i , X i,k Represents the output feature map of the kth filter of the i-th convolutional layer; L(X,Y;W) represents the initial network loss of the model when no filter channel is pruned, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the k-th filter channel of the j-th filter in the i-th convolutional layer; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K , R represents a real number set; X represents the model input data, Y represents the model output value, and W represents the model weight matrix.
4. The model pruning method according to claim 3, characterized in that: The model network loss is expressed as: Where n represents the number of prediction categories. Represents the predicted probability of the tth class, expressed as Function f() represents a network flow.
5. The model pruning method according to claim 1, characterized in that: After obtaining the pruning sensitivity of each filter channel, it also includes: Get the model initial network loss of each filter channel before pruning the filter channel, and construct the loss function weight matrix; Performing Taylor expansion on the loss function weight matrix and omitting high-order terms to obtain a Taylor expansion of the loss function; The Relu activation function is used to activate the channel weight of each filter channel in the Taylor expansion of the loss function, and the updated channel weight of each filter channel is obtained, which is updated to the pruning sensitivity of each filter.
6. The model pruning method according to claim 5, characterized in that: The loss function weight matrix is subjected to Taylor formula expansion, and high-order terms are omitted to obtain the loss function Taylor expansion, which is expressed as: in, Represents the change in model network loss after pruning the k-th filter channel of the j-th filter of the i-th convolutional layer; represents the feature map of the kth filter channel output of the jth filter of the i-th convolutional layer; L(X,Y;W) represents the initial network loss of the model before pruning the filter channel, L(X,Y;W i,j,k←0 ) represents the model network loss after pruning the kth filter channel of the jth filter of the i-th convolutional layer, W i,j,k←0 represents the kth filter channel in the jth filter of the ith convolutional layer; X represents the model input data, Y represents the model output value, and W represents the model weight matrix; W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the set of real numbers; It means partial derivative.
7. The model pruning method according to claim 6, characterized in that: The Relu activation function is used to activate the channel weight of each filter channel in the Taylor expansion of the loss function to obtain the updated channel weight of each filter channel, which is expressed as: Among them, Relu() represents the Relu activation function.
8. The model pruning method according to claim 1, characterized in that: The relative importance of each filter channel is expressed as: Among them, I i,j,k represents the relative importance of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k represents the channel weight of the kth filter channel in the jth filter of the i-th convolutional layer, W i,j,k ∈R K×K ,R represents the real number set; || ||2 represents the L2 norm; C i With C i+1 Respectively represent the number of input channels and output channels of the i-th convolutional layer, 1≤j≤C i+1 , 1≤k≤C i .
9. The model pruning method according to claim 1, characterized in that: The importance score of each filter channel is expressed as: Among them, S i,j,k represents the importance score of the kth filter channel in the jth filter of the i-th convolutional layer, and β is a preset hyperparameter; represents the pruning sensitivity of the kth filter channel in the jth filter of the i-th convolutional layer after pruning, I i,j,k represents the relative importance of the k-th filter channel in the j-th filter of the i-th convolutional layer.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the model pruning method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Global rank perception neural network model compression method based on filter feature map
CN114037844A
Convolutional neural network model pruning method and device, electronic equipment and storage medium
CN114330713A
Pruning method and device for multi-task neural network model
CN114492783A
Neural network compression method combining channel global sorting guidance pruning and quantization
CN115661511A
Joint pruning method and system based on global multi-source interlayer
CN116341645A
Cited By
Convolutional neural network pruning method and device based on static and dynamic combination
CN119990229A
A static-dynamic joint-based convolutional neural network pruning method and device
CN119990229B
Elevator lever drum brake fault detection method, device and equipment
CN121456527A
An elevator lever drum brake fault detection method, device and equipment
CN121456527B
