CN109583586B - Convolution kernel processing method and device in voice recognition or image recognition - Google Patents
Convolution kernel processing method and device in voice recognition or image recognition Download PDFInfo
- Publication number
- CN109583586B CN109583586B CN201811482784.0A CN201811482784A CN109583586B CN 109583586 B CN109583586 B CN 109583586B CN 201811482784 A CN201811482784 A CN 201811482784A CN 109583586 B CN109583586 B CN 109583586B
- Authority
- CN
- China
- Prior art keywords
- convolution kernel
- pruning
- neural network
- matrix
- convolution
- 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.)
- Active
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/08—Learning methods
- G06N3/082—Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- General Health & Medical Sciences (AREA)
- Biomedical Technology (AREA)
- Biophysics (AREA)
- Computational Linguistics (AREA)
- Life Sciences & Earth Sciences (AREA)
- Evolutionary Computation (AREA)
- Artificial Intelligence (AREA)
- Molecular Biology (AREA)
- Computing Systems (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Health & Medical Sciences (AREA)
- Image Analysis (AREA)
Abstract
The embodiment of the application discloses a convolution kernel processing method and a convolution kernel processing device, firstly, a target pruning template is determined according to the size of a convolution kernel in a convolution neural network, the target pruning template comprises a pruning matrix, and the pruning matrix comprises 0 and 1; and then determining a target pruning matrix from the target pruning template, and pruning the convolution kernel by using the target pruning matrix, namely reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix and discarding the convolution kernel corresponding to the position of 0 in the target pruning matrix. The retained convolution kernel is a convolution kernel which has a large influence on the output result, and the discarded convolution kernel is a convolution kernel which does not influence the output result. Therefore, by defining the pruning template, the problem that the data reading speed and the calculation performance are influenced due to fragmentation of memory reading caused by random pruning positions in the traditional pruning algorithm is solved, so that the data reading performance is improved, and the calculation performance of the convolutional neural network is improved.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a convolution kernel processing method and apparatus.
Background
With the continuous development of deep learning, the deep learning is more and more emphasized by many fields such as computer vision, natural language processing and speech recognition, especially convolutional neural networks. The convolutional neural network comprises a plurality of convolutional kernels, so that the input data are subjected to feature extraction by using the convolutional kernels, and then the result is obtained by using the extracted features. Generally, the more convolution kernels, the more features are extracted, and the more accurate the final result is. However, when the number of convolution kernels increases, the amount of calculation increases, and the amount of calculation resources consumed also increases, so that the calculation efficiency is low. Therefore, how to process the convolution kernel to reduce the amount of computation on the premise of not affecting the accuracy of the output result is an urgent technical problem to be solved.
Disclosure of Invention
In view of this, embodiments of the present disclosure provide a convolution kernel processing method and apparatus, so as to reduce the amount of computation and increase the computation speed without affecting the output result.
In order to solve the above problem, the technical solution provided by the embodiment of the present application is as follows:
in a first aspect of embodiments of the present application, there is provided a convolution kernel processing method, including:
determining a target pruning template according to the size of the convolution kernel; the target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix are sequentially connected; the number of 1's in the pruning matrix is less than the convolution kernel size and not less than 1;
determining a target pruning matrix from the target pruning template;
and pruning the convolution kernels according to the target pruning matrix, reserving the convolution kernels corresponding to the positions of 1 in the target pruning matrix, and discarding the convolution kernels corresponding to the positions of 0.
In one possible implementation, the method further includes:
initializing the weight of the convolution kernel, setting the weight of the convolution kernel corresponding to the position of 1 in the target pruning matrix as an original value, and setting the weight value of the convolution kernel corresponding to the position of 0 in the target pruning matrix as 0;
carrying out forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain the output loss of the convolutional neural network;
judging whether the output loss amount is less than or equal to a preset threshold value or not;
if so, saving the weight of the convolution kernel in the convolution neural network.
In one possible implementation manner, when the output loss amount is greater than a preset threshold, the method further includes:
performing back propagation calculation according to the output loss amount and the convolutional neural network structure to obtain the convolution kernel weight variation;
updating the convolution kernel weight according to the target pruning matrix and the convolution kernel weight variable quantity;
and performing forward propagation calculation again according to the convolutional neural network structure and the convolutional kernel weight to obtain an output loss amount.
In a possible implementation manner, the updating the convolution kernel weights according to the target pruning matrix and the convolution kernel weight variation includes:
and taking the sum of the convolution kernel weight variation and the original value of the convolution kernel weight as the updated original value of the convolution kernel.
In a possible implementation manner, the performing forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain an output loss amount of the convolutional neural network includes:
carrying out forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain an output result of the convolutional neural network;
and taking the difference between the standard output result corresponding to the convolutional neural network structure and the output result as the output loss of the convolutional neural network.
In one possible implementation, the saving the weight of the convolution kernel in the convolutional neural network includes:
and performing data compression according to the target pruning matrix, and storing the weight of the convolution kernel which is not 0.
In one possible implementation, the number of 1's in the pruning matrix is equal to half the convolution kernel size minus 1.
In a second aspect of embodiments of the present application, there is provided a convolution kernel processing apparatus, including:
the first determining unit is used for determining a target pruning template according to the convolution kernel size; the target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix are sequentially connected; the number of 1's in the pruning matrix is less than the convolution kernel size and greater than 1;
the second determining unit is used for determining a target pruning matrix from the target pruning template;
and the processing unit is used for pruning the convolution kernels according to the target pruning matrix, reserving the convolution kernels corresponding to the positions which are 1 in the target pruning matrix and discarding the convolution kernels corresponding to the positions which are 0.
In one possible implementation, the apparatus further includes:
the initialization unit is used for initializing the weight of the convolution kernel, the convolution kernel weight corresponding to the position of 1 in the target pruning matrix is set as an original value, and the convolution kernel weight corresponding to the position of 0 in the target pruning matrix is set as 0;
the first calculation unit is used for carrying out forward propagation calculation according to a convolutional neural network structure and the convolutional kernel weight to obtain the output loss of the convolutional neural network;
the judging unit is used for judging whether the output loss amount is smaller than or equal to a preset threshold value or not;
and the storage unit is used for storing the weight of the convolution kernel in the convolution neural network when the judgment result of the judgment unit is yes.
In one possible implementation, the apparatus further includes:
the second calculating unit is used for performing back propagation calculation according to the output loss amount and the convolutional neural network structure to obtain the convolutional kernel weight variation when the judgment result of the judging unit is that the output loss amount is larger than a preset threshold;
and the updating unit is used for updating the convolution kernel weight according to the target pruning matrix and the convolution kernel weight variable quantity, and continuously utilizing the first calculating unit to obtain the output loss quantity.
In a possible implementation manner, the updating unit is specifically configured to use a sum of the convolution kernel weight variation and an original value of the convolution kernel weight as an updated original value of the convolution kernel.
In one possible implementation manner, the first computing unit includes:
the first calculation subunit is configured to perform forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight, and obtain an output result of the convolutional neural network;
and the second calculation subunit is used for taking the difference between the standard output result corresponding to the convolutional neural network structure and the output result as the output result of the convolutional neural network.
In a possible implementation manner, the storing unit is specifically configured to perform data compression according to the target pruning matrix, and store the weight of the convolution kernel of which the convolution kernel weight is not 0.
In one possible implementation, the number of 1's in the pruning matrix is equal to half the convolution kernel size minus 1.
In a third aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored therein instructions that, when run on a terminal device, cause the terminal device to perform the method for convolution kernel processing according to the first aspect.
In a fourth aspect of embodiments of the present application, there is further provided a computer program product, which when run on a terminal device, causes the terminal device to execute the method for convolution kernel processing according to the first aspect.
Therefore, the embodiment of the application has the following beneficial effects:
according to the embodiment of the application, firstly, a target pruning template is determined according to the size of a convolution kernel in a convolution neural network, wherein the target pruning template comprises a pruning matrix, and the pruning matrix comprises 0 and 1; and then determining a target pruning matrix from the target pruning template, and pruning the convolution kernel by using the target pruning matrix, namely, reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix, and discarding the convolution kernel corresponding to the position of 0 in the target pruning matrix. The retained convolution kernel is a convolution kernel which has a large influence on the output result, and the discarded convolution kernel is a convolution kernel which does not influence the output result, so that the calculation amount is reduced and the calculation speed is increased under the condition of not influencing the accuracy of the output result. And moreover, 1 in the target pruning matrix is sequentially connected, so that the reserved convolution kernel parameters are connected, the problem that the data reading time is long due to the dispersion of the convolution kernel parameters is solved, and the calculation efficiency is further improved.
Drawings
Fig. 1 is a flowchart of a convolution kernel processing method according to an embodiment of the present application;
FIG. 2 is a diagram illustrating an exemplary pruning template provided in an embodiment of the present application;
fig. 3 is a flowchart of another convolution kernel processing method according to an embodiment of the present application;
fig. 4 is a structural diagram of a convolution kernel processing apparatus according to an embodiment of the present application.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, embodiments accompanying the drawings are described in detail below.
In order to facilitate understanding of the technical solutions provided in the embodiments of the present application, the following description will first describe the background art of the present application.
The inventor finds that, in the research on the conventional convolution kernel pruning processing method, the conventional convolution kernel processing method adopts random pruning to process, and the randomness of the processed convolution kernel is high due to the random pruning, so that the convolution kernel which affects the accuracy of the data result can be pruned. Moreover, random pruning can disperse the parameters of the pruned convolution kernels, which affects the parameter reading rate and further causes the calculation speed to be slow.
Based on this, the present application provides a convolution kernel processing method and apparatus, and the present application provides a target pruning template, where the target pruning template may include at least one pruning matrix, and the pruning matrix includes 0 and 1. When the convolution kernel needs to be processed, a target pruning template is determined according to the size of the convolution kernel, a target pruning matrix is determined from the target pruning template, then the target pruning matrix is used for processing the convolution kernel, the convolution kernel corresponding to the position of 1 in the target pruning matrix is retained, and the convolution kernel corresponding to the position of 0 in the target pruning matrix is discarded, so that the purpose of pruning the convolution kernel based on the pruning template is achieved. Therefore, the convolution kernel processing method provided by the application solves the problem that the fragmentation of memory reading is caused by random pruning positions in the traditional pruning algorithm so as to influence the data reading speed and the calculation performance by defining the pruning template, thereby improving the data reading performance and the calculation performance of the neural network.
To facilitate the technical solutions provided in the present application, the following first explains the technical terms referred to in the present application.
A Convolutional Neural Network (CNN) is a feed-forward Neural Network that includes Convolutional layers (Convolutional layers) and pooling layers (pooling layers). The convolution layer is used for extracting the features of the input data, and the more the number of convolution layers is, the more the features are extracted, so that the more accurate the output result is. However, as the number of convolutional layers increases, the amount of data to be calculated increases, and the calculation pressure increases.
Pruning, which means to prune the unimportant parts of the convolutional neural network, reduce the size of the network structure, and simplify the structure of the network. In specific implementation, the network structure to be subtracted is found by setting rules, and then the part of the network structure is cut off. It should be noted that the cut-out partial network structure does not have a great influence on the final output result of the convolutional neural network. After the partial structure is cut off, the performance of the whole network is partially affected, so that retraining is needed to restore the performance of the convolutional neural network.
And the pruning template is a template which is generated according to a set rule and is used for pruning the convolution kernel of the convolution neural network. The pruning template can comprise at least one pruning matrix, and when the pruning template is actually applied, partial convolution kernel reservation and partial convolution kernel pruning are determined by using the pruning matrix.
The forward propagation algorithm is an algorithm which is carried out from front to back as the name implies, namely, input data is input into a convolutional neural network to obtain output; the output value obtained by the forward propagation algorithm has a great deviation from the actual value, the weight in the convolutional neural network needs to be optimized, the back propagation algorithm needs to be used at the moment, the variable quantity of the weight is obtained through the back propagation algorithm, and the weight is updated according to the variable quantity, so that the difference between the output value of the finally trained convolutional neural network and the actual value is small.
The convolution kernel processing method provided by the embodiment of the present application will be described below with reference to the drawings.
Referring to fig. 1, which is a flowchart of a convolution kernel processing method provided in an embodiment of the present application, as shown in fig. 1, the method may include:
s101: and determining a target pruning template according to the size of the convolution kernel.
In this embodiment, first, the size of a convolution kernel in the used convolutional neural network needs to be determined, and a target pruning template is determined according to the size of the convolution kernel.
In practical application, a user can select convolution kernels with different sizes according to own requirements, and common convolution kernel sizes include: 3 x 3, 5 x 5, or 7 x 7, etc., each convolution kernel size corresponding to a respective one of the target pruning templates. The target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix is sequentially connected, so that the continuity of the parameters of the convolution kernel after pruning is ensured. And the number of 1's in the pruning matrix is less than the convolution kernel size and not less than 1.
It should be noted that the pruning matrix size is the same as the convolution kernel size. For example, at a convolution kernel size of 3 x 3, the pruning matrix is 3 x 3; when the convolution kernel size is 5 × 5, the pruning matrix is 5 × 5; with a convolution kernel size of 7 x 7, the pruning matrix is 7 x 7. In addition, when the pruning matrix is 3 x 3, the number of 1 in the pruning matrix is more than 1 and less than 9; when the pruning matrix is 5 x 5, the number of 1 in the pruning matrix is more than 1 and less than 25; when the pruning matrix is 7 x 7, the number of 1's in the pruning matrix is greater than 1 and less than 49.
In specific implementation, in order to avoid that the accuracy of the output result of the convolutional neural network after pruning is affected when the number of 1's in the pruning matrix is small, the number of 1's in the pruning matrix is usually not less than the size of the convolution kernel minus the half of 1 and less than the size of the convolution kernel, that is, the number of 1's in the pruning matrix is at least equal to the size of the convolution kernel minus the half of 1. For example, when the pruning matrix is 3 x 3, the number of 1's in the pruning matrix is 4; when the pruning matrix is 5 x 5, the number of 1's in the pruning matrix is 12.
For the convenience of understanding the characteristics of the pruning matrix, the following takes a target pruning template with a convolution kernel size of 3 × 3 as an example, referring to fig. 2, which includes 6 pruning matrices, each of which includes 4 1, and 1 is connected.
It should be noted that, in practical applications, 1 in the pruning matrix in the pruning template may not be connected, but in order to reduce data dispersion caused by random pruning, positions of 1 in the pruning matrix should be connected as much as possible.
S102: and determining a target pruning matrix from the target pruning template.
In this embodiment, after the target pruning template is determined, a target pruning matrix required for pruning is determined from the target pruning template, so that the target pruning matrix is used to perform pruning processing on the convolution kernel.
In practical application, a random selection rule can be set, and one of the pruning matrixes is randomly selected from the target pruning template to be determined as a target pruning matrix. Or a selection rule can be preset by a user, and one pruning matrix is selected from the target pruning template as a target pruning matrix according to the preset rule.
S103: and pruning the convolution kernels according to the target pruning matrix, reserving the convolution kernels corresponding to the positions of 1 in the target pruning matrix, and discarding the convolution kernels corresponding to the positions of 0.
In this embodiment, after the target pruning matrix is determined, the target pruning matrix is used to prune the convolution kernel. Specifically, the convolution kernel corresponding to the position of 1 in the target pruning matrix is retained, and the convolution kernel corresponding to the position of 0 is discarded, so that the pruning target is realized, the number of convolution kernels is reduced, and the calculation amount is further reduced.
As can be seen from the above embodiments, in the embodiments of the present application, a target pruning template is first determined according to the size of a convolution kernel in a convolutional neural network, where the target pruning template includes a pruning matrix, and the pruning matrix includes 0 and 1; and then determining a target pruning matrix from the target pruning template, and pruning the convolution kernel by using the target pruning matrix, namely reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix and discarding the convolution kernel corresponding to the position of 0 in the target pruning matrix. The retained convolution kernel is a convolution kernel which has a large influence on the output result, and the discarded convolution kernel is a convolution kernel which does not influence the output result, so that the calculation amount is reduced and the calculation speed is increased under the condition of not influencing the accuracy of the output result. And moreover, 1 in the target pruning matrix is sequentially connected, so that the reserved convolution kernel parameters are connected, the problem that the data reading time is long due to the dispersion of the convolution kernel parameters is solved, the calculation efficiency is further improved, and the operation performance of the convolution neural network is improved.
It can be understood that after the pruning processing is performed on the convolution kernel, the performance of the pruned convolution neural network is affected, and in order to maintain the performance of the network, the pruned convolution neural network needs to be trained. The following describes training a convolutional neural network with reference to the drawings.
Referring to fig. 3, which is a flowchart of another convolution kernel processing method provided in the embodiment of the present application, as shown in fig. 3, the method may include:
s301: and initializing the weight of the convolution kernel, setting the weight of the convolution kernel corresponding to the position of 1 in the target pruning matrix as an original value, and setting the weight value of the convolution kernel corresponding to the position of 0 in the target pruning matrix as 0.
In this embodiment, to implement training of the convolutional neural network, first, the weights of the convolution kernels are initialized, the convolution kernel weight corresponding to the position where 1 in the target pruning matrix is determined is set as an original value, that is, the retained convolution kernel weight value remains unchanged from the original initial value, and the convolution kernel weight value corresponding to the position where 0 in the target pruning matrix is set as 0, that is, the discarded convolution kernel weight value is set as 0. That is, in training, it is not necessary to train a convolution kernel whose convolution kernel weight is 0, and the amount of calculation is reduced.
S302: and performing forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain the output loss of the convolutional neural network.
In this embodiment, after the convolution kernel weight is initialized, forward propagation calculation is performed according to the convolution neural network structure and the convolution kernel weight, so as to obtain an output loss amount of the convolution neural network.
In specific implementation, a set of training data is obtained and input into the pruned convolutional neural network. Then, forward propagation calculation is carried out by utilizing the structure of the pruned convolutional neural network and the convolutional kernel weight to obtain the output result of the convolutional neural network on the training data; and subtracting the standard output result corresponding to the convolutional neural network structure from the output result, and taking the difference value of the standard output result and the output result as the output loss of the convolutional neural network.
In actual training, the training data includes input data and output data, the output data is a standard output result corresponding to the input data, when the input data is input to the pruned convolutional neural network, the convolutional neural network can obtain an output result, then the output data and the output result are subtracted to obtain a difference value, namely the output loss amount of the neural network.
S303: judging whether the output loss amount is less than or equal to a preset threshold value or not; if so, executing S306; otherwise, S304 is performed.
In this embodiment, after obtaining the output loss amount corresponding to the convolutional neural network during the first training, determining whether the output loss amount is less than or equal to the preset threshold, where the preset threshold is the preset maximum value of the output loss amount, and if the output loss amount obtained in S302 is less than or equal to the preset threshold, it indicates that the performance of the pruned convolutional neural network is within an acceptable range, and the accuracy of the output result is not greatly affected, and if the performance is applicable, performing S306; if the loss of the output result is greater than the preset threshold, it indicates that the performance of the neural network after pruning is poor, and the influence on the accuracy of the output result is large, training needs to be continued, the weight of the convolution kernel is adjusted, and then S304 is executed.
S304: and performing back propagation calculation according to the output loss amount and the convolutional neural network structure to obtain the convolutional kernel weight variation.
In this embodiment, when the output loss obtained by using the pruned convolutional neural network is greater than the preset threshold, it indicates that the performance of the convolutional neural network still needs to be improved, and the weight in the convolutional kernel needs to be adjusted, and then the back propagation calculation is performed according to the output loss and the convolutional neural network structure to obtain the weight variation of each convolutional kernel in the convolutional neural network, so as to adjust the convolutional kernel weight by using the weight variation.
S305: and updating the weight of the convolution kernel according to the target pruning matrix and the variable quantity of the weight of the convolution kernel, and continuously executing S302.
In this embodiment, when the variable quantity of each convolution kernel weight is obtained through back propagation calculation, the convolution kernel weights are updated according to the target pruning matrix.
It will be appreciated that, since the convolution kernel corresponding to the position of 1 in the target pruning matrix is reserved, only the convolution kernel weight of this part needs to be further refined. In specific implementation, the convolution kernel weight variation is added to the original value of the convolution kernel weight, and the sum of the convolution kernel weight variation and the original value of the convolution kernel weight is used as the updated original value of the convolution kernel. That is, only the convolution kernel with the original value needs to be updated, and the convolution kernel weight of 0 does not need to be updated.
For example, a convolution kernel with a weight of p as the original value0If the variation is Δ p, the updated original value of the weight of the convolution kernel is p ═ p0+Δp。
S306: the weights of the convolution kernels in the convolutional neural network are saved.
In this embodiment, when it is determined that the output loss amount of the pruned convolutional neural network is less than or equal to the preset threshold, which indicates that the convolutional neural network is reliable, the weights of the convolutional kernels in the convolutional neural network and the structure of the convolutional neural network are stored, so as to facilitate subsequent use.
In practical application, in order to save the storage resources occupied by storage, data can be compressed according to the target pruning matrix, only the convolution kernel weight which is not 0 is stored, and the part of the convolution kernel weight which is 0 is not stored, so that the storage capacity is reduced.
According to the embodiment, after the convolution kernel is pruned, the pruned convolution neural network can be trained to keep the performance of the pruned convolution neural network, so that the convolution neural network does not influence the output result. Moreover, during training, training of the pruned convolution kernel is not needed, so that the calculation amount is reduced, and the training speed is improved.
In addition, after the convolutional neural network is trained, the convolutional neural network can be directly used for recognizing voice, images and the like. Because part of the convolution kernels in the convolution neural network are pruned, data can be prepared according to the target pruning matrix before convolution calculation, and the data preparation amount is reduced. For example, in the pruning matrix 2 in fig. 2, only the positions 2, 3, 4, and 5 are set to 1, and only the convolution data corresponding to the positions can be prepared, so that the data preparation amount can be reduced, and the calculation efficiency can be improved.
Based on the above method embodiment, the present application further provides a convolution kernel processing apparatus, which will be described below with reference to the accompanying drawings.
Referring to fig. 4, which is a block diagram of a convolution kernel processing apparatus provided in an embodiment of the present application, the apparatus may include:
a first determining unit 401, configured to determine a target pruning template according to the convolution kernel size; the target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix are sequentially connected; the number of 1's in the pruning matrix is less than the convolution kernel size and greater than 1;
a second determining unit 402, configured to determine a target pruning matrix from the target pruning template;
a processing unit 403, configured to prune the convolution kernel according to the target pruning matrix, reserve the convolution kernel corresponding to the position that is 1 in the target pruning matrix, and discard the convolution kernel corresponding to the position that is 0.
In one possible implementation, the apparatus further includes:
the initialization unit is used for initializing the weight of the convolution kernel, the convolution kernel weight corresponding to the position of 1 in the target pruning matrix is set as an original value, and the convolution kernel weight corresponding to the position of 0 in the target pruning matrix is set as 0;
the first calculation unit is used for carrying out forward propagation calculation according to a convolutional neural network structure and the convolutional kernel weight to obtain the output loss of the convolutional neural network;
the judging unit is used for judging whether the output loss amount is smaller than or equal to a preset threshold value or not;
and the storage unit is used for storing the weight of the convolution kernel in the convolution neural network when the judgment result of the judgment unit is yes.
In one possible implementation, the apparatus further includes:
the second calculating unit is used for performing back propagation calculation according to the output loss amount and the convolutional neural network structure to obtain the convolutional kernel weight variation when the judgment result of the judging unit is that the output loss amount is larger than a preset threshold;
and the updating unit is used for updating the convolution kernel weight according to the target pruning matrix and the convolution kernel weight variable quantity, and continuously utilizing the first calculating unit to obtain the output loss quantity.
In a possible implementation manner, the updating unit is specifically configured to use a sum of the convolution kernel weight variation and an original value of the convolution kernel weight as an updated original value of the convolution kernel.
In one possible implementation manner, the first computing unit includes:
the first calculation subunit is configured to perform forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight, and obtain an output result of the convolutional neural network;
and the second calculation subunit is used for taking the difference between the standard output result corresponding to the convolutional neural network structure and the output result as the output result of the convolutional neural network.
In a possible implementation manner, the storing unit is specifically configured to perform data compression according to the target pruning matrix, and store the weight of the convolution kernel of which the convolution kernel weight is not 0.
In one possible implementation, the number of 1's in the pruning matrix is equal to half the convolution kernel size minus 1.
It should be noted that, the implementation of each unit or module in this embodiment may refer to the implementation of fig. 1 to fig. 3, and details of this embodiment are not described herein again.
In addition, an embodiment of the present application further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed on a terminal device, the terminal device is caused to execute the above method for processing a convolution kernel.
The embodiment of the present application further provides a computer program product, and when the computer program product runs on a terminal device, the terminal device is enabled to execute the above method for processing a convolution kernel.
As can be seen from the above embodiments, in the embodiments of the present application, a target pruning template is first determined according to the size of a convolution kernel in a convolutional neural network, where the target pruning template includes a pruning matrix, and the pruning matrix includes 0 and 1; and then determining a target pruning matrix from the target pruning template, and pruning the convolution kernel by using the target pruning matrix, namely reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix and discarding the convolution kernel corresponding to the position of 0 in the target pruning matrix. The retained convolution kernel is a convolution kernel which has a large influence on the output result, and the discarded convolution kernel is a convolution kernel which does not influence the output result, so that the calculation amount is reduced and the calculation speed is increased under the condition of not influencing the accuracy of the output result. And moreover, 1 in the target pruning matrix is sequentially connected, so that the reserved convolution kernel parameters are connected, the problem that the data reading time is long due to the dispersion of the convolution kernel parameters is solved, the calculation efficiency is further improved, and the operation performance of the convolution neural network is improved.
It should be noted that, in the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the system or the device disclosed by the embodiment, the description is simple because the system or the device corresponds to the method disclosed by the embodiment, and the relevant points can be referred to the method part for description.
It should be understood that in the present application, "at least one" means one or more, "a plurality" means two or more. "and/or" for describing an association relationship of associated objects, indicating that there may be three relationships, e.g., "a and/or B" may indicate: only A, only B and both A and B are present, wherein A and B may be singular or plural. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "at least one of the following" or similar expressions refer to any combination of these items, including any combination of single item(s) or plural items. For example, at least one (one) of a, b, or c, may represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A convolution kernel processing method applied to speech recognition or image recognition, the method comprising:
determining a target pruning template according to the size of the convolution kernel; the target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix are sequentially connected; the number of 1's in the pruning matrix is less than the convolution kernel size and not less than 1;
determining a target pruning matrix from the target pruning template;
and pruning the convolution kernel according to the target pruning matrix, reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix, and discarding the convolution kernel corresponding to the position of 0, wherein the convolution kernel after pruning is used for convolution calculation in a convolution neural network, and the convolution neural network is used for voice recognition or image recognition.
2. The method of claim 1, further comprising:
initializing the weight of the convolution kernel, setting the weight of the convolution kernel corresponding to the position of 1 in the target pruning matrix as an original value, and setting the weight value of the convolution kernel corresponding to the position of 0 in the target pruning matrix as 0;
carrying out forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain the output loss of the convolutional neural network;
judging whether the output loss amount is less than or equal to a preset threshold value or not;
if so, saving the weight of the convolution kernel in the convolution neural network.
3. The method of claim 2, wherein when the output loss amount is greater than a preset threshold, the method further comprises:
performing back propagation calculation according to the output loss amount and the convolutional neural network structure to obtain the convolution kernel weight variation;
updating the convolution kernel weight according to the target pruning matrix and the convolution kernel weight variable quantity;
and performing forward propagation calculation again according to the convolutional neural network structure and the convolutional kernel weight to obtain an output loss amount.
4. The method of claim 3, wherein the updating the convolution kernel weights according to the target pruning matrix and the convolution kernel weight variance comprises:
and taking the sum of the convolution kernel weight variation and the original value of the convolution kernel weight as the updated original value of the convolution kernel.
5. The method according to any one of claims 2 to 4, wherein the performing forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain an output loss amount of the convolutional neural network comprises:
carrying out forward propagation calculation according to the convolutional neural network structure and the convolutional kernel weight to obtain an output result of the convolutional neural network;
and taking the difference between the standard output result corresponding to the convolutional neural network structure and the output result as the output loss of the convolutional neural network.
6. The method of claim 2, wherein the saving weights for the convolution kernels in the convolutional neural network comprises:
and performing data compression according to the target pruning matrix, and storing the weight of the convolution kernel which is not 0.
7. The method of claim 1, wherein the number of 1's in the pruning matrix is equal to the convolution kernel size minus one-half of 1.
8. A convolution kernel processing apparatus, applied to speech recognition or image recognition, the apparatus comprising:
the first determining unit is used for determining a target pruning template according to the convolution kernel size; the target pruning template comprises at least one pruning matrix; the pruning matrix comprises 0 and 1, and the 1 in the pruning matrix are sequentially connected; the number of 1's in the pruning matrix is less than the convolution kernel size and greater than 1;
the second determining unit is used for determining a target pruning matrix from the target pruning template;
and the processing unit is used for pruning the convolution kernel according to the target pruning matrix, reserving the convolution kernel corresponding to the position of 1 in the target pruning matrix and abandoning the convolution kernel corresponding to the position of 0, wherein the convolution kernel after pruning is used for convolution calculation in a convolution neural network, and the convolution neural network is used for voice recognition or image recognition.
9. A computer-readable storage medium having stored therein instructions that, when run on a terminal device, cause the terminal device to perform the convolution kernel processing method of any one of claims 1-7.
10. A computer program product, which, when run on a terminal device, causes the terminal device to perform the method of convolution kernel processing of any one of claims 1-7.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811482784.0A CN109583586B (en) | 2018-12-05 | 2018-12-05 | Convolution kernel processing method and device in voice recognition or image recognition |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811482784.0A CN109583586B (en) | 2018-12-05 | 2018-12-05 | Convolution kernel processing method and device in voice recognition or image recognition |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN109583586A CN109583586A (en) | 2019-04-05 |
| CN109583586B true CN109583586B (en) | 2021-03-23 |
Family
ID=65927150
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201811482784.0A Active CN109583586B (en) | 2018-12-05 | 2018-12-05 | Convolution kernel processing method and device in voice recognition or image recognition |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN109583586B (en) |
Families Citing this family (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110188865B (en) * | 2019-05-21 | 2022-04-26 | 深圳市商汤科技有限公司 | Information processing method and device, electronic equipment and storage medium |
| CN110298348B (en) * | 2019-06-12 | 2020-04-28 | 苏州中科天启遥感科技有限公司 | Remote sensing image building sample area extraction method and system, storage medium and equipment |
| CN113361702A (en) * | 2020-03-05 | 2021-09-07 | 阿里巴巴集团控股有限公司 | Convolutional neural network pruning, reasoning method, device and computer readable medium |
| CN113392953B (en) * | 2020-03-12 | 2025-01-28 | 澜起科技股份有限公司 | Method and apparatus for pruning convolutional layers in a neural network |
| CN113496010B (en) * | 2020-03-18 | 2025-01-03 | 阿里巴巴集团控股有限公司 | Data processing methods, devices and methods for identifying infringement of neural network models |
| CN111582446B (en) * | 2020-04-28 | 2022-12-06 | 北京达佳互联信息技术有限公司 | System for neural network pruning and neural network pruning processing method |
Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107368885A (en) * | 2017-07-13 | 2017-11-21 | 北京智芯原动科技有限公司 | Network model compression method and device based on more granularity beta prunings |
-
2018
- 2018-12-05 CN CN201811482784.0A patent/CN109583586B/en active Active
Patent Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107368885A (en) * | 2017-07-13 | 2017-11-21 | 北京智芯原动科技有限公司 | Network model compression method and device based on more granularity beta prunings |
Non-Patent Citations (2)
| Title |
|---|
| "Structured Pruning of Deep Convolutional Neural Networks";Sajid Anwar;《arXiv》;20151229;摘要,第3.1节、第4节 * |
| Sajid Anwar."Structured Pruning of Deep Convolutional Neural Networks".《arXiv》.2015, * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109583586A (en) | 2019-04-05 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109583586B (en) | Convolution kernel processing method and device in voice recognition or image recognition | |
| CN111488985B (en) | Deep neural network model compression training methods, devices, equipment and media | |
| CN113361698B (en) | Neural network model processing method and device, data processing method and device | |
| CN112687266B (en) | Speech recognition method, device, computer equipment and storage medium | |
| CN113011532A (en) | Classification model training method and device, computing equipment and storage medium | |
| CN110321964A (en) | Identification model update method and relevant apparatus | |
| CN110705708A (en) | Compression method and device of convolutional neural network model and computer storage medium | |
| CN115329744B (en) | Natural language processing method, system, equipment and storage medium | |
| CN116580223B (en) | Data processing and model fine-tuning method, device, electronic device and storage medium | |
| CN112036461A (en) | Handwritten digital image recognition method, device, equipment and computer storage medium | |
| CN120598057A (en) | Question-answering reasoning method, device, equipment, and medium based on key-value cache compression | |
| CN110659735A (en) | Method, device and equipment for dynamically adjusting neural network channel | |
| CN120896677A (en) | An adaptive channel compression communication segmentation learning system, method, and medium | |
| CN113128660A (en) | Deep learning model compression method and related equipment | |
| CN113128664A (en) | Neural network compression method, device, electronic equipment and storage medium | |
| CN118364879A (en) | A quantitative training method, device, equipment and storage medium | |
| CN111881293A (en) | Risk content identification method and device, server and storage medium | |
| CN110717022A (en) | A robot dialogue generation method, device, readable storage medium and robot | |
| CN119128353B (en) | Model fine-tuning method, device, server and storage medium based on low-rank adaptation | |
| CN110838021B (en) | Conversion rate estimation method and device, electronic equipment and storage medium | |
| CN113705600A (en) | Feature map determination method and device, computer equipment and storage medium | |
| CN116415658B (en) | Search methods, devices, and computer storage media for neural network architectures | |
| CN119829709A (en) | Training of question-answering large model and question-answering task processing method and device | |
| CN113255576B (en) | Face recognition method and device | |
| CN116306942A (en) | Reasoning processing method, device and electronic equipment for language processing model |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |