Neural network channel pruning method and device based on multi-task assistance

Through the multi-task-assisted neural network channel pruning method, multi-task learning and L1 regularization constraints are used to automatically perform model pruning, which solves the problems of relying on manual intervention and over-design in the existing technology, and improves the accuracy and generalization of the model. chemical, reducing power consumption.

CN118798293APending Publication Date: 2024-10-18CHINA MOBILE GROUP ZHEJIANG +2

Patent Information

Application Number
CN202311394640.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-25
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing network pruning methods rely on manual intervention, are difficult to improve accuracy and generalization, and suffer from over-design and high power consumption.

Method used

The multi-task-assisted neural network channel pruning method is used to determine the task content of the backbone network, construct and initialize the encoding vector, and perform training and network structure pruning in the weight generation network, combined with L1 regularization constraints to perform channel pruning, and improve Model accuracy and generalization.

Benefits of technology

It realizes automated model pruning, reduces manual intervention, improves the accuracy and generalization of network pruning, reduces the complexity and power consumption of the model, and enhances the generalization ability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118798293A_ABST
    Figure CN118798293A_ABST
Patent Text Reader

Abstract

The invention provides a neural network channel pruning method and device based on multi-task assistance, and the method comprises the steps: determining the task content of a backbone network, and the task content comprises a main task and an auxiliary task; constructing and initializing a coding vector of the backbone network, wherein the coding vector at least comprises a first coding vector of a current-layer network and a second coding vector of an upper-layer network; l1 coefficient regularization constraint is added to the coding vector, a constraint result is obtained, the coding vector serves as a handle of the current layer network, and pruning of a channel corresponding to the coding vector is carried out on the current layer network by combining the handle with the constraint result; and inputting the first coding vector and the second coding vector into a constructed weight generation network for training and network structure pruning to obtain a trained pruning network. The method can improve the precision of the main task and further enhance the generalization ability of the network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of neural network technology, and in particular to a neural network channel pruning method and device based on multi-task assistance. Background Art

[0002] At present, Convolutional Neural Networks (CNN) have become the preferred architecture for a variety of image-related tasks, including image recognition, semantic segmentation, object detection, etc. As researchers explore more complex image tasks, the size of CNN networks continues to grow, which poses a challenge to model deployment in edge device application scenarios; in addition, in pursuit of accuracy goals, CNN networks often have over-designed convolutional layers, resulting in large memory and power consumption and high inference latency. Therefore, effectively compressing deep convolutional neural networks to achieve efficient storage and computing has attracted increasing attention. Network pruning is an important method to accelerate neural networks and reduce the burden of model storage and transmission, and is widely used in the industry. As a subfield of model compression, network pruning aims to discard certain parameters in the model while maintaining or even improving model performance as much as possible.

[0003] Traditional network pruning methods mainly rely on data-driven sparsity constraints or manually designed strategies, manually setting the compression ratio of each layer based on human experts or heuristic methods, and pruning and selecting filters by calculating the significance score of each filter. This method requires more manual intervention and is prone to fall into suboptimal solutions.

[0004] Therefore, how to improve the accuracy and generalization of network pruning is a technical problem that needs to be solved at present. Summary of the invention

[0005] The present invention provides a neural network channel pruning method and device based on multi-task assistance, which are used to solve the above-mentioned defects in the prior art and improve the accuracy and generalization of network pruning.

[0006] The present invention provides a neural network channel pruning method based on multi-task assistance, comprising:

[0007] Determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0008] Constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: a first encoding vector of the current layer network and a second encoding vector of the previous layer network;

[0009] Adding an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, using the encoding vector as a handle of the current layer network, and combining the handle with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0010] The first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0011] According to a multi-task assisted neural network channel pruning method provided by the present invention, the method further includes:

[0012] The weight parameters of the pruned network are fine-tuned based on the main task to obtain a final target network.

[0013] According to a multi-task assisted neural network channel pruning method provided by the present invention, the first encoding vector and the second encoding vector are input into a weight generation network for training and network structure pruning to obtain a trained pruned network, including:

[0014] Inputting the first encoding vector and the second encoding vector into a weight generation network to obtain weight parameters of the current layer network;

[0015] Acquire the main task loss and the auxiliary task loss of the weight generation network based on the weight parameters, and determine the total loss based on the main task loss and the auxiliary task loss;

[0016] The parameters of the weight generation network are updated based on the total loss, and the network structure of the weight generation network is pruned through a parameter updating process until the network parameters reach the target values, thereby obtaining a trained pruned network.

[0017] According to a multi-task assisted neural network channel pruning method provided by the present invention, the weight generation network includes a self-attention module, a weight embedding module and an output conversion module;

[0018] The self-attention module is used to perform self-attention calculation on the first encoding vector and the second encoding vector to obtain a self-attention result, and average pool the self-attention result along the channel dimension to obtain a coding matrix;

[0019] The weight embedding module is used to map the encoding matrix to the embedding space to obtain an embedding matrix;

[0020] The output conversion module is used to convert the embedding vector of the embedding matrix to obtain the weight parameter.

[0021] According to a multi-task assisted neural network channel pruning method provided by the present invention, the self-attention calculation is performed on the first encoding vector and the second encoding vector to obtain a self-attention result, and the self-attention result is averagely pooled along the channel dimension to obtain a coding matrix, including:

[0022] Obtaining the query value and the sum value of the first encoding vector and the key value of the second encoding vector through a convolution operation;

[0023] Perform self-attention calculation based on the query value, the sum value and the key value to obtain the self-attention result;

[0024] The self-attention result is subjected to element-by-element calculation of the multi-head self-attention output along the channel dimension based on the average pooling operation to obtain the encoding matrix.

[0025] According to a multi-task assisted neural network channel pruning method provided by the present invention, mapping the encoding matrix to an embedding space to obtain an embedding matrix includes:

[0026] Performing a convolution operation on the encoding matrix to map the number of channels of the encoding matrix to an m-dimensional embedding space to obtain the embedding matrix;

[0027] The step of transforming the embedding matrix to obtain the weight parameter includes:

[0028] Performing a convolution operation on the embedding matrix, mapping the number of channels of the encoding matrix to the length and width of the convolution kernel, and obtaining an output weight matrix;

[0029] A weight parameter corresponding to each element of the output weight matrix is ​​determined.

[0030] A multi-task assisted neural network channel pruning method provided by the present invention also includes:

[0031] Determining that the task content is a remote sensing image processing task;

[0032] Determine that the main task of the remote sensing image processing task is semantic segmentation, and the auxiliary tasks include edge detection and color reconstruction.

[0033] The present invention also provides a multi-task assisted neural network channel pruning device, comprising:

[0034] A determination unit, used to determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0035] A construction unit, used to construct and initialize the coding vector of the backbone network, wherein the coding vector at least includes: a first coding vector of the current layer network and a second coding vector of the previous layer network;

[0036] A constraint unit, used to add an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, use the encoding vector as a handle of the current layer network, and use the handle in combination with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0037] A pruning unit is used to input the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0038] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the multi-task-assisted neural network channel pruning method as described above is implemented.

[0039] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the multi-task-assisted neural network channel pruning methods described above.

[0040] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the multi-task-assisted neural network channel pruning methods described above.

[0041] The present invention provides a multi-task-assisted neural network channel pruning method and device, by determining the task content of the backbone network, the task content includes a main task and an auxiliary task, then constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: the first encoding vector of the current layer network and the second encoding vector of the previous layer network, further adding an L1 coefficient regularization constraint to the encoding vector, obtaining a constraint result, using the encoding vector as the handle of the current layer network, combining the handle with the constraint result to prune the channel corresponding to the encoding vector of the current layer network, and finally inputting the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network. The present invention applies multi-task learning to model pruning tasks, and in the process of super network training, adds multiple auxiliary tasks in addition to the main task, thereby improving the accuracy of the main task and further enhancing the generalization ability of the network. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0043] Figure 1 It is a flow chart of a multi-task-assisted neural network channel pruning method provided by the present invention;

[0044] Figure 2 It is a flow chart of the weight network generation and backbone network of the present invention;

[0045] Figure 3 It is a schematic diagram of the backbone network of the multi-task assisted neural network channel pruning method provided by the present invention;

[0046] Figure 4 It is a schematic diagram of a weight generation network of a multi-task assisted neural network channel pruning method provided by the present invention;

[0047] Figure 5 It is a structural schematic diagram of a neural network channel pruning device based on multi-task assistance provided by the present invention;

[0048] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] The current CNN model channel pruning method is still the traditional network pruning method. This method generally follows the following steps: first, train a transition parameterized model; then, sort the channels according to their importance and add weight sparsity terms to the network's objective function to delete unimportant channels; finally, retrain the model weights to restore the model's accuracy.

[0051] This method has two problems: a) The goal of model pruning is to remove unimportant channels rather than effectively evaluate the impact of channels on the overall accuracy of the model, which can easily lead to some channels that are unimportant in the current iteration but more important in other iterations being deleted in advance; b) The compression rate or weight threshold of each layer in this type of method is generally set manually, the level of automation is insufficient, and it is easy to enter a local optimal rather than a global optimal network structure.

[0052] The new meta-learning-based channel pruning method MetaPruning can automatically implement filter-level pruning of the model, obtain the channel compression ratio of each layer, and directly meet specific pruning goals such as reducing computational delay or reducing network parameters. However, in the specific implementation process, MetaPruning usually takes a long time in the model search phase before reaching convergence, and limited traversal may not necessarily find the network with the highest accuracy. Specifically, MetaPruning uses genetic algorithms to find the optimal pruning structure in the following steps: first, randomly generate N encoding vectors (encoding vectors can be called genes of the network, N = 50) and the corresponding network accuracy; then, according to the final accuracy level, find the k genes with the highest accuracy, and find the network with the highest accuracy as the final result through mutation (randomly changing part of the gene) and exchange (random combination of two genes). It can be seen that the process of evolutionary algorithm searching for the optimal model is a process of limited traversal and search, which may not necessarily find the network with the highest accuracy, and it takes a long time to search.

[0053] Multi-task learning is a technical means widely used in various application scenarios such as autonomous driving and indoor navigation robots that require simultaneous processing of multiple visual tasks. It has been widely proven that it can reduce inference time and improve the generalization performance of the model through shared representations between tasks. The essence of network channel pruning is the abandonment of unimportant channels, which itself can easily lead to the accidental deletion of important channels, thereby causing a decrease in the generalization performance of the model. Therefore, the present invention believes that the technical means of multi-task learning can be used to better retain features with strong generalization ability in the channel pruning stage, so as to improve the accuracy and generalization of the CNN pruned network.

[0054] Based on the above characteristics and shortcomings of the prior art, the present invention proposes an automatic convolutional neural network channel pruning method assisted by multiple tasks.

[0055] Reference Figure 1 The present invention provides a multi-task assisted neural network channel pruning method, comprising the following steps:

[0056] Step 110: Determine the task content of the backbone network, where the task content includes a main task and an auxiliary task.

[0057] Step 120: construct and initialize the encoding vector of the backbone network, wherein the encoding vector includes at least: a first encoding vector of the current layer network and a second encoding vector of the previous layer network.

[0058] Step 130: Add an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, use the encoding vector as a handle of the current layer network, and use the handle in combination with the constraint result to prune the channel corresponding to the encoding vector in the current layer network.

[0059] Step 140: Input the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0060] The following is a detailed description of each step of the present invention.

[0061] Reference Figure 2 First, determine the task content of the backbone network, which includes the main task and the auxiliary task. The task content in this embodiment uses a multi-task auxiliary structure, that is, the backbone network includes auxiliary heads of multiple auxiliary tasks related to the target task in addition to the target task, and the total loss is obtained by weighted calculation of the target task loss function and the auxiliary task loss function.

[0062] In other words, the auxiliary head is an additional branch layer added to the convolutional neural network, sharing a part of the network's feature extractor with the main task. Each auxiliary head consists of a set of layers, including convolution, pooling, and fully connected layers, and finally outputs the prediction results of the auxiliary task.

[0063] The role of the auxiliary head is to provide additional supervision signals by supervised learning of the auxiliary tasks, helping the entire network to better learn the relevant features between tasks. By sharing the feature extractor with the main task, the auxiliary task can obtain a more robust feature expression from the feature extraction process. During the training process, the main task and the auxiliary task will jointly participate in the calculation of the loss function. Usually, the weight of the loss function of the main task is larger because the main task is usually the task of more attention. The weight of the loss function of the auxiliary task is smaller, but it still plays a role in the parameter optimization of the entire network.

[0064] By introducing the auxiliary head, the generalization ability and performance of the network model can be improved through joint training of multiple tasks. The existence of the auxiliary head can help the network better learn the shared features between tasks, reduce the risk of overfitting, and provide better network model interpretability and explainability.

[0065] Through the above step 120, the encoding vector of the backbone network is constructed and initialized, and the encoding vector at least includes: the first encoding vector of the current layer network and the second encoding vector of the previous layer network.

[0066] It should be noted that each convolutional layer of the backbone network in this embodiment is designed with a corresponding encoding vector z m , in order to control the output of this layer, the encoding vector z m The length of is equal to the number of output channels of this layer of network, and the encoding vector z m The initialization is usually random.

[0067] In order to distinguish, the encoding vector of the current layer network is recorded as z m , the encoding vector z of the previous layer of the network m-1 Similarly, the encoding vector of the next layer of the network is recorded as z m+1 , and so on.

[0068] Through the above step 130, the L1 coefficient regularization constraint is added to the coding vector to obtain the constraint result, the coding vector is used as the handle of the current layer network, and the handle is combined with the constraint result to prune the channel corresponding to the coding vector of the current layer network.

[0069] It should be noted that by regularizing the vector encoding, the weights of some channels in the encoding vector can be pushed close to zero, thereby achieving the sparsity of the encoding vector. This can reduce the complexity of the model and facilitate feature selection and interpretation.

[0070] It should be noted that the coefficient of L1 sparse regularization needs to be set appropriately. A coefficient that is too small may not effectively promote the sparsity of the weights, while a coefficient that is too large may lead to excessive sparsity and affect the performance of the model. By constraining the weight of the encoding vector through L1 sparse regularization, the weights of some channels in the encoding vector can be made close to zero, thus achieving the sparsity of the encoding vector.

[0071] It should be noted that the handle in the pruning process usually refers to the reference or identification of a specific weight or node in the neural network model to which the pruning operation is applied. The handle can be used to determine the location, node or parameter that needs to be pruned and apply the pruning operation to these locations. By adjusting the handle, the model can be pruned accurately and the amplitude and range of pruning can be controlled.

[0072] Through this embodiment, by using the encoding vector as a handle for pruning operations, effective model pruning can be achieved to improve the efficiency and inference speed of the model while maintaining high performance and accuracy.

[0073] Through the above step 140, the first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0074] It should be noted that during the back propagation process of training, the parameters of the backbone network do not need to be updated, only the parameters of the weight generation network need to be updated. Since all operations in the weight generation network structure in this embodiment, the calculation of the loss function, and the L1 regularization operation are in a differentiable form, the back propagation can directly calculate the gradient through the chain derivative rule and update the network weights of the weight generation network.

[0075] In actual operation, a new encoding vector is randomly generated in each iteration. By inputting different encoding vectors, the weight generation network gradually learns to generate network parameters from the encoding vector and prunes the network structure until the network parameters reach the target value, thus obtaining a trained pruned network.

[0076] In some embodiments, the present invention further includes step 150, fine-tuning the weight parameters of the pruned network based on the main task to obtain a final target network.

[0077] It should be noted that after obtaining the trained pruned network, in the weight fine-tuning process in the post-group stage, multi-task assistance is no longer used, and the target task is directly used to calculate the total loss function.

[0078] The neural network channel pruning method based on multi-task assistance provided by the present invention determines the task content of the backbone network, which includes the main task and the auxiliary task, and then constructs and initializes the encoding vector of the backbone network, the encoding vector at least includes: the first encoding vector of the current layer network and the second encoding vector of the previous layer network, further adds the L1 coefficient regularization constraint to the encoding vector, obtains the constraint result, uses the encoding vector as the handle of the current layer network, combines the handle with the constraint result to prune the channel corresponding to the encoding vector of the current layer network, and finally inputs the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network. The present invention applies multi-task learning to the model pruning task, and in the super network training process, adds multiple auxiliary tasks in addition to the main task, so as to improve the accuracy of the main task and further enhance the generalization ability of the network.

[0079] Furthermore, the present invention utilizes the idea of ​​meta-learning to construct a weight-generating super-network weight-generating network, and trains the weight-generating network to generate the weights of the backbone network. Unlike the existing meta-learning algorithms, the present invention applies an L1 sparsification constraint to the coding vector to achieve automatic pruning of the channels corresponding to the coding vector, thereby avoiding the step of MetaPruning finding the optimal network structure through a genetic algorithm, and can improve the efficiency of model pruning. Therefore, the present invention can not only avoid the manual intervention and suboptimal solution of the channel pruning of the traditional CNN model, but also avoid the time loss of MetaPruning in the process of searching for the optimal network structure. In addition, in order to further improve the accuracy of the target task and the generalization ability of the backbone network, the present invention incorporates multi-task learning technology into the model pruning process. In specific implementation, in the model training stage, multiple auxiliary tasks are used so that channels that have a greater impact on the generalization of the network are not deleted prematurely.

[0080] In some embodiments, the step of inputting the first encoding vector and the second encoding vector into a weight generation network for training and network structure pruning to obtain a trained pruned network includes:

[0081] Inputting the first encoding vector and the second encoding vector into a weight generation network to obtain weight parameters of the current layer network;

[0082] Acquire the main task loss and the auxiliary task loss of the weight generation network based on the weight parameters, and determine the total loss based on the main task loss and the auxiliary task loss;

[0083] The parameters of the weight generation network are updated based on the total loss, and the network structure of the weight generation network is pruned through a parameter updating process until the network parameters reach the target values, thereby obtaining a trained pruned network.

[0084] This embodiment is a process of weight generation network and network structure pruning.

[0085] The present invention uses a multi-task assisted random method to train the weight generation network. The weight generation network consists of multiple weight blocks WetGen Block. The present invention first uses a random initialization method to initialize the parameters of each WetGen Block network. Subsequently, a random number between 0 and 1 is used to randomly generate the encoding vector of each layer. During the forward propagation process, the weight generation network can generate the weight parameters of each layer of the backbone network, and use them to calculate the main task loss and the loss of multiple auxiliary tasks, thereby calculating the total loss of the network.

[0086] After determining the total loss, the parameters of the weight generation network are continuously updated through the back-propagation process. A new encoding vector is randomly generated in each iteration. By inputting different encoding vectors, the weight generation network gradually learns to generate network parameters from the encoding vector and prune the network structure.

[0087] It should be noted that in order to further improve the accuracy of the model, you can choose to take out the total epoch during the training process. The training weights generate the network network, thus obtaining the pruned network structure. Finally, the remaining epochs continue to fine-tune the network parameters.

[0088] The present invention generates a network by training weights and prunes the network structure during the training process. It can be combined with multi-task assistance so that channels that have a greater impact on the generalization of the network will not be deleted prematurely, thereby improving the accuracy of the main task and further enhancing the generalization ability of the network.

[0089] In some embodiments, it also includes:

[0090] Determining that the task content is a remote sensing image processing task;

[0091] Determine that the main task of the remote sensing image processing task is semantic segmentation, and the auxiliary tasks include edge detection and color reconstruction.

[0092] This embodiment is a process of determining task content and backbone network.

[0093] First of all, it should be pointed out that the backbone network generally chooses classic visual task network structures such as DeeplabV3+, MaskRCNN, YoloV5, etc., or is designed based on the classic network structure according to the target tasks, data conditions, and hardware conditions in actual production.

[0094] DeeplabV3+ is a network structure for image semantic segmentation, MaskRCNN is a network structure for object detection and instance segmentation, and YoloV5 is a lightweight object detection network structure.

[0095] The multi-task auxiliary head generally selects other tasks related to the target task. In this embodiment, the semantic segmentation task of remote sensing images is taken as an example to design the backbone network and the multi-task auxiliary head. The dataset uses the classic dataset in the remote sensing field for semantic segmentation.

[0096] Reference Figure 3 In this embodiment, the edge detection task and the color reconstruction task are added to the main task of semantic segmentation. The specific backbone network and multi-task auxiliary head are as follows:

[0097] The edge detection task is used to detect whether a pixel is a target edge, and the color reconstruction task is used to detect whether the original color information can be restored from the feature extraction results. The loss weights of both are set to 0.1, and the loss weight of the main task semantic segmentation is set to 0.8. The total loss of the network can be expressed as:

[0098] L 总 =αL 语义分割 +βL 边缘检测 +λL 色彩重建

[0099] Among them, α=0.8, β=λ=0.1, respectively represent the weights of the loss function of each visual task. The values ​​of α, β, and λ can be set flexibly without too much limitation. In this embodiment, the assistance of multiple tasks can effectively enhance the generalization characteristics of the model itself.

[0100] In some embodiments, the weight generation network includes a self-attention module, a weight embedding module, and an output conversion module;

[0101] The self-attention module is used to perform self-attention calculation on the first encoding vector and the second encoding vector to obtain a self-attention result, and average pool the self-attention result along the channel dimension to obtain a coding matrix;

[0102] Specifically, the query value and the sum value of the first coding vector and the key value of the second coding vector are obtained through a convolution operation;

[0103] Perform self-attention calculation based on the query value, the sum value and the key value to obtain the self-attention result;

[0104] The self-attention result is subjected to element-by-element calculation of the multi-head self-attention output along the channel dimension based on the average pooling operation to obtain the encoding matrix.

[0105] The weight embedding module is used to map the encoding matrix to the embedding space to obtain an embedding matrix;

[0106] Specifically, the method comprises: performing a convolution operation on the encoding matrix, mapping the number of channels of the encoding matrix to an m-dimensional embedding space, and obtaining the embedding matrix;

[0107] The output conversion module is used to convert the embedding vector of the embedding matrix to obtain the weight parameter.

[0108] Specifically manifested as:

[0109] Performing a convolution operation on the embedding matrix, mapping the number of channels of the encoding matrix to the length and width of the convolution kernel, and obtaining an output weight matrix;

[0110] A weight parameter corresponding to each element of the output weight matrix is ​​determined.

[0111] Specifically, the weight generation network belongs to the category of super network, with the encoding vector z of the current layer m and the encoding vector z of the previous layer m-1 As input, it directly outputs the weight parameters of the current layer. It consists of multiple WetGen Blocks, each of which is responsible for generating the weight parameters of the current layer. The network structure of a single WetGen Block is shown in the figure below:

[0112] Reference Figure 4 , WetGen Block consists of three layers, namely, self-attention module, weight embedding module and output transformation module. For any input z m and z m-1 , the network structure of the self-attention module is an n-head self-attention structure, and then the n self-attention calculation results are averaged pooled along the channel dimension to obtain the encoding matrix Z m The network structure of the weight embedding module is a 1x1 convolution operation, which is used to map the two-dimensional encoding matrix to the embedding space. The output conversion module is also a 1x1 convolution operation, which is used to further convert the embedding vector into the final output result, that is, the weight parameter.

[0113] Taking the Lth layer of the convolutional neural network as an example, the dimension of the weight parameter of this layer is c out *c in *w*h, where c in and c out Represent the number of channels in the input and output layers, respectively, and w and h represent the length and width of the convolution kernel. That is z m The length of is equal to the number of output channels; That is z m-1 The length of is equal to the number of input channels. The calculation formula of the self-attention module is as follows:

[0114]

[0115]

[0116]

[0117] Where Q, K, and V represent query, key, and value respectively. Q, K, and V are respectively encoded by the vector z m 、z m-1 Calculated by 1*1 convolution operation, multi-head self-attention can fully learn z in different spatial dimensions. m 、z m-1Finally, the average pooling operation is used to calculate the multi-head self-attention output element by element along the channel direction to obtain the encoding matrix

[0118] Furthermore, the embedding space module transforms the weight matrix Z through a 1x1 convolution operation. m The number of channels is mapped to m dimensions, and we get

[0119] E m =W E Z m +B E

[0120] Among them, W E is the weight matrix E m The weight of B E E is the weight matrix m The bias.

[0121] Finally, the output conversion module again passes a 1x1 convolution operation to convert the weight matrix O m The number of channels is mapped to w*h, and we get

[0122] O m =W o E m +B o

[0123] Among them, W o is the weight matrix O m The weight of B o is the weight matrix O m The bias.

[0124] Then there is an output weight O m Each element in represents each weight value required by the convolutional layer. By further adding L1 sparse regularization constraints to the encoding vector, the weights of some channels in the encoding vector are made close to 0. Based on the results of the sparse regularization constraints, the channels corresponding to the elements in the vector are pruned.

[0125] The following is a description of the multi-task-assisted neural network channel pruning device provided by the present invention. The multi-task-assisted neural network channel pruning device described below and the multi-task-assisted neural network channel pruning method described above can refer to each other.

[0126] Reference Figure 5 The present invention provides a multi-task assisted neural network channel pruning device, comprising:

[0127] A determination unit 510, configured to determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0128] A construction unit 520 is used to construct and initialize the coding vector of the backbone network, wherein the coding vector includes at least: a first coding vector of the current layer network and a second coding vector of the previous layer network;

[0129] A constraint unit 530 is used to add an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, use the encoding vector as a handle of the current layer network, and use the handle in combination with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0130] The pruning unit 540 is used to input the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0131] In some embodiments, the apparatus further comprises a fine-tuning module, the fine-tuning module being configured to:

[0132] The weight parameters of the pruned network are fine-tuned based on the main task to obtain a final target network.

[0133] In some embodiments, the step of inputting the first encoding vector and the second encoding vector into a weight generation network for training and network structure pruning to obtain a trained pruned network includes:

[0134] Inputting the first encoding vector and the second encoding vector into a weight generation network to obtain weight parameters of the current layer network;

[0135] Acquire the main task loss and the auxiliary task loss of the weight generation network based on the weight parameters, and determine the total loss based on the main task loss and the auxiliary task loss;

[0136] The parameters of the weight generation network are updated based on the total loss, and the network structure of the weight generation network is pruned through a parameter updating process until the network parameters reach the target values, thereby obtaining a trained pruned network.

[0137] In some embodiments, the weight generation network includes a self-attention module, a weight embedding module, and an output conversion module;

[0138] The self-attention module is used to perform self-attention calculation on the first encoding vector and the second encoding vector to obtain a self-attention result, and average pool the self-attention result along the channel dimension to obtain a coding matrix;

[0139] The weight embedding module is used to map the encoding matrix to the embedding space to obtain an embedding matrix;

[0140] The output conversion module is used to convert the embedding vector of the embedding matrix to obtain the weight parameter.

[0141] In some embodiments, performing self-attention calculation on the first encoding vector and the second encoding vector to obtain a self-attention result, and averaging pooling the self-attention result along the channel dimension to obtain a coding matrix includes:

[0142] Obtaining the query value and the sum value of the first encoding vector and the key value of the second encoding vector through a convolution operation;

[0143] Perform self-attention calculation based on the query value, the sum value and the key value to obtain the self-attention result;

[0144] The self-attention result is subjected to element-by-element calculation of the multi-head self-attention output along the channel dimension based on the average pooling operation to obtain the encoding matrix.

[0145] In some embodiments, mapping the encoding matrix to an embedding space to obtain an embedding matrix includes:

[0146] Performing a convolution operation on the encoding matrix to map the number of channels of the encoding matrix to an m-dimensional embedding space to obtain the embedding matrix;

[0147] The step of transforming the embedding matrix to obtain the weight parameter includes:

[0148] Performing a convolution operation on the embedding matrix, mapping the number of channels of the encoding matrix to the length and width of the convolution kernel, and obtaining an output weight matrix;

[0149] A weight parameter corresponding to each element of the output weight matrix is ​​determined.

[0150] In some embodiments, it also includes:

[0151] Determining that the task content is a remote sensing image processing task;

[0152] Determine that the main task of the remote sensing image processing task is semantic segmentation, and the auxiliary tasks include edge detection and color reconstruction.

[0153] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the neural network channel pruning method based on multi-task assistance, and the method includes:

[0154] Determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0155] Constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: a first encoding vector of the current layer network and a second encoding vector of the previous layer network;

[0156] Adding an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, using the encoding vector as a handle of the current layer network, and combining the handle with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0157] The first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0158] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0159] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer can execute the multi-task assisted neural network channel pruning method provided by the above methods, the method comprising:

[0160] Determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0161] Constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: a first encoding vector of the current layer network and a second encoding vector of the previous layer network;

[0162] Adding an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, using the encoding vector as a handle of the current layer network, and combining the handle with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0163] The first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0164] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the multi-task-assisted neural network channel pruning method provided by the above methods, the method comprising:

[0165] Determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task;

[0166] Constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: a first encoding vector of the current layer network and a second encoding vector of the previous layer network;

[0167] Adding an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, using the encoding vector as a handle of the current layer network, and combining the handle with the constraint result to prune the channel corresponding to the encoding vector to the current layer network;

[0168] The first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

[0169] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0170] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0171] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A multi-task assisted neural network channel pruning method, characterized in that: include: Determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task; Constructing and initializing the encoding vector of the backbone network, the encoding vector at least includes: a first encoding vector of the current layer network and a second encoding vector of the previous layer network; Adding an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, using the encoding vector as a handle of the current layer network, and combining the handle with the constraint result to prune the channel corresponding to the encoding vector to the current layer network; The first encoding vector and the second encoding vector are input into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

2. The multi-task assisted neural network channel pruning method according to claim 1, characterized in that: The method further comprises: The weight parameters of the pruned network are fine-tuned based on the main task to obtain a final target network.

3. The multi-task assisted neural network channel pruning method according to claim 1, characterized in that: The step of inputting the first encoding vector and the second encoding vector into a weight generation network for training and network structure pruning to obtain a trained pruned network includes: Inputting the first encoding vector and the second encoding vector into a weight generation network to obtain weight parameters of the current layer network; Acquire the main task loss and the auxiliary task loss of the weight generation network based on the weight parameters, and determine the total loss based on the main task loss and the auxiliary task loss; The parameters of the weight generation network are updated based on the total loss, and the network structure of the weight generation network is pruned through a parameter updating process until the network parameters reach the target values, thereby obtaining a trained pruned network.

4. The multi-task assisted neural network channel pruning method according to claim 2, characterized in that: The weight generation network includes a self-attention module, a weight embedding module and an output conversion module; The self-attention module is used to perform self-attention calculation on the first encoding vector and the second encoding vector to obtain a self-attention result, and average pool the self-attention result along the channel dimension to obtain a coding matrix; The weight embedding module is used to map the encoding matrix to the embedding space to obtain an embedding matrix; The output conversion module is used to convert the embedding vector of the embedding matrix to obtain the weight parameter.

5. The multi-task assisted neural network channel pruning method according to claim 4, characterized in that: The self-attention calculation is performed on the first encoding vector and the second encoding vector to obtain a self-attention result, and the self-attention result is averagely pooled along the channel dimension to obtain a coding matrix, including: Obtaining the query value and the sum value of the first encoding vector and the key value of the second encoding vector through a convolution operation; Perform self-attention calculation based on the query value, the sum value and the key value to obtain the self-attention result; The self-attention result is subjected to element-by-element calculation of the multi-head self-attention output along the channel dimension based on the average pooling operation to obtain the encoding matrix.

6. The multi-task assisted neural network channel pruning method according to claim 5, characterized in that: Mapping the encoding matrix to an embedding space to obtain an embedding matrix includes: Performing a convolution operation on the encoding matrix to map the number of channels of the encoding matrix to an m-dimensional embedding space to obtain the embedding matrix; The step of transforming the embedding matrix to obtain the weight parameter includes: Performing a convolution operation on the embedding matrix, mapping the number of channels of the encoding matrix to the length and width of the convolution kernel, and obtaining an output weight matrix; A weight parameter corresponding to each element of the output weight matrix is ​​determined.

7. The multi-task assisted neural network channel pruning method according to claim 1, characterized in that: Also includes: Determining that the task content is a remote sensing image processing task; It is determined that the main task of the remote sensing image processing task is semantic segmentation, and the auxiliary tasks include edge detection and color reconstruction.

8. A multi-task assisted automatic convolutional neural network channel pruning device, characterized in that: include: A determination unit, used to determine the task content of the backbone network, wherein the task content includes a main task and an auxiliary task; A construction unit, used to construct and initialize the coding vector of the backbone network, wherein the coding vector at least includes: a first coding vector of the current layer network and a second coding vector of the previous layer network; A constraint unit, used to add an L1 coefficient regularization constraint to the encoding vector to obtain a constraint result, use the encoding vector as a handle of the current layer network, and use the handle in combination with the constraint result to prune the channel corresponding to the encoding vector to the current layer network; A pruning unit is used to input the first encoding vector and the second encoding vector into the constructed weight generation network for training and network structure pruning to obtain a trained pruned network.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the multi-task assisted neural network channel pruning method as described in any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the multi-task-assisted neural network channel pruning method as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Relation enhanced sentence sorting method based on Bert model

    CN112307745A

  • Automatic pruning method and platform for convolutional neural network general compression architecture

    CN112396181A

  • Online question and answer community expert recommendation method based on multi-head self-attention mechanism

    CN115408603A

  • Edible mushroom infectious microbe detection method based on attention multi-source feature fusion

    CN116824205A

Cited By

  • Auxiliary learning architecture searching method and device

    CN119692401A