WO2023159751A1 - 模型剪枝方法、装置、计算设备及存储介质 - Google Patents
模型剪枝方法、装置、计算设备及存储介质 Download PDFInfo
- Publication number
- WO2023159751A1 WO2023159751A1 PCT/CN2022/090010 CN2022090010W WO2023159751A1 WO 2023159751 A1 WO2023159751 A1 WO 2023159751A1 CN 2022090010 W CN2022090010 W CN 2022090010W WO 2023159751 A1 WO2023159751 A1 WO 2023159751A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- filter
- weight
- scaling factor
- layer
- importance score
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/04—Architecture, e.g. interconnection topology
- G06N3/045—Combinations of networks
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/21—Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
- G06F18/217—Validation; Performance evaluation; Active pattern learning techniques
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
- G06N3/082—Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
Definitions
- the present application relates to the technical field of artificial intelligence, and in particular to a model pruning method, device, computing device and storage medium.
- CNN convolutional neural network
- the present application provides a model pruning method, the method includes: obtaining the weight of each filter in the convolutional neural network model and the first scaling factor of each filter, wherein the weight of each filter
- the first scaling factor is the scaling factor corresponding to each filter in the batch normalization layer, and the convolution layer where each filter is located and the batch normalization layer are adjacent network layers; according to The weight of each filter and the first scaling factor of each filter determine the importance score of each filter; the convolutional neural network model is pruned according to the importance score of each filter.
- the present application provides a model pruning device, which includes: an acquisition module, configured to acquire the weight of each filter in the convolutional neural network model and the first scaling factor of each filter, wherein, The first scaling factor of each filter is the corresponding scaling factor of each filter in the batch normalization layer, and the convolutional layer where each filter is located is adjacent to the batch normalization layer
- the network layer the determination module is used to determine the importance score of each filter according to the weight of each filter and the first scaling factor of each filter; the processing module is used to determine the importance score of each filter according to the importance of each filter The score prunes the convolutional neural network model.
- the embodiment of the present application provides a computer-readable storage medium, which includes a program or an instruction, and when the program or instruction is run on the computer, the computer is caused to perform the following steps:
- the convolutional neural network model is pruned according to the importance score of each filter.
- the embodiment of the present application provides a computing device, which includes a processor and a memory;
- the memory is used to store computer programs
- the processor is configured to execute a computer program stored in the memory, so that the device performs the following steps:
- the convolutional neural network model is pruned according to the importance score of each filter.
- FIG. 1 is a schematic diagram of two adjacent convolutional layers in a convolutional neural network model provided by an embodiment of the present application
- Fig. 2 is a schematic diagram of the relationship between a filter and a convolution kernel provided by an embodiment of the present application
- FIG. 3 is a schematic flow diagram of a model pruning method provided in an embodiment of the present application.
- Fig. 4 is a schematic diagram after cutting off part of the filter provided by the embodiment of the present application.
- Fig. 5 is a schematic structural view of a model pruning device provided in an embodiment of the present application.
- FIG. 6 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
- the convolutional layer is the basic structure of the convolutional neural network and is used for feature extraction.
- a convolutional layer can contain one or more filters. Different filters can detect features of different dimensions, such as shape, color, contrast, and so on.
- the convolution kernel is an important part of the filter, and a filter can be composed of one or more different convolution kernels.
- a convolutional neural network can include one or more convolutional layers, and each convolutional layer has a corresponding input channel (input channel) and output channel (output channel).
- Cin(m,k) is used to represent the kth input channel corresponding to the mth convolutional layer
- Cout(m,k) is used to represent the kth output corresponding to the mth convolutional layer channel, where m and k are both positive integers.
- Each convolutional layer contains one or more filters. Different filters in the same convolutional layer respectively generate the data of one output channel of the convolutional layer.
- the number of output channels of the convolutional layer is determined by the convolution
- the number of filters in the layer is determined, and the filters correspond to the output channels one by one.
- Each filter contains one or more convolution kernels. Different convolution kernels in the same filter correspond to one input channel of the convolution layer, and the convolution kernel is only responsible for convolution with the data of the corresponding input channel.
- FIG. 1 is a schematic diagram of two adjacent convolutional layers in a convolutional neural network model provided by an embodiment of the present application. These two convolutional layers are convolutional layer m and convolutional layer m+ 1, which in turn represent the mth convolutional layer and the m+1th convolutional layer in the model, where m is a positive integer. It should be understood that the convolutional neural network model contains multiple convolutional layers, and there is a sequence between the convolutional layers.
- the convolutional layer m is the previous convolutional layer of the convolutional layer m+1, and the convolutional layer m+1 It is the next convolutional layer of the convolutional layer m, and it can also be said that the convolutional layer m+1 is the next adjacent convolutional layer of the convolutional layer m.
- the convolutional layer m has corresponding 3 input channels, which are represented by Cin(m,1), Cin(m,2) and Cin(m,3), and the convolutional layer m also has corresponding The 4 output channels of are represented by Cout(m,1), Cout(m,2), Cout(m,3) and Cout(m,4) respectively.
- the batch size (batch-size) is equal to 1
- the feature map A a 3-channel feature map, such as an RGB three-channel image
- the squares filled with left slashes in feature map A represent the data of the input channel Cin(m,1)
- the squares filled with dots represent the data of the input channel Cin(m,2)
- the squares filled with vertical lines represent the input channel Cin( m,3) data.
- the convolutional layer m contains 4 filters, which are represented by filter1, filter2, filter3 and filter4 respectively.
- Each of the above filters contains the same number of convolution kernels as the input channels of the convolutional layer m.
- Each convolution kernel in corresponds to an input channel of the convolutional layer m, and is respectively responsible for convolution with the data of the corresponding input channel.
- filter1 includes three convolution kernels, which are respectively represented by convolution kernel 1, convolution kernel 2, and convolution kernel 3, which in turn correspond to the input channel Cin of the convolution layer m (m,1), Cin(m,2), and Cin(m,3). Therefore, the convolution kernel 1 is responsible for convolving the data of the input channel Cin(m,1), the convolution kernel 2 is responsible for convolving the data of Cin(m,2), and the convolution kernel 3 is responsible for convolving the data of the input channel Cin( m,1) data for convolution. It should be noted that the filter and the convolution kernel described in the embodiment of the present application are not the same concept. As shown in Figure 2, the convolution kernel is a two-dimensional array composed of weights, and the filter is composed of multiple A three-dimensional structure formed by stacking convolution kernels, the two are in different hierarchical results, and have an inclusion relationship.
- each filter will generate a feature map of an output channel, that is, a single-channel feature graph, or the data of a single channel.
- the output result obtained by filter1 convoluting the feature map A is Map1, where the color (white) of Map1 is used to indicate that it corresponds to the output channel Cout(m,1); filter2 is convolved with the feature map A to obtain Map2, using Light gray indicates that Map2 corresponds to the output channel Cout(m,2); filter3 is convolved with feature map A to obtain Map3, and dark gray indicates that Map3 corresponds to the output channel Cout(m,3); filter4 is convolved with feature map A Get Map4, and use black to indicate that Map4 corresponds to the output channel Cout(m,4).
- the BN layer is usually used to normalize data to improve data distribution, which has the advantages of alleviating overfitting, improving gradient propagation, allowing higher learning rates, and improving training and convergence speeds.
- the excitation layer is usually used to increase the nonlinearity of the neural network model, and map features to high-dimensional nonlinear intervals for interpretation to solve problems that cannot be solved by linear models.
- Commonly used excitation functions in the excitation layer include sigmoid, tanh, ReLu, Leaky Relu, ELU, Maxout, etc., which are not specifically limited in this application.
- convolutional layer + BN layer + excitation layer is a commonly used structure in convolutional neural network models.
- ⁇ and ⁇ are used to scale and translate the data of the corresponding channel respectively, and each in the convolutional layer
- One filter produces data for one output channel respectively, so there is a one-to-one correspondence between filters in a convolutional layer and scaling factors in the associated BN layer.
- the excitation layer can further perform nonlinear mapping on the output result of the BN layer to increase the nonlinearity.
- the convolutional layer m has a corresponding BN layer and a corresponding excitation layer, which are represented by BN layer m and excitation layer m respectively. It can be understood that the convolution layer m, BN layer m and excitation layer m constitute the structure of convolution layer + BN layer + excitation layer commonly used in convolutional neural networks. These three network layers can be regarded as a group , the three network layers within the same group are related network layers.
- the scaling factors ⁇ 1, ⁇ 2, ⁇ 3 and ⁇ 4 in the BN layer m correspond to the output channels Cout(m,1), Cout(m,2), Cout(m,3) and Cout(m, 4), responsible for scaling the data of the corresponding output channel;
- the parameters ⁇ 1, ⁇ 2, ⁇ 3, and ⁇ 4 in the BN layer m are also in one-to-one correspondence with the output channels of the convolutional layer m, and are responsible for shifting the data of the corresponding output channel. It should be noted that these ⁇ parameters in the BN layer m are not shown in the figure.
- the BN layer m inputs the above results into the incentive layer m, and the incentive layer m performs nonlinear mapping on them respectively to obtain Map1*( ⁇ 1), Map2*( ⁇ 2), Map3*( ⁇ 3) and Map4*( ⁇ 4),
- the above results form the feature map B (a 4-channel feature map).
- the feature map B contains 4 channels of data, which will be used as the input of the convolutional layer m+1, so the convolutional layer m+1 needs to have corresponding four input channels, namely Cin(m+1,1) , Cin(m+1,2), Cin(m+1,3) and Cin(m+1,4).
- the "input” and “output” in the input channel and output channel are actually relative to a certain convolutional layer, and can be directly called channels, so the output channel Cout(m ,1), Cout(m,2), Cout(m,3), Cout(m,4) and the input channel Cin(m+1,1), Cin(m+1,2) of the convolutional layer m+1 ), Cin(m+1,3), and Cin(m+1,4) are actually one-to-one correspondence, and the corresponding input channel and output channel actually refer to the same type of channel.
- Cout(m,1) in the convolutional layer m refers to the channel type represented by white
- Cin(m+1,1) in the convolutional layer m+1 also refers to the channel type of white
- Cout (m,1) and Cin(m+1,1) correspond to the same type of channel.
- Fig. 3 is a schematic flow chart of a model pruning method provided in the embodiment of the present application, the method includes the following steps:
- the above-mentioned convolutional neural network model may be any model based on convolutional neural network, which is not specifically limited in this application.
- the convolutional neural network model can be a convolutional neural network model for image recognition, a convolutional neural network model for speech recognition, or a convolutional neural network model for semantic understanding.
- the convolutional layer where each filter is located can have an adjacent BN layer (that is, two adjacent network layers, the output of the convolutional layer is the input of the BN layer), and each filter There will be a corresponding scaling factor in its adjacent BN layer, that is, a specific ⁇ parameter. It should be understood that the ⁇ parameter is learned by the convolutional neural network model in the previous model training process.
- the first scaling factor of a filter refers to the scaling factor corresponding to the filter in the BN layer.
- step S301 may also be: obtaining the weights of multiple filters in the convolutional neural network model and the first scaling factors of the multiple filters, and the first scaling factor of each filter in the multiple filters
- the scaling factor is the scaling factor corresponding to each filter in the batch normalization layer, .
- the above multiple filters can be all filters in the convolutional neural network model, or some filters in the convolutional neural network model, that is to say, only for the convolutional neural network model It is not necessary to evaluate the importance of all filters in the convolutional neural network model.
- weight refers to one or more weight values, and multiple weight values can be represented by a weight vector or a weight matrix.
- the weight of a 3 ⁇ 3 convolution kernel refers to all weight values in the convolution kernel, that is, 9 weight values, and all weight values in the convolution kernel can be used in a matrix (ie, a two-dimensional array) It is called the weight matrix of the convolution kernel, and it can also be represented by a vector, which is called the weight vector of the convolution kernel.
- the weight of a certain filter is composed of the weights of all the convolution kernels that constitute the filter, that is, the weight of the filter is a set of weight matrix/weight vector, which can also be represented by a multidimensional array, and can also be directly understood as All weight values in all filters that make up this filter.
- the determining the importance score of each filter according to the weight of each filter and the first scaling factor of each filter may include: determining the weight of each filter Norm value; an importance score for each filter is determined based on the norm value of each filter's weight and each filter's first scaling factor.
- the above-mentioned norm value may be an L1 norm value (or an m1 norm value), or an L2 norm value (or an m2 norm value), which is not specifically limited in this application.
- the L1 norm refers to the sum of the absolute values of each element in the vector/matrix
- the L2 norm refers to the sum of the squares of each element in the vector/matrix, and then calculates the square root. Unless otherwise specified, the following will take the L2 norm as an example for introduction.
- the weight of the filter that is, the weight of the filter itself, can obviously be used as an evaluation index of the importance of the filter.
- the L2 norm value of the filter weight is calculated, and the larger the value, the higher the importance of the filter is indicated to a certain extent.
- use here Represents the weight vector of the j-th convolution kernel in the i-th filter in the m-th convolutional layer, using Represents the L2 norm value of the i-th filter weight in the m-th convolutional layer, because the weight of the filter is composed of the weights of all convolution kernels that make up the filter, so It can be calculated by the following formula (1):
- i, j, m are all positive integers.
- the embodiment of this application will As the first score of the i-th filter in the m-th convolutional layer.
- each convolutional layer can have a corresponding BN layer, the output of the convolutional layer is used as the input of the corresponding BN layer, and the filter in the convolutional layer has the same relationship with the scaling factor in the corresponding BN layer
- the BN layer reduces or enlarges the output of the filter according to the corresponding scaling factor. Therefore, the scaling factor in the corresponding BN layer can also be used as an evaluation index of filter importance, and the larger the value, the higher the importance of the filter to a certain extent. Therefore, in the embodiment of the present application, the scaling factor corresponding to a certain filter in the BN layer is directly used as the second score of the filter.
- the importance score of the filter can be determined.
- the importance score of the filter can be obtained by multiplying the first score and the second score of the filter; the weighted sum of the first score and the second score of the filter can also be obtained to obtain the filter
- the importance score of the filter; the first score and the second score of the filter can also be averaged to obtain the importance score of the filter, which is not specifically limited in this application. Unless otherwise specified, the description below is based on the multiplication of the first score and the second score.
- filter1 in the convolution layer m is composed of convolution kernel 1, convolution kernel 2 and convolution kernel 3, and the weights of convolution kernel 1, convolution kernel 2 and convolution kernel 3
- the vector in turn is expressed as Therefore, the L2 norm value of the filter1 weight It can be calculated by the following formula (2), and the calculated As filter1's first score:
- filter1 is located in the convolutional layer m, and the convolutional layer m and the BN layer m are two adjacent network layers, the output of the convolutional layer m is the input of the BN layer m, and the convolutional layer m
- Each filter has a corresponding scaling factor in the BN layer.
- the scaling factor corresponding to filter1 in the BN layer m is ⁇ 1, which is learned by the convolutional neural network model in the previous training process, and here directly uses ⁇ 1 as the second score of filter1.
- the importance score of each filter (or only part of the filters) in the convolutional neural network model can be calculated.
- the previous step S301 may also include: obtaining weight information of each filter; therefore, step S302 may also be: according to the weight of each filter, the scaling factor corresponding to each filter and the weight information of each filter to determine the importance score of each filter.
- the convolution layer where each filter is located includes a plurality of first convolution kernels; the next adjacent convolution layer of the convolution layer where each filter is located includes a plurality of second convolution kernels;
- the weight information of each filter includes the weight of the second convolution kernel corresponding to each filter.
- the channel corresponding to the second convolution kernel corresponding to each filter is the same as the channel corresponding to each filter. That is, each filter has a "correspondence" with its corresponding second convolution kernel in the next convolutional layer, meaning that their corresponding channels are the same.
- the convolutional layer m includes 4 filters, each of which contains multiple convolution kernels, and the convolutional layer m+1 includes 5 filters, of which Each filter also contains multiple convolution kernels.
- the convolutional layer m includes convolution
- the kernel is called the first convolution kernel, that is, the convolution kernel contained in each filter in the convolution layer m is called the first convolution kernel, and the convolution kernel included in the convolution layer m+1 is all
- the second convolution kernel that is, the convolution kernel contained in each filter in the convolution layer m+1 is called the second convolution kernel.
- each filter in the convolutional layer m has a corresponding second convolution kernel in the convolutional layer m+1, that is, each filter in the convolutional layer m is connected to the convolutional layer m Part of the second convolution kernel in +1 corresponds.
- filter1 in the convolutional layer m has a corresponding relationship with the input channel Cin(m+1, 1) of the convolutional layer m+1, and each filter in the convolutional layer m+1 is represented by a small white square
- the represented convolution kernel corresponds to the input channel Cin(m+1,1) of the convolutional layer m+1.
- the convolution kernel represented by the small white square in each filter in filter1 and convolutional layer m+1 corresponds to Cin(m+1,1), they correspond to the same channel, so filter1 and convolution
- the convolution kernels represented by small white squares in each filter in layer m+1 also have a corresponding relationship. Therefore, the second convolution kernel corresponding to filter1 in convolution layer m, that is, the second convolution kernel corresponding to filter1 in convolution layer m in convolution layer m+1, refers to convolution layer m+1
- These convolution kernels are represented by small white squares in .
- the weight of the convolution kernel corresponding to a certain filter in the next convolution layer is called the correlation weight of the filter.
- the L2 norm value of the weight the larger the value, the higher the importance of the filter to a certain extent.
- use here Represents the L2 norm value of the relevant weight of the i-th filter in the m-th convolutional layer, and the relevant weight of the i-th filter in the m-th convolutional layer is determined by the filter in the m+1th convolution
- the weight composition of the corresponding (second) convolution kernel in the product layer so It can be calculated by the following formula (4):
- the importance score of the filter can be determined.
- the importance score of a filter can be determined according to the product of the first score, the second score and the third score of a certain filter; The weighted sum of the second score and the third score is used to obtain the importance score of the filter; the first score, the second score and the third score of a certain filter can also be averaged to obtain the importance score of the filter.
- Applications are not specifically limited. Unless otherwise specified, the introduction below is based on the multiplication of the first score, the second score and the third score to obtain the importance score.
- the convolutional layer m+1 contains 5 filters, which are represented by filter5, filter6, filter7, filter8 and filter9 respectively, which in turn represent the first in the convolutional layer m+1. to the 5th filter.
- Each of the above-mentioned 5 filters includes 4 convolution kernels, and different convolution kernels in the same filter correspond to an input channel of the convolution layer m+1 respectively.
- filter1 in the convolutional layer m corresponds to the input channel Cin(m+1,1) of the convolutional layer m+1
- the small white squares in each filter (filter5 to filter9) in the convolutional layer m+1 represent The representative convolution kernel corresponds to Cin(m+1,1)
- filter1 also corresponds to the above convolution kernel in the convolution layer m+1
- the weight of these convolution kernels is filter1 relative weights.
- the convolution kernels represented by the small white squares in filter5 to filter9 their weight vectors are in order So the relative weight of filter1 It can be calculated by the following formula (5), and the calculated As filter1's third score:
- the importance score of each filter in the convolutional neural network model can be calculated.
- the previous method cannot be used Compute the third score of these convolution kernels.
- the filters in the last convolutional layer can be ignored/disregarded directly, and the importance scores of these filters are not calculated, that is, these filters do not participate in model pruning, and do not perform importance between filters Comparison.
- the pruning rate of the model can be reasonably selected by technical personnel according to the complexity of the model, application scenarios, etc., and is not specifically limited in this application.
- pruning the convolutional neural network model according to the importance score of each filter may include: sorting the importance score of each filter to obtain a sorting result; The sorting result and the pruning rate determine the target filter in the convolutional neural network model; the target filter in the convolutional neural network model is cut off to obtain a pruned model.
- the respective importance scores of each filter in the model can be calculated through the preceding steps S301 and S302. Then, the importance score of each filter is sorted to obtain the corresponding sorting result, for example, all the filters in the convolutional neural network model can be sorted according to the importance score from high to low. Next, the filter with a lower importance score in the convolutional neural network model is determined as the target filter in the model, and the target filter is pruned to obtain the pruned model.
- the pruning rate of the model is set to 5%, that is, 5% of the filters in the model need to be pruned.
- the filters in this convolutional layer correspond to the output channels of this convolutional layer, after some filters in this convolutional layer are cut off, the output channels of this convolutional layer will be The number decreased.
- the filter in this convolutional layer also has a corresponding relationship with the convolution kernel in the next adjacent convolutional layer, when a certain filter in this convolutional layer is cut off, it will cause the filter in the next The corresponding input channel in the adjacent convolutional layer is gone, and the number of convolution kernels in each filter in the next convolutional layer should be reduced accordingly. These filters need to remove the convolution corresponding to the input channel nuclear.
- the feature map B is reduced from the original 4 channels to three channels, and there are only three channels of data.
- this feature map B is input into the convolutional layer m+1, the number of input channels required by the convolutional layer m+1
- there is no Cin(m+1,2) therefore, the convolution kernels represented in light gray in each filter in the convolutional layer m+1 (these convolution kernels correspond to Cin(m+ 1,2)) can also be removed.
- the removed filters correspond to the pruned filter2 in the convolutional layer m.
- the method may further include: acquiring training data, and using the training data to fine-tune the above-mentioned pruned model to obtain a target model.
- the training data includes one or more types of image data, voice data, and text data, which is determined by the specific type/function of the convolutional neural network model, which is not specifically limited in this application.
- the fine-tuning here is to use the training data to retrain the pruned model so that it can restore the accuracy of the original model (that is, the model before pruning) as much as possible. level.
- model fine-tuning this application will not introduce too much.
- the weight of the filter itself, the scaling factor corresponding to the filter in the BN layer (that is, the first scaling factor) and the relevant weight of the filter can be used as the evaluation index of the importance of the filter.
- FIG. 5 is a schematic structural diagram of a model pruning device 500 provided by an embodiment of the present application.
- the model pruning device 500 includes an acquisition module 501 , a determination module 502 and a processing module 503 .
- the obtaining module 501 is used to obtain the weight of each filter in the convolutional neural network model and the first scaling factor of each filter, wherein the first scaling factor of each filter is the weight of each filter in batch normalization
- the corresponding scaling factor in the normalization layer, the convolutional layer and the batch normalization layer where each filter is located are adjacent network layers
- the determination module 502 is used to determine the importance score of each filter according to the weight of each filter and the first scaling factor of each filter
- the processing module 503 is used for pruning the convolutional neural network model according to the importance score of each filter.
- the obtaining module 501 is also configured to obtain weight information of each filter, wherein the convolution layer where each filter is located includes a plurality of first convolution kernels, and each filter The next adjacent convolution layer of the convolution layer where the filter is located includes a plurality of second convolution kernels, and the weight information of each filter includes the weight of the second convolution kernel corresponding to each filter ;
- the determining module 502 is also used for: determining the importance score of each filter according to the weight of each filter, the first scaling factor of each filter and the weight information of each filter.
- the channel corresponding to the second convolution kernel corresponding to each filter is the same as the channel corresponding to each filter.
- the determination module 502 is also used to: determine the norm value of the weight of each filter and the norm value of the weight of the second convolution kernel corresponding to each filter; The norm value, the first scaling factor of each filter and the norm value of the weight of the second convolution kernel corresponding to each filter determine the importance score of each filter.
- the above norm value is one or more of L1 norm value and L2 norm value.
- the determining module 502 is further configured to: according to the norm value of the weight of each filter, the first scaling factor of each filter, and the norm of the weight of the second convolution kernel corresponding to each filter The product of the values determines the importance score for each filter.
- the processing module 503 is also used to: sort the importance scores of each filter to obtain the sorting result; determine the target filter in the convolutional neural network model according to the sorting result and the pruning ratio; The target filter in the convolutional neural network model is pruned to obtain the pruned model.
- the processing module 503 is also used to: acquire training data, wherein the training data includes one or more of image data, speech data, and text data; fine-tune the pruned model through the training data , to get the target model.
- Each module in the above-mentioned model pruning device 500 is specifically used to implement the method in any one of the embodiments in FIG. 3 , please refer to the relevant introduction above, which will not be repeated here.
- FIG. 6 is a schematic structural diagram of a computing device 600 provided by an embodiment of the present application.
- the computing device 600 may be a computing device such as a notebook computer, a tablet computer, and a server, which is not specifically limited in this application.
- the computing device 600 includes a processor 601, a memory 602, and a communication interface 603, and the computing device 600 is specifically configured to implement any embodiment of the model pruning method in FIG. 3 .
- the processor 601, the memory 602, and the communication interface 603 may be connected to each other through an internal bus 604, and may also communicate through other means such as wireless transmission.
- the bus 604 is used as an example.
- the bus 604 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus.
- PCI peripheral component interconnect
- EISA extended industry standard architecture
- the bus 604 can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in FIG. 6 , but it does not mean that there is only one bus or one type of bus.
- the processor 601 may be composed of at least one general-purpose processor, such as a central processing unit (central processing unit, CPU), or a combination of a CPU and a hardware chip.
- the aforementioned hardware chip may be an application-specific integrated circuit (application-specific integrated circuit, ASIC), a programmable logic device (programmable logic device, PLD) or a combination thereof.
- the aforementioned PLD may be a complex programmable logic device (complex programmable logic device, CPLD), a field-programmable gate array (field-programmable gate array, FPGA), a general array logic (generic array logic, GAL) or any combination thereof.
- Processor 601 executes various types of digitally stored instructions, such as software or firmware programs stored in memory 602, which enable computing device 600 to provide various services.
- the memory 602 is used to store program codes, which are executed under the control of the processor 601 .
- the memory 602 can include a volatile memory (volatile memory), such as a random access memory (random access memory, RAM); the memory 602 can also include a non-volatile memory (non-volatile memory), such as a read-only memory (read-only memory). only memory, ROM), flash memory (flash memory), hard disk (hard disk drive, HDD) or solid-state drive (solid-state drive, SSD); the memory 602 may also include a combination of the above types.
- the memory 602 may store program codes, which may specifically include program codes for executing any embodiment of the model pruning method in FIG. 3 , which will not be repeated here.
- the communication interface 402 can be a wired interface, a wireless interface or an internal interface, and is used for communicating with other modules or devices.
- the wired interface can be an Ethernet interface, local interconnect network (local interconnect network, LIN), etc.
- the wireless interface can be a cellular network interface or use a wireless local area network interface, etc.
- the internal interface can be a PCIe interface or the like.
- this embodiment can be implemented by a general physical server, for example, an ARM server or an X86 server.
- the server can be an independent server, or it can provide cloud services, cloud databases, cloud computing, cloud functions, and cloud storage.
- Cloud servers for basic cloud computing services such as network services, cloud communications, middleware services, domain name services, security services, content delivery network (Content Delivery Network, CDN) and big data and artificial intelligence platforms.
- This embodiment can also be implemented based on a general-purpose physical server combined with a virtual machine implemented by NFV technology.
- a virtual machine refers to a complete computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. This application does not make any Specific limits.
- the computing device 600 shown in FIG. 6 may also be a server cluster composed of at least one server, which is not specifically limited in this application.
- An embodiment of the present application further provides a computer program product, and when the computer program product runs on a processor, the method in any embodiment in FIG. 3 is implemented.
- the implementation of all or part of the processes in the above method embodiments can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. During execution, it may include the processes of the embodiments of the above-mentioned methods.
- the storage medium may be a magnetic disk, an optical disk, a read-only memory (read-only memory, ROM) or a random access memory (random access memory, RAM) and the like.
- AI artificial intelligence
- the embodiments of the present application may acquire and process relevant data based on artificial intelligence technology.
- artificial intelligence is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. .
- Artificial intelligence basic technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation/interaction systems, and mechatronics.
- Artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning/deep learning.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Evolutionary Computation (AREA)
- Life Sciences & Earth Sciences (AREA)
- Artificial Intelligence (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computing Systems (AREA)
- Software Systems (AREA)
- Molecular Biology (AREA)
- Computational Linguistics (AREA)
- Biophysics (AREA)
- Biomedical Technology (AREA)
- Mathematical Physics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Evolutionary Biology (AREA)
- Complex Calculations (AREA)
- Image Analysis (AREA)
Abstract
本申请涉及人工智能技术领域,公开了一种模型剪枝方法、装置、计算设备及存储介质。该方法包括:首先,获取卷积神经网络模型中每个过滤器的权重和每个过滤器的第一缩放因子,其中,每个过滤器的第一缩放因子是每个过滤器在批量归一化层中对应的缩放因子,每个过滤器所在的卷积层和批量归一化层是相邻的网络层;然后,根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分;最后,根据每个过滤器的重要性得分对卷积神经网络模型进行剪枝。本申请实施例能够准确地选出卷积神经网络模型中相对不重要的过滤器,模型剪枝后的精度损失很小。
Description
优先权申明
本申请要求于2022年2月22日提交中国专利局、申请号为202210162485.9,发明名称为“模型剪枝方法、装置、计算设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及人工智能技术领域,尤其涉及一种模型剪枝方法、装置、计算设备及存储介质。
目前,基于卷积神经网络(convolutional neural network,CNN)的模型在很多任务中都表现出了良好的性能。但是这些模型中常常含有大量的冗余信息,需要耗费大量的计算开销,因此,模型压缩成为了必不可少的一步。
模型剪枝是一种常用的模型压缩方法,过滤器(filter)剪枝又是用于卷积神经网络模型的一种结构化剪枝类型,过滤器剪枝的操作过程主要可以分为两步:首先,选出模型中相对不重要的filter并剪除,得到剪枝后的模型;然后,对剪枝后的模型进行微调(fine-tuning),以恢复模型精度。如何选出相对不重要的filter,成为了过滤器剪枝中的关键技术问题。
然而,发明人意识到在一些现有的模型剪枝方法中,所采用的filter重要性的衡量标准还不够好,导致模型剪枝后的精度损失过大。
发明内容
为了解决现有技术中的上述问题,本申请实施例中提供一种模型剪枝方法、装置、计算设备及存储介质,能够更准确地选出模型中相对不重要的filter,使得模型剪枝后的精度损失很小。
第一方面,本申请提供了一种模型剪枝方法,该方法包括:获取卷积神经网络模型中每个过滤器的权重和每个过滤器的第一缩放因子,其中,每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分;根据每个过滤器的重要性得分对卷积神经网络模型进行剪枝。
第二方面,本申请提供了一种模型剪枝装置,该装置包括:获取模块,用于获取卷积神经网络模型中每个过滤器的权重和每个过滤器的第一缩放因子,其中,每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;确定模块,用于根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分;处理模块,用于根据每个过滤器的重要性得分对卷积神经网络模型进行剪枝。
第三方面,本申请实施例提供一种计算机可读存储介质,其中,包括程序或指令,当所述程序或指令在计算机上运行时,使得计算机执行以下步骤:
获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;
根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;
根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
第四方面,本申请实施例提供了一种计算设备,其中,包括处理器和存储器;
所述存储器,用于存储计算机程序;
所述处理器,用于执行所述存储器中存储的计算机程序,以使得所述设备执行以下步骤的指令:
获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;
根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;
根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
综上所述,本申请实施例通过获取卷积神经网络模型中每个过滤器的权重和每个过滤器的缩放因子,能够确定该卷积神经网络中每个过滤器的重要性得分。其中,重要性得分用于衡量卷积神经网络模型中的各个过滤器的重要性,过滤器的重要性得分越高,则说明该过滤器在卷积神经网络模型中的重要性越高,过滤器的重要性得分越低,则说明该过滤器在卷积神经网络模型中的重要性越低。因此,根据重要性得分便可以准确地选出卷积神经网络模型中相对不太重要的过滤器,进而将重要性较低的这些过滤器给剪除,既实现了模型压缩的目的,减少模型中的冗余信息,又使得模型剪枝后的精度损失较小,可以很好地保留原始模型的精度和性能。
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍。显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种卷积神经网络模型中的两个相邻卷积层的示意图;
图2是本申请实施例提供的一种过滤器与卷积核的关系示意图;
图3是本申请实施例提供的一种模型剪枝方法的流程示意图;
图4是本申请实施例提供的一种剪除部分过滤器之后的示意图;
图5是本申请实施例提供的一种模型剪枝装置的结构示意图;
图6是本申请实施例提供的一种计算设备的结构示意图。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。显然,下面所描述的实施例仅仅是本申请的一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
需要说明的是,在本申请实施例中使用的术语仅仅出于描述特定实施例的目的,而非旨在限制本申请。在本申请实施例和权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指包含一个或多个相关联的列出项目的任意或所有可能组合。
为了便于理解本申请实施例中的技术方案,下面对本申请实施例中涉及的部分术语及概念进行简单介绍。
1、卷积层(convolutional layer)、过滤器(filter)及卷积核(kernel):
卷积层是构成卷积神经网络的基本结构,用于特征提取。
过滤器是卷积层的重要组成部分,一个卷积层中可以包含一个或者多个过滤器,不同过滤器可以分别探测不同维度的特征,比如形状、颜色、对比度等等。
卷积核是过滤器的重要组成部分,一个过滤器可以由一个或者多个不同的卷积核来构成。
需要说明的是,卷积神经网络可以包括一个或多个卷积层,每个卷积层都有对应的输入通道(input channel)和输出通道(output channel)。为了便于描述,本申请实施例用Cin(m,k)表示第m个卷积层对应的第k个输入通道,用Cout(m,k)表示第m个卷积层对应的第k个输出通道,其中,m、k均为正整数。每个卷积层都包含一个或多个filter,同一个卷积层中的不同filter分别产生本卷积层的一个输出通道的数据,换句话说,卷积层的输出通道数目由该卷积层中filter的个数所决定,filter与输出通道一一对应。每个filter又包含一个或多个卷积核,同一个filter中的不同卷积核分别对应本卷积层的一个输入通道,卷积核只负责与对应的输入通道的数据进行卷积。
举例来说,图1是本申请实施例提供的一种卷积神经网络模型中的两个相邻卷积层的示意图,这两个卷积层分别是卷积层m和卷积层m+1,依次代表的是该模型中的第m个卷积层和第m+1个卷积层,m为正整数。应理解,卷积神经网络模型中包含多个卷积层,各卷积层之间具有先后顺序,卷积层m是卷积层m+1的上一个卷积层,卷积层m+1是卷积层m的下一个卷积层,也可以说卷积层m+1是卷积层m的下一个相邻卷积层。
如图1所示,卷积层m有对应的3个输入通道,分别用Cin(m,1)、Cin(m,2)和Cin(m,3)来表示,卷积层m还有对应的4个输出通道,分别用Cout(m,1)、Cout(m,2)、Cout(m,3)和Cout(m,4)来表示。这里假设批尺寸(batch-size)等于1,特征图A(一个3通道特征图,比如是RGB三通道的图像)作为卷积层m的输入,包含了上述3个输入通道的数据,其中,特征图A中的以左斜线填充的方块表示输入通道Cin(m,1)的数据,点填充的方块表示输入通道Cin(m,2)的数据,竖线填充的方块表示输入通道Cin(m,3)的数据。卷积层m中包含了4个过滤器,分别用filter1、filter2、filter3和filter4来表示,上述每一个过滤器都包含与卷积层m的输入通道同等数目的卷积核,同一个过滤器中的各卷积核分别对应卷积层m的一个输入通道,分别负责与对应输入通道的数据进行卷积。
以上述filter1为例,如图2所示,filter1包括三个卷积核,分别用卷积核1、卷积核2、卷积核3来表示,它们依次对应卷积层m的输入通道Cin(m,1)、Cin(m,2)和Cin(m,3)。因此,卷积核1负责与输入通道Cin(m,1)的数据进行卷积,卷积核2负责与Cin(m,2)的数据进行卷积,卷积核3负责与输入通道Cin(m,1)的数据进行卷积。需要特别说明的是,本申请实施例中所述的过滤器与卷积核并非是同一个概念,如图2所示,卷积核是由权重组成的二维数组,而过滤器是由多个卷积核堆叠形成的三维架构,二者处在不同的层次结果当中,具有包含关系。
如图1所示,特征图A输入卷积层m之后,分别与卷积层m中的各个filter进行卷积,每个filter都会产生一个输出通道的特征图(feature map),即单通道特征图,或者说是单个通道的数据。其中,filter1对特征图A进行卷积得到的输出结果为Map1,这里用Map1的颜色(白色)表示它对应的是输出通道Cout(m,1);filter2与特征图A卷积得到Map2,用浅灰色表示Map2对应的是输出通道Cout(m,2);filter3与特征图A卷积得到Map3,用深灰色表示Map3对应的是输出通道Cout(m,3);filter4与特征图A卷积得到Map4,用黑色表示Map4对应的是输出通道Cout(m,4)。
2、批量归一化(batch normalization,BN)层和激励层(activating layer):
BN层通常用于对数据进行归一化处理以改善数据分布,具有减轻过拟合、改善梯度传播、容许较高的学习率、提高训练和收敛速度等优点。BN层中有两种可学习参数,分别是缩放因子γ和偏差β。
激励层通常用于增加神经网络模型的非线性,将特征映射到高维的非线性区间进行解释,以解决线性模型所不能解决的问题。激励层中常用的激励函数有sigmoid、tanh、ReLu、Leaky Relu、ELU、Maxout等等,本申请不具体限定。
需要说明的是,卷积层+BN层+激励层的结构是卷积神经网络模型中的一种常用结构。针对卷积层的每一个输出通道,在该卷积层的相关BN层中都有一组对应的γ和β,γ和β分 别用于缩放和平移对应通道的数据,而卷积层中的每一个过滤器分别产生一个输出通道的数据,因此,卷积层中的过滤器与相关BN层中的缩放因子具有一一对应关系。卷积层的输出结果经过BN层的处理之后,激励层可以进一步把BN层输出的结果做非线性映射,以增加非线性。
承接上例,如图1所示,卷积层m有一个对应的BN层和一个对应的激励层,分别用BN层m和激励层m来表示。可以理解的是,卷积层m、BN层m和激励层m便组成了卷积神经网络中常用的卷积层+BN层+激励层的结构,可以将这三个网络层看为一组,同一组内的三个网络层是相关的网络层。其中,BN层m中的缩放因子γ1、γ2、γ3和γ4依次对应卷积层m的输出通道Cout(m,1)、Cout(m,2)、Cout(m,3)和Cout(m,4),负责缩放对应的输出通道的数据;BN层m中的参数β1、β2、β3、β4与卷积层m的各输出通道也是一一对应的,负责平移对应输出通道的数据。需要说明的是,图中未画出BN层m中的这些β参数。
如图1所示,卷积层m中的每个filter分别与特征图A进行卷积计算得到的输出结果都要经过BN层m的处理,即卷积层m的输出结果Map1、Map2、Map3和Map4会输入到BN层m进行处理。可以理解的是,因为Map1对应的是输出通道Cout(m,1),所以BN层m会采用γ1对Map1的数据进行缩放并且用β1进行平移,从而得到Map1(γ1)。同理,BN层m分别对Map2、Map3、Map4进行处理后得到Map2(γ2)、Map3(γ3)和Map4(γ4)。
然后,BN层m将上述结果输入到激励层m中,激励层m分别对它们做非线性映射得到Map1*(γ1)、Map2*(γ2)、Map3*(γ3)和Map4*(γ4),上述结果便组成了特征图B(一个4通道特征图)。显然,特征图B包含了4个通道的数据,它将作为卷积层m+1的输入,所以卷积层m+1需要有对应的四个输入通道,即Cin(m+1,1)、Cin(m+1,2)、Cin(m+1,3)和Cin(m+1,4)。因此,卷积层m+1的输入通道的数目等于卷积层m中的过滤器的个数,即本卷积层的输入通道的数目由上一个相邻卷积层中的过滤器的个数所决定,上一卷积层的过滤器与本卷积层的输入通道具有一一对应关系。需要说明的是,卷积层m+1也有对应的BN层和激励层,但图1没有画出这部分。
应理解,输入通道和输出通道中的“输入”和“输出”实际是相对于某个卷积层来说的,都可以直接称为通道,所以说,卷积层m的输出通道Cout(m,1)、Cout(m,2)、Cout(m,3)、Cout(m,4)与卷积层m+1的输入通道Cin(m+1,1)、Cin(m+1,2)、Cin(m+1,3)、Cin(m+1,4)其实是一一对应的,对应的输入通道和输出通道其实指的是相同类别的通道。比如,卷积层m中的Cout(m,1)指是白色代表的这个通道类型,而卷积层m+1中的Cin(m+1,1)也是指白色这个通道类型,所以说Cout(m,1)和Cin(m+1,1)对应的其实是相同类型的通道。
基于上述内容,下面介绍本申请中的模型剪枝方法的实施例。
请参阅图3,图3是本申请实施例提供的一种模型剪枝方法的流程示意图,该方法包括以下步骤:
S301、获取卷积神经网络模型中每个过滤器的权重和每个过滤器的第一缩放因子,其中,每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子。
其中,上述卷积神经网络模型可以是任意一个基于卷积神经网络的模型,本申请不具体限定。比如,卷积神经网络模型可以是用于图像识别的卷积神经网络模型,也可以是用于语音识别的卷积神经网络模型,还可以是用于语义理解的卷积神经网络模型。
由前述内容可知,每个过滤器所在的卷积层都可以有一个相邻的BN层(即相邻的两个网络层,该卷积层的输出是该BN层的输入),每个过滤器在其相邻的BN层中都会有一个对应的缩放因子,即某一个具体的γ参数,应理解,γ参数是该卷积神经网络模型在之前的模型训练过程中学习得到的。某个过滤器的第一缩放因子,指的就是该过滤器在BN层中对应的那个缩放因子。
在可能的实施例中,步骤S301还可以是:获取卷积神经网络模型中多个过滤器的权重和 多个过滤器的第一缩放因子,多个过滤器中的每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,。需要说明的是,上述多个过滤器可以是卷积神经网络模型中的所有过滤器,也可以是卷积神经网络模型中的部分过滤器,也就是说,可以只对卷积神经网络模型中的部分过滤器的重要性进行评估,而不需要对卷积神经网络模型中的所有过滤器的重要性进行评估。
还需要说明的是,本申请实施例中所述的“权重”,指的是一个或多个权重值,多个权重值可以用权重向量或权重矩阵来表示。比如,某个3×3的卷积核的权重指的是该卷积核中的所有权重值,即9个权重值,该卷积核中的所有权重值可以用矩阵(即二维数组)来表示,称为该卷积核的权重矩阵,也可以用向量来表示,称为该卷积核的权重向量。再如,某个过滤器的权重由构成该过滤器的所有卷积核的权重组成,即过滤器的权重是一组权重矩阵/权重向量,也可以用多维数组来表示,还可以直接理解为组成该过滤器的所有卷积核中的所有权重值。
S302、根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分。
其中,重要性得分用于衡量过滤器的重要性。若过滤器的重要性得分越高,则说明该过滤器在卷积神经网络模型中的重要性越高;若过滤器的重要性得分越低,则说明该过滤器在卷积神经网络模型中的重要性越低。因此,根据重要性得分便可以准确地选出卷积神经网络模型中相对不太重要的过滤器,进而可以将重要性较低的这些过滤器给剪除,避免将模型中较为重要的过滤器给剪除,能够降低对模型精度的影响。
在一种可能的实施例中,所述根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分,可以包括:确定每个过滤器的权重的范数值;根据每个过滤器的权重的范数值和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分。
其中,上述范数值可以是L1范数值(或者m1范数值),也可以是L2范数值(或者m2范数值),本申请不做具体限定。应理解,L1范数指的是向量/矩阵中各个元素的绝对值之和,L2范数指的向量/矩阵中各个元素的平方和,然后再求平方根。若无特殊说明,下文皆以L2范数为例进行介绍。
具体来说,过滤器的权重,即过滤器自身的权重,显然可以作为过滤器重要性的一个评价指标。本申请实施例通过计算过滤器权重的L2范数值,其值越大,在一定程度上表明该过滤器的重要性越高。这里用
表示第m个卷积层中的第i个filter中的第j个卷积核的权重向量,用
表示第m个卷积层中的第i个filter权重的L2范数值,因为过滤器的权重由构成该过滤器的所有卷积核的权重组成,所以
可以通过下式(1)进行计算:
由前文的介绍可知,每个卷积层都可以有一个相应的BN层,该卷积层的输出作为相应BN层的输入,而且该卷积层中的filter与相应BN层中的缩放因子具有一一对应的关系,BN层是根据对应的缩放因子将filter的输出结果进行缩小或者放大的。因此,相应BN层中的缩放因子也可以作为过滤器重要性的一个评价指标,其值越大,在一定程度上表明该过滤器的重要性越高。所以,本申请实施例直接以某个过滤器在BN层中对应的缩放因子作为该过滤器的第二得分。
最后,根据某个过滤器的第一得分和第二得分,便可以确定该过滤器的重要性得分。
在可能的实施例中,可以将过滤器的第一得分和第二得分相乘得到该过滤器的重要性得分;也可以对过滤器的第一得分和第二得分进行加权求和得到该过滤器的重要性得分;还可以对过滤器的第一得分和第二得分求平均得到该过滤器的重要性得分,本申请不做具体限定。 若无特殊说明,下文皆以第一得分和第二得分相乘的方式进行介绍。
以filter1为例,请参见图2,卷积层m中的filter1由卷积核1、卷积核2和卷积核3构成,卷积核1、卷积核2、卷积核3的权重向量依次表示为
于是,filter1权重的L2范数值
可以通过下式(2)进行计算,将计算出的
作为filter1的第一得分:
再参见图1,filter1位于卷积层m中,并且卷积层m和BN层m是相邻的两个网络层,卷积层m的输出是BN层m的输入,卷积层m中的每个过滤器在BN层中都有一个对应的缩放因子。其中,filter1在BN层m中对应的缩放因子为γ1,γ1是该卷积神经网络模型在之前的训练过程中学习得到的,这里直接以γ1作为filter1的第二得分。
同理,可以计算出卷积神经网络模型中的每一个过滤器(或者只计算部分过滤器)的重要性得分。
在一种可能的实施例中,上一个步骤S301还可以包括:获取每个过滤器的权重信息;于是,步骤S302还可以是:根据每个过滤器的权重、每个过滤器对应的缩放因子和每个过滤器的权重信息,确定每个过滤器的重要性得分。
其中,所述每个过滤器所在的卷积层包括多个第一卷积核;所述每个过滤器所在的卷积层的下一个相邻卷积层包括多个第二卷积核;所述每个过滤器的权重信息包括所述每个过滤器对应的所述第二卷积核的权重。
上述范数值可以是L1范数值,也可以是L2范数值。可以理解的是,如果采用两类范数值,对于过滤器重要性的衡量会更加全面,比如,可以将某个过滤器权重的L1范数值和该过滤器权重的L2范数值相乘或者加权求和,以作为该过滤器的权重的范数值。若无特殊说明,下文皆以L2范数为例进行介绍。
在可能的实施例中,每个过滤器对应的所述第二卷积核所对应的通道和所述每个过滤器对应的通道相同。也就是说,每个过滤器与其在下一个卷积层中对应的第二个卷积核所具有的“对应关系”,指的是它们对应的通道相同。
例如,如图1所示,卷积层m中包括4个过滤器,它们中的每个过滤器都包含多个卷积核,卷积层m+1中包括5个过滤器,它们中的每个过滤器也都包含多个卷积核。为了便于描述以及区分两个相邻卷积层中的卷积核,在卷积层m和卷积层m+1这两个相邻的卷积层中,将卷积层m包括的卷积核都称为第一卷积核,即卷积层m中的每一个过滤器所包含的卷积核都称为第一卷积核,并且将卷积层m+1包括的卷积核都称为第二卷积核,即卷积层m+1中的每一个过滤器所包含的卷积核都称为第二卷积核。可以理解的是,卷积层m中的每个过滤器在卷积层m+1中都有对应的第二卷积核,即卷积层m中的每个过滤器分别与卷积层m+1中的部分第二卷积核对应。比如,卷积层m中的filter1与卷积层m+1的输入通道Cin(m+1,1)具有对应关系,卷积层m+1中的每个过滤器中的以白色小方块所表示的卷积核对应的也是卷积层m+1的输入通道Cin(m+1,1)。因为filter1和卷积层m+1中的每个过滤器中的以白色小方块表示的卷积核对应的都是Cin(m+1,1),它们对应相同的通道,所以filter1和卷积层m+1中的每个过滤器中的以白色小方块表示的卷积核也具有对应关系。于是,卷积层m中的filter1对应的第二卷积核,即卷积层m中的filter1在卷积层m+1中对应的第二卷积核,指的就是卷积层m+1中的以白色小方块表示的这些卷积核。
具体来说,由前文的介绍可知,某个过滤器与其下一个相邻卷积层的一个输入通道具有对应关系,并且卷积层中的卷积核与该卷积层的输入通道也具有对应关系,于是,某个过滤器与其下一个相邻卷积层中的部分卷积核(与该过滤器对应相同输入通道的卷积核)也具有对应关系。因此,某个过滤器在下一个卷积层中对应的那些卷积核的权重,也可以作为该过 滤器重要性的一个评价指标。
本申请实施例将某个过滤器在下一个卷积层中对应的卷积核(即上文所述的第二卷积核)的权重称为该过滤器的相关权重,通过计算过滤器的相关权重的L2范数值,其值越大,在一定程度上表明该过滤器的重要性越高。这里用
表示第m个卷积层中的第i个filter的相关权重的L2范数值,并且第m个卷积层中的第i个filter过滤器的相关权重由该过滤器在第m+1个卷积层中对应的(第二)卷积核的权重组成,于是
可以通过下式(4)进行计算:
其中,
表示卷积层m+1中的第j个过滤器中的第i个卷积核的权重向量。可以看出,第m个卷积层中的第i个过滤器的相关权重,是由卷积层m+1中的所有过滤器中的第i个卷积核的权重向量组成的。将上面计算出的
作为第m个卷积层中的第i个过滤器的第三得分。
关于过滤器的第一得分和第二得分的计算,与前文方法一致,这里不重复介绍。
最后,根据某个过滤器的第一得分、第二得分和第三得分,便可以确定该过滤器的重要性得分。
在可能的实施例中,可以根据某个过滤器的第一得分、第二得分和第三得分的乘积,确定该过滤器的重要性得分;也可以对某个过滤器的第一得分、第二得分和第三得分进行加权求和得到该过滤器的重要性得分;还可以对某个过滤器的第一得分、第二得分和第三得分求平均得到该过滤器的重要性得分,本申请不做具体限定。若无特殊说明,下文皆以第一得分、第二得分和第三得分相乘得到重要性得分的方式进行介绍。
举例来说,如图1所示,卷积层m+1中包含了5个filter,分别用filter5、filter6、filter7、filter8和filter9来表示,它们依次代表卷积层m+1中的第1至第5个过滤器。上述5个过滤器中的每一个过滤器都包含4个卷积核,同一过滤器中的不同卷积核分别对应卷积层m+1的一个输入通道。并且,卷积层m中的各个过滤器与卷积层m+1的输入通道存在一一对应关系。因此,卷积层m中的过滤器与卷积层m+1中的卷积核也具有对应关系。
比如,卷积层m中的filter1对应卷积层m+1的输入通道Cin(m+1,1),卷积层m+1中的各个过滤器(filter5至filter9)中的白色小方块所代表的卷积核,对应的也是Cin(m+1,1),于是,filter1与卷积层m+1中的上述卷积核之间也是对应的,上述这些卷积核的权重即为filter1的相关权重。假设filter5至filter9中的白色小方块所代表的卷积核,它们的权重向量依次为
于是filter1的相关权重
可以通过下式(5)进行计算,将计算出的
作为filter1的第三得分:
关于filter1的第一得分和第二得分的计算方式,与前文一致,这里不重复介绍。
同理,可以计算出卷积神经网络模型中的每一个过滤器的重要性得分。
需要说明的是,对于卷积神经网络模型中的最后一个卷积层中的卷积核,由于其之后没有卷积层了(没有下一个相邻的卷积层),所以无法用前面的方法计算这些卷积核的第三得分。在一种方案中,可以直接忽略/不考虑最后一个卷积层中的过滤器,不计算这些过滤器的重要性得分,即这些过滤器不参与模型剪枝,不进行过滤器之间重要性的比较。在另一种方案中,由于模型中的最后一个卷积层之后通常还会接着线性层(全连接层),最后一个卷积层中的这些过滤器与后面这个线性层的输入通道也会具有对应关系,因此,可以将最后一个卷积层中的每个过滤器在其之后的线性层中对应的输入通道的权重,作为该过滤器的相关权重,然后 计算过滤器的相关权重的范数值,得到该过滤器的第三得分,进而可以确定最后一个卷积层中的这些过滤器各自的重要性得分。
S303、根据每个过滤器的重要性得分对卷积神经网络模型进行剪枝。
可以理解的是,对于模型的剪枝率,可以由技术人员根据模型的复杂度、应用场景等进行合理选择,本申请不具体限定。
在可能的实施例中,根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝,可以包括:对每个过滤器的重要性得分进行排序,获得排序结果;根据排序结果和剪枝率确定卷积神经网络模型中的目标过滤器;将卷积神经网络模型中的目标过滤器剪除,得到剪枝后的模型。
具体来说,通过前面的步骤S301和S302可以计算出模型中的每个过滤器各自的重要性得分。然后,对每个过滤器的重要性得分进行排序,可以得到相应的排序结果,比如,可以将按照重要性得分从高到低对卷积神经网络模型中的所有过滤器进行排序。接着,将卷积神经网络模型中重要性得分较低的过滤器确定为该模型中的目标过滤器,将目标过滤器进行剪除便得到剪枝后的模型。
例如,假设某个卷积神经网络模型中总共有100个过滤器,模型的剪枝率设定为5%,即需要剪除该模型中5%的过滤器。通过步骤S301和S302得到该模型中的所有过滤器的重要性得分之后,按照重要性得分从高到低对该模型中的所有过滤器进行排序,得到排序结果,然后再根据剪枝率,将排序最靠后的五个过滤器确定为该模型中的目标过滤器,将该模型中的目标过滤器剪除便可以得到剪枝后的模型,剪枝完成。
需要说明的是,由于本卷积层中的过滤器与本卷积层的输出通道是一一对应是,将本卷积层中的部分过滤器剪除之后,会导致本卷积层的输出通道数目减少。而且,由于本卷积层中的过滤器和下一个相邻卷积层中的卷积核也具有对应关系,当剪除本卷积层中的某个过滤器时,会导致该过滤器在下一个相邻卷积层中对应的输入通道也就没有了,下一个卷积层中的每个过滤器中的卷积核数目要相应减少,这些过滤器都需要移除对应该输入通道的卷积核。
例如,如图4所示,假设卷积层m中的filter2被确定为了目标过滤器,在filter2被剪除之后,卷积层m所对应的输出通道相应减少了,即filter2在卷积层m中对应的输出通道Cout(m,2)没有了,卷积层m的输出通道变为了三个。因此,当特征图A再次输入卷积层m时,得到的输出结果中便没有Cout(m,2)通道的数据,不会产生Map2,于是BN层m中的Map(γ2)以及激励层m中的Map*(γ2)也不会有了。所以,特征图B从原来的4个通道减少为了三个通道,只有三个通道的数据,将这个特征图B输入卷积层m+1时,卷积层m+1所需要的输入通道数目也相应减少了,没有了Cin(m+1,2),因此,卷积层m+1中的各个filter中的以浅灰色所表示的卷积核(这些卷积核对应的是Cin(m+1,2))也可以移除,移除的这些过滤器对应的其实就是卷积层m中被剪枝的filter2。
在可能的实施例中,在上述步骤S303之后,该方法还可以包括:获取训练数据,通过训练数据对上述剪枝后的模型进行微调得到目标模型。其中,训练数据包括图像数据、语音数据、文本数据中的一种或多种类型,由卷积神经网络模型模型的具体类型/功能来决定,本申请不做具体限定。
可以理解的是,模型剪枝后会有一定的精度损失,这里的微调就是用训练数据对剪枝之后的模型重新进行训练,使其尽量恢复到原始模型(即剪枝之前的模型)的精度水平。关于模型微调,本申请不做过多介绍。
综上所述,本申请实施例通过获取卷积神经网络模型中每个过滤器的权重和每个过滤器的缩放因子,能够确定该卷积神经网络中每个过滤器的重要性得分。其中,重要性得分用于衡量过滤器的重要性,若过滤器的重要性得分越高,则说明该过滤器在卷积神经网络模型中的重要性越高,若过滤器的重要性得分越低,则说明该过滤器在卷积神经网络模型中的重要性越低。本申请实施例还可以获取每个过滤器的权重信息,在每个过滤器的权重和每个过滤器的第一缩放因子的基础上,再结合每个过滤器的权重信息来确定每个过滤器的重要性得分。 可以看出,本申请实施例可以以filter自身的权重、filter在BN层中对应的缩放因子(即第一缩放因子)以及filter的相关权重作为filter重要性的评价指标,根据这三种评价指标对卷积神经网络模型中的过滤器的重要性进行评估,从而确定出相对不重要的filter并剪除。可以理解的是,通过融合以上三种评价指标,对filter重要性的衡量更加全面,能够更准确地选出模型中相对不重要的filter进行剪枝,既实现了模型压缩的目的,减少模型中的冗余信息,又使得模型剪枝后的精度损失较小,可以很好地保留原始模型的精度和性能。
请参见图5,图5是本申请实施例提供的一种模型剪枝装置500的结构示意图,该模型剪枝装置500包括获取模块501、确定模块502和处理模块503。
获取模块501用于,获取卷积神经网络模型中每个过滤器的权重和每个过滤器的第一缩放因子,其中,每个过滤器的第一缩放因子是每个过滤器在批量归一化层中对应的缩放因子,每个过滤器所在的卷积层和批量归一化层是相邻的网络层
确定模块502用于,根据每个过滤器的权重和每个过滤器的第一缩放因子,确定每个过滤器的重要性得分
处理模块503用于,根据每个过滤器的重要性得分对卷积神经网络模型进行剪枝。
在可能的实施例中,获取模块501还用于,获取每个过滤器的权重信息,其中,所述每个过滤器所在的卷积层包括多个第一卷积核,所述每个过滤器所在的卷积层的下一个相邻卷积层包括多个第二卷积核,所述每个过滤器的权重信息包括所述每个过滤器对应的所述第二卷积核的权重;确定模块502还用于:根据每个过滤器的权重、每个过滤器的第一缩放因子和每个过滤器的权重信息,确定每个过滤器的重要性得分。
在可能的实施例中,所述每个过滤器对应的所述第二卷积核所对应的通道和所述每个过滤器对应的通道相同。
在可能的实施例中,确定模块502还用于:确定每个过滤器的权重的范数值和每个过滤器对应的第二卷积核的权重的范数值;根据每个过滤器的权重的范数值、每个过滤器的第一缩放因子和每个过滤器对应的第二卷积核的权重的范数值,确定每个过滤器的重要性得分。
在可能的实施例中,上述范数值是L1范数值和L2范数值中的一种或多种。
在可能的实施例中,确定模块502还用于:根据每个过滤器的权重的范数值、每个过滤器的第一缩放因子和每个过滤器对应的第二卷积核的权重的范数值的乘积,确定每个过滤器的重要性得分。
在可能的实施例中,处理模块503还用于:对每个过滤器的重要性得分进行排序,获得排序结果;根据排序结果和剪枝率确定卷积神经网络模型中的目标过滤器;将卷积神经网络模型中的目标过滤器剪除,得到剪枝后的模型。
在可能的实施例中,处理模块503还用于:获取训练数据,其中,训练数据包括图像数据、语音数据、文本数据中的一种或多种;通过训练数据对剪枝后的模型进行微调,得到目标模型。
上述模型剪枝装置500中的各个模块具体用于实现图3中的任一实施例的方法,请参见上文相关介绍,这里不重复。
图6是本申请实施例提供的一种计算设备600的结构示意图。计算设备600可以是笔记本电脑、平板电脑以及服务器等计算设备,本申请不做具体限定。
计算设备600包括处理器601、存储器602以及通信接口603,所述计算设备600具体用于实现图3的模型剪枝方法中的任一实施例。其中,处理器601、存储器602以及通信接口603可以通过内部总线604相互连接,也可通过无线传输等其他手段实现通信。本申请实施例以通过总线604连接为例,总线604可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线604可以分为地址总线、数据总线、控制总线等。为便于表示,图6中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
处理器601可以由至少一个通用处理器构成,例如中央处理器(central processing unit,CPU),或者CPU和硬件芯片的组合。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,ASIC)、可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD)、现场可编程逻辑门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合。处理器601执行各种类型的数字存储指令,例如存储在存储器602中的软件或者固件程序,它能使计算设备600提供多种服务。
存储器602用于存储程序代码,并由处理器601来控制执行。存储器602可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM);存储器602也可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM)、快闪存储器(flash memory)、硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器602还可以包括上述种类的组合。存储器602可以存储有程序代码,具体可以包括用于执行图3的模型剪枝方法的任一实施例的程序代码,这里不再进行赘述。
通信接口402可以为有线接口、无线接口或者内部接口,用于与其他模块或设备进行通信。有线接口可以是以太接口、局域互联网络(local interconnect network,LIN)等,无线接口可以是蜂窝网络接口或使用无线局域网接口等,内部接口可以是PCIe接口等等。
需要说明的是,本实施例可以是通用的物理服务器实现的,例如,ARM服务器或者X86服务器,服务器可以是独立的服务器,也可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、内容分发网络(Content Delivery Network,CDN)以及大数据和人工智能平台等基础云计算服务的云服务器。本实施例也可以是基于通用的物理服务器结合NFV技术实现的虚拟机实现的,虚拟机指通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统,本申请不作具体限定。应理解,图6所示的计算设备600还可以是至少一个服务器构成的服务器集群,本申请不作具体限定。
还需要说明的,图6仅仅是本申请实施例的一种可能的实现方式,实际应用中,计算设备600还可以包括更多或更少的部件,这里不作限制。关于本申请实施例中未出示或未描述的内容,可参见前述图3的模型剪枝方法的实施例中的相关阐述,这里不再赘述。
本申请实施例中还提供一种计算机可读存储介质,计算机可读存储介质中存储有指令,当其在处理器上运行时,图3的任一实施例的方法得以实现。所述计算机可读存储介质可以是非易失性,也可以是易失性。
本申请实施例中还提供一种计算机程序产品,当计算机程序产品在处理器上运行时,图3的任一实施例的方法得以实现。
本领域普通技术人员可以理解实现上述方法实施例中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(read-only memory,ROM)或随机存储记忆体(random access memory,RAM)等等。
本申请实施例可以基于人工智能技术对相关的数据进行获取和处理。其中,人工智能(Artificial Intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。
人工智能基础技术一般包括如传感器、专用人工智能芯片、云计算、分布式存储、大数据处理技术、操作/交互系统、机电一体化等技术。人工智能软件技术主要包括计算机视觉技术、机器人技术、生物识别技术、语音处理技术、自然语言处理技术以及机器学习/深度学习等几大方向。
以上所揭露的仅为本申请一种较佳实施例而已,当然不能以此来限定本申请之权利范围, 本领域普通技术人员可以理解实现上述实施例的全部或部分流程,并依本申请权利要求所作的等同变化,仍属于发明所涵盖的范围。
Claims (20)
- 一种模型剪枝方法,其中,所述方法包括:获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
- 根据权利要求1所述的方法,其中,所述方法还包括:获取所述每个过滤器的权重信息,其中,所述每个过滤器所在的卷积层包括多个第一卷积核,所述每个过滤器所在的卷积层的下一个相邻卷积层包括多个第二卷积核,所述每个过滤器的权重信息包括所述每个过滤器对应的所述第二卷积核的权重;所述根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分。
- 根据权利要求2所述的方法,其中,所述每个过滤器对应的所述第二卷积核所对应的通道和所述每个过滤器对应的通道相同。
- 根据权利要求3所述的方法,其中,所述根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分,包括:确定所述每个过滤器的权重的范数值和所述每个过滤器对应的所述第二卷积核的权重的范数值;根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分。
- 根据权利要求4所述的方法,其中,所述根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值的乘积,确定所述每个过滤器的重要性得分。
- 根据权利要求5所述的方法,其中,所述根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝,包括:对所述每个过滤器的重要性得分进行排序,获得排序结果;根据所述排序结果和剪枝率确定所述卷积神经网络模型中的目标过滤器;将所述卷积神经网络模型中的所述目标过滤器剪除,得到剪枝后的模型。
- 根据权利要求6所述的方法,其中,所述方法还包括:获取训练数据,所述训练数据包括图像数据、语音数据、文本数据中的一种或多种;通过所述训练数据对所述剪枝后的模型进行微调,得到目标模型。
- 一种模型剪枝装置,其中,所述装置包括:获取模块,用于获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;确定模块,用于根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;处理模块,用于根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
- 一种计算设备,其中,包括处理器和存储器;所述存储器,用于存储计算机程序;所述处理器,用于执行所述存储器中存储的计算机程序,以使得所述设备执行以下步骤的指令:获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
- 根据权利要求9所述的计算设备,其中,所述步骤还包括:获取所述每个过滤器的权重信息,其中,所述每个过滤器所在的卷积层包括多个第一卷积核,所述每个过滤器所在的卷积层的下一个相邻卷积层包括多个第二卷积核,所述每个过滤器的权重信息包括所述每个过滤器对应的所述第二卷积核的权重;所述根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分。
- 根据权利要求10所述的计算设备,其中,所述每个过滤器对应的所述第二卷积核所对应的通道和所述每个过滤器对应的通道相同。
- 根据权利要求11所述的计算设备,其中,所述根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分,包括:确定所述每个过滤器的权重的范数值和所述每个过滤器对应的所述第二卷积核的权重的范数值;根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分。
- 根据权利要求12所述的计算设备,其中,所述根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值的乘积,确定所述每个过滤器的重要性得分。
- 根据权利要求13所述的计算设备,其中,所述根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝,包括:对所述每个过滤器的重要性得分进行排序,获得排序结果;根据所述排序结果和剪枝率确定所述卷积神经网络模型中的目标过滤器;将所述卷积神经网络模型中的所述目标过滤器剪除,得到剪枝后的模型。
- 一种计算机可读存储介质,其中,包括程序或指令,当所述程序或指令在计算机上运行时,使得计算机执行以下步骤:获取卷积神经网络模型中每个过滤器的权重和所述每个过滤器的第一缩放因子,其中,所述每个过滤器的第一缩放因子是所述每个过滤器在批量归一化层中对应的缩放因子,所述每个过滤器所在的卷积层和所述批量归一化层是相邻的网络层;根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分;根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝。
- 根据权利要求15所述的计算机可读存储介质,其中,所述步骤还包括:获取所述每个过滤器的权重信息,其中,所述每个过滤器所在的卷积层包括多个第一卷积核,所述每个过滤器所在的卷积层的下一个相邻卷积层包括多个第二卷积核,所述每个过滤器的权重信息 包括所述每个过滤器对应的所述第二卷积核的权重;所述根据所述每个过滤器的权重和所述每个过滤器的第一缩放因子,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分。
- 根据权利要求16所述的计算机可读存储介质,其中,所述每个过滤器对应的所述第二卷积核所对应的通道和所述每个过滤器对应的通道相同。
- 根据权利要求17所述的计算机可读存储介质,其中,所述根据所述每个过滤器的权重、所述每个过滤器的第一缩放因子和所述每个过滤器的权重信息,确定所述每个过滤器的重要性得分,包括:确定所述每个过滤器的权重的范数值和所述每个过滤器对应的所述第二卷积核的权重的范数值;根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分。
- 根据权利要求18所述的计算机可读存储介质,其中,所述根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值,确定所述每个过滤器的重要性得分,包括:根据所述每个过滤器的权重的范数值、所述每个过滤器的第一缩放因子和所述每个过滤器对应的所述第二卷积核的权重的范数值的乘积,确定所述每个过滤器的重要性得分。
- 根据权利要求19所述的计算机可读存储介质,其中,所述根据所述每个过滤器的重要性得分对所述卷积神经网络模型进行剪枝,包括:对所述每个过滤器的重要性得分进行排序,获得排序结果;根据所述排序结果和剪枝率确定所述卷积神经网络模型中的目标过滤器;将所述卷积神经网络模型中的所述目标过滤器剪除,得到剪枝后的模型。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210162485.9A CN114565078A (zh) | 2022-02-22 | 2022-02-22 | 模型剪枝方法、装置、计算设备及存储介质 |
| CN202210162485.9 | 2022-02-22 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2023159751A1 true WO2023159751A1 (zh) | 2023-08-31 |
Family
ID=81713820
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2022/090010 Ceased WO2023159751A1 (zh) | 2022-02-22 | 2022-04-28 | 模型剪枝方法、装置、计算设备及存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN114565078A (zh) |
| WO (1) | WO2023159751A1 (zh) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120851105A (zh) * | 2025-07-07 | 2025-10-28 | 广东工业大学 | 面向在轨检测识别网络的通用轻量化方法及系统 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110263841A (zh) * | 2019-06-14 | 2019-09-20 | 南京信息工程大学 | 一种基于滤波器注意力机制和bn层缩放系数的动态结构化网络剪枝方法 |
| US20190294929A1 (en) * | 2018-03-20 | 2019-09-26 | The Regents Of The University Of Michigan | Automatic Filter Pruning Technique For Convolutional Neural Networks |
| CN111461322A (zh) * | 2020-03-13 | 2020-07-28 | 中国科学院计算技术研究所 | 一种深度神经网络模型压缩方法 |
| CN112183748A (zh) * | 2020-09-30 | 2021-01-05 | 中国科学院自动化研究所 | 基于稀疏卷积神经网络的模型压缩方法、系统及相关设备 |
| CN114330713A (zh) * | 2022-01-11 | 2022-04-12 | 平安科技(深圳)有限公司 | 卷积神经网络模型剪枝方法和装置、电子设备、存储介质 |
-
2022
- 2022-02-22 CN CN202210162485.9A patent/CN114565078A/zh active Pending
- 2022-04-28 WO PCT/CN2022/090010 patent/WO2023159751A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20190294929A1 (en) * | 2018-03-20 | 2019-09-26 | The Regents Of The University Of Michigan | Automatic Filter Pruning Technique For Convolutional Neural Networks |
| CN110263841A (zh) * | 2019-06-14 | 2019-09-20 | 南京信息工程大学 | 一种基于滤波器注意力机制和bn层缩放系数的动态结构化网络剪枝方法 |
| CN111461322A (zh) * | 2020-03-13 | 2020-07-28 | 中国科学院计算技术研究所 | 一种深度神经网络模型压缩方法 |
| CN112183748A (zh) * | 2020-09-30 | 2021-01-05 | 中国科学院自动化研究所 | 基于稀疏卷积神经网络的模型压缩方法、系统及相关设备 |
| CN114330713A (zh) * | 2022-01-11 | 2022-04-12 | 平安科技(深圳)有限公司 | 卷积神经网络模型剪枝方法和装置、电子设备、存储介质 |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120851105A (zh) * | 2025-07-07 | 2025-10-28 | 广东工业大学 | 面向在轨检测识别网络的通用轻量化方法及系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114565078A (zh) | 2022-05-31 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111860398B (zh) | 遥感图像目标检测方法、系统及终端设备 | |
| CN110084221B (zh) | 一种基于深度学习的带中继监督的序列化人脸关键点检测方法 | |
| CN107945204B (zh) | 一种基于生成对抗网络的像素级人像抠图方法 | |
| CN110837870B (zh) | 基于主动学习的声呐图像目标识别方法 | |
| CN112668716B (zh) | 一种神经网络模型的训练方法及设备 | |
| CN109949255B (zh) | 图像重建方法及设备 | |
| US20240012965A1 (en) | Steady flow prediction method in plane cascade based on generative adversarial network | |
| CN110852383B (zh) | 基于注意力机制深度学习网络的目标检测方法及装置 | |
| WO2021088101A1 (zh) | 基于改进的条件生成对抗网络的绝缘子分割方法 | |
| CN107341518A (zh) | 一种基于卷积神经网络的图像分类方法 | |
| CN113657595A (zh) | 神经网络实时剪枝方法、系统及神经网络加速器 | |
| CN110458084B (zh) | 一种基于倒置残差网络的人脸年龄估计方法 | |
| Saraswat et al. | Plant Disease Identification Using Plant Images | |
| CN113436125B (zh) | 基于风格迁移的侧扫声呐仿真图像生成方法、装置及设备 | |
| CN115035371A (zh) | 基于多尺度特征融合神经网络的井壁裂缝识别方法 | |
| CN114925320B (zh) | 一种数据处理方法及相关装置 | |
| CN114841335A (zh) | 基于变分蒸馏的多模态联合表示学习方法及系统 | |
| CN113033448A (zh) | 一种基于多尺度卷积和注意力的遥感影像去云残差神经网络系统、方法、设备及存储介质 | |
| CN112288084A (zh) | 一种基于特征图通道重要性程度的深度学习目标检测网络压缩方法 | |
| CN114092793A (zh) | 适用于复杂水下环境的端到端生物目标检测方法 | |
| WO2023159751A1 (zh) | 模型剪枝方法、装置、计算设备及存储介质 | |
| CN115601787B (zh) | 一种基于缩略表示的快速人体姿态估计方法 | |
| US20230186077A1 (en) | Adaptive token depth adjustment in transformer neural networks | |
| CN111639751A (zh) | 一种用于二值卷积神经网络的非零填补训练方法 | |
| CN116977840A (zh) | 海洋生物目标检测方法、系统、存储介质及设备 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22928024 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 22928024 Country of ref document: EP Kind code of ref document: A1 |

