Image classification model compression method based on soft pruning

By dynamically adjusting the structure during the training of the image classification model and using a soft pruning method to select and update important parameters, the problems of high resource consumption and performance degradation of traditional pruning methods are solved, achieving efficient model compression and accuracy preservation.

CN118228799BActive Publication Date: 2026-11-24YUNNAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410404766.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-03
Publication Date
2026-11-24
Estimated Expiration
2044-04-03

AI Technical Summary

Technical Problem

Existing deep neural network models for image classification suffer from high computational resources and power consumption due to their large number of parameters. Traditional pruning methods also suffer from high resource consumption and performance degradation, and are prone to erroneously pruning important connections during the pruning process.

Method used

A soft pruning-based approach is adopted to dynamically adjust the structure during the training of the image classification model. By calculating the zeroing rate and the absolute value of the gradient, important parameters are selected for updating, and non-critical parameters are gradually pruned to avoid erroneous pruning and achieve model compression.

Benefits of technology

While ensuring classification accuracy, it reduces training time and resource consumption, automatically obtains high-performance models, avoids erroneous pruning of important connections, and achieves effective model compression.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118228799B_ABST
    Figure CN118228799B_ABST
Patent Text Reader

Abstract

This invention discloses a method for compressing an image classification model based on soft pruning. First, image training samples are acquired and the image classification model is initialized. In each training round of the soft pruning phase, the zeroing rate for the current round is calculated. After each batch of training in the current round, the number of updated parameters for each layer of the network is obtained based on the zeroing rate. Then, the parameters with the largest absolute gradient value are selected for updating, while the remaining parameters are not updated. After each training round, the parameters with the smallest absolute values ​​are set to zero according to the zeroing rate. When the training reaches a given number of pruning rounds, the image classification model is pruned according to a preset pruning rate. Subsequent training uses conventional methods. This invention can dynamically adjust the structure of the image classification model during network model training, achieving effective compression of the image classification model while ensuring classification accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision technology, and more specifically, relates to an image classification model compression method based on soft pruning. Background Technology

[0002] In recent years, deep neural networks (DNNs) have attracted widespread attention and have been extensively applied in fields such as image classification. However, DNN models for image classification typically have millions or even billions of parameters. Such complex and large models place extremely high demands on the CPU and GPU of computers, consume a large amount of memory, and generate huge computational costs. Image classification model compression aims to solve the resource constraints and power consumption problems caused by the excessive number of parameters and computational burden. Its methods include, but are not limited to, pruning, quantization, and distillation techniques, which can achieve the goal of efficiently running image classification models in resource-constrained environments such as embedded devices and mobile terminals.

[0003] The traditional three-stage pruning process involves first training an initial dense network, then identifying and pruning redundant parts of the network based on pruning algorithm evaluation metrics, and finally fine-tuning the pruned model. However, many traditional pruning algorithms are greedy and aggressive, potentially causing many important network connections to be incorrectly pruned, leading to significant performance degradation. Therefore, they often require repeated pruning and fine-tuning operations, resulting in substantial time and resource consumption during training. The lottery hypothesis, proposed in recent years, has brought a new perspective to the field of pruning. It posits that a randomly initialized network already contains a subnetwork with performance comparable to redundant and complex networks, and this subnetwork can be discovered early in training, or even before training begins.

[0004] While numerous in-training pruning methods have emerged, they all suffer from various problems. Y. Guo et al. proposed dynamically maintaining the network structure during training, but their method requires an additional discriminant matrix to determine which connections to retain, necessitating continuous updates to the mask matrix during training. Y. He et al. addressed structured pruning, allowing subsequent updates to pruned filters during training, but artificially imposed a fixed sparsity rate on each layer. However, in deep neural networks, the parameters of each layer have different impacts on the final result. For image classification tasks, the preceding feature extraction layers and the final output classification layer are crucial; therefore, artificially setting the same pruning rate for each layer is clearly not optimal. M. Zhu et al. proposed a progressive pruning approach, but their method is greedy and unrecoverable, heavily influenced by the learning rate. Stochastic gradient descent and its many variants typically decay the learning rate during training. They observed that pruning with extremely low learning rates makes it difficult for subsequent training steps to recover from the accuracy loss caused by forcing weights to zero. Summary of the Invention

[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide an image classification model compression method based on soft pruning, which can dynamically adjust the structure of the image classification model during the network model training process, and achieve effective compression of the image classification model while ensuring classification accuracy.

[0006] To achieve the above-mentioned objective, the image classification model compression method based on soft pruning of the present invention includes the following steps:

[0007] S1: Obtain the corresponding training sample set according to the actual application scenario of the image classification model. Each training sample includes an image sample and its corresponding label.

[0008] S2: Initialize the parameters of the image classification model to be compressed, denoted as follows: , This indicates the number of layers in an image classification model. Indicates the first The parameter matrix of the layer, , They represent the first Layer, First The number of neurons in a layer, where layer 0 represents the input layer;

[0009] S3: Increase training rounds ;

[0010] S4: Execute the... Training in softwood pruning includes the following steps:

[0011] S4.1: Calculate the zeroing rate for the current training round using the following formula. :

[0012] ,

[0013] in, This indicates the preset final pruning rate. This represents the maximum preset number of soft pruning training rounds. Indicated by training rounds Let be a monotonically increasing function of the variable, and ;

[0014] S4.2: Divide the training sample set into... One training batch;

[0015] S4.3: Let the training batch number ;

[0016] S4.4: Input the image samples from the current training batch into the current image classification model, and calculate the loss function based on the labels and image classification results. Then, the gradient matrix of the parameters of each layer is calculated. Let the gradient of each parameter be denoted as . , , ;

[0017] S4.5: For the network parameters of each layer, adjust the zeroing rate according to the current round. Calculate the number of parameters that need to be updated for this layer. :

[0018] ,

[0019] in, This indicates the search for the 0 norm;

[0020] S4.6: For the network parameters of each layer, calculate the parameters according to the absolute value of the gradient. Sort from largest to smallest, select the first... One parameter is used as the parameter for this layer in this round of update, and its gradient remains unchanged, while the gradients of the remaining parameters are set to 0;

[0021] S4.7: Update all network parameters based on the current gradient;

[0022] S4.8: Determine if If yes, proceed to step S4.9; otherwise, proceed to step S4.10.

[0023] S4.9: Order Return to step S4.4;

[0024] S4.10: Sort all current parameters of the image classification model in descending order of their absolute values, and then... Set each parameter to 0. This represents the total number of parameters in the image classification model;

[0025] S5: Determine if If yes, proceed to step S6; otherwise, proceed to step S7.

[0026] S6: Order Return to step S4;

[0027] S7: Prune the image classification model based on the parameters that are 0 in the current image classification model;

[0028] S8: Order ;

[0029] S9: Determine if , This indicates the total number of training rounds of the network. If yes, proceed to step S10; otherwise, the image classification model compression ends.

[0030] S10: Divide the training sample set into... The model performs a training batch, and then sequentially inputs the image samples from each training batch into the current image classification model. The loss function is then calculated based on the labels and image classification results. Update the parameters of the current image classification model; return to step S8.

[0031] This invention relates to an image classification model compression method based on soft pruning. First, image training samples are acquired and the image classification model is initialized. In each training round of the soft pruning training phase, the zeroing rate for the current round is calculated. After each batch of training in the current round is completed, the number of updated parameters for each layer of the network is obtained according to the zeroing rate. Then, the parameters with the largest absolute gradient value are selected for updating, while the other parameters are not updated. After each training round, the parameters with the smallest absolute values ​​are set to zero according to the zeroing rate. When the training reaches a given number of pruning rounds, the image classification model is pruned according to a preset pruning rate. Subsequent training is then carried out using conventional training methods.

[0032] The present invention has the following beneficial effects:

[0033] 1) This invention abandons the three-stage pruning process of "pre-training-pruning-fine-tuning". Given the pruning rate of the network, a high-performance model can be automatically obtained after the image classification model training is completed, reducing the consumption of time and resources.

[0034] 2) By limiting gradients and incrementally zeroing out networks during network training, this invention avoids erroneous pruning of important network connections, and can effectively ensure the classification accuracy of the model during compression. Attached Figure Description

[0035] Figure 1 This is a flowchart illustrating a specific implementation of the image classification model compression method based on soft pruning according to the present invention.

[0036] Figure 2 This is a flowchart of the soft pruning training process in this invention;

[0037] Figure 3 This is an example diagram of image classification model compression in this embodiment;

[0038] Figure 4 This is a graph showing the relationship between the parameter update ratio and the parameter zeroing ratio under different zeroing rate calculation formulas in this embodiment. Detailed Implementation

[0039] The specific embodiments of the present invention will now be described with reference to the accompanying drawings to enable those skilled in the art to better understand the invention. It should be particularly noted that in the following description, detailed descriptions of known functions and designs that might obscure the main content of the invention will be omitted here.

[0040] Example

[0041] Figure 1 This is a flowchart illustrating a specific implementation of the image classification model compression method based on soft pruning according to the present invention. Figure 1 As shown, the specific steps of the image classification model compression method based on soft pruning of the present invention include:

[0042] S101: Obtain the training sample set:

[0043] The corresponding training sample set is obtained based on the actual application scenario of the image classification model. Each training sample includes an image sample and its corresponding label.

[0044] S102: Initialize the image classification model:

[0045] The parameters of the image classification model to be compressed are initialized, and their parameters are denoted as follows. , This indicates the number of layers in an image classification model. Indicates the first The parameter matrix of the layer, , They represent the first Layer, First The number of neurons in each layer, with layer 0 representing the input layer. Subsequent compression operations involve dynamically pruning this initial image classification model during its training process.

[0046] S103: Set the number of training epochs. .

[0047] S104: Execute the... Rotary pruning training:

[0048] In this invention, the entire training process can be divided into two main stages. The first stage is soft pruning training. After soft pruning training is completed, a pruning compression is performed, followed by the second stage of normal training, thereby completing the entire image classification model compression process. Figure 2 This is a flowchart of the soft pruning training process in this invention. (For example...) Figure 2 As shown, the specific steps of soft pruning training in this invention include:

[0049] S201: Calculate the zeroing rate for this round:

[0050] The training process of a redundant and dense network is similar to the development of the human brain. During childhood, the brain activates a large number of neurons and connections when encountering a new task. Through continuous learning, the brain uses only a small number of neurons and connections when faced with the same task again in adulthood. Based on this principle, this invention updates weights with larger gradients, while weights with smaller gradients show less change in value after updating, thus maintaining their original values. Therefore, this invention introduces a zeroing rate. This allows for dynamic adjustment of its substructures during network training, with a zeroing rate. The calculation formula is:

[0051] ,

[0052] in, This indicates the preset final pruning rate. This represents the maximum preset number of soft pruning training rounds; in this embodiment, it is set as the total number of network training rounds. Half of it. Indicated by training rounds Let be a monotonically increasing function of the variable, and This embodiment designs three different methods for calculating the zero-set rate, and their calculation formulas are as follows:

[0053] ,

[0054] ,

[0055] .

[0056] S202: Divide the training batches:

[0057] Divide the training sample set into Training batches.

[0058] S203: Let the training batch number... .

[0059] S204: Perform training for the current batch.

[0060] The image samples from the current training batch are input into the current image classification model, and the loss function is calculated based on the labels and image classification results. Then, the gradient matrix of the parameters of each layer is calculated. Let the gradient of each parameter be denoted as . , , .

[0061] S205: Calculate the number of updated parameters:

[0062] For the network parameters of each layer, the zeroing rate is determined according to the current round. Calculate the number of parameters that need to be updated for this layer. :

[0063] ,

[0064] in, This indicates the search for the 0 norm.

[0065] S206: Update parameter gradient:

[0066] For the network parameters of each layer, the parameters are sorted according to the absolute value of the gradient. Sort from largest to smallest, select the first... One parameter is used as the parameter for this layer in this round of update, and its gradient remains unchanged, while the gradients of the remaining parameters are set to 0.

[0067] S207: Update parameters:

[0068] Update all network parameters based on the current gradient.

[0069] S208: Determine if If yes, proceed to step S209; otherwise, proceed to step S210.

[0070] S209: Order Return to step S204.

[0071] S210: Soft pruning operation:

[0072] Sort all the current parameters of the image classification model in descending order of their absolute values, and then... Set each parameter to 0. This represents the total number of parameters in the image classification model.

[0073] S105: Determine if If yes, proceed to step S106; otherwise, proceed to step S107.

[0074] S106: Order Return to step S104.

[0075] S107: Image classification model pruning:

[0076] The image classification model is pruned based on the parameters that are zero in the current image classification model, that is, the parameters that are zero are deleted.

[0077] S108: Order .

[0078] S109: Determine if , This indicates the total number of training rounds for the network. If so, proceed to step S110; otherwise, the image classification model compression ends.

[0079] S110: Routine Training

[0080] Divide the training sample set into The model performs a training batch, and then sequentially inputs the image samples from each training batch into the current image classification model. The loss function is then calculated based on the labels and image classification results. Update the parameters of the current image classification model. Then return to step S108.

[0081] As described above, in the soft pruning training process of this invention, the weights of some parameters with lower weights are set to zero, thereby achieving pruning and compression of the image classification model. This invention adopts an incremental zeroing rate calculation method, that is, the number of zeroing rates increases with the increase of training rounds. At the same time, the pruning threshold is obtained based on the global ranking of network parameters, which more comprehensively considers the importance of parameters in different layers, thereby achieving the optimal sparsity of different layers. Figure 3 This is an example diagram of image classification model compression in this embodiment. For example... Figure 3 As shown, taking a multilayer perceptron with a single hidden layer and two output neurons as an example, its corresponding weight matrix can be expressed as follows: and :

[0082] , ,

[0083] During the training of each network round, the parameters are updated based on the absolute value of the gradient of each network layer.

[0084] When a network training epoch ends, the parameters are sorted in descending order according to the absolute value of each parameter, and the last one is... Setting a parameter to 0 doesn't actually delete it; instead, it allows the zeroed-out parameter to continue updating in the next training epoch. This operation preserves the model's expressive power while avoiding erroneous pruning of the network during training. Some network connections may seem unimportant at this stage, but their importance gradually increases as the network trains and other parameters are zeroed.

[0085] In this invention, during the early stages of image classification model training, before the parameter values ​​have converged, a relatively small zeroing rate should be used to ensure normal model training. As the model training gradually converges, only important parameter connections are updated, and the zeroing rate gradually approaches the pruning rate. The zeroing rate for the current round is calculated using a zeroing rate growth function. Afterwards, two main steps are performed for each training epoch: First, after obtaining the gradients of the model parameters through backpropagation, for each layer of the network parameters, only the gradients of the first layer are updated. The parameters are set as follows, while the remaining parameters remain unchanged. Secondly, after each training epoch, a global descending sort is performed based on the absolute values ​​of the parameter weights, placing the parameters ranked last... The parameter weights are set to 0, while allowing them to continue to be updated in subsequent training. Figure 4 This is a graph showing the relationship between the parameter update ratio and the parameter zeroing ratio under different zeroing rate calculation formulas in this embodiment. For example... Figure 4 As shown, in this invention, the parameter update ratio and the parameter zeroing ratio exhibit an inverse relationship.

[0086] To better illustrate the technical solution of this invention, specific examples are used to experimentally verify the invention. In this embodiment, the training sample sets are CIFAR-10 and ImageNet, and the image classification models used are the common VGG-16, RestNet-20, RestNet-32, and WideResNet-16-8. Four existing model compression methods are selected as comparison methods:

[0087] SNIP, see the document "Lee, Namhoon, Thalaiyasingam Ajanthan, and Philip HSTorr. "Snip: Single-shot network pruning based on connection sensitivity." arXiv preprint arXiv:1810.02340 (2018).";

[0088] SM, see "Dettmers, Tim, and Luke Zettlemoyer. "Sparse networks from scratch: Faster training without losing performance." arXiv preprintarXiv:1907.04840 (2019).";

[0089] For DSR, see the document "Mostafa, Hesham, and Xin Wang. "Parameter efficienttraining of deep convolutional neural networks by dynamic sparsereparameterization." International Conference on Machine Learning. PMLR, 2019.";

[0090] DPF, see the literature "Lin, Tao, et al. "Dynamic model pruning with feedback." arXiv preprint arXiv:2006.07253 (2020)."

[0091] Using the present invention and four comparison methods, image classification models were compressed by performing pruning operations at different pruning resolutions. The Top-1 accuracy of each image classification model was then tested. Table 1 compares the accuracy of each image classification model on the CIFAR-10 dataset at different pruning rates in this embodiment.

[0092]

[0093] Table 1

[0094] As shown in Table 1, on the CIFAR-10 image classification dataset, the accuracy of the proposed method after pruning and compression under different models and pruning rates is superior to the four comparative methods. Especially under high sparsity conditions, the proposed method shows a significant improvement compared to other methods.

[0095] Next, on the larger image classification dataset ImageNet, the ResNet-50-based image classification model was pruned and compressed. The initial dense ResNet-50 achieved a Top-1 accuracy of 76.80% with 25.56M parameters. The compression methods compared included SNIP, SM, DSR, and others.

[0096] SET, see the literature "Mocanu, Decebal Constantin, et al. "Scalable training ofartificial neural networks with adaptive sparse connectivity inspired by network science." Nature communications 9.1 (2018): 2383.";

[0097] DST, see the document "Liu, Junjie, et al. "Dynamic sparse training: Findefficient sparse network from scratch with trainable masked layers." arXivpreprint arXiv:2005.06870 (2020).";

[0098] RigL, see the document "Evci, Utku, et al. "Rigging the lottery: Making alltickets winners." International conference on machine learning. PMLR, 2020.".

[0099] Table 2 is a comparison of the accuracy of various image classification models on the ImageNet dataset under different pruning rates in this embodiment.

[0100]

[0101] Table 2

[0102] As shown in Table 2, on the larger image classification dataset ImageNet, compared with existing methods, the present invention can achieve better classification accuracy with the same or even fewer parameters.

[0103] Although the illustrative specific embodiments of the present invention have been described above to enable those skilled in the art to understand the invention, it should be understood that the invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the invention as defined and determined by the appended claims, and all inventions utilizing the concept of the present invention are protected.

Claims

1. A compression method for image classification models based on soft pruning, characterized in that, Includes the following steps: S1: Obtain the corresponding training sample set according to the actual application scenario of the image classification model. Each training sample includes an image sample and its corresponding label. S2: Initialize the parameters of the image classification model to be compressed, denoted as follows: , This indicates the number of layers in an image classification model. Indicates the first The parameter matrix of the layer, , They represent the first Layer, First The number of neurons in a layer, where layer 0 represents the input layer; S3: Increase training rounds ; S4: Execute the... Training in softwood pruning includes the following steps: S4.1: Calculate the zeroing rate for the current training round using any one of the following three formulas. : , , , in, This indicates the preset final pruning rate. This represents the maximum preset number of soft pruning training rounds; S4.2: Divide the training sample set into... One training batch; S4.3: Let the training batch number ; S4.4: Input the image samples from the current training batch into the current image classification model, and calculate the loss function based on the labels and image classification results. Then, the gradient matrix of the parameters of each layer is calculated. Let the gradient of each parameter be denoted as . , , ; S4.5: For the network parameters of each layer, adjust the zeroing rate according to the current round. Calculate the number of parameters that need to be updated for this layer. : ; in, This indicates the search for the 0 norm; S4.6: For the network parameters of each layer, calculate the parameters according to the absolute value of the gradient. Sort from largest to smallest, select the first... One parameter is used as the parameter for this layer in this round of update, and its gradient remains unchanged, while the gradients of the remaining parameters are set to 0; S4.7: Update all network parameters based on the current gradient; S4.8: Determine if If yes, proceed to step S4.9; otherwise, proceed to step S4.

10. S4.9: Order Return to step S4.4; S4.10: Sort all current parameters of the image classification model in descending order of their absolute values, and then... Set each parameter to 0. This represents the total number of parameters in the image classification model; S5: Determine if If yes, proceed to step S6; otherwise, proceed to step S7. S6: Order Return to step S4; S7: Prune the image classification model based on the parameters that are 0 in the current image classification model; S8: Order ; S9: Determine if , This indicates the total number of training rounds of the network. If yes, proceed to step S10; otherwise, the image classification model compression ends. S10: Divide the training sample set into... The model performs a training batch, and then sequentially inputs the image samples from each training batch into the current image classification model. The loss function is then calculated based on the labels and image classification results. Update the parameters of the current image classification model; return to step S8.

2. The image classification model compression method according to claim 1, characterized in that, The maximum number of soft pruning training rounds , This indicates the total number of training rounds for the network.