Pruning Method and Apparatus Based on Neural Network Model
By coupling and grouping neural network models and calculating mask matrices, the neural network model is automatically pruned, solving the problems of poor versatility and time-consuming and labor-intensive processes in existing technologies, and improving pruning efficiency and effectiveness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- YINGCHE XINGCHUANG INTELLIGENT TECH (SHANGHAI) CO LTD
- Filing Date
- 2022-08-23
- Publication Date
- 2026-07-31
AI Technical Summary
Existing model pruning methods have poor versatility and are time-consuming and labor-intensive, making them difficult to apply to all neural network models.
By acquiring the pre-trained neural network model and pruning rate, the network layers of the model are coupled and grouped, the mask matrices of the parent node group and child node group are calculated, and the model is pruned using these matrices and trained to obtain the pruned model.
It realizes automated pruning of neural network models, takes into account the coupling and correlation of each layer, improves pruning efficiency and effect, and reduces dependence on specific models.
Smart Images

Figure CN115456163B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a pruning method and apparatus based on a neural network model. Background Technology
[0002] Deep neural network models have achieved great success in the field of computer science. Deep learning has stood out from traditional machine learning. Deep learning models have deep and complex structures, which also endow deep neural networks with the ability to learn advanced semantic features from big data. At the same time, the complex structure brings a series of problems: (1) For deep networks with a large number of layers and neurons, the computational latency is difficult to meet the application standards, especially for some real-time tasks; (2) The deployment of deep models has gradually expanded from bulky servers to terminal devices such as wearable devices, mobile phones, robots, and drones. Such devices have strict limitations on computing power and memory space. Therefore, reducing the size of the model and the computational cost has become a promising topic.
[0003] Studies of the human brain have revealed that as people age, the number of neuronal synapses increases and then decreases, with some useless synapses emerging. Based on this phenomenon, the problem of model pruning was introduced.
[0004] The most direct way to prune a model is to reduce the number of operations involved in the computation, thereby fundamentally solving the pressure on computation and memory. Most existing model pruning methods require manual specification of which layers to prune and which not to prune, meaning that specific pruning configurations must be designed for specific models. This results in poor versatility, is time-consuming and labor-intensive, and cannot be applied to all models. Summary of the Invention
[0005] This invention provides a pruning method and apparatus based on a neural network model to solve the problems of existing model pruning methods being unapplicable to all models, having poor versatility, and being time-consuming and labor-intensive.
[0006] This invention provides a pruning method based on a neural network model, comprising:
[0007] Obtain a pre-trained neural network model and pruning rate, wherein the neural network model is pre-trained using an image training set;
[0008] The network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups;
[0009] Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0010] The parent mask matrix and child mask matrix are used to prune the corresponding layers in the neural network model, and the training image set is input into the pruned neural network model for training to obtain the pruned and trained neural network model.
[0011] According to a pruning method based on a neural network model provided by the present invention, the network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups, including:
[0012] Perform a backpropagation on the neural network model to obtain the computational graph during backpropagation;
[0013] Search the computation graph for the hierarchical relationships of nodes that meet the pruning layer conditions to obtain the parent node group relationship for each node.
[0014] Based on the parent node group relationship corresponding to each node, establish the parent node group and child node group.
[0015] According to a pruning method based on a neural network model provided by the present invention, the step of searching and computing the hierarchical relationship of nodes in the graph that meet the pruning layer conditions to obtain the parent node group relationship corresponding to each node includes:
[0016] For a node k that meets the pruning layer conditions, search for the subsequent nodes of node k in the computation graph;
[0017] If the subsequent node meets the pruning layer conditions, the subsequent node is added to the parent node group of node k.
[0018] According to a pruning method based on a neural network model provided by the present invention, the step of establishing a parent node group and a child node group based on the parent node group relationship corresponding to each node includes:
[0019] Merge all parent node groups and remove duplicates to obtain all parent nodes;
[0020] Based on the inclusion relationship between each parent node and its parent node group, each parent node is expanded into a parent node group;
[0021] Perform subset inclusion relationship judgment on each expanded parent node group to remove duplicate parent node groups;
[0022] Based on the parent node group relationship of each node, determine the child node group corresponding to each parent node group.
[0023] According to a pruning method based on a neural network model provided by the present invention, the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group are calculated according to the pruning rate, including:
[0024] Count the number N of parameters in all layers of all parent node groups according to the output channel, and sort them in ascending order of absolute value.
[0025] The first N×r output channels are determined as output channels to be pruned. Based on the index corresponding to the output channels to be pruned, a one-dimensional vector is generated for each parent node group, where r is the pruning rate.
[0026] The parent mask matrix and child mask matrix are calculated based on the one-dimensional vector.
[0027] According to a pruning method based on a neural network model provided by the present invention, the parent mask matrix and the child mask matrix are calculated based on the one-dimensional vector, including:
[0028] Initialize all elements in the parent and child mask matrices to 1;
[0029] Record the index x corresponding to the 0 value in the one-dimensional vector;
[0030] Set all element values corresponding to the same index as x in the output dimension of the parent mask matrix to 0;
[0031] Set all element values corresponding to the indices with the same index as x in the input dimension of the submask matrix to 0.
[0032] According to the present invention, a pruning method based on a neural network model is provided, wherein the pruning rate is 0.2 to 0.6.
[0033] The present invention also provides a pruning device based on a neural network model, comprising:
[0034] A pre-trained model acquisition module is used to acquire a pre-trained neural network model and a pruning rate. The neural network model is pre-trained using an image training set.
[0035] The coupling grouping module is used to couple and group the network layers of the neural network model to obtain multiple parent node groups and child node groups;
[0036] The mask matrix calculation module is used to calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group according to the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0037] The model pruning training module is used to prune the corresponding layers in the neural network model using the parent mask matrix and the child mask matrix, and input the training image set into the pruned neural network model for training to obtain the pruned neural network model.
[0038] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the pruning method based on the neural network model as described above.
[0039] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the pruning method based on a neural network model as described above.
[0040] The present invention provides a pruning method and apparatus based on a neural network model. This method involves acquiring a pre-trained neural network model and a pruning rate, where the neural network model is pre-trained using an image training set. The network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups. Based on the pruning rate, a parent mask matrix corresponding to each layer in each parent node group and a child mask matrix corresponding to each layer in each child node group are calculated. The parent and child mask matrices are consistent with the parameter dimensions of their respective layers. The parent and child mask matrices are used to prune the corresponding layers in the neural network model. The training image set is then input into the pruned neural network model for training, resulting in a pruned and trained neural network model. When using the method and apparatus of this invention for pruning, only the pruning target (i.e., the final result after pruning, such as a total number of channels being less than a set value) needs to be input. No specific pruning configuration needs to be designed for a particular model. The method automatically searches for which layers need pruning based on the coupling grouping, without requiring a deep understanding of the network's hierarchical structure. This achieves automated pruning of the neural network model and considers the coupling and correlation of each layer, which is more conducive to accelerating pruning and improving performance. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0042] Figure 1 This is a flowchart illustrating the pruning method based on a neural network model provided by the present invention.
[0043] Figure 2 This is a network structure diagram of the UNet segmentation model in the pruning method based on a neural network model provided by the present invention;
[0044] Figure 3 yes Figure 2 A schematic diagram of the structure of each layer in the UNet segmentation model network;
[0045] Figure 4 This is a schematic diagram of the automated pruning device provided by the present invention;
[0046] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0048] The pruning method based on a neural network model in this embodiment of the invention is as follows: Figure 1 As shown, it includes:
[0049] Step S110: Obtain the pre-trained neural network model and pruning rate. The pruning rate is set according to the actual situation, specifically based on the computing power of the terminal device where the finally trained neural network model is deployed. For example, terminal devices such as wearable devices, mobile phones, robots, and drones have relatively low computing power, so a larger pruning rate can be set. This reduces the number of operations involved in the model's computation, resulting in higher model efficiency. Considering that a pruning rate that is too high will affect the accuracy of the model's computation results, the preferred pruning rate is 0.2 to 0.6.
[0050] In this step, the neural network model is pre-trained using an image training set. The training images of drivable areas detected in autonomous driving scenarios can be used as input to pre-train the neural network model.
[0051] Step S120: Couple and group the network layers of the neural network model to obtain multiple parent node groups and child node groups. The layers in the parent node groups will be regarded as pruning-dominant layers, and the layers in the child node groups will be regarded as passive pruning layers.
[0052] Step S130: Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group according to the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layer. The parameter represents the output channel or input channel of the layer, specifically the index of the output channel and the input channel. The mask matrix indicates which output channels or input channels in the corresponding layer will be pruned.
[0053] Step S140: Prune the corresponding layers in the neural network model using the parent mask matrix and child mask matrix, and input the training image set into the pruned neural network model for training to obtain the pruned neural network model.
[0054] The pruning method based on the neural network model in this embodiment only requires inputting the pruning target (i.e., the final result after pruning, such as the total number of channels being less than a set value) when in use. It does not require designing corresponding pruning configurations for specific models. It can automatically search for which layers need to be pruned based on coupling groups, without needing to deeply understand the hierarchical structure of the network. This achieves automated pruning of the neural network model. Moreover, it takes into account the coupling and correlation of each layer, which is more conducive to accelerating pruning and improving the effect.
[0055] In this embodiment, step S120 includes:
[0056] Perform a backpropagation on the neural network model to obtain the computational graph during backpropagation.
[0057] Search the computation graph for the hierarchical relationships of nodes that meet the pruning layer conditions to obtain the parent node group relationship for each node. Here, a node represents a layer in the neural network model, and the pruning layer conditions are set as needed to determine which types of layers to prune, for example: pruning only ordinary convolutional layers.
[0058] Based on the parent node group relationship corresponding to each node, establish the parent node group and child node group.
[0059] In this step, a single backpropagation makes it easy to quickly find the parent-child node relationships at each layer, so as to establish parent node groups and child node groups.
[0060] Specifically, the search computation graph establishes the hierarchical relationships of nodes that meet the pruning layer conditions to obtain the parent node group relationships corresponding to each node, including:
[0061] For a node k that meets the pruning layer criteria, search for its successor node in the computation graph. If the successor node meets the pruning layer criteria, add it to node k's parent node group. Although a successor node is a child node of k, it also meets the pruning layer criteria; therefore, it is also a parent node and belongs to the same parent node group as node k. The following uses a semantic segmentation network model (UNet segmentation model) as an example to illustrate the parent-child node relationships between layers.
[0062] like Figure 2 As shown, the encoder network on the left continuously downsamples, while the decoder network on the right continuously upsamples. Simultaneously, features at the same resolution from the encoder are fused into layers in the decoder. Both the encoder and decoder have four convolutional block layers with different resolutions, as shown... Figure 3As shown, the structure of each convolutional block layer consists of convolutional block layers of ResNet50 (Residual Network).
[0063] The input in each convolutional block is denoted as f0, the output of the first 1×1 convolutional layer is denoted as f1, the output of the second 3×3 convolutional layer is denoted as f2, and the output of the third 1×1 convolutional layer is denoted as f3.
[0064] Taking a single convolutional block layer structure as an example, in a single convolutional block layer, the layers that output f0 and f3 respectively are the parent nodes, and their child nodes are the layers that output f1 (because of the horizontal connection layers, f0 and f3 need to be merged, so the number of channels of f0 and f3 must be the same, and both are parent nodes). At the same time, the layer that outputs f1 is also the parent node of the layer that outputs f2, and the layer that outputs f2 is also the parent node of the layer that outputs f3. f3 is also the input of the next convolutional block layer, and so on, so that the relationship between the child nodes and parent nodes of the entire model can be obtained. When a node has multiple child nodes or parent nodes, it is called the child node group or parent node group of that node.
[0065] In addition, for the entire model, some layers in the encoder and decoder need to be merged, so the layer to be merged in the decoder is a child node of the corresponding encoder layer.
[0066] Regarding the mask relationship between child and parent nodes, taking the ResNet50 convolutional block layer structure as an example, if the layer outputting f0 is pruned, its output channels will be pruned. Since the layer outputting f3 shares the same parent node as the layer outputting f0, the mask used for pruning is the same. However, the layer outputting f1 is a child node of the layer outputting f0, so the input channels of the layer outputting f1 will be pruned. It should be noted that the pruning is implemented using mask matrices. The mask at the pruned position is 0, meaning it does not participate in model training, while the mask at other unpruned positions is 1, meaning it participates in training.
[0067] Specifically, establishing parent node groups and child node groups based on the parent node group relationship corresponding to each node includes:
[0068] Merge all parent node groups and remove duplicates to obtain all parent nodes. For example, if all parent node groups are [a], [a,b,c], [a,b], [d], [e], the parent nodes after deduplication are a, b, c, d, e.
[0069] Based on the inclusion relationship between each parent node and its parent node group, each parent node is expanded into a parent node group. For example, parent node group [a] is expanded into [a,b,c], [a,b,c] is expanded into [a,b,c], and [a,b] is expanded into [a,b,c].
[0070] Perform subset inclusion relationship judgment on each expanded parent node group to remove duplicate parent node groups. For the three expanded parent node groups [a,b,c], remove duplicates and keep only one.
[0071] Based on the parent node group relationship of each node, determine the child node group corresponding to each parent node group.
[0072] The process of establishing parent and child node groups described above involves deduplicating parent nodes, expanding the parent node group, and removing duplicate parent node groups. This process removes redundant node data during pruning, improving pruning efficiency.
[0073] In this embodiment, step S130 includes:
[0074] Count the number N of parameters in all layers of all parent node groups according to the output channel, and sort them in ascending order of absolute value.
[0075] The first N×r output channels are identified as the output channels to be pruned. Based on the index of each output channel to be pruned, a one-dimensional vector is generated for each parent node group, where r is the pruning rate. The index of the zero element in this one-dimensional vector is the index of the pruned channel, indicating that the channel corresponding to that index will be pruned. The length of the one-dimensional vector is equal to the number of output channels in the parent node group and the number of input channels in the child node group. The one-dimensional vectors in the same parent node group and its corresponding child node group are identical.
[0076] The parent mask matrix and child mask matrix are calculated based on the one-dimensional vector. Since the one-dimensional vector in the same parent node group is the same as that in its corresponding child node group, when the one-dimensional vector is extended into a mask matrix, the one-dimensional vector is applied to the output dimension of the parent mask matrix and the input dimension of the child mask matrix.
[0077] Specifically, calculating the parent mask matrix and child mask matrix based on the one-dimensional vector includes:
[0078] Initialize all elements in the parent and child mask matrices to 1.
[0079] Record the index x corresponding to the 0 value in the one-dimensional vector.
[0080] Set all element values corresponding to the same index as x in the output dimension of the parent mask matrix to 0.
[0081] Set all element values corresponding to the indices with the same index as x in the input dimension of the submask matrix to 0.
[0082] The pruning device based on a neural network model provided by the present invention will be described below. The pruning device based on a neural network model described below and the pruning method based on a neural network model described above can be referred to and correspond to each other.
[0083] like Figure 4 As shown, the pruning device based on a neural network model of the present invention includes:
[0084] The pre-trained model acquisition module 410 is used to acquire a pre-trained neural network model and a pruning rate. The neural network model is pre-trained using an image training set.
[0085] The coupling grouping module 420 is used to couple and group the network layers of the neural network model to obtain multiple parent node groups and child node groups.
[0086] The mask matrix calculation module 430 is used to calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group according to the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0087] The model pruning training module 440 is used to prune the corresponding layers in the neural network model using the parent mask matrix and the child mask matrix, and input the training image set into the pruned neural network model for training to obtain the pruned neural network model.
[0088] The neural network model-based pruning device in this embodiment only requires inputting the pruning target (i.e., the final result after pruning, such as the total number of channels being less than a set value) when in use. It does not require designing corresponding pruning configurations for specific models. It can automatically search which layers need to be pruned based on coupling groups, without needing to deeply understand the hierarchical structure of the network. This achieves automated pruning of the neural network model. Moreover, it takes into account the coupling and correlation of each layer, which is more conducive to accelerating pruning and improving the effect.
[0089] Optionally, the coupling grouping module 420 includes:
[0090] The computation graph acquisition module is used to perform a backpropagation of the neural network model and obtain the computation graph during the backpropagation.
[0091] The computation graph search module is used to search for the hierarchical relationships of nodes in the computation graph that meet the pruning layer conditions, so as to obtain the parent node group relationship corresponding to each node.
[0092] The parent-child node group creation module is used to create parent and child node groups based on the parent node group relationship corresponding to each node.
[0093] Optionally, the computation graph search module is specifically used to search for subsequent nodes of node k in the computation graph for a node k that meets the pruning layer conditions.
[0094] If the subsequent node meets the pruning layer conditions, the subsequent node is added to the parent node group of node k.
[0095] Optionally, the parent-child node group creation module includes:
[0096] The merge and deduplication module is used to merge all parent node groups and remove duplicates to obtain all parent nodes.
[0097] The parent node expansion module is used to expand each parent node into a parent node group based on the inclusion relationship between each parent node and the parent node group.
[0098] The parent node group deduplication module is used to determine the subset inclusion relationship of each expanded parent node group in order to remove duplicate parent node groups.
[0099] The child node group determination module is used to determine the child node group corresponding to each parent node group based on the parent node group relationship of each node.
[0100] Optionally, the mask matrix calculation module 430 includes:
[0101] The parameter count module is used to count the number of parameters N in all layers of all parent node groups, divided by output channel, and sort them in ascending order of absolute value.
[0102] A one-dimensional vector generation module is used to determine the first N×r output channels as output channels to be pruned, and generate a one-dimensional vector for each parent node group according to the index corresponding to the output channel to be pruned, where r is the pruning rate.
[0103] The mask matrix calculation module is used to calculate the parent mask matrix and the child mask matrix based on the one-dimensional vector.
[0104] Optionally, the mask matrix calculation module is specifically used to initialize all elements in the parent mask matrix and the child mask matrix to be 1; record the index corresponding to the 0 value in the one-dimensional vector as x; set all element values corresponding to the same index as x in the output dimension of the parent mask matrix to 0; and set all element values corresponding to the same index as x in the input dimension of the child mask matrix to 0.
[0105] Optionally, the pruning rate is 0.2 to 0.6.
[0106] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute a pruning method based on a neural network model, the method including:
[0107] Obtain a pre-trained neural network model and pruning rate, wherein the neural network model is pre-trained using an image training set.
[0108] The network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups.
[0109] Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0110] The parent mask matrix and child mask matrix are used to prune the corresponding layers in the neural network model, and the training image set is input into the pruned neural network model for training to obtain the pruned and trained neural network model.
[0111] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0112] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer is able to execute the pruning method based on a neural network model provided by the above methods, the method comprising:
[0113] Obtain a pre-trained neural network model and pruning rate, wherein the neural network model is pre-trained using an image training set.
[0114] The network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups.
[0115] Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0116] The parent mask matrix and child mask matrix are used to prune the corresponding layers in the neural network model, and the training image set is input into the pruned neural network model for training to obtain the pruned and trained neural network model.
[0117] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the pruning method based on a neural network model provided by the methods described above, the method comprising:
[0118] Obtain a pre-trained neural network model and pruning rate, wherein the neural network model is pre-trained using an image training set.
[0119] The network layers of the neural network model are coupled and grouped to obtain multiple parent node groups and child node groups.
[0120] Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers.
[0121] The parent mask matrix and child mask matrix are used to prune the corresponding layers in the neural network model, and the training image set is input into the pruned neural network model for training to obtain the pruned and trained neural network model.
[0122] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0123] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for pruning a neural network model, the method comprising: include: Obtain a pre-trained neural network model and pruning rate, wherein the neural network model is pre-trained using an image training set; Perform a backpropagation on the neural network model to obtain the computational graph during backpropagation; Search the computation graph for the hierarchical relationships of nodes that meet the pruning layer conditions to obtain the parent node group relationship for each node. Based on the parent node group relationship corresponding to each node, establish a parent node group and a child node group; Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers. The parent mask matrix and child mask matrix are used to prune the corresponding layers in the neural network model, and the training image set is input into the pruned neural network model for training to obtain the pruned and trained neural network model.
2. The pruning method based on a neural network model according to claim 1, characterized in that, The search computation graph identifies the hierarchical relationships of nodes that meet the pruning layer conditions, to obtain the parent node group relationships corresponding to each node, including: For a node k that meets the pruning layer conditions, search for the subsequent nodes of node k in the computation graph; If the subsequent node meets the pruning layer conditions, the subsequent node is added to the parent node group of node k.
3. The pruning method of a neural network model based pruning method according to claim 1, characterized in that, The step of establishing parent node groups and child node groups based on the parent node group relationship corresponding to each node includes: Merge all parent node groups and remove duplicates to obtain all parent nodes; Based on the inclusion relationship between each parent node and its parent node group, each parent node is expanded into a parent node group; Perform subset inclusion relationship judgment on each expanded parent node group to remove duplicate parent node groups; Based on the parent node group relationship of each node, determine the child node group corresponding to each parent node group.
4. The pruning method of a neural network model based pruning method according to claim 1, characterized in that, Calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group based on the pruning rate, including: Count the number N of parameters in all layers of all parent node groups according to the output channel, and sort them in ascending order of absolute value. The first N×r output channels are determined as output channels to be pruned. Based on the index corresponding to the output channels to be pruned, a one-dimensional vector is generated for each parent node group, where r is the pruning rate. The parent mask matrix and child mask matrix are calculated based on the one-dimensional vector.
5. The pruning method of a neural network model based pruning method according to claim 4, characterized in that, Calculating the parent mask matrix and child mask matrix based on the one-dimensional vector includes: Initialize all elements in the parent and child mask matrices to 1; Record the index x corresponding to the 0 value in the one-dimensional vector; Set all element values corresponding to the same index as x in the output dimension of the parent mask matrix to 0; Set all element values corresponding to the indices with the same index as x in the input dimension of the submask matrix to 0.
6. The neural network model based pruning method according to any one of claims 1-5, characterized in that, The pruning rate is 0.2 to 0.
6.
7. A neural network model based pruning apparatus, characterized by, include: A pre-trained model acquisition module is used to acquire a pre-trained neural network model and a pruning rate. The neural network model is pre-trained using an image training set. The computation graph acquisition module is used to perform a backpropagation of the neural network model and acquire the computation graph during the backpropagation. The computation graph search module is used to search the hierarchical relationships of nodes in the computation graph that meet the pruning layer conditions, so as to obtain the parent node group relationship corresponding to each node. The parent-child node group creation module is used to create parent node groups and child node groups based on the parent node group relationship corresponding to each node. The mask matrix calculation module is used to calculate the parent mask matrix corresponding to each layer in each parent node group and the child mask matrix corresponding to each layer in each child node group according to the pruning rate. The parent mask matrix and the child mask matrix are consistent with the parameter dimensions of the corresponding layers. The model pruning training module is used to prune the corresponding layers in the neural network model using the parent mask matrix and the child mask matrix, and input the training image set into the pruned neural network model for training to obtain the pruned neural network model.
8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the pruning method based on the neural network model as described in any one of claims 1 to 6. 9.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, When the computer program is executed by the processor, it implements the pruning method based on the neural network model as described in any one of claims 1 to 6.