WO2021103597A1 - 一种神经网络的模型压缩的方法和设备 - Google Patents

一种神经网络的模型压缩的方法和设备 Download PDF

Info

Publication number
WO2021103597A1
WO2021103597A1 PCT/CN2020/103697 CN2020103697W WO2021103597A1 WO 2021103597 A1 WO2021103597 A1 WO 2021103597A1 CN 2020103697 W CN2020103697 W CN 2020103697W WO 2021103597 A1 WO2021103597 A1 WO 2021103597A1
Authority
WO
WIPO (PCT)
Prior art keywords
network
layer
clipping
channel
small
Prior art date
Application number
PCT/CN2020/103697
Other languages
English (en)
French (fr)
Inventor
郭韶燕
Original Assignee
苏州浪潮智能科技有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 苏州浪潮智能科技有限公司 filed Critical 苏州浪潮智能科技有限公司
Priority to KR1020227018397A priority Critical patent/KR20220091575A/ko
Priority to US17/780,479 priority patent/US11928599B2/en
Publication of WO2021103597A1 publication Critical patent/WO2021103597A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/082Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0495Quantised networks; Sparse networks; Compressed networks

Definitions

  • the field relates to the computer field, and more specifically to a method and device for model compression of a neural network.
  • the key technologies of deep neural networks are widely used in the fields of image classification, object detection, speech recognition and natural language processing.
  • the model size and computing requirements increase, so that they rely on high-power computing platforms.
  • research on deep neural network model compression technology for embedded applications has been carried out in order to reduce model size and storage space requirements , Optimize the model calculation process.
  • the existing clipping algorithms are divided into two types: non-structural clipping and structural clipping.
  • the expression of the cropped model is that the cropped model weight value is 0, and the un cropped model weight value is non-zero float data, so the model size does not change essentially.
  • non-structural cropping algorithms are used, and the cropped model usually uses methods such as data indexing to change the actual model size.
  • the model after the structural cropping algorithm usually needs to reduce the parameters of the current convolutional layer according to the cropping ratio, and add the corresponding convolution operation in the current convolutional layer according to the index number of the cropping channel.
  • the compressed model after cropping has a low compression rate. When the model is loaded, a specific decompression module needs to be added; a network with a shortcut structure has excessive cropping of some convolutional layers.
  • the purpose of the embodiments of the present invention is to propose a neural network model compression method, which can directly reduce the amount of calculation and reduce the size of the model.
  • the model can be loaded with one click to reduce the difficulty of use.
  • one aspect of the embodiments of the present invention provides a method for model compression of a neural network, which includes the following steps:
  • recording the input and output parameters of each network layer in the network layer includes:
  • dividing the network layer into several small networks according to input and output parameters includes:
  • the current network layer is divided into a small network
  • the current network layer is divided into a small network.
  • the channel clipping algorithm includes: a dynamic channel clipping algorithm and a channel clipping algorithm based on automatic machine learning.
  • the decomposition calculation of each clipping small network according to the clipping channel index number includes:
  • the corresponding index number in the output channel corresponding to the corresponding layer is clipped according to the clipping channel index number of the corresponding layer in each clipping small network.
  • a device for model compression of a neural network which is characterized in that the device includes:
  • At least one processor At least one processor
  • Memory stores program code that can be run by the processor, and the program code executes the following steps when being run by the processor:
  • each clipping small network is decomposed and calculated.
  • recording the input and output parameters of each network layer in the network layer includes:
  • dividing the network layer into several small networks according to input and output parameters includes:
  • the current network layer is divided into a small network
  • the current network layer is divided into a small network.
  • the channel clipping algorithm includes: a dynamic channel clipping algorithm and a channel clipping algorithm based on automatic machine learning.
  • the decomposition calculation of each clipping small network according to the clipping channel index number includes:
  • the corresponding index number in the output channel corresponding to the corresponding layer is clipped according to the clipping channel index number of the corresponding layer in each clipping small network.
  • the neural network model compression method provided by the embodiment of the present invention records the input and output parameters of each layer of the network; and divides the network layer into several small networks according to the input and output parameters. ; Set the clipping flag of the first convolutional layer in each small network to 0 to obtain the clipping small network; use the channel clipping algorithm to train each clipping small network to obtain the network weight and weight mask; record the weight The clipping channel index number of each convolutional layer of the clipping small network with a mask of 0; the technical solution of decomposing each clipping small network according to the clipping channel index number can directly reduce the calculation amount and reduce the model size. During network deployment, the model can be loaded with one click to reduce the difficulty of use.
  • Fig. 1 is a schematic flowchart of a method for model compression of a neural network according to an embodiment of the present invention.
  • the first aspect of the embodiments of the present invention proposes an embodiment of a method for model compression of a neural network.
  • Figure 1 shows a schematic flow chart of the method.
  • the method may include the following steps:
  • S1 records the input and output parameters of each layer of the network in the network layer, and can label each layer, from the 0th layer to the nth layer;
  • S2 divides the network layer into several small networks according to input and output parameters, and divides the n-layer large network into m small networks according to different parameters;
  • S3 sets the cropping flag of the first convolutional layer in each small network to 0 to obtain a cropped small network.
  • the cropping flags of other layers are all set to 1, 0 means no cropping, and 1 means cropping;
  • S4 uses the channel clipping algorithm to train each clipping small network to obtain the network weight and weight mask (mask).
  • any channel clipping algorithm can be used to train the clipping small network. After training, many network parameters are obtained. Here We need to use weights and weight masks. If the weights are cropped, the mask is 0, otherwise it is 1;
  • S5 records the index number of the clipping channel of each convolutional layer of the clipping small network with a weight mask of 0, that is, if the channel is clipped, its index number is recorded;
  • S6 decomposes and calculates each clipping small network according to the clipping channel index number, that is, if the clipping small network has k layers, according to the channel clipping index number of the kth layer, the corresponding index number of the output channel of the k-1 layer is clipped , Until each layer of the small network is traversed.
  • the final network parameters only include weights (uncut). For example, if the weight is 5x10x3x3, the index number of the k-th layer records 0, 1, and 2 in the second dimension, and the index number in the first dimension of 10x8x3x2 in the weight of the k-1 layer is 0, 1, 2 Make cropping.
  • the compression algorithm of a neural network provided by the present invention, in a network with a shortcut structure, reasonably cuts the network to ensure performance. After cropping the model, there is no need to add a specific convolution operation, the model size is directly reduced, and when model inference is implemented, one-click loading without decoding is required.
  • the amount of calculation can be directly reduced, and the size of the model can be reduced.
  • the model can be loaded with one click to reduce the difficulty of use.
  • recording the input and output parameters of each network layer in the network layer includes:
  • dividing the network layer into several small networks according to input and output parameters includes:
  • the current network layer and the previous network layer are divided into the same small network; if the current network layer If the number of inputs or outputs is not 1, the current network layer is divided into a small network; if the number of inputs and outputs of the current network layer are both 1, and the input name is the same as the input of one of the other network layers If the names are consistent, the current network layer is divided into a small network.
  • the channel clipping algorithm includes: a dynamic channel clipping algorithm and a channel clipping algorithm based on automatic machine learning.
  • Other channel clipping algorithms can also be used. In theory, any algorithm can be used.
  • decomposing each clipping small network according to the clipping channel index number includes:
  • the corresponding index in the output channel corresponding to the corresponding layer No. for cropping is, if the pruning small network has i layers, the corresponding index numbers of the output channels of the i-1 layer are cropped according to the channel cropping index number of the i-th layer, until each layer of the small network is traversed.
  • the final network parameters only include weights (uncut).
  • the index number of the k-th layer records 0, 1, 2 in the second dimension
  • the index number in the first dimension of 10x8x3x2 in the weight of the i-1th layer is 0, 1, 2 Make cropping.
  • the present invention can add the following two modules to the existing quantization algorithm to complete the above method:
  • Network segmentation module When channel cropping, select crop input channel instead of output channel. This is because, first: if the convolutional layer contains bias, it is necessary to ensure that the output channel index of the cropped convolutional layer is consistent with the bias index; second: if the adjacent layer of the convolutional layer is the batchnorm layer (existing network structure Usually conv, batchnorm), in the batchnorm layer calculation, the clipped channel is restored, losing the meaning of clipping.
  • each layer of each subnet has only one input and one output;
  • each subnet is gradually stepped from the last layer Upward decomposition calculation, that is, record the clipped channel index numbers of the n layer, and clip the channel index numbers of the output channel n layer record of the n-1 layer until all the layers are traversed.
  • the above-mentioned programs can be stored in a computer readable storage medium.
  • the storage medium may be a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
  • the foregoing computer program embodiment can achieve the same or similar effects as any of the foregoing method embodiments corresponding thereto.
  • the method disclosed according to the embodiment of the present invention may also be implemented as a computer program executed by a CPU, and the computer program may be stored in a computer-readable storage medium.
  • the computer program executes the above-mentioned functions defined in the method disclosed in the embodiment of the present invention.
  • the second aspect of the embodiments of the present invention proposes a neural network model compression device, which is characterized in that the device includes:
  • At least one processor At least one processor
  • Memory stores program code that can be run by the processor, and the program code executes the following steps when being run by the processor:
  • each clipping small network is decomposed and calculated.
  • recording the input and output parameters of each network layer in the network layer includes:
  • dividing the network layer into several small networks according to input and output parameters includes:
  • the current network layer and the previous network layer are divided into the same small network; if the current network layer If the number of inputs or outputs is not 1, the current network layer is divided into a small network; if the number of inputs and outputs of the current network layer are both 1, and the input name is the same as the input of one of the other network layers If the names are consistent, the current network layer is divided into a small network.
  • the channel clipping algorithm includes: a dynamic channel clipping algorithm and a channel clipping algorithm based on automatic machine learning.
  • decomposing each clipping small network according to the clipping channel index number includes:
  • the corresponding index number in the output channel corresponding to the corresponding layer is clipped according to the clipping channel index number of the corresponding layer in each clipping small network.
  • the above method steps and system units or modules can also be implemented using a controller and a computer readable storage medium for storing a computer program that enables the controller to implement the above steps or unit or module functions.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Mathematical Physics (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • General Engineering & Computer Science (AREA)
  • Biomedical Technology (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • Biophysics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Medical Informatics (AREA)
  • Image Analysis (AREA)

Abstract

一种神经网络的模型压缩的方法和设备,该方法包括以下步骤:记录网络层中每一层网络的输入和输出参数(S1);根据输入和输出参数将网络层分为若干小网络(S2);将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络(S3);使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码(S4);记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号(S5);根据裁剪通道索引号对每个裁剪小网络进行分解计算(S6)。通过使用上述方法,能够直接减少计算量,并减小模型大小,在网络部署时,可一键加载模型,降低使用难度。

Description

一种神经网络的模型压缩的方法和设备
本申请要求于2019年11月29日提交中国专利局、申请号为201911198187.X、发明名称为“一种神经网络的模型压缩的方法和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本领域涉及计算机领域,并且更具体地涉及一种神经网络的模型压缩的方法和设备。
背景技术
结合大数据的获取,深度神经网络关键技术广泛应用于图像分类、物体检测、语音识别和自然语言处理等领域。随着深度神经网络模型性能不断提升,模型体积和计算需求提高,以致其依赖高功耗的计算平台。为解决在实时嵌入式系统中的存储资源和内存访问带宽的限制,以及计算资源相对不足的问题,已开展嵌入式应用的深度神经网络模型压缩技术研究,以便缩减模型体积和对存储空间的需求,优化模型计算过程。
综合现有的深度模型压缩方法,它们主要分为四类:参数修剪和共享、低秩因子分解、转移/紧凑卷积滤波器、知识蒸馏。低秩因子分解、转移/紧凑卷积滤波器、知识蒸馏这三种方法,通常涉及到网络结构的改变,故本发明主要针对参数裁剪和共享改进。
现有的裁剪算法,分为两种非结构性裁剪和结构性裁剪。裁剪后的模型的表现形式为,裁剪掉的模型权重数值为0,而未被裁剪掉的模型权重数值为非0的float数据,因此模型大小本质上没有发生改变。在实际应用中,使用非结构性裁剪算法,裁剪的模型,通常使用数据索引等方法,使实际模型大小发生改变。结构性裁剪算法后的模型,通常需将当前卷积层的参数按裁剪比例减少,并在当前卷积层按照裁剪通道的索引号,添加相应的卷积运算。但是裁剪压缩后的模型,压缩率低,在模型加载时,需添 加特定解压模块;具有shortcut结构的网络,对某些卷积层裁剪过度。
发明内容
有鉴于此,本发明实施例的目的在于提出一种神经网络的模型压缩的方法,能够直接减少计算量,并减小模型大小,在网络部署时,可一键加载模型,降低使用难度。
基于上述目的,本发明的实施例的一个方面提供了一种神经网络的模型压缩的方法,包括以下步骤:
记录网络层中每一层网络的输入和输出参数;
根据输入和输出参数将网络层分为若干小网络;
将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;
使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码;
记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号;根据裁剪通道索引号对每个裁剪小网络进行分解计算。
根据本发明的一个实施例,记录网络层中每一层网络的输入和输出参数包括:
记录网络层中每一层网络的输入个数、输出个数、输入名称和输出名称。
根据本发明的一个实施例,根据输入和输出参数将网络层分为若干小网络包括:
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将当前网络层与上一网络层分为同一个小网络;
如果当前网络层的输入个数或输出个数不为1,则将当前网络层分为 一个小网络;
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将当前网络层分为一个小网络。
根据本发明的一个实施例,通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。
根据本发明的一个实施例,根据裁剪通道索引号对每个裁剪小网络进行分解计算包括:
从每个裁剪小网络中最后一层向第一层依次遍历,根据每个裁剪小网络中相应层的裁剪通道索引号将相应层对应的输出通道中的相应索引号进行裁剪。
本发明的实施例的另一个方面,还提供了一种神经网络的模型压缩的设备,其特征在于,设备包括:
至少一个处理器;和
存储器,存储器存储有处理器可运行的程序代码,程序代码在被处理器运行时执行以下步骤:
记录网络层中每一层网络的输入和输出参数;
根据输入和输出参数将网络层分为若干小网络;
将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;
使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码;
记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号;
根据裁剪通道索引号对每个裁剪小网络进行分解计算。
根据本发明的一个实施例,记录网络层中每一层网络的输入和输出参数包括:
记录网络层中每一层网络的输入个数、输出个数、输入名称和输出名 称。
根据本发明的一个实施例,根据输入和输出参数将网络层分为若干小网络包括:
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将当前网络层与上一网络层分为同一个小网络;
如果当前网络层的输入个数或输出个数不为1,则将当前网络层分为一个小网络;
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将当前网络层分为一个小网络。
根据本发明的一个实施例,通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。
根据本发明的一个实施例,根据裁剪通道索引号对每个裁剪小网络进行分解计算包括:
从每个裁剪小网络中最后一层向第一层依次遍历,根据每个裁剪小网络中相应层的裁剪通道索引号将相应层对应的输出通道中的相应索引号进行裁剪。
本发明具有以下有益技术效果:本发明实施例提供的神经网络的模型压缩的方法,通过记录网络层中每一层网络的输入和输出参数;根据输入和输出参数将网络层分为若干小网络;将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码;记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号;根据裁剪通道索引号对每个裁剪小网络进行分解计算的技术方案,能够直接减少计算量,并减小模型大小,在网络部署时,可一键加载模型,降低使用难度。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的实施例。
图1为根据本发明一个实施例的神经网络的模型压缩的方法的示意性流程图。
具体实施方式
为使本发明的目的、技术方案和优点更加清楚明白,以下结合具体实施例,并参照附图,对本发明实施例进一步详细说明。
基于上述目的,本发明的实施例的第一个方面,提出了一种神经网络的模型压缩的方法的一个实施例。图1示出的是该方法的示意性流程图。
如图1中所示,该方法可以包括以下步骤:
S1记录网络层中每一层网络的输入和输出参数,可以对每一层进行标号,从第0层标记到第n层;
S2根据输入和输出参数将网络层分为若干小网络,根据参数的不同将n层的大网络分为m个小网络;
S3将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络,其他层的裁剪标志位都设置为1,0表示不裁剪,1表示裁剪;
S4使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码(mask),理论上可以采用任意一种通道裁剪算法对裁剪小网络进行训练,训练后得到很多网络参数,这里我们需要用到权重和权重的掩码,若该权重被裁剪,则mask为0,否则为1;
S5记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号,即若该通道被裁剪,则记录其索引号;
S6根据裁剪通道索引号对每个裁剪小网络进行分解计算,即,如果裁 剪小网络有k层,按照第k层的通道裁剪索引号,将k-1层的输出通道相应的索引号进行裁剪,直至遍历完成该小网络的每一层。最后的到的网络参数,仅包括权重(未裁剪的)。例如,权重是5x10x3x3,第k层的索引号记录的是第二维中的0、1、2,则将第k-1层权重中10x8x3x2的第一维中的索引号为0、1、2进行裁剪。
本发明提供的一种神经网络的压缩算法,在具有shortcut结构的网络中,合理裁剪网络,保证性能。裁剪后的模型,无需增加特定卷积运算,模型大小直接减少,并实现模型推理时,一键加载,无需解码。
通过以上技术方案,能够直接减少计算量,并减小模型大小,在网络部署时,可一键加载模型,降低使用难度。
在本发明的一个优选实施例中,记录网络层中每一层网络的输入和输出参数包括:
记录网络层中每一层网络的输入个数、输出个数、输入名称和输出名称。
在本发明的一个优选实施例中,根据输入和输出参数将网络层分为若干小网络包括:
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将当前网络层与上一网络层分为同一个小网络;如果当前网络层的输入个数或输出个数不为1,则将当前网络层分为一个小网络;如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将当前网络层分为一个小网络。
在本发明的一个优选实施例中,通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。还可以使用其他的通道裁剪算法,理论上可以使用任何一种算法。
在本发明的一个优选实施例中,根据裁剪通道索引号对每个裁剪小网络进行分解计算包括:
从每个裁剪小网络中最后一层向第一层依次遍历,根据每个裁剪小网 络中相应层(即当前所遍历的层)的裁剪通道索引号将相应层对应的输出通道中的相应索引号进行裁剪。即,如果裁剪小网络有i层,按照第i层的通道裁剪索引号,将i-1层的输出通道相应的索引号进行裁剪,直至遍历完成该小网络的每一层。最后的到的网络参数,仅包括权重(未裁剪的)。例如,权重是5x10x3x3,第k层的索引号记录的是第二维中的0、1、2,则将第i-1层权重中10x8x3x2的第一维中的索引号为0、1、2进行裁剪。
本发明可以在现有量化算法中添加以下两个模块以完成上述方法:
1)网络切分模块。在通道裁剪时,选择裁剪输入通道而不是输出通道。这是由于,第一:卷积层如含有bias,则需保证裁剪的卷积层输出通道索引号与bias索引号一致;第二:若卷积层相邻层为batchnorm层(现有网络结构通常为conv、batchnorm),在batchnorm层计算时,被裁剪的通道又被复原,失去裁剪的意义。在实验中发现,对于直连的网络结构,即每一层只有一个输入和一个输出,可将所有卷积层裁剪,第一个卷积层除外(一般CNN网络,输入图像通道为3,如果将其通道直接较少,相当于直接减少图像原始信息)。但对于resnet50含有shortcut结构的网络,虽可以将所有卷积层裁剪,在实际中并不能减少计算。减少当前卷积层的输入通道,相当于减少其上一层(相邻连接)的输出通道。当两个卷积层的输入都来自于同一层时,必须保证两个卷积层裁剪的输入通道索引号一致,但两个不同的卷积,同一索引输入通道重要性不同,因此保证两个不同卷积裁剪输入通道索引号一致,不可实现。因此,shortcut结构中,只裁剪具有单个输入和单个输出的卷积。
2)通道索引压缩模块。裁剪后的网络,对于被裁剪的输入通道,其权重为0。实际中,为了实现被裁剪的通道不参与计算,在该卷积层之前通常添加一个卷积层,将被裁剪的通道mask,但这种方式在减少当前层计算量时,也增加了额外的卷积计算。因此为了实现真正意义上的计算量直接减少,分析卷积计算,以及相连层的关系,并最终实现卷积计算的实际减少。其核心思想为当前被裁剪的输入通道,与其相连层(conv、batchnorm)的输出通道也可相应的裁剪。对于resnet50网络,其具体步骤为:第一,将网络结构拆分为n个子网,每个子网的每一层仅有一个输入和一个输出; 第二,将每个子网,从最后一层逐步向上分解计算,即记录n层被裁剪的通道索引号,并将n-1层的输出通道n层记录的通道索引号裁剪,直至遍历完成所有层。
通过以上技术方案,能够实现系统安全等级灵活控制,保证服务正常运行,实现同一套存储系统满足用户的多种安全级别要求,实现配置内容的简化处理,避免冗长,解决系统不允许直接修改其中文件场景下用户无法直接修改配置文件的问题,实现存储系统各项服务安全的统一、灵活控制,避免了直接手动修改配置文件可能出错的问题。
需要说明的是,本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关硬件来完成,上述的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,的存储介质可为磁碟、光盘、只读存储器(Read-Only Memory,ROM)或随机存取存储器(Random Access Memory,RAM)等。上述计算机程序的实施例,可以达到与之对应的前述任意方法实施例相同或者相类似的效果。
此外,根据本发明实施例公开的方法还可以被实现为由CPU执行的计算机程序,该计算机程序可以存储在计算机可读存储介质中。在该计算机程序被CPU执行时,执行本发明实施例公开的方法中限定的上述功能。
基于上述目的,本发明的实施例的第二个方面,提出了一种神经网络的模型压缩的设备,其特征在于,设备包括:
至少一个处理器;和
存储器,存储器存储有处理器可运行的程序代码,程序代码在被处理器运行时执行以下步骤:
记录网络层中每一层网络的输入和输出参数;
根据输入和输出参数将网络层分为若干小网络;
将每个小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;
使用通道裁剪算法对每个裁剪小网络进行训练,得到网络权重和权重掩码;
记录权重掩码为0的裁剪小网络的每一个卷积层的裁剪通道索引号;
根据裁剪通道索引号对每个裁剪小网络进行分解计算。
在本发明的一个优选实施例中,记录网络层中每一层网络的输入和输出参数包括:
记录网络层中每一层网络的输入个数、输出个数、输入名称和输出名称。
在本发明的一个优选实施例中,根据输入和输出参数将网络层分为若干小网络包括:
如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将当前网络层与上一网络层分为同一个小网络;如果当前网络层的输入个数或输出个数不为1,则将当前网络层分为一个小网络;如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将当前网络层分为一个小网络。
在本发明的一个优选实施例中,通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。
在本发明的一个优选实施例中,根据裁剪通道索引号对每个裁剪小网络进行分解计算包括:
从每个裁剪小网络中最后一层向第一层依次遍历,根据每个裁剪小网络中相应层的裁剪通道索引号将相应层对应的输出通道中的相应索引号进行裁剪。
需要特别指出的是,上述系统的实施例采用了上述方法的实施例来具体说明各模块的工作过程,本领域技术人员能够很容易想到,将这些模块应用到上述方法的其他实施例中。
此外,上述方法步骤以及系统单元或模块也可以利用控制器以及用于存储使得控制器实现上述步骤或单元或模块功能的计算机程序的计算机可 读存储介质实现。
本领域技术人员还将明白的是,结合这里的公开所描述的各种示例性逻辑块、模块、电路和算法步骤可以被实现为电子硬件、计算机软件或两者的组合。为了清楚地说明硬件和软件的这种可互换性,已经就各种示意性组件、方块、模块、电路和步骤的功能对其进行了一般性的描述。这种功能是被实现为软件还是被实现为硬件取决于具体应用以及施加给整个系统的设计约束。本领域技术人员可以针对每种具体应用以各种方式来实现的功能,但是这种实现决定不应被解释为导致脱离本发明实施例公开的范围。
上述实施例,特别是任何“优选”实施例是实现的可能示例,并且仅为了清楚地理解本发明的原理而提出。可以在不脱离本文所描述的技术的精神和原理的情况下对上述实施例进行许多变化和修改。所有修改旨在被包括在本公开的范围内并且由所附权利要求保护。

Claims (10)

  1. 一种神经网络的模型压缩的方法,其特征在于,包括以下步骤:
    记录网络层中每一层网络的输入和输出参数;
    根据所述输入和输出参数将所述网络层分为若干小网络;
    将每个所述小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;
    使用通道裁剪算法对每个所述裁剪小网络进行训练,得到网络权重和权重掩码;
    记录所述权重掩码为0的所述裁剪小网络的每一个卷积层的裁剪通道索引号;
    根据所述裁剪通道索引号对每个所述裁剪小网络进行分解计算。
  2. 根据权利要求1所述的方法,其特征在于,记录网络层中每一层网络的输入和输出参数包括:
    记录所述网络层中每一层网络的输入个数、输出个数、输入名称和输出名称。
  3. 根据权利要求2所述的方法,其特征在于,根据所述输入和输出参数将所述网络层分为若干小网络包括:
    如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将所述当前网络层与上一网络层分为同一个所述小网络;
    如果所述当前网络层的输入个数或输出个数不为1,则将所述当前网络层分为一个所述小网络;
    如果所述当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将所述当前网络层分为一个所述小网络。
  4. 根据权利要求1所述的方法,其特征在于,所述通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。
  5. 根据权利要求1所述的方法,其特征在于,根据所述裁剪通道索引号对每个所述裁剪小网络进行分解计算包括:
    从每个所述裁剪小网络中最后一层向第一层依次遍历,根据每个所述裁剪小网络中相应层的裁剪通道索引号将所述相应层对应的输出通道中的相应索引号进行裁剪。
  6. 一种神经网络的模型压缩的设备,其特征在于,所述设备包括:
    至少一个处理器;和
    存储器,所述存储器存储有处理器可运行的程序代码,所述程序代码在被处理器运行时执行以下步骤:
    记录网络层中每一层网络的输入和输出参数;
    根据所述输入和输出参数将所述网络层分为若干小网络;
    将每个所述小网络中的第一个卷积层的裁剪标志位设置为0,得到裁剪小网络;
    使用通道裁剪算法对每个所述裁剪小网络进行训练,得到网络权重和权重掩码;
    记录所述权重掩码为0的所述裁剪小网络的每一个卷积层的裁剪通道索引号;
    根据所述裁剪通道索引号对每个所述裁剪小网络进行分解计算。
  7. 根据权利要求6所述的设备,其特征在于,记录网络层中每一层网络的输入和输出参数包括:
    记录所述网络层中每一层网络的输入个数、输出个数、输入名称和输出名称。
  8. 根据权利要求7所述的设备,其特征在于,根据所述输入和输出参数将所述网络层分为若干小网络包括:
    如果当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层的输入名称均不一致,则将所述当前网络层与上一网络层分为同一个 所述小网络;
    如果所述当前网络层的输入个数或输出个数不为1,则将所述当前网络层分为一个所述小网络;
    如果所述当前网络层的输入个数和输出个数均为1,且输入名称与其它网络层之一的输入名称一致,则将所述当前网络层分为一个所述小网络。
  9. 根据权利要求6所述的设备,其特征在于,所述通道裁剪算法包括:动态通道裁剪算法和基于自动机器学习的通道裁剪算法。
  10. 根据权利要求6所述的设备,其特征在于,根据所述裁剪通道索引号对每个所述裁剪小网络进行分解计算包括:
    从每个所述裁剪小网络中最后一层向第一层依次遍历,根据每个所述裁剪小网络中相应层的裁剪通道索引号将所述相应层对应的输出通道中的相应索引号进行裁剪。
PCT/CN2020/103697 2019-11-29 2020-07-23 一种神经网络的模型压缩的方法和设备 WO2021103597A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
KR1020227018397A KR20220091575A (ko) 2019-11-29 2020-07-23 신경망 모델을 압축하는 방법 및 기기
US17/780,479 US11928599B2 (en) 2019-11-29 2020-07-23 Method and device for model compression of neural network

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911198187.X 2019-11-29
CN201911198187.XA CN111126595A (zh) 2019-11-29 2019-11-29 一种神经网络的模型压缩的方法和设备

Publications (1)

Publication Number Publication Date
WO2021103597A1 true WO2021103597A1 (zh) 2021-06-03

Family

ID=70497075

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/103697 WO2021103597A1 (zh) 2019-11-29 2020-07-23 一种神经网络的模型压缩的方法和设备

Country Status (4)

Country Link
US (1) US11928599B2 (zh)
KR (1) KR20220091575A (zh)
CN (1) CN111126595A (zh)
WO (1) WO2021103597A1 (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111126595A (zh) * 2019-11-29 2020-05-08 苏州浪潮智能科技有限公司 一种神经网络的模型压缩的方法和设备
CN113255907B (zh) * 2021-05-20 2024-05-14 广州广电运通金融电子股份有限公司 一种网络模型经裁剪以进行图像识别的方法
US11763082B2 (en) * 2021-07-12 2023-09-19 International Business Machines Corporation Accelerating inference of transformer-based models
CN113537490A (zh) * 2021-07-13 2021-10-22 广州虎牙科技有限公司 一种神经网络裁剪方法及电子设备
CN116992946B (zh) * 2023-09-27 2024-05-17 荣耀终端有限公司 模型压缩方法、装置、存储介质和程序产品

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107832847A (zh) * 2017-10-26 2018-03-23 北京大学 一种基于稀疏化后向传播训练的神经网络模型压缩方法
CN108304928A (zh) * 2018-01-26 2018-07-20 西安理工大学 基于改进聚类的深度神经网络的压缩方法
US20190130250A1 (en) * 2017-10-30 2019-05-02 Samsung Electronics Co., Ltd. Method and apparatus with neural network performing convolution
CN109978142A (zh) * 2019-03-29 2019-07-05 腾讯科技(深圳)有限公司 神经网络模型的压缩方法和装置
CN111126595A (zh) * 2019-11-29 2020-05-08 苏州浪潮智能科技有限公司 一种神经网络的模型压缩的方法和设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107832847A (zh) * 2017-10-26 2018-03-23 北京大学 一种基于稀疏化后向传播训练的神经网络模型压缩方法
US20190130250A1 (en) * 2017-10-30 2019-05-02 Samsung Electronics Co., Ltd. Method and apparatus with neural network performing convolution
CN108304928A (zh) * 2018-01-26 2018-07-20 西安理工大学 基于改进聚类的深度神经网络的压缩方法
CN109978142A (zh) * 2019-03-29 2019-07-05 腾讯科技(深圳)有限公司 神经网络模型的压缩方法和装置
CN111126595A (zh) * 2019-11-29 2020-05-08 苏州浪潮智能科技有限公司 一种神经网络的模型压缩的方法和设备

Also Published As

Publication number Publication date
US20230004809A1 (en) 2023-01-05
KR20220091575A (ko) 2022-06-30
US11928599B2 (en) 2024-03-12
CN111126595A (zh) 2020-05-08

Similar Documents

Publication Publication Date Title
WO2021103597A1 (zh) 一种神经网络的模型压缩的方法和设备
CN109978142B (zh) 神经网络模型的压缩方法和装置
US7689616B2 (en) Techniques for specifying and collecting data aggregations
EP3076310B1 (en) Variable virtual split dictionary for search optimization
CN110796251A (zh) 基于卷积神经网络的图像压缩优化方法
CN111178039B (zh) 一种模型训练方法、装置、实现文本处理的方法及装置
WO2022057468A1 (zh) 一种深度学习模型推理加速的方法、系统、设备及介质
CN110298446A (zh) 面向嵌入式系统的深度神经网络压缩和加速方法及系统
US20230289567A1 (en) Data Processing Method, System and Device, and Readable Storage Medium
CN112488304A (zh) 一种卷积神经网络中的启发式滤波器剪枝方法和系统
CN114861907A (zh) 数据计算方法、装置、存储介质和设备
CN112200310B (zh) 智能处理器、数据处理方法及存储介质
CN111241204B (zh) 一种梯度数据的同步方法、装置、设备及存储介质
CN111027693A (zh) 一种基于去权重剪枝的神经网络压缩方法及系统
CN117009093A (zh) 降低神经网络推理所需内存占用量的重计算方法和系统
CN115774605A (zh) Kubernetes的预测式弹性伸缩方法及系统
CN115331690B (zh) 一种用于通话语音的噪声实时消除的方法
KR102393761B1 (ko) 이미지 처리를 위한 인공 신경망 모델 학습 방법 및 시스템
CN109993304B (zh) 一种基于语义分割的检测模型压缩方法
WO2021238289A1 (zh) 序列处理的方法与装置
CN112329923B (zh) 一种模型压缩方法、装置、电子设备及可读存储介质
CN111767204B (zh) 溢出风险检测方法、装置及设备
CN113298225A (zh) 数据处理方法、音频降噪方法和神经网络模型
CN111047013A (zh) 卷积神经网络结构优化方法、装置和电子设备
CN117540780B (zh) 一种神经网络模型的压缩方法和相关装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20892240

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 20227018397

Country of ref document: KR

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20892240

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 20892240

Country of ref document: EP

Kind code of ref document: A1