Neural network model pruning method and apparatus
By adding branches to the convolution connection for pruning training and merging, the problem of performance and accuracy loss caused by neural network model pruning in the existing technology is solved, and more thorough model pruning and resource optimization are achieved.
Patent Information
- Application Number
- PCT/CN2024/077797
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-28
- Filing Date
- 2024-02-20
- Publication Date
- 2024-10-31
AI Technical Summary
Existing neural network model pruning methods can easily lead to performance loss and accuracy loss. Especially in mobile phone devices, the channel pruning algorithm has difficulty in pruning jump connection structures, resulting in incomplete pruning of the model, resulting in overall performance and accuracy loss.
Add branches to the convolution connection to be pruned, perform pruning training, use the gate function to determine whether the branch meets the pruning conditions, and obtain the maximum number of pruning channels, perform pruning merging, and realize pruning of the convolution connection.
Through this method, the performance loss and accuracy loss of the neural network model are reduced, more thorough model pruning is achieved, the lightweight and accuracy of the model are improved, especially in mobile devices, the demand for computing and memory resources is effectively reduced. .
Smart Images

Figure CN2024077797_31102024_PF_FP_ABST
Abstract
Description
Pruning method and device for neural network model
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This disclosure is based on Chinese patent application CN202310491379.X filed on April 28, 2023, entitled “Pruning Method and Device for Neural Network Model”, and claims the priority of the patent application, and all the contents disclosed therein are incorporated into this disclosure by reference. Technical Field
[0003] The present disclosure relates to the field of convolutional neural networks, and more specifically, to a method and apparatus for pruning a neural network model. Background Art
[0004] Image denoising for mobile devices typically requires a lightweight and highly accurate network model. Most existing channel pruning algorithms impose a penalty term on the loss function, gradually reducing the parameters of some channels within the convolution kernel during learning. This prunes channels with smaller parameters, thereby creating structural sparsity. The loss function of these methods includes both a loss term related to network model accuracy and a penalty term that penalizes the convolution channels. During pruning training, the loss term related to network model accuracy is small, while the penalty term is large. The penalty term dominates the loss function, reducing the parameters of certain channels within the convolution kernel and, consequently, decreasing accuracy, which in turn increases the loss term related to network model accuracy. When the loss term related to network model accuracy and the penalty term become close, they compete with each other, and the penalty term no longer dominates. Consequently, the parameters of certain channels within the convolution kernel no longer decrease, and pruning training terminates. During pruning, the pruned channels with relatively small parameters still account for a certain proportion of the network model's weight. Therefore, this pruning method inevitably results in performance degradation of the network model. In addition, most channel pruning algorithms based on convolutional neural networks have the same accuracy requirements for each convolutional layer, that is, the accuracy requirements are placed equally on each convolutional layer, and each layer is pruned and trained separately. In order to balance the accuracy requirements, some layers may no longer be pruned. However, for the entire network, the importance of each layer varies. In vertical comparison, the pruned channels are relatively less important in the current convolutional layer, but may be more important than the unpruned channels in other layers, resulting in some unnecessary accuracy loss in the pruned network. In addition, existing channel pruning methods have difficulty pruning jump connection structures. However, mobile phone noise reduction models usually contain a large number of jump connection structures, so existing channel pruning methods do not prune the model thoroughly.
[0005] In summary, existing pruning methods have the problem of easily causing performance loss and accuracy loss in the model.
[0006] Summary of the Invention
[0007] The embodiments of the present disclosure provide a method and apparatus for pruning a neural network model to at least solve the problem in the related art of performance loss and accuracy loss in the neural network model after pruning.
[0008] According to one embodiment of the present disclosure, a pruning method for a neural network model is provided, comprising: adding a branch to a convolutional connection to be pruned, and performing pruning training on the branch, wherein the branch includes two first convolutional layers; judging whether the branch meets a pruning condition based on the pruning training result, and obtaining a maximum number of pruning channels if the branch meets the pruning condition; pruning the branch according to the maximum number of pruning channels, and merging the pruned branch with the convolutional connection to complete the pruning of the convolutional connection.
[0009] According to another embodiment of the present disclosure, a pruning device for a neural network model is provided, comprising: a training module for adding branches to convolutional connections to be pruned and performing pruning training on the branches, wherein the branches include two first convolutional layers; a judgment module for judging whether the branches meet pruning conditions based on the pruning training results, and obtaining a maximum number of pruning channels if the branches meet the pruning conditions; and a merging module for pruning the branches according to the maximum number of pruning channels, and merging the pruned branches with the convolutional connections to complete the pruning of the convolutional connections.
[0010] According to another embodiment of the present disclosure, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.
[0011] According to another embodiment of the present disclosure, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] FIG1 is a hardware structure block diagram of a computer terminal for a pruning method of a neural network model according to an embodiment of the present disclosure;
[0013] FIG2 is a flow chart of a pruning method for a neural network model according to an embodiment of the present disclosure;
[0014] FIG3 is a structural block diagram of a pruning device for a neural network model according to an embodiment of the present disclosure;
[0015] FIG4 is a schematic diagram showing the principles of a neural network model before and after pruning using the pruning method according to an embodiment of the present disclosure;
[0016] FIG5 is a schematic diagram showing the principles of a neural network model before and after pruning using the pruning method according to an embodiment of the present disclosure;
[0017] FIG6 is a schematic diagram showing the principles of a neural network model before and after pruning using the pruning method according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0018] Hereinafter, the embodiments of the present disclosure will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0019] It should be noted that the terms "first", "second", etc. in the description and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0020] The embodiments of the present disclosure mainly relate to a pruning method based on heavy parameters of a neural network model, and in particular to a channel pruning method in the field of mobile phone image denoising. In recent years, most of the progress in machine learning has been based on deep learning, among which convolutional neural networks use strategies such as local receptive field, weight sharing and downsampling to reduce network complexity, and are thus widely used. However, in actual applications, large networks are difficult to deploy due to the large amount of computing and memory resources they require, and are even more restricted in devices with limited hardware resources such as mobile phones. Therefore, it is necessary to perform lightweight processing on the network model. Common lightweight processing methods include quantization, pruning, and distillation. Pruning refers to reducing the number of parameters and the amount of computation by removing unimportant parts of the network, among which channel pruning is particularly practical. Channel pruning uses some measurement methods to identify and prune unimportant channels from a well-trained model, thereby effectively reducing the number of floating-point operations and memory usage.
[0021] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 1 is a hardware structure block diagram of a computer terminal for a pruning method of a neural network model in an embodiment of the present disclosure. As shown in Figure 1, the computer terminal may include one or more (only one is shown in Figure 1) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned computer terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that the structure shown in Figure 1 is only for illustration and does not limit the structure of the above-mentioned computer terminal. For example, the computer terminal may also include more or fewer components than those shown in Figure 1, or have a configuration different from that shown in Figure 1.
[0022] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the pruning method of the neural network model in the embodiment of the present disclosure. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0023] The transmission device 106 is used to receive or transmit data via a network. Examples of such networks may include wireless networks provided by a computer terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0024] In this embodiment, a pruning method for a neural network model running on the above-mentioned computer terminal is provided. FIG2 is a flow chart of the pruning method for a neural network model according to an embodiment of the present disclosure. As shown in FIG2 , the flow chart includes the following steps:
[0025] Step S202: adding a branch to the convolution connection to be pruned and performing pruning training on the branch, wherein the branch includes two first convolutional layers;
[0026] In one exemplary embodiment, the branch further includes a gating function for determining whether the branch meets the pruning condition. The gating function type includes at least one of the following: a Sigmoid function and a Tanh function. In actual implementation, the gating function type may also be other types of S-shaped curve functions, which are not specifically limited here.
[0027] In an exemplary embodiment, the first convolutional layer includes at least a 1x1 convolutional layer. In actual implementation, a 1x1 convolution only linearly restructures the matrix across channels and does not change the data size or distribution. Therefore, replacing the original connection with the added branch can achieve similar accuracy to the original connection with fewer parameters and computational complexity.
[0028] In an exemplary embodiment, performing pruning training on a branch includes: constructing a loss function for pruning training, and performing pruning training according to the loss function, wherein the loss function is:
[0029] Among them, L total is the loss of the neural network model, X is the result predicted by the neural network model, Y is the real data, θ is the universal set of parameters, L is the objective function, g is the gate function, n is the number of convolutional layers of the convolutional connection to be pruned, and δ(g) is the variance of the gate function value.
[0030] In an exemplary embodiment, when the convolution connection includes a skip connection structure, a branch is added between each convolution connection except the skip connection structure.
[0031] Step S204: judging whether the branch meets the pruning condition based on the pruning training result, and obtaining the maximum number of pruning channels if the branch meets the pruning condition;
[0032] In an exemplary embodiment, if the value of the gating function reaches a preset threshold range, it is determined that the branch meets the pruning condition, and an adaptive method is used to obtain the maximum number of pruned channels.
[0033] Step S206: prune the branches according to the maximum number of pruning channels, and merge the pruned branches with the convolutional connections to complete the pruning of the convolutional connections.
[0034] In an exemplary embodiment, the pruned branches are merged with the convolutional connections, including: merging the two first convolutional layers with the corresponding second convolutional layers in the convolutional connections, respectively, to obtain two third convolutional layers to form a pruned neural network model.
[0035] In an exemplary embodiment, merging the pruned branch with the convolutional connection includes: when there is an activation function between the first convolutional layers in the convolutional connection, after merging the pruned branch with the convolutional connection, the activation function is located between the two third convolutional layers.
[0036] In an exemplary embodiment, when the convolution connection includes a jump connection structure and the added branches all meet the pruning conditions, the branches are respectively merged with the corresponding second convolutional layers in the convolution connection to obtain a fourth convolutional layer, and a convolution operation is performed on the merged fourth convolutional layer.
[0037] In the above embodiment, the first, second, third, and fourth in the first convolutional layer, the second convolutional layer, the third convolutional layer, and the fourth convolutional layer are only used to distinguish different convolutional layers and are not used to limit specific features.
[0038] Through the above steps, branches are added to the convolutional connections to be pruned, and pruning training is performed on the branches, where the branches include two first convolutional layers. Based on the pruning training results, whether the branches meet the pruning conditions is determined, and if the branches meet the pruning conditions, the maximum number of pruned channels is obtained. The branches are pruned according to the maximum number of pruned channels, and the pruned branches are merged with the convolutional connections to complete the pruning of the convolutional connections. This solves the problem of performance loss and precision loss in neural network models after pruning in related technologies, and achieves the effect of reducing performance loss and precision loss in neural network models.
[0039] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the embodiment of the present disclosure is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD-ROM), including a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the method described in the embodiment of the present disclosure.
[0040] In this embodiment, a pruning device for a neural network model is also provided. The device is used to implement the above-mentioned embodiments and preferred implementations. The details that have been described will not be repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and conceivable.
[0041] Figure 3 is a structural block diagram of a pruning device for a neural network model according to an embodiment of the present disclosure. As shown in Figure 3, the pruning device 30 includes: a training module 310, which is used to add branches to the convolutional connections to be pruned and perform pruning training on the branches, wherein the branches include two first convolutional layers; a judgment module 320, which is used to judge whether the branches meet the pruning conditions based on the pruning training results, and obtain the maximum number of pruning channels when the branches meet the pruning conditions; a merging module 330, which is used to prune the branches according to the maximum number of pruning channels, and merge the pruned branches with the convolutional connections to complete the pruning of the convolutional connections.
[0042] In an exemplary embodiment, in a training module, a loss function for the pruning training is constructed, and the pruning training is performed according to the loss function, wherein the loss function is:
[0043] Among them, L totalis the loss of the neural network model, X is the result predicted by the neural network model, Y is the real data, θ is the universal set of parameters, L is the objective function, g is the gate function, n is the number of convolutional layers of the convolutional connection to be pruned, and δ(g) is the variance of the gate function value.
[0044] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0045] An embodiment of the present disclosure further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.
[0046] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0047] An embodiment of the present disclosure further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0048] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0049] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.
[0050] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present disclosure can be implemented using a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented using program codes executable by the computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be performed in a different order than herein, or they can be made into individual integrated circuit modules, or multiple modules or steps can be made into a single integrated circuit module for implementation. Thus, the embodiments of the present disclosure are not limited to any specific combination of hardware and software.
[0051] In order to enable those skilled in the art to better understand the technical solutions of the embodiments of the present disclosure, the following is an elaboration with reference to scenario embodiments.
[0052] Scenario Example 1
[0053] The present disclosure proposes a pruning method for a neural network model that can be applied to a mobile phone image denoising model. FIG4 is a schematic diagram of the principles of the neural network model before and after pruning using the pruning method of the present disclosure. As shown in a in FIG4 , the method performs pruning training by adding a branch after the convolutional layer to be pruned. The branch consists of two 1*1 convolutions and a gate function. The data passes through ConvA and ConvB, and the number of channels is first reduced and then restored. By adding a penalty term to the loss function of the entire network, the information of the original connection is gradually transferred to the branch during the training process, thereby realizing the reconstruction of the parameters of the original connection. The loss function is as follows:
[0054] This loss function adds a penalty term and δ(g). Among them, It reflects the proportion of the branch in the network. The smaller the item is, the more important the added branch is in the network. In order to make the gate value as close to 0 and 1 as possible, the variance of the gate value is added as a penalty term (any expression that can reflect the size of the variance is acceptable). Small, δ(g) large. The gate function g determines whether the branch is effective. When the threshold is reached, the branch is used to replace the original connection. The maximum number of channels that can be pruned is adaptively adjusted until the prediction accuracy drops significantly, thereby achieving maximum channel pruning. Because 1*1 convolution only linearly reorganizes the matrix on the channel and does not change the data size and distribution, using the added branch to replace the original connection can achieve similar accuracy to the original connection with fewer parameters and computational complexity. Finally, ConvA and ConvB are merged into the upper and lower convolutional layers respectively to obtain the pruned convolutional layer.
[0055] In this scenario embodiment, the ResNet network model is used as an example to illustrate the implementation process of the embodiment of the present disclosure. For the pre-trained ResNet network model, it can be divided into two cases for explanation. Figure 5 is a schematic diagram of the principle of the neural network model before and after pruning using the pruning method of the embodiment of the present disclosure. As shown in Figure 5 a, the convolution layer ConvN to ConvO is a normal convolution connection, while ConvM to ConvN, and ConvO to ConvP need special processing due to the presence of jump connections.
[0056] For the ordinary convolution connection from ConvM to ConvN, we can refer to the pruning principle shown in Figure 4. After the convolution layer to be pruned, we add a branch consisting of two 1*1 convolutions and a gate function for pruning training, thereby reconstructing the parameters of the original convolution branch. The process can be divided into three steps:
[0057] Step 1: Add branches to the convolution to be pruned, as shown in a in Figure 4. During pruning training, freeze the connection between the convolution layer ConvN and the convolution layer ConvO, and the data flows from ConvN to the convolution layers ConvA and ConvB in the branch in sequence, where ConvA and ConvB are both 1*1 convolutions.
[0058] During implementation, the number of output channels of ConvN can be set to 16. The number of input channels of ConvA is then set to 16, and the number of output channels of ConvA and ConvB are set to 15 and 16, respectively. The data undergoes linear reorganization through ConvA, reducing the number of channels to 15, and then passes through ConvB to restore the number of channels to 16. Finally, a gate function, g, determines whether the branch is valid. g can use an sigmoid curve function, not limited to Sigmoid or Tanh. Because 1x1 convolutions only linearly reorganize matrices across channels and do not change the size or image distribution, replacing the original connection with the added branch when the conditions are met can achieve similar accuracy with fewer parameters and computation.
[0059] Step 2: Determine whether the added branch can replace the original connection. To determine whether the branch can replace the original connection, a penalty term is imposed on the loss of the entire network. The following loss function is used to optimize the network:
[0060] Among them, L total is the loss of the neural network model, X is the result predicted by the neural network model, Y is the real data, θ is the universal set of parameters, L is the objective function and the objective function is related to performance, g is the gate function, and the value of the learning range is [0,1]. n is the number of convolutional layers of the convolution connection to be pruned, that is, the number of gate values, and δ(g) is the variance of the gate function value. (Not limited to variance, other expressions that make the variance larger are acceptable.) This loss function adds a penalty term based on the loss between the predicted result and the real data. and δ(g). Among them, It reflects the proportion of the branch in the network. The smaller the value, the more important the added branch is in the network. During training, try to make the value of this item smaller. For each convolution layer, when the value is smaller than a certain threshold (such as 0.1), it means that the added branch is sufficient to replace the original connection, thereby achieving the purpose of pruning the original connection. For convolution layers that do not reach this threshold, it means that the added branch is not enough to replace the original connection, and pruning is not allowed. Taking the average here can prevent the sum result from being too large and increase the stability of the equation. In addition, due to Minimizing the gate value encompasses two scenarios: either the gate values of each layer are evenly distributed near the mean or scattered between [0, 1]. If the gate values are evenly distributed near the mean, the importance of the branch and the original connection are similar, defeating the purpose of pruning training and preventing pruning. Therefore, to keep the gate values as close to 0 and 1 as possible, the variance of the gate values, δ(g), is added as a penalty term. During training, δ(g) is maximized to create a clearer difference in importance between the original connection and the branch, making it easier to identify suitable branches for pruning.
[0061] Step 3: Adaptively adjust the maximum number of pruned channels and merge the original convolution layer with the added 1*1 convolution layer. Gradually reduce the number of output channels of ConvA with a step size of 1 (the number of input channels of ConvB is consistent with the number of output channels of ConvA) until the accuracy of the network prediction results is significantly reduced. This is the minimum number of channels that need to be retained while maintaining accuracy, thereby achieving the adaptive maximum number of pruned channels. As shown in Figure 4(b), after pruning, branches ConvN and ConvA are merged into ConvN', and ConvB and ConvO are merged into ConvO'. Then the number of input channels of ConvN' is 16, and the number of output channels is the number of channels after pruning; the number of input channels of ConvO' is the number of channels after pruning, and the number of output channels is 16. This completes the reconstruction of the number of channels. Since the gate function g takes a value close to 1 after the pruning condition is met, the purpose of determining whether pruning is possible has been achieved, so the gate function is omitted during merging. If there is an activation function between ConvN and ConvO, the activation function is placed between ConvN' and ConvO' after pruning.
[0062] The above steps implement the heavy parameter-based channel pruning of the connection between ConvN and ConvO in ResNet.
[0063] Special treatment is performed on the jump connection part in resnet. The branch adding method is shown in b in Figure 5. After pruning training, if the two added branches meet the pruning conditions, they are merged according to the merging method shown in c in Figure 5. As shown in c in Figure 5, after the pruning operation between ConvM and ConvN, and ConvO and ConvP, ConvP needs to be merged with ConvR and ConvT. Since ConvR and ConvT have different parameters and cannot be added directly, ConvP is convolved with ConvR and ConvT respectively to merge into ConvP_r' and ConvP_t' and then added. Note that after adding ConvP_r' and ConvP_t', the corresponding bias term is added twice, and should be subtracted once. The other operation methods are the same as ordinary convolution. After ConvN' and ConvR are merged, they are recorded as ConvN", and after ConvO' and ConvS are merged, they are recorded as ConvO".
[0064] In the actual implementation process, since the convolution added in the branch is 1*1 convolution, it basically does not cause an increase in computing power.
[0065] In the implementation process, assume that the input and output image sizes of ConvM, ConvN, ConvO and ConvP in Figure 5 are all 32*32, the input and output channels are all 16, ConvM, ConvN, ConvO and ConvP are all 3*3 convolutions, and after pruning, ConvM', ConvN", ConvO", ConvP_r' and ConvP_t' output 10 channels. Then the network computing power before pruning is: FLOPs = 32*32*16*3 2 *16*4≈9.44M
[0066] After pruning, ConvM', ConvN", ConvO", ConvP_r' and ConvP_t' output 10 channels, so the computing power is: FLOPs = 32*32*16*3^2*10+32*32*10*3^2*10*4≈5.16M
[0067] Since the convolution added to the branch is a 1*1 convolution, it basically does not cause an increase in computing power. However, after pruning, the computing power is reduced accordingly due to the reduction in the number of channels and parameters of the network.
[0068] Figure 6 is a schematic diagram of the principles of a neural network model before and after pruning using the pruning method of an embodiment of the present disclosure. As shown in a in Figure 6, if there is a convolution ConvX at the jump connection of the residual structure; as shown in b in Figure 5, ConvX remains unchanged during training; as shown in c in Figure 5, ConvR, ConvX and ConvP are merged together on the jump connection during merging.
[0069] The main innovation of the disclosed embodiments is to propose a channel pruning method based on heavy parameters for lightweight convolutional neural networks. Compared with existing pruning methods, the following improvements are made:
[0070] Existing pruning methods place accuracy requirements evenly on each convolutional layer, comparing the importance of each channel in each layer separately without considering the impact of the current layer on subsequent layers. However, the disclosed embodiment takes into account the longitudinal comparison of the importance of channels in different layers, so the channels that are ultimately pruned are the least important channels in the entire network. Compared to existing pruning methods that directly discard relatively unimportant channels, the disclosed embodiment uses a complete learning process based on re-parameterization and adds corresponding penalty terms to gradually transfer the information of relatively unimportant channels to the branch path, retaining more information and helping to maintain network accuracy. Compared to existing methods that prune the residual network as a whole, the disclosed embodiment performs more sophisticated processing on the residual network, processing each pair of convolutional connections in the residual network separately. By moving ConvP to two lines, performing convolutions separately and then summing, the problem of difficulty in handling jump connections in the residual network is overcome. In addition, some residual network pruning methods require that the output parameters of ConvM and ConvO must be consistent before processing, but this method does not impose any conditional restrictions here; and the added 1*1 convolution basically does not increase the computing power requirements of the network.
[0071] The above description is merely a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Those skilled in the art will appreciate that various modifications and variations of the present disclosure are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present disclosure should be included within the scope of protection of the present disclosure.
Claims
1. A pruning method for a neural network model, comprising: Adding a branch to the convolution connection to be pruned, and performing pruning training on the branch, wherein the branch includes two first convolutional layers; According to the pruning training result, determining whether the branch meets the pruning condition, and obtaining a maximum number of pruning channels when the branch meets the pruning condition; The branches are pruned according to the maximum number of pruning channels, and the pruned branches are merged with the convolutional connections to complete the pruning of the convolutional connections.
2. The method according to claim 1, wherein: The branch also includes: a gating function for determining whether the branch satisfies the pruning condition, and the type of the gating function includes at least one of the following: a Sigmoid function and a Tanh function.
3. The method according to claim 1, wherein: The type of the first convolutional layer includes at least: a 1*1 convolutional layer.
4. The method according to any one of claims 1 or 2, wherein: The pruning training of the branch comprises: Construct a loss function for the pruning training, and perform the pruning training according to the loss function, wherein the loss function is: Among them, L total is the loss of the neural network model, X is the result predicted by the neural network model, Y is the real data, θ is the universal set of parameters, L is the objective function, g is the gate function, n is the number of convolutional layers of the convolutional connection to be pruned, and δ(g) is the variance of the gate function value.
5. The method according to claim 4, wherein: The step of judging whether the branch satisfies a pruning condition according to the pruning training result, and obtaining a maximum number of pruning channels when the branch satisfies the pruning condition, includes: If the value of the gating function reaches a preset threshold range, it is determined that the branch meets the pruning condition, and an adaptive method is used to obtain the maximum number of pruning channels.
6. The method according to claim 1, wherein: The merging of the pruned branch with the convolution connection comprises: The two first convolutional layers are respectively merged with the corresponding second convolutional layers in the convolutional connection to obtain two third convolutional layers to form a neural network model that completes the pruning.
7. The method according to claim 6, wherein: The merging of the pruned branch with the convolution connection comprises: In the case where an activation function exists between the first convolutional layers in the convolutional connection, after the pruned branch is merged with the convolutional connection, the activation function is located between two of the third convolutional layers.
8. The method according to claim 1, wherein: The step of adding a branch to the convolution connection to be pruned includes: In the case where the convolution connection includes a skip connection structure, the branch is added between each of the convolution connections except the skip connection structure.
9. The method according to claim 8, wherein: The merging of the pruned branch with the convolution connection comprises: When the convolution connection includes the jump connection structure and the added branches all meet the pruning conditions, the branches are respectively merged with the corresponding second convolution layers in the convolution connection to obtain a fourth convolution layer, and a convolution operation is performed on the merged fourth convolution layer.
10. A pruning device for a neural network model, comprising: A training module, configured to add a branch to the convolution connection to be pruned, and perform pruning training on the branch, wherein the branch includes two first convolution layers; A judgment module is configured to judge whether the branch meets the pruning condition according to the pruning training result, and obtain a maximum number of pruning channels when the branch meets the pruning condition; A merging module is configured to prune the branches according to the maximum number of pruning channels, and merge the pruned branches with the convolutional connections to complete the pruning of the convolutional connections.
11. The device according to claim 10, wherein: The training module is further configured to: construct a loss function for the pruning training, and perform the pruning training according to the loss function, wherein the loss function is: Among them, L total is the loss of the neural network model, X is the result predicted by the neural network model, Y is the real data, θ is the universal set of parameters, L is the objective function, g is the gate function, n is the number of convolutional layers of the convolutional connection to be pruned, and δ(g) is the variance of the gate function value.
12. A computer-readable storage medium having a computer program stored therein, wherein: When the computer program is executed by a processor, the method described in any one of claims 1 to 9 is implemented.
13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 9 when executing the computer program.
Citation Information
Patent Citations
Neural network generation method and device, data processing method and device, electronic equipment and medium
CN114492754A
Multi-target detection method, device, equipment, medium and product
CN114972950A
Neural network parameter optimization method, neural network computing method and apparatus thereof suitable for hardware implementation
KR101987475B1
Method and System for Machine Learning Based Classification of Vascular Branches
US20170262733A1
Dynamic pruning of neurons on-the-fly to accelerate neural network inferences
US20210027166A1
Cited By
Lightweight target detection method based on content awareness
CN119579864A
Robust model compression method for distributed external scene image recognition
CN119625088A
A robust model compression method for distributed outdoor scene image recognition
CN119625088B
Training method of gate position distribution model and gate position distribution method
CN120654970A
