CN114492783A - Pruning method and device for multitask neural network model - Google Patents
Pruning method and device for multitask neural network model Download PDFInfo
- Publication number
- CN114492783A CN114492783A CN202011153067.0A CN202011153067A CN114492783A CN 114492783 A CN114492783 A CN 114492783A CN 202011153067 A CN202011153067 A CN 202011153067A CN 114492783 A CN114492783 A CN 114492783A
- Authority
- CN
- China
- Prior art keywords
- pruning
- model
- pruned
- layer
- preset
- 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.)
- Granted
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
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/04—Architecture, e.g. interconnection topology
- G06N3/045—Combinations of networks
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
Description
技术领域technical field
本发明涉及计算机技术领域,具体而言,涉及一种多任务神经网络模型的剪枝方法及装置。The present invention relates to the field of computer technology, and in particular, to a method and device for pruning a multi-task neural network model.
背景技术Background technique
深度学习的发展使得深度神经网络越来越多地被应用到如图像识别、检测及跟踪等计算机视觉任务中,且网络模型越来越多地趋向于往更宽更深的方向设计。深度学习的成功很大程度上依赖于模型大量的参数以及具有强大性能的计算设备。但是,由于深度神经网络巨大的内存需求和计算消耗使其较难部署到低存储、低功耗的硬件平台上(如移动设备),这极大地限制了其应用。因此,研究如何在保证现有深度神经网络模型性能不变的情况下,有效压缩神经网络模型是需要解决的重要问题。The development of deep learning has made deep neural networks more and more applied to computer vision tasks such as image recognition, detection and tracking, and network models tend to be designed in a wider and deeper direction. The success of deep learning largely depends on the large number of parameters of the model and the computing equipment with powerful performance. However, due to the huge memory requirements and computational consumption of deep neural networks, it is difficult to deploy them on low-storage, low-power hardware platforms (such as mobile devices), which greatly limits their applications. Therefore, it is an important problem to study how to effectively compress the neural network model while keeping the performance of the existing deep neural network model unchanged.
那么,如何提供一种对多任务神经网络模型的剪枝方法成为亟待解决的问题。Then, how to provide a pruning method for multi-task neural network models has become an urgent problem to be solved.
发明内容SUMMARY OF THE INVENTION
本发明提供了一种多任务神经网络模型的剪枝方法及装置,以实现对多任务神经网络模型的剪枝。具体的技术方案如下:The invention provides a method and device for pruning a multi-task neural network model, so as to realize the pruning of the multi-task neural network model. The specific technical solutions are as follows:
第一方面,本发明实施例提供了一种多任务神经网络模型的剪枝方法,所述方法包括:In a first aspect, an embodiment of the present invention provides a method for pruning a multi-task neural network model, the method comprising:
获得训练完成的多任务神经网络模型,作为待剪枝模型;Obtain the trained multi-task neural network model as the model to be pruned;
针对所述待剪枝模型的每一卷积层,执行如下步骤A-C,以确定出每一卷积层在不同预设层剪枝率下的敏感度信息;For each convolutional layer of the model to be pruned, the following steps A-C are performed to determine the sensitivity information of each convolutional layer under different preset layer pruning rates;
步骤A:针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝;Step A: for each preset layer pruning rate, based on the preset layer pruning rate and each convolution kernel in the convolution layer, pre-prune the convolution layer;
步骤B:基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值;Step B: Based on the first training data, determine the loss value of each task corresponding to the pre-pruned model to be pruned corresponding to the preset layer pruning rate;
步骤C:基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;Step C: Determine the sensitivity information of the convolutional layer at the preset layer pruning rate based on the loss value of each task corresponding to the pre-pruned model to be pruned;
基于所述待剪枝模型对应的通道信息,对所述待剪枝模型的卷积层中的卷积核进行分组;grouping the convolution kernels in the convolution layer of the to-be-pruned model based on the channel information corresponding to the to-be-pruned model;
基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型。Based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning of each convolutional layer at different layers The sensitivity information under the rate is used to determine the target pruning model.
可选的,所述基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型的步骤,包括:Optionally, the pruning rate based on the current model, the grouping situation of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolution layer, and each convolution kernel. The sensitivity information of layers under different layer pruning rates, and the steps to determine the target pruning model, including:
基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到当前的剪枝模型;Based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning of each convolutional layer at different layers Sensitivity information at the rate, prune the to-be-pruned model to obtain the current pruning model;
基于第二训练数据,确定所述当前的剪枝模型对应的各第二训练数据对应的检测信息;determining, based on the second training data, detection information corresponding to each second training data corresponding to the current pruning model;
若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型达到预设剪枝条件,将所述当前的剪枝模型确定为目标剪枝模型。If it is determined that the current pruning model meets the preset pruning condition based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data, the current pruning model The pruning model is determined as the target pruning model.
可选的,所述方法还包括:Optionally, the method further includes:
若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型未达到预设剪枝条件,调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率;If, based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data, it is determined that the current pruning model does not meet the preset pruning conditions, and the current pruning model is adjusted. The value of the model pruning rate to get the new current model pruning rate;
基于新的当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到新的当前的剪枝模型;Based on the new current model pruning rate, the grouping of convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning of each convolutional layer at different layers According to the sensitivity information at the rate, prune the model to be pruned to obtain a new current pruning model;
基于第三训练数据,确定所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息;Based on the third training data, determining the detection information corresponding to each third training data corresponding to the new current pruning model;
若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型达到预设剪枝条件,将所述新的当前的剪枝模型确定为目标剪枝模型;If it is determined that the new current pruning model meets the preset pruning condition based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, determining the new current pruning model as the target pruning model;
若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型未达到预设剪枝条件,返回所述调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率的步骤。If based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, it is determined that the new current pruning model does not meet the preset pruning conditions , and return to the step of adjusting the value of the current model pruning rate to obtain a new current model pruning rate.
可选的,所述基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息的步骤,包括:Optionally, the step of determining the sensitivity information of the convolutional layer at the preset layer pruning rate based on the loss value of each task corresponding to the pre-pruned model to be pruned includes:
基于预剪枝后的待剪枝模型对应的各任务损失值以及预设目标函数,确定预剪枝后的待剪枝模型对应的损失值;Based on the loss value of each task corresponding to the pre-pruned model to be pruned and the preset objective function, determine the loss value corresponding to the pre-pruned model to be pruned;
基于所述预剪枝后的待剪枝模型对应的损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;其中,所述预设目标函数的表达式为:Based on the loss value corresponding to the pre-pruned model to be pruned, the sensitivity information of the convolutional layer at the preset layer pruning rate is determined; wherein, the expression of the preset objective function is:
其中,Objective表示预剪枝后的待剪枝模型对应的损失值,lossi表示所述待剪枝模型中第i个任务对应的任务损失值,wi表示所述待剪枝模型中第i个任务对应的任务权重;L表示所述待剪枝模型的任务的数量。Among them, Objective represents the loss value corresponding to the pre-pruned model to be pruned, loss i represents the task loss value corresponding to the i-th task in the to-be-pruned model, and w i represents the i-th task in the to-be-pruned model The task weights corresponding to each task; L represents the number of tasks of the model to be pruned.
可选的,所述基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝的步骤,包括:Optionally, the step of pre-pruning the convolution layer based on the preset layer pruning rate and each convolution kernel in the convolution layer includes:
针对该卷积层的每一卷积核,基于该卷积核中的各权重参数,确定该卷积核对应的剪枝范数值;For each convolution kernel of the convolution layer, based on each weight parameter in the convolution kernel, determine the pruning norm value corresponding to the convolution kernel;
基于该预设层剪枝率以及该卷积层中各卷积核对应的剪枝范数值,依据预设剪枝规则,对该卷积层进行预剪枝,其中,所述预设剪枝规则为:优先针对所对应剪枝范数值小的卷积核进行预剪枝。Based on the preset layer pruning rate and the pruning norm value corresponding to each convolution kernel in the convolution layer, the convolution layer is pre-pruned according to preset pruning rules, wherein the preset pruning The rule is: Pre-pruning is performed preferentially on the corresponding convolution kernel with a small pruning norm value.
第二方面,本发明实施例提供了一种多任务神经网络模型的剪枝装置,所述装置包括:In a second aspect, an embodiment of the present invention provides a device for pruning a multi-task neural network model, the device comprising:
获得模块,被配置为获得训练完成的多任务神经网络模型,作为待剪枝模型;The obtaining module is configured to obtain the trained multi-task neural network model as the model to be pruned;
第一确定模块,被配置为针对所述待剪枝模型的每一卷积层,通过如下单元,确定出每一卷积层在不同预设层剪枝率下的敏感度信息;The first determining module is configured to, for each convolutional layer of the model to be pruned, determine the sensitivity information of each convolutional layer under different preset layer pruning rates through the following units;
预剪枝单元,被配置为针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝;a pre-pruning unit, configured to perform pre-pruning on the convolution layer based on the preset layer pruning rate and each convolution kernel in the convolution layer for each preset layer pruning rate;
第一确定单元,被配置为基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值;The first determining unit is configured to determine, based on the first training data, the loss value of each task corresponding to the pre-pruned model to be pruned corresponding to the preset layer pruning rate;
第二确定单元,被配置为基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;The second determining unit is configured to determine the sensitivity information of the convolutional layer at the preset layer pruning rate based on the loss value of each task corresponding to the pre-pruned model to be pruned;
分组模块,被配置为基于所述待剪枝模型对应的通道信息,对所述待剪枝模型的卷积层中的卷积核进行分组;a grouping module, configured to group the convolution kernels in the convolutional layer of the model to be pruned based on the channel information corresponding to the model to be pruned;
第二确定模块,被配置为基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型。The second determination module is configured to be based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and each The sensitivity information of the convolutional layer at different layer pruning rates determines the target pruning model.
可选的,所述第二确定模块,包括:Optionally, the second determining module includes:
第一剪枝单元,被配置为基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到当前的剪枝模型;The first pruning unit is configured to be based on the current model pruning rate, the grouping situation of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and each convolution kernel. Sensitivity information of a convolutional layer under different layer pruning rates, prune the to-be-pruned model to obtain the current pruning model;
第三确定单元,被配置为基于第二训练数据,确定所述当前的剪枝模型对应的各第二训练数据对应的检测信息;a third determining unit, configured to determine, based on the second training data, detection information corresponding to each second training data corresponding to the current pruning model;
第四确定单元,被配置为若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型达到预设剪枝条件,将所述当前的剪枝模型确定为目标剪枝模型。a fourth determination unit, configured to determine that the current pruning model reaches a preset level based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data The pruning condition is to determine the current pruning model as the target pruning model.
可选的,所述第二确定模块还包括:Optionally, the second determining module further includes:
调整单元,被配置为若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型未达到预设剪枝条件,调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率;An adjustment unit, configured to determine that the current pruning model does not reach the preset pruning value based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data branch condition, adjust the value of the current model pruning rate to obtain the new current model pruning rate;
第二剪枝单元,被配置为基于新的当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到新的当前的剪枝模型;The second pruning unit is configured to be based on the new current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and each Sensitivity information of a convolutional layer under different layer pruning rates, pruning the to-be-pruned model to obtain a new current pruning model;
第五确定单元,被配置为基于第三训练数据,确定所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息;a fifth determining unit, configured to determine, based on the third training data, detection information corresponding to each third training data corresponding to the new current pruning model;
第六确定单元,被配置为若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型达到预设剪枝条件,将所述新的当前的剪枝模型确定为目标剪枝模型;a sixth determining unit, configured to determine the new current pruning based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data The model reaches the preset pruning condition, and the new current pruning model is determined as the target pruning model;
若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型未达到预设剪枝条件,返回触发所述调整单元。If based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, it is determined that the new current pruning model does not meet the preset pruning conditions , and return to trigger the adjustment unit.
可选的,所述第二确定单元,被具体配置为基于预剪枝后的待剪枝模型对应的各任务损失值以及预设目标函数,确定预剪枝后的待剪枝模型对应的损失值;Optionally, the second determining unit is specifically configured to determine the loss corresponding to the pre-pruned model to be pruned based on the loss value of each task corresponding to the pre-pruned model to be pruned and the preset objective function. value;
基于所述预剪枝后的待剪枝模型对应的损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;其中,所述预设目标函数的表达式为:Based on the loss value corresponding to the pre-pruned model to be pruned, the sensitivity information of the convolutional layer at the preset layer pruning rate is determined; wherein, the expression of the preset objective function is:
其中,Objective表示预剪枝后的待剪枝模型对应的损失值,lossi表示所述待剪枝模型中第i个任务对应的任务损失值,wi表示所述待剪枝模型中第i个任务对应的任务权重;L表示所述待剪枝模型的任务的数量。Among them, Objective represents the loss value corresponding to the pre-pruned model to be pruned, loss i represents the task loss value corresponding to the i-th task in the to-be-pruned model, and w i represents the i-th task in the to-be-pruned model The task weights corresponding to each task; L represents the number of tasks of the model to be pruned.
可选的,所述预剪枝单元,被具体配置为针对该卷积层的每一卷积核,基于该卷积核中的各权重参数,确定该卷积核对应的剪枝范数值;Optionally, the pre-pruning unit is specifically configured to, for each convolution kernel of the convolution layer, determine the pruning norm value corresponding to the convolution kernel based on each weight parameter in the convolution kernel;
基于该预设层剪枝率以及该卷积层中各卷积核对应的剪枝范数值,依据预设剪枝规则,对该卷积层进行预剪枝,其中,所述预设剪枝规则为:优先针对所对应剪枝范数值小的卷积核进行预剪枝。Based on the preset layer pruning rate and the pruning norm value corresponding to each convolution kernel in the convolution layer, the convolution layer is pre-pruned according to preset pruning rules, wherein the preset pruning The rule is: Pre-pruning is performed preferentially on the corresponding convolution kernel with a small pruning norm value.
由上述内容可知,本发明实施例提供的一种多任务神经网络模型的剪枝方法及装置,获得训练完成的多任务神经网络模型,作为待剪枝模型;针对待剪枝模型的每一卷积层,执行如下步骤A-C,以确定出每一卷积层在不同预设层剪枝率下的敏感度信息;步骤A:针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝;步骤B:基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值;步骤C:基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;基于待剪枝模型对应的通道信息,对待剪枝模型的卷积层中的卷积核进行分组;基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型。It can be seen from the above content that the method and device for pruning a multi-task neural network model provided by the embodiments of the present invention obtain a trained multi-task neural network model as the model to be pruned; for each volume of the model to be pruned Layering, perform the following steps A-C to determine the sensitivity information of each convolutional layer under different preset layer pruning rates; Step A: for each preset layer pruning rate, based on the preset layer pruning rate and each convolution kernel in the convolution layer, pre-pruning the convolution layer; step B: based on the first training data, determine the pre-pruned model to be pruned corresponding to the pruning rate of the preset layer. Corresponding to the loss value of each task; Step C: Based on the loss value of each task corresponding to the pre-pruned model to be pruned, determine the sensitivity information of the convolutional layer at the preset layer pruning rate; Based on the model to be pruned Corresponding channel information, group the convolution kernels in the convolutional layer of the model to be pruned; based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the volume of each convolutional layer in each layer The pruning norm value corresponding to the accumulation kernel and the sensitivity information of each convolutional layer under different layer pruning rates are used to determine the target pruning model.
应用本发明实施例,利用待剪枝网络中各多个任务对应的任务损失值,共同确定各层卷积层在不同预设层剪枝率下的敏感度信息,进而,基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型,以实现对多任务神经网络模型的剪枝。并且结合多个任务对应的任务损失值作为剪枝目标,综合考虑多个任务的精度进行敏感度分析和剪枝,有效保留稀疏模型的泛化性能,能够平衡剪枝后的模型多个任务的精度损失,降低重新训练难度。当然,实施本发明的任一产品或方法并不一定需要同时达到以上所述的所有优点。By applying the embodiments of the present invention, the task loss values corresponding to multiple tasks in the network to be pruned are used to jointly determine the sensitivity information of each layer of convolutional layers under different preset layer pruning rates, and then, based on the current model pruning The branch rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the sensitivity information of each convolutional layer at different layer pruning rates, Determine the target pruning model to achieve pruning of multi-task neural network models. In addition, combining the task loss values corresponding to multiple tasks as the pruning target, comprehensively considering the accuracy of multiple tasks for sensitivity analysis and pruning, the generalization performance of the sparse model is effectively preserved, and the pruned model can be balanced for multiple tasks. Accuracy loss, reducing the difficulty of retraining. Of course, it is not necessary for any product or method of the present invention to achieve all of the advantages described above at the same time.
本发明实施例的创新点包括:The innovative points of the embodiments of the present invention include:
1、利用待剪枝网络中各多个任务对应的任务损失值,共同确定各层卷积层在不同预设层剪枝率下的敏感度信息,进而,基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型,以实现对多任务神经网络模型的剪枝。并且结合多个任务对应的任务损失值作为剪枝目标,综合考虑多个任务的精度对模型进行敏感度分析和剪枝,有效保留稀疏模型的泛化性能,能够平衡剪枝后的模型多个任务的精度损失,降低重新训练难度。1. Use the task loss values corresponding to multiple tasks in the network to be pruned to jointly determine the sensitivity information of each layer of convolutional layers under different preset layer pruning rates, and then, based on the current model pruning rate, to be The grouping of the convolution kernels of the pruning model, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the sensitivity information of each convolutional layer under different layer pruning rates, determine the target pruning model to implement pruning of multi-task neural network models. In addition, the task loss value corresponding to multiple tasks is used as the pruning target, and the sensitivity analysis and pruning of the model are performed comprehensively considering the accuracy of multiple tasks, which effectively retains the generalization performance of the sparse model, and can balance multiple models after pruning. The accuracy loss of the task reduces the difficulty of retraining.
2、设置预设剪枝条件,基于当前的剪枝模型对应的当前损失值,确定当前的剪枝模型达到预设剪枝条件,来确定是否对待剪枝模型剪枝成功,在确定对待剪枝模型剪枝成功的情况下,将当前的剪枝模型确定为目标剪枝模型;在确定对待剪枝模型剪枝不成功的情况下,调整当前的剪枝模型的取值,重新对待剪枝模型剪枝,直至确定对待剪枝模型剪枝成功,得到目标剪枝模型,以得到检测信息好且存储空间需求小的目标剪枝模型。2. Set the preset pruning conditions, and based on the current loss value corresponding to the current pruning model, determine that the current pruning model meets the preset pruning conditions to determine whether the pruning model to be pruned is successfully pruned. In the case of successful model pruning, determine the current pruning model as the target pruning model; if it is determined that the pruning model to be pruned is unsuccessful, adjust the value of the current pruning model, and re-treat the pruning model Pruning is performed until it is determined that the pruning model to be pruned is successfully pruned, and the target pruning model is obtained, so as to obtain the target pruning model with good detection information and small storage space requirement.
3、利用预设目标函数,基于各任务损失值及其对应的任务权重,确定预剪枝后的待剪枝模型对应的损失值,进而确定该卷积层在该预设层剪枝率下的敏感度信息,实现综合考虑多个任务的精度对模型进行敏感度分析和剪枝,实现对模型的有效剪枝。3. Using the preset objective function, based on the loss value of each task and its corresponding task weight, determine the loss value corresponding to the pre-pruned model to be pruned, and then determine that the convolutional layer is under the preset layer pruning rate The sensitivity information of the model is comprehensively considered, and the sensitivity analysis and pruning of the model are carried out considering the accuracy of multiple tasks, and the effective pruning of the model is realized.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单介绍。显而易见地,下面描述中的附图仅仅是本发明的一些实施例。对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that are required in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.
图1为本发明实施例提供的多任务神经网络模型的剪枝方法的一种流程示意图;1 is a schematic flowchart of a method for pruning a multi-task neural network model according to an embodiment of the present invention;
图2为本发明实施例提供的多任务神经网络模型的剪枝装置的一种结构示意图。FIG. 2 is a schematic structural diagram of a device for pruning a multi-task neural network model according to an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整的描述。显然,所描述的实施例仅仅是本发明的一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, but not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
需要说明的是,本发明实施例及附图中的术语“包括”和“具有”以及它们的任何变形,意图在于覆盖不排他的包含。例如包含的一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其他步骤或单元。It should be noted that the terms "comprising" and "having" and any modifications thereof in the embodiments of the present invention and the accompanying drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the steps or units listed, but optionally also includes steps or units not listed, or optionally also includes For other steps or units inherent to these processes, methods, products or devices.
本发明提供了一种多任务神经网络模型的剪枝方法及装置,以实现对多任务神经网络模型的剪枝。下面对本发明实施例进行详细说明。The invention provides a method and device for pruning a multi-task neural network model, so as to realize the pruning of the multi-task neural network model. The embodiments of the present invention will be described in detail below.
图1为本发明实施例提供的多任务神经网络模型的剪枝方法的一种流程示意图。该方法可以包括如下步骤:FIG. 1 is a schematic flowchart of a method for pruning a multi-task neural network model according to an embodiment of the present invention. The method may include the following steps:
S101:获得训练完成的多任务神经网络模型,作为待剪枝模型。S101: Obtain a trained multi-task neural network model as a model to be pruned.
本发明实施例所提供的多任务神经网络模型的剪枝方法,可以应用于任一具有计算能力的电子设备,该电子设备可以为终端或者服务器。The method for pruning a multi-task neural network model provided by the embodiment of the present invention can be applied to any electronic device with computing capability, and the electronic device can be a terminal or a server.
其中,该多任务神经网络模型为可以实现至少两种检测任务的神经网络模型。该检测任务可以包括但不限于分类、定位以及语义分割等任务,本发明实施并不对多任务神经网络模型的具体任务类型进行限定。Wherein, the multi-task neural network model is a neural network model that can realize at least two detection tasks. The detection tasks may include, but are not limited to, tasks such as classification, localization, and semantic segmentation. The implementation of the present invention does not limit the specific task types of the multi-task neural network model.
该训练完成的多任务神经网络模型可以指:已基于训练数据进行训练且检测信息的检测精度不低于预设精度阈值的多任务神经网络模型。The trained multi-task neural network model may refer to a multi-task neural network model that has been trained based on the training data and the detection accuracy of the detection information is not lower than a preset accuracy threshold.
S102:针对待剪枝模型的每一卷积层,执行如下步骤S1021-S1023,以确定出每一卷积层在不同预设层剪枝率下的敏感度信息。S102: For each convolutional layer of the model to be pruned, perform the following steps S1021-S1023 to determine the sensitivity information of each convolutional layer under different preset layer pruning rates.
S1021:针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝;S1021: For each preset layer pruning rate, pre-prune the convolution layer based on the preset layer pruning rate and each convolution kernel in the convolution layer;
S1022:基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值;S1022: Based on the first training data, determine the loss value of each task corresponding to the pre-pruned model to be pruned corresponding to the preset layer pruning rate;
S1023:基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息。S1023: Determine the sensitivity information of the convolutional layer at the preset layer pruning rate based on the loss values of each task corresponding to the pre-pruned model to be pruned.
其中,该预设层剪枝率为用于指示针对各层卷积层进行预剪枝过程中,所设置的用于控制进行预剪枝的卷积层所需剪枝的比例,即进行预剪枝的卷积层需要预剪枝的卷积核占该卷积层的总卷积核的比例。该预设层剪枝率的取值范围为(0,1),预设层剪枝率为多个,多个预设层剪枝率中相邻的每两个预设层剪枝率之间的差值可以相同。The preset layer pruning rate is used to indicate the required pruning ratio of the pre-pruned convolutional layer during the pre-pruning process for each convolutional layer. A pruned convolutional layer requires the proportion of pre-pruned convolutional kernels to the total convolutional kernels of the convolutional layer. The value range of the preset layer pruning rate is (0, 1), the preset layer pruning rate is multiple, and the pruning rate of every two adjacent preset layers among the multiple preset layer pruning rates The difference between can be the same.
本步骤中,电子设备可以针对待剪枝模型的每一卷积层,确定每一卷积层在不同预设层剪枝率下的敏感度信息,即针对待剪枝模型的每一卷积层,依次针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中的各卷积核,对该卷积层进行预剪枝,即基于该卷积层中的各卷积核,确定出该预设层剪枝率对应的待预剪枝的卷积核,对该预设层剪枝率对应的待预剪枝的卷积核的预剪枝,例如:设置该预设层剪枝率对应的待预剪枝的卷积核对应的权重值为0,实现对该预设层剪枝率对应的待预剪枝的卷积核的预剪枝;进而,基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值,即多个任务各自对应的任务损失值;基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息,以确定出待剪枝模型的每一卷积层在每一预设层剪枝率下的敏感度信息。举例而言,若待剪枝模型的卷积层存在10个,预设层剪枝率包括1%-99%中的整百分数,即99个,则待剪枝模型的所有卷积层的敏感度信息的数量包括10*99=990个。In this step, the electronic device may determine, for each convolutional layer of the model to be pruned, the sensitivity information of each convolutional layer under different preset layer pruning rates, that is, for each convolutional layer of the model to be pruned layer, for each preset layer pruning rate in turn, based on the preset layer pruning rate and each convolution kernel in the convolution layer, the convolution layer is pre-pruned, that is, based on the convolution layer in the convolution layer. For each convolution kernel, determine the convolution kernel to be pre-pruned corresponding to the preset layer pruning rate, and the pre-pruning of the convolution kernel to be pre-pruned corresponding to the preset layer pruning rate, for example: Setting the weight value corresponding to the convolution kernel to be pre-pruned corresponding to the pruning rate of the preset layer to 0, to realize the pre-pruning of the convolution kernel to be pre-pruned corresponding to the pruning rate of the preset layer; and then , based on the first training data, determine the loss value of each task corresponding to the pre-pruned model to be pruned corresponding to the preset layer pruning rate, that is, the task loss values corresponding to multiple tasks; The loss value of each task corresponding to the model to be pruned, determine the sensitivity information of the convolutional layer under the pruning rate of the preset layer, and determine that each convolutional layer of the model to be pruned is pruned at each preset layer. Sensitivity information under branch rate. For example, if there are 10 convolutional layers in the model to be pruned, and the preset layer pruning rate includes an integer percentage from 1% to 99%, that is, 99, then the sensitivity of all convolutional layers of the model to be pruned The number of degree information includes 10*99=990.
其中,该第一训练数据可以为训练完成该待剪枝模型的训练数据的部分数据,也可以为待剪枝模型对应的其他训练数据,这都是可以的。第一训练数据可以包括样本图像及其对应的标定信息,其中,样本图像包括该待剪枝模型需要检测的目标,样本图像对应的标定信息包括该待剪枝模型的各任务对应的检测标签的具体内容。例如:待剪枝模型需要检测的目标为人员,该待剪枝模型的各任务对应的检测标签为人员身份及人员所在位置,相应的,该样本图像包括各人员,样本图像对应的标定信息包括:所包括人员的人员身份信息以及在图像中的位置信息。Wherein, the first training data may be partial data of the training data of the model to be pruned after training, or may be other training data corresponding to the model to be pruned, which is all possible. The first training data may include a sample image and its corresponding calibration information, wherein the sample image includes the target to be detected by the model to be pruned, and the calibration information corresponding to the sample image includes the detection label corresponding to each task of the model to be pruned. details. For example, the target to be detected by the model to be pruned is a person, and the detection labels corresponding to each task of the model to be pruned are the identity of the person and the location of the person. Correspondingly, the sample image includes each person, and the calibration information corresponding to the sample image includes : Personnel identification information and location information of the persons included in the image.
相应的,在一种实现中,上述基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值的过程,可以是:将第一训练数据中的每一样本图像输入该预设层剪枝率对应的预剪枝后的待剪枝模型中,得到该样本图像对应的预测信息,其中,该预测信息包括该待剪枝模型的各任务对应的预测信息;针对每一任务,基于该任务对应的预设损失函数、该样本图像对应的该任务对应的预测信息以及第一训练数据中该样本图像对应的该任务对应的标定信息,确定该样本图像对应的该任务对应的任务子损失值,以得到样本图像对应的该任务对应的任务子损失值;并针对每一任务,基于各样本图像对应的该任务对应的任务子损失值,确定该任务对应的任务损失值。其中,各任务对应的预设损失函数可以为相关技术中任一类型的损失函数,在此不作限定。Correspondingly, in one implementation, the above-mentioned process of determining the loss value of each task corresponding to the pre-pruned model to be pruned corresponding to the preset layer pruning rate based on the first training data may be: Each sample image in the training data is input into the pre-pruned model to be pruned corresponding to the preset layer pruning rate, and the prediction information corresponding to the sample image is obtained, wherein the prediction information includes the prediction information of the to-be-pruned model. The prediction information corresponding to each task; for each task, based on the preset loss function corresponding to the task, the prediction information corresponding to the task corresponding to the sample image, and the calibration information corresponding to the task corresponding to the sample image in the first training data , determine the task sub-loss value corresponding to the task corresponding to the sample image, so as to obtain the task sub-loss value corresponding to the task corresponding to the sample image; and for each task, based on the task sub-loss value corresponding to the task corresponding to each sample image value to determine the task loss value corresponding to the task. The preset loss function corresponding to each task may be any type of loss function in the related art, which is not limited herein.
其中,预剪枝前后任务对应的任务损失值的变化越小,表征对该卷积层中预剪枝该预设层剪枝率对应的卷积核,对该任务损失值对应的任务的检测信息影响越小,即预剪枝的该预设层剪枝率对应的卷积核,对该任务损失值对应的任务检测信息的影响越小,相应的,可以表征相应于该任务损失值对应的任务来说,该预剪枝的该预设层剪枝率对应的卷积核的敏感度不高。Among them, the smaller the change of the task loss value corresponding to the task before and after pre-pruning, the smaller the change of the task loss value, which represents the pre-pruning of the convolution layer in the convolution layer corresponding to the pruning rate of the preset layer, and the detection of the task corresponding to the task loss value. The smaller the influence of information, that is, the convolution kernel corresponding to the pruning rate of the preset layer of pre-pruning, the smaller the influence of the task detection information corresponding to the task loss value. Correspondingly, the corresponding loss value corresponding to the task can be represented. For the task of the pre-pruning, the sensitivity of the convolution kernel corresponding to the pruning rate of the preset layer of the pre-pruning is not high.
在本发明的一种实现方式中,所述S1021,可以包括如下步骤:In an implementation manner of the present invention, the S1021 may include the following steps:
针对该卷积层的每一卷积核,基于该卷积核中的各权重参数,确定该卷积核对应的剪枝范数值;For each convolution kernel of the convolution layer, based on each weight parameter in the convolution kernel, determine the pruning norm value corresponding to the convolution kernel;
基于该预设层剪枝率以及该卷积层中各卷积核对应的剪枝范数值,依据预设剪枝规则,对该卷积层进行预剪枝,其中,预设剪枝规则为:优先针对所对应剪枝范数值小的卷积核进行预剪枝。Based on the preset layer pruning rate and the pruning norm value corresponding to each convolution kernel in the convolution layer, the convolution layer is pre-pruned according to the preset pruning rule, wherein the preset pruning rule is: : Prioritize pre-pruning for convolution kernels with small corresponding pruning norm values.
本实现方式中,电子设备可以针对该卷积层的每一卷积核,利用L1-norm算法,基于该卷积核中的各权重参数,确定该卷积核对应的剪枝范数值。具体的可以是:将该卷积核中的各权重参数的绝对值加和,所得结果作为该卷积核对应的剪枝范数值。其中,该卷积核对应的剪枝范数值越大表示该卷积核越重要,在预剪枝以及后续的剪枝过程中选择剪枝该卷积核的概率越小。In this implementation manner, the electronic device may use the L1-norm algorithm for each convolution kernel of the convolution layer to determine the pruning norm value corresponding to the convolution kernel based on each weight parameter in the convolution kernel. Specifically, the absolute value of each weight parameter in the convolution kernel may be added, and the obtained result may be used as the pruning norm value corresponding to the convolution kernel. Among them, the larger the pruning norm value corresponding to the convolution kernel, the more important the convolution kernel is, and the lower the probability of choosing to prune the convolution kernel in the pre-pruning and subsequent pruning processes.
后续的,基于该预设层剪枝率以及该卷积层中各卷积核对应的剪枝范数值,依据预设剪枝规则,对该卷积层进行预剪枝。即优先针对所对应剪枝范数值小的卷积核进行预剪枝。即在该卷积层内按照该预设层剪枝率,从所对应剪枝范数值由小到大剪去卷积核及其对应的输出特征图通道。Subsequently, based on the preset layer pruning rate and the pruning norm value corresponding to each convolution kernel in the convolution layer, the convolution layer is pre-pruned according to a preset pruning rule. That is, pre-pruning is preferentially performed on the convolution kernel with a small corresponding pruning norm value. That is, in the convolutional layer, according to the preset layer pruning rate, the convolution kernel and its corresponding output feature map channel are pruned from the corresponding pruning norm value from small to large.
其中,上述的剪去卷积核及其对应的输出特征图通道可以是:将卷积核中的包含的各权重参数设置为0,或者设置卷积核对应的权重值为0,以及设置卷积核对应的输出特征图通道对应的权重值为0。Among them, the above-mentioned trimming of the convolution kernel and its corresponding output feature map channel may be: setting each weight parameter contained in the convolution kernel to 0, or setting the weight value corresponding to the convolution kernel to 0, and setting the volume The weight value corresponding to the output feature map channel corresponding to the product kernel is 0.
S103:基于待剪枝模型对应的通道信息,对待剪枝模型的卷积层中的卷积核进行分组。S103: Based on the channel information corresponding to the model to be pruned, group the convolution kernels in the convolution layer of the model to be pruned.
在一种实现中,待剪枝模型中可能存在多个卷积层以ElementwiseLayer函数连接,鉴于ElementwiseLayer函数的数据处理方式,对于待剪枝模型中以ElementwiseLayer函数连接的多个卷积层来说,当需要剪去某一层中的一个卷积核时,需要将其他卷积层中所对应通道标识与该需要剪去的卷积核对应的通道标识相同的卷积核。鉴于此,电子设备可以预先确定待剪枝模型对应的通道信息,进而,基于待剪枝模型对应的通道信息,对待剪枝模型的卷积层中的卷积核进行分组。其中,将对应相同通道标识的卷积核分为一组,对应不同通道标识的卷积核分为不同组,不以ElementwiseLayer函数连接的卷积层的卷积核,即不对应通道标识的卷积核可以分为一组。In one implementation, there may be multiple convolutional layers connected by the ElementwiseLayer function in the model to be pruned. In view of the data processing method of the ElementwiseLayer function, for the multiple convolutional layers connected by the ElementwiseLayer function in the model to be pruned, When a convolution kernel in a certain layer needs to be clipped, the corresponding channel identification in other convolutional layers needs to be the same convolution kernel as the channel identification corresponding to the convolution kernel to be clipped. In view of this, the electronic device can pre-determine channel information corresponding to the model to be pruned, and further, based on the channel information corresponding to the model to be pruned, group the convolution kernels in the convolution layer of the model to be pruned. Among them, the convolution kernels corresponding to the same channel identification are divided into one group, the convolution kernels corresponding to different channel identifications are divided into different groups, and the convolution kernels of the convolutional layers not connected by the ElementwiseLayer function are the volumes that do not correspond to the channel identification. Kernels can be grouped into groups.
S104:基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型。S104: Based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning of each convolutional layer at different layers The sensitivity information under the rate is used to determine the target pruning model.
电子设备本地或所连接的存储设备可以预先存储有当前的模型剪枝率,该模型剪枝率为用于限定对该待剪枝模型进行剪枝过程中减去卷积核及其对应的输出特征图通道的比例,即用于限定对该待剪枝模型进行剪枝过程中减去卷积核及其对应的输出特征图通道的总数,占该待剪枝模型包括的卷积核及其对应的输出特征图通道的总数的比值。The current model pruning rate may be pre-stored in the local or connected storage device of the electronic device, and the model pruning rate is used to limit the subtraction of the convolution kernel and its corresponding output during the pruning process of the model to be pruned. The ratio of feature map channels, which is used to limit the total number of convolution kernels and their corresponding output feature map channels in the process of pruning the model to be pruned, accounting for the convolution kernel and its corresponding output feature map channels included in the model to be pruned. The ratio of the total number of corresponding output feature map channels.
每一层卷积层中各卷积核对应的剪枝范数值为:基于该卷积核中的各权重参数所确定的值,用于表征该卷积核在其所在卷积层中的重要性,其中,卷积层中卷积核对应的剪枝范数值越大示该卷积核越重要,在预剪枝以及后续的剪枝过程中选择剪枝该卷积核的概率越小。The pruning norm value corresponding to each convolution kernel in each convolution layer is: the value determined based on each weight parameter in the convolution kernel, which is used to characterize the importance of the convolution kernel in the convolution layer where it is located. The larger the value of the pruning norm corresponding to the convolution kernel in the convolution layer, the more important the convolution kernel is, and the smaller the probability of choosing to prune the convolution kernel in the pre-pruning and subsequent pruning process.
电子设备对待剪枝模型的卷积层中的卷积核进行分组后,可以得到待剪枝模型的卷积核的分组情况,其中,对于对应同一通道标识的卷积核来说,其需要同时进行剪枝或同时保留,对于不对应通道标识的卷积核来说,基于其对应的剪枝范数值进行剪枝或保留。After the electronic device groups the convolution kernels in the convolution layer of the model to be pruned, the grouping situation of the convolution kernels of the model to be pruned can be obtained. Perform pruning or retain at the same time. For convolution kernels that do not correspond to channel identifiers, perform pruning or retention based on their corresponding pruning norm values.
电子设备可以基于当前的模型剪枝率以及每一卷积层在不同层剪枝率下的敏感度信息,确定每一层卷积层对应的剪枝率,其中,卷积层的敏感度信息表征其越不敏感,其对应的剪枝率越高。进而,电子设备针对每一层卷积层,基于该卷积层对应的剪枝率、待剪枝模型的卷积核的分组情况以及每一层卷积层中各卷积核对应的剪枝范数值,确定出每一层卷积层需要剪枝的具体的卷积核及其对应的输出特征图通道;基于所确定的每一层卷积层需要剪枝的具体的卷积核及其对应的输出特征图通道,进行剪枝,得到目标剪枝模型。The electronic device can determine the pruning rate corresponding to each convolutional layer based on the current model pruning rate and the sensitivity information of each convolutional layer at different pruning rates, where the sensitivity information of the convolutional layer is The less sensitive it is, the higher the corresponding pruning rate. Further, for each convolutional layer, the electronic device is based on the pruning rate corresponding to the convolutional layer, the grouping of the convolutional kernels of the model to be pruned, and the pruning corresponding to each convolutional kernel in each convolutional layer. Norm value, determine the specific convolution kernel that needs to be pruned for each convolution layer and its corresponding output feature map channel; based on the determined specific convolution kernel that needs to be pruned for each convolution layer, The corresponding output feature map channel is pruned to obtain the target pruning model.
其中,上述确定每一层卷积层需要剪枝的具体的卷积核及其对应的输出特征图通道的原则可以包括:优先针对卷积层中所对应剪枝范数值小的卷积核进行剪枝,且当一层卷积层中的一卷积核需要剪枝,且该卷积核属于对应一通道标识的卷积核组中,需要对该卷积核组中所有对应的卷积核及其对应的输出特征图通道进行剪枝。Wherein, the above-mentioned principle of determining the specific convolution kernel that needs to be pruned for each convolutional layer and its corresponding output feature map channel may include: preferentially performing the pruning for the convolution kernel with a small corresponding pruning norm value in the convolutional layer. Pruning, and when a convolution kernel in a convolutional layer needs to be pruned, and the convolution kernel belongs to the convolution kernel group corresponding to a channel identifier, all corresponding convolution kernels in the convolution kernel group need to be pruned. The kernel and its corresponding output feature map channel are pruned.
应用本发明实施例,利用待剪枝网络中各多个任务对应的任务损失值,共同确定各层卷积层在不同预设层剪枝率下的敏感度信息,进而,基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型,以实现对多任务神经网络模型的剪枝。并且结合多个任务对应的任务损失值作为剪枝目标,综合考虑多个任务的精度进行敏感度分析和剪枝,有效保留稀疏模型的泛化性能,能够平衡剪枝后的模型多个任务的精度损失,降低重新训练难度。By applying the embodiments of the present invention, the task loss values corresponding to multiple tasks in the network to be pruned are used to jointly determine the sensitivity information of each layer of convolutional layers under different preset layer pruning rates, and then, based on the current model pruning The branch rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the sensitivity information of each convolutional layer at different layer pruning rates, Determine the target pruning model to achieve pruning of multi-task neural network models. In addition, combining the task loss values corresponding to multiple tasks as the pruning target, comprehensively considering the accuracy of multiple tasks for sensitivity analysis and pruning, the generalization performance of the sparse model is effectively preserved, and the pruned model can be balanced for multiple tasks. Accuracy loss, reducing the difficulty of retraining.
考虑到所设置的当前的模型剪枝率可能设置的不够合适,可能出现当前的模型剪枝率设置的偏小,理论上在检测精度的约束下,待剪枝模型还可以剪枝更多的卷积核和/或其对应的输出特征图通道的情况,即可以得到剪枝后的数据量更小的且检测精度不低的模型;或者可能出现当前的模型剪枝率设置的偏大,剪枝后所得的模型的数据量降低,但剪枝后所得的模型的检测精度不高的情况。上述情况中剪枝后所得的模型均可以认为为不够合适的模型。鉴于此,在本发明的另一实施例中,所述S104,可以包括如下步骤:Considering that the current model pruning rate may not be set properly, it may appear that the current model pruning rate setting is too small. In theory, under the constraint of detection accuracy, the model to be pruned can also prune more In the case of the convolution kernel and/or its corresponding output feature map channel, a model with a smaller amount of pruned data and a low detection accuracy can be obtained; or the current model pruning rate setting may be too large, The data volume of the model obtained after pruning is reduced, but the detection accuracy of the model obtained after pruning is not high. In the above cases, the models obtained after pruning can be considered as inadequate models. In view of this, in another embodiment of the present invention, the S104 may include the following steps:
基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对待剪枝模型进行剪枝,得到当前的剪枝模型;Based on the current model pruning rate, the grouping of convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning rate of each convolutional layer at different layers Sensitivity information, prune the model to be pruned to obtain the current pruning model;
基于第二训练数据,确定当前的剪枝模型对应的各第二训练数据对应的检测信息;Based on the second training data, determine the detection information corresponding to each second training data corresponding to the current pruning model;
若基于当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定当前的剪枝模型达到预设剪枝条件,将当前的剪枝模型确定为目标剪枝模型。If it is determined that the current pruning model meets the preset pruning conditions based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data, the current pruning model is determined as Target pruning model.
其中,第二训练数据可以为训练完成该待剪枝模型的训练数据的部分数据,也可以为待剪枝模型对应的其他训练数据,这都是可以的。该第二训练数据可以包括与第一训练数据相同的数据,也可以包括与第一训练数据不同的数据。Wherein, the second training data may be partial data of the training data of the model to be pruned after training, or may be other training data corresponding to the model to be pruned, which is all possible. The second training data may include the same data as the first training data, or may include data different from the first training data.
上述基于第二训练数据,确定当前的剪枝模型对应的各第二训练数据对应的检测信息的过程,可以为:将每一第二训练数据中的样本图像,输入当前的剪枝模型,得到各第二训练数据对应的各任务的检测信息。The above-mentioned process of determining the detection information corresponding to each second training data corresponding to the current pruning model based on the second training data may be: inputting the sample images in each second training data into the current pruning model to obtain Detection information of each task corresponding to each second training data.
上述基于当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定当前的剪枝模型达到预设剪枝条件的过程,可以是:基于增大后的当前的模型剪枝率的取值之后剪枝所得的模型、第二训练数据、所确定的各第二训练数据对应的各任务的检测信息、各第二训练数据中的标定信息以及该任务对应的预设精确度确定方式,确定该任务的新的剪枝后模型的精确度,若判断待剪枝模型对应的该任务的精确度与该新的剪枝后模型的精确度的差值不在可接受的精度下降范围内,且差值大于可接受的精度下降范围的上限值,则可以确定当前的剪枝模型达到预设剪枝条件。The above-mentioned process of determining that the current pruning model reaches the preset pruning condition based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data may be: based on increasing the The model obtained after pruning, the second training data, the detection information of each task corresponding to each second training data determined, the calibration information in each second training data, and the The preset accuracy determination method corresponding to the task determines the accuracy of the new pruned model for the task. If the accuracy of the task corresponding to the model to be pruned is judged to be the difference between the accuracy of the new pruned model If the value is not within the acceptable precision reduction range, and the difference is greater than the upper limit of the acceptable precision reduction range, it can be determined that the current pruning model meets the preset pruning conditions.
其中,可以理解的是,不同任务其对应的预设精确度确定方式可以存在不同,具体的预设精确度确定方式可以参照相关技术中确定神经网络模型的各任务的精确度的确定方式。It can be understood that the corresponding preset accuracy determination methods for different tasks may be different, and the specific preset accuracy determination methods can refer to the determination methods for determining the accuracy of each task of the neural network model in the related art.
以待剪枝模型的任务包括目标检测任务和语义分割任务为例进行说明,目标检测任务对应的剪枝精确度可以是通过mAP(Mean Average Precision)值表示;语义分割任务对应的剪枝精确度可以是mIOU(Mean Intersection-Over-Union)值表示。其中,mAP值和mIOU值的计算过程,可以参见相关技术中神经网络模型中目标检测任务的mAP值和语义分割任务的mIOU值的计算过程,在此不再赘述。Taking the tasks of the model to be pruned, including the target detection task and the semantic segmentation task as an example, the pruning accuracy corresponding to the target detection task can be expressed by the mAP (Mean Average Precision) value; the pruning accuracy corresponding to the semantic segmentation task It can be represented by mIOU (Mean Intersection-Over-Union) value. For the calculation process of the mAP value and the mIOU value, please refer to the calculation process of the mAP value of the target detection task and the mIOU value of the semantic segmentation task in the neural network model in the related art, which will not be repeated here.
在本发明的另一实施例中,所述S104,还可以包括如下步骤:In another embodiment of the present invention, the S104 may further include the following steps:
若基于当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定当前的剪枝模型未达到预设剪枝条件,调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率;If it is determined based on the detection information corresponding to each second training data corresponding to the current pruning model and the calibration information in each second training data, it is determined that the current pruning model does not meet the preset pruning conditions, and the current model pruning rate is adjusted. The value of , to get the new current model pruning rate;
基于新的当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到新的当前的剪枝模型;Based on the new current model pruning rate, the grouping of convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the pruning of each convolutional layer at different layers According to the sensitivity information at the rate, prune the model to be pruned to obtain a new current pruning model;
基于第三训练数据,确定新的当前的剪枝模型对应的各第三训练数据对应的检测信息;Based on the third training data, determine the detection information corresponding to each third training data corresponding to the new current pruning model;
若基于新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定新的当前的剪枝模型达到预设剪枝条件,将新的当前的剪枝模型确定为目标剪枝模型;If it is determined that the new current pruning model meets the preset pruning conditions based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, the new current pruning model The pruning model is determined as the target pruning model;
若基于新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定新的当前的剪枝模型未达到预设剪枝条件,返回所述调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率的步骤。If, based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, it is determined that the new current pruning model does not meet the preset pruning conditions, and then return the The steps of adjusting the value of the current model pruning rate to obtain the new current model pruning rate.
电子设备若判断待剪枝模型对应的该任务的精确度与该新的剪枝后模型的精确度的差值,不在可接受的精度下降范围内,则可以确定当前的剪枝模型未达到预设剪枝条件。If the electronic device judges that the difference between the accuracy of the task corresponding to the model to be pruned and the accuracy of the new model after pruning is not within the acceptable range of accuracy reduction, it can be determined that the current pruning model does not meet the predetermined accuracy. Set pruning conditions.
相应的,可以调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率,基于新的当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对待剪枝模型进行剪枝,得到新的当前的剪枝模型;基于第三训练数据,确定新的当前的剪枝模型对应的各第三训练数据对应的检测信息;若基于当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定新的当前的剪枝模型达到预设剪枝条件,将新的当前的剪枝模型确定为目标剪枝模型;若基于当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定新的当前的剪枝模型未达到预设剪枝条件,返回所述调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率的步骤。Correspondingly, the value of the current model pruning rate can be adjusted to obtain a new current model pruning rate, based on the new current model pruning rate, the grouping of the convolution kernels of the model to be pruned, each layer. The pruning norm value corresponding to each convolution kernel in the convolutional layer and the sensitivity information of each convolutional layer under different layer pruning rates are pruned, and the new current pruning model is obtained by pruning the model to be pruned; The third training data is to determine the detection information corresponding to each third training data corresponding to the new current pruning model; if the detection information corresponding to each third training data corresponding to the current pruning model and the the calibration information, determine that the new current pruning model reaches the preset pruning conditions, and determine the new current pruning model as the target pruning model; if the third training data corresponding to the current pruning model corresponds to The detection information and the calibration information in each third training data, determine that the new current pruning model does not meet the preset pruning conditions, return the value of the adjusted current model pruning rate, and obtain a new current model pruning branch rate steps.
其中,若判断待剪枝模型对应的该任务的精确度与该新的剪枝精确度的差值不在可接受的精度下降范围内,且待剪枝模型对应的该任务的精确度与该新的剪枝后模型的精确度的差值超过可接受的精度下降范围的上限值,则可以调小当前的模型剪枝率的取值,得到新的当前的模型剪枝率;若判断待剪枝模型对应的该任务的精确度与该新的剪枝后模型的精确度的差值在可接受的精度下降范围内,且待剪枝模型对应的改任务的精确度与该信的剪枝后模型的精确度的差值低于可接受的精度下降范围的上限值,则可以调大当前的模型剪枝率的取值,得到新的当前的模型剪枝率。Among them, if it is judged that the difference between the accuracy of the task corresponding to the model to be pruned and the new accuracy of pruning is not within the acceptable accuracy reduction range, and the accuracy of the task corresponding to the model to be pruned is the same as the new accuracy If the difference of the accuracy of the model after pruning exceeds the upper limit of the acceptable accuracy reduction range, the value of the current model pruning rate can be reduced to obtain the new current model pruning rate; The difference between the accuracy of the task corresponding to the pruned model and the accuracy of the new pruned model is within the acceptable accuracy drop range, and the accuracy of the modified task corresponding to the model to be pruned is the same as the accuracy of the new pruned model. If the difference in the accuracy of the post-branching model is lower than the upper limit of the acceptable accuracy drop range, the value of the current model pruning rate can be increased to obtain a new current model pruning rate.
上述第三训练数据可以为与第二训练数据相同的数据,也可以为待剪枝模型对应的不同于第二训练数据的数据。The third training data may be the same data as the second training data, or may be data corresponding to the model to be pruned that is different from the second training data.
在本发明的另一实施例中,所述S1023,可以包括如下步骤:In another embodiment of the present invention, the S1023 may include the following steps:
基于预剪枝后的待剪枝模型对应的各任务损失值以及预设目标函数,确定预剪枝后的待剪枝模型对应的损失值;Based on the loss value of each task corresponding to the pre-pruned model to be pruned and the preset objective function, determine the loss value corresponding to the pre-pruned model to be pruned;
基于预剪枝后的待剪枝模型对应的损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;其中,预设目标函数的表达式为:Based on the loss value corresponding to the pre-pruned model to be pruned, the sensitivity information of the convolutional layer at the preset layer pruning rate is determined; wherein, the expression of the preset objective function is:
其中,Objective表示预剪枝后的待剪枝模型对应的损失值,lossi表示所述待剪枝模型中第i个任务对应的任务损失值,wi表示待剪枝模型中第i个任务对应的任务权重;L表示待剪枝模型的任务的数量。Among them, Objective represents the loss value corresponding to the pre-pruned model to be pruned, loss i represents the task loss value corresponding to the i-th task in the to-be-pruned model, and w i represents the i-th task in the to-be-pruned model The corresponding task weight; L represents the number of tasks to be pruned.
一种情况中,可以将待剪枝模型在预剪枝前后对应的损失值变化,确定为该预设层剪枝率下的敏感度信息。例如,可以是:将预剪枝后的待剪枝模型对应的损失值,与预剪枝前的待剪枝模型对应的损失值的差值,确定为该卷积层在该预设层剪枝率下的敏感度信息。相应的,预剪枝后的待剪枝模型对应的损失值,相较于预剪枝前待剪枝模型对应的损失值,上升的越小,表征该卷积层在该预设层剪枝率下的对剪枝后模型的检测信息的精度影响越小,且该卷积层在该预设层剪枝率下的敏感度越低。In one case, the change of the corresponding loss value of the model to be pruned before and after pre-pruning can be determined as the sensitivity information under the pruning rate of the preset layer. For example, it may be: the difference between the loss value corresponding to the model to be pruned after pre-pruning and the loss value corresponding to the model to be pruned before pre-pruning is determined as the pruning of the convolutional layer at the preset layer. Sensitivity information under branch rate. Correspondingly, the loss value corresponding to the model to be pruned after pre-pruning, compared with the loss value corresponding to the model to be pruned before pre-pruning, the smaller the increase is, it indicates that the convolutional layer is pruned at the preset layer. The smaller the impact on the accuracy of the detection information of the pruned model at the lower rate, the lower the sensitivity of the convolutional layer under the preset layer pruning rate.
一种情况中,各任务对应的任务权重可以根据任务对应的任务损失值的范围进行选取,使得加权后的任务损失值在同一数据量级。In one case, the task weight corresponding to each task can be selected according to the range of the task loss value corresponding to the task, so that the weighted task loss value is at the same data level.
相应于上述方法实施例,本发明实施例提供了一种多任务神经网络模型的剪枝装置,如图2所示,所述装置可以包括:Corresponding to the above method embodiments, the embodiments of the present invention provide an apparatus for pruning a multi-task neural network model. As shown in FIG. 2 , the apparatus may include:
获得模块210,被配置为获得训练完成的多任务神经网络模型,作为待剪枝模型;The obtaining
第一确定模块220,被配置为针对所述待剪枝模型的每一卷积层,通过如下单元,确定出每一卷积层在不同预设层剪枝率下的敏感度信息;The first determining
预剪枝单元221,被配置为针对各预设层剪枝率,基于该预设层剪枝率以及该卷积层中各卷积核,对该卷积层进行预剪枝;The
第一确定单元222,被配置为基于第一训练数据,确定该预设层剪枝率对应的预剪枝后的待剪枝模型所对应各任务损失值;The first determining
第二确定单元223,被配置为基于预剪枝后的待剪枝模型对应的各任务损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;The second determination unit 223 is configured to determine the sensitivity information of the convolutional layer at the preset layer pruning rate based on the loss value of each task corresponding to the pre-pruned model to be pruned;
分组模块230,被配置为基于所述待剪枝模型对应的通道信息,对所述待剪枝模型的卷积层中的卷积核进行分组;The
第二确定模块240,被配置为基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型。The
应用本发明实施例,利用待剪枝网络中各多个任务对应的任务损失值,共同确定各层卷积层在不同预设层剪枝率下的敏感度信息,进而,基于当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,确定目标剪枝模型,以实现对多任务神经网络模型的剪枝。并且结合多个任务对应的任务损失值作为剪枝目标,综合考虑多个任务的精度进行敏感度分析和剪枝,有效保留稀疏模型的泛化性能,能够平衡剪枝后的模型多个任务的精度损失,降低重新训练难度。By applying the embodiments of the present invention, the task loss values corresponding to multiple tasks in the network to be pruned are used to jointly determine the sensitivity information of each layer of convolutional layers under different preset layer pruning rates, and then, based on the current model pruning The branch rate, the grouping of the convolution kernels of the model to be pruned, the pruning norm value corresponding to each convolution kernel in each convolutional layer, and the sensitivity information of each convolutional layer at different layer pruning rates, Determine the target pruning model to achieve pruning of multi-task neural network models. In addition, combining the task loss values corresponding to multiple tasks as the pruning target, comprehensively considering the accuracy of multiple tasks for sensitivity analysis and pruning, the generalization performance of the sparse model is effectively preserved, and the pruned model can be balanced for multiple tasks. Accuracy loss, reducing the difficulty of retraining.
在本发明的另一实施例中,所述第二确定模块240,包括:In another embodiment of the present invention, the second determining
第一剪枝单元(图中未示出),被配置为基于当前的模型剪枝率、所述待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到当前的剪枝模型;The first pruning unit (not shown in the figure) is configured to be based on the current model pruning rate, the grouping of the convolution kernels of the model to be pruned, and the corresponding convolution kernels in each convolution layer. The pruning norm value and the sensitivity information of each convolutional layer under different layer pruning rates, prune the to-be-pruned model to obtain the current pruning model;
第三确定单元(图中未示出),被配置为基于第二训练数据,确定所述当前的剪枝模型对应的各第二训练数据对应的检测信息;a third determining unit (not shown in the figure), configured to determine, based on the second training data, detection information corresponding to each second training data corresponding to the current pruning model;
第四确定单元(图中未示出),被配置为若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型达到预设剪枝条件,将所述当前的剪枝模型确定为目标剪枝模型。The fourth determination unit (not shown in the figure) is configured to determine the current pruning model based on detection information corresponding to each second training data corresponding to the current pruning model and calibration information in each second training data The current pruning model reaches the preset pruning condition, and the current pruning model is determined as the target pruning model.
在本发明的另一实施例中,所述第二确定模块240还包括:In another embodiment of the present invention, the second determining
调整单元(图中未示出),被配置为若基于所述当前的剪枝模型对应的各第二训练数据对应的检测信息以及各第二训练数据中的标定信息,确定所述当前的剪枝模型未达到预设剪枝条件,调整当前的模型剪枝率的取值,得到新的当前的模型剪枝率;An adjustment unit (not shown in the figure), configured to determine the current pruning model based on detection information corresponding to each second training data corresponding to the current pruning model and calibration information in each second training data If the branch model does not meet the preset pruning conditions, adjust the value of the current model pruning rate to obtain the new current model pruning rate;
第二剪枝单元(图中未示出),被配置为基于新的当前的模型剪枝率、待剪枝模型的卷积核的分组情况、每一层卷积层中各卷积核对应的剪枝范数值以及每一卷积层在不同层剪枝率下的敏感度信息,对所述待剪枝模型进行剪枝,得到新的当前的剪枝模型;The second pruning unit (not shown in the figure) is configured to be based on the new current model pruning rate, the grouping of the convolution kernels of the model to be pruned, and the corresponding convolution kernels in each convolution layer. The pruning norm value and the sensitivity information of each convolutional layer under different layer pruning rates, prune the to-be-pruned model to obtain a new current pruning model;
第五确定单元(图中未示出),被配置为基于第三训练数据,确定所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息;a fifth determining unit (not shown in the figure), configured to determine, based on the third training data, detection information corresponding to each third training data corresponding to the new current pruning model;
第六确定单元(图中未示出),被配置为若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型达到预设剪枝条件,将所述新的当前的剪枝模型确定为目标剪枝模型;The sixth determination unit (not shown in the figure) is configured to determine if based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data. The new current pruning model reaches preset pruning conditions, and the new current pruning model is determined as the target pruning model;
若基于所述新的当前的剪枝模型对应的各第三训练数据对应的检测信息以及各第三训练数据中的标定信息,确定所述新的当前的剪枝模型未达到预设剪枝条件,返回触发所述调整单元。If based on the detection information corresponding to each third training data corresponding to the new current pruning model and the calibration information in each third training data, it is determined that the new current pruning model does not meet the preset pruning conditions , and return to trigger the adjustment unit.
在本发明的另一实施例中,所述第二确定单元223,被具体配置为基于预剪枝后的待剪枝模型对应的各任务损失值以及预设目标函数,确定预剪枝后的待剪枝模型对应的损失值;In another embodiment of the present invention, the second determining unit 223 is specifically configured to determine the pre-pruned model based on the loss value of each task corresponding to the pre-pruned model to be pruned and the preset objective function. The loss value corresponding to the model to be pruned;
基于所述预剪枝后的待剪枝模型对应的损失值,确定该卷积层在该预设层剪枝率下的敏感度信息;其中,所述预设目标函数的表达式为:Based on the loss value corresponding to the pre-pruned model to be pruned, the sensitivity information of the convolutional layer at the preset layer pruning rate is determined; wherein, the expression of the preset objective function is:
其中,Objective表示预剪枝后的待剪枝模型对应的损失值,lossi表示所述待剪枝模型中第i个任务对应的任务损失值,wi表示所述待剪枝模型中第i个任务对应的任务权重;L表示所述待剪枝模型的任务的数量。Among them, Objective represents the loss value corresponding to the pre-pruned model to be pruned, loss i represents the task loss value corresponding to the i-th task in the to-be-pruned model, and w i represents the i-th task in the to-be-pruned model The task weights corresponding to each task; L represents the number of tasks of the model to be pruned.
在本发明的另一实施例中,所述预剪枝单元221,被具体配置为针对该卷积层的每一卷积核,基于该卷积核中的各权重参数,确定该卷积核对应的剪枝范数值;In another embodiment of the present invention, the
基于该预设层剪枝率以及该卷积层中各卷积核对应的剪枝范数值,依据预设剪枝规则,对该卷积层进行预剪枝,其中,所述预设剪枝规则为:优先针对所对应剪枝范数值小的卷积核进行预剪枝。Based on the preset layer pruning rate and the pruning norm value corresponding to each convolution kernel in the convolution layer, the convolution layer is pre-pruned according to preset pruning rules, wherein the preset pruning The rule is: Pre-pruning is performed preferentially on the corresponding convolution kernel with a small pruning norm value.
上述系统、装置实施例与系统实施例相对应,与该方法实施例具有同样的技术效果,具体说明参见方法实施例。装置实施例是基于方法实施例得到的,具体的说明可以参见方法实施例部分,此处不再赘述。本领域普通技术人员可以理解:附图只是一个实施例的示意图,附图中的模块或流程并不一定是实施本发明所必须的。The foregoing system and device embodiments correspond to the system embodiments, and have the same technical effects as the method embodiments. For specific descriptions, refer to the method embodiments. The apparatus embodiment is obtained based on the method embodiment, and the specific description can refer to the method embodiment section, which will not be repeated here. Those of ordinary skill in the art can understand that the accompanying drawing is only a schematic diagram of an embodiment, and the modules or processes in the accompanying drawing are not necessarily necessary to implement the present invention.
本领域普通技术人员可以理解:实施例中的装置中的模块可以按照实施例描述分布于实施例的装置中,也可以进行相应变化位于不同于本实施例的一个或多个装置中。上述实施例的模块可以合并为一个模块,也可以进一步拆分成多个子模块。Those skilled in the art may understand that: the modules in the apparatus in the embodiment may be distributed in the apparatus in the embodiment according to the description of the embodiment, and may also be located in one or more apparatuses different from this embodiment with corresponding changes. The modules in the foregoing embodiments may be combined into one module, or may be further split into multiple sub-modules.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions depart from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011153067.0A CN114492783B (en) | 2020-10-26 | 2020-10-26 | A pruning method and device for a multi-task neural network model |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011153067.0A CN114492783B (en) | 2020-10-26 | 2020-10-26 | A pruning method and device for a multi-task neural network model |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN114492783A true CN114492783A (en) | 2022-05-13 |
| CN114492783B CN114492783B (en) | 2025-09-23 |
Family
ID=81471340
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202011153067.0A Active CN114492783B (en) | 2020-10-26 | 2020-10-26 | A pruning method and device for a multi-task neural network model |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114492783B (en) |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115345295A (en) * | 2022-08-12 | 2022-11-15 | 重庆邮电大学 | Language model pruning method based on pre-pruning and combined pruning |
| CN116128044A (en) * | 2022-12-13 | 2023-05-16 | 际络科技(上海)有限公司 | Model pruning method, image processing method and related devices |
| CN118409872A (en) * | 2024-07-02 | 2024-07-30 | 山东海量信息技术研究院 | Model pruning method, device and medium based on memory calculation force perception |
| CN118821893A (en) * | 2024-09-19 | 2024-10-22 | 浙江大华技术股份有限公司 | A network pruning method, device, terminal and computer-readable storage medium |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107451602A (en) * | 2017-07-06 | 2017-12-08 | 浙江工业大学 | A kind of fruits and vegetables detection method based on deep learning |
| CN110619385A (en) * | 2019-08-31 | 2019-12-27 | 电子科技大学 | Structured network model compression acceleration method based on multi-stage pruning |
| CN111242287A (en) * | 2020-01-15 | 2020-06-05 | 东南大学 | Neural network compression method based on channel L1 norm pruning |
| CN111652211A (en) * | 2020-05-21 | 2020-09-11 | 哈尔滨市科佳通用机电股份有限公司 | A fault detection method for foreign objects hanging on the mounting seat of the anti-snake shock absorber of a motor vehicle |
| US20200311549A1 (en) * | 2017-10-26 | 2020-10-01 | Xilinx, Inc. | Method of pruning convolutional neural network based on feature map variation |
-
2020
- 2020-10-26 CN CN202011153067.0A patent/CN114492783B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107451602A (en) * | 2017-07-06 | 2017-12-08 | 浙江工业大学 | A kind of fruits and vegetables detection method based on deep learning |
| US20200311549A1 (en) * | 2017-10-26 | 2020-10-01 | Xilinx, Inc. | Method of pruning convolutional neural network based on feature map variation |
| CN110619385A (en) * | 2019-08-31 | 2019-12-27 | 电子科技大学 | Structured network model compression acceleration method based on multi-stage pruning |
| CN111242287A (en) * | 2020-01-15 | 2020-06-05 | 东南大学 | Neural network compression method based on channel L1 norm pruning |
| CN111652211A (en) * | 2020-05-21 | 2020-09-11 | 哈尔滨市科佳通用机电股份有限公司 | A fault detection method for foreign objects hanging on the mounting seat of the anti-snake shock absorber of a motor vehicle |
Non-Patent Citations (1)
| Title |
|---|
| LI H , ET AL: "Pruning filters for efficient convnets", ARXIV, 10 March 2017 (2017-03-10), pages 1 - 13, XP093160610, DOI: 10.48550/arXiv.1608.08710 * |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115345295A (en) * | 2022-08-12 | 2022-11-15 | 重庆邮电大学 | Language model pruning method based on pre-pruning and combined pruning |
| CN116128044A (en) * | 2022-12-13 | 2023-05-16 | 际络科技(上海)有限公司 | Model pruning method, image processing method and related devices |
| CN118409872A (en) * | 2024-07-02 | 2024-07-30 | 山东海量信息技术研究院 | Model pruning method, device and medium based on memory calculation force perception |
| CN118821893A (en) * | 2024-09-19 | 2024-10-22 | 浙江大华技术股份有限公司 | A network pruning method, device, terminal and computer-readable storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114492783B (en) | 2025-09-23 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11348249B2 (en) | Training method for image semantic segmentation model and server | |
| CN108564129B (en) | Trajectory data classification method based on generation countermeasure network | |
| CN113837308B (en) | Knowledge distillation-based model training method and device and electronic equipment | |
| CN114492783A (en) | Pruning method and device for multitask neural network model | |
| CN111008640A (en) | Image recognition model training and image recognition method, device, terminal and medium | |
| KR20200022739A (en) | Method and device to recognize image and method and device to train recognition model based on data augmentation | |
| CN106203103B (en) | File virus detection method and device | |
| CN110135681A (en) | Risk subscribers recognition methods, device, readable storage medium storing program for executing and terminal device | |
| CN111507396B (en) | Method and device for relieving error classification of unknown class samples by neural network | |
| CN111178364A (en) | Image identification method and device | |
| CN111985279A (en) | Training method and device of multivariate attribute prediction model and storage medium | |
| CN110175655B (en) | Data identification method and device, storage medium and electronic equipment | |
| CN111881972A (en) | Black product user identification method and device, server and storage medium | |
| CN113361621B (en) | Methods and apparatus for training models | |
| CN114330690A (en) | Convolutional neural network compression method, device and electronic device | |
| CN113762403A (en) | Image processing model quantization method, device, electronic device and storage medium | |
| CN115546554A (en) | Sensitive image recognition method, device, device and computer-readable storage medium | |
| CN110069647A (en) | Image tag denoising method, device, equipment and computer readable storage medium | |
| CN114239684A (en) | Transformer substation equipment anomaly detection model optimization method and device and computer equipment | |
| CN116152597B (en) | Training method and device for target detection model | |
| CN114648646B (en) | Image classification method and device | |
| CN113763193B (en) | Group detection method, device, electronic device and computer storage medium | |
| CN116402116A (en) | Neural network pruning method, system, device, medium and image processing method | |
| CN109308565B (en) | Crowd performance grade identification method and device, storage medium and computer equipment | |
| CN115982634A (en) | App classification method, apparatus, electronic equipment and computer program product |
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 |





