2023年12月14日发(作者:)

94视觉低级任务中的CNN压缩研究视觉低级任务中的CNN压缩研究Research

on

CNN

Compression

in

Computer

Visioa

Low-level

Tasks

龚壮展

赵鑫海(广东工业大学,广东广州510006)摘要:卷积神经网络的发展给计算机视觉任务提供了多种解决方法。网络深度的增加,使得模型参数和所需内存也随之

增加,这给模型应用到算力和内存等资源有限的设备上带来了困难。卷积神经网络的压缩是一个重要的研究方向,提出利用

Tuckar分解对视觉低级任务(computer

vision

low-laval

t

asks)中的卷积神经网络进行压缩遥实验证实了

Tuckar分解对

压缩该任务模型的有效性,在去噪神经网络DnCNN中,模型参数量减少了

85%~88%,浮点运算次数FLOPs(FLoating

point

of

OParations)减少了

85%~88%遥在超分辨率神经网络VDSR中,模型的参数量减少了

85%,浮点运算次数FLOPs减

少了

85%

遥关键词:卷积神经网络(CNN);Tucker(塔克)分解;模型参数;浮点运算次数;CNN压缩Abstract:Deployme;t

of

convolutional

neural

network

provides

a

variety

of

solutions

for

computer

vision

the

in-

crease

of

network

depth|the

model

p

arameters

snd

required

memory

ylso

incre

ase,which

makes

it

difficult

to

opply

the

model

to

devices

with

limited

computing

power

rnd

memory

compression

of

convolution

al

neural

network

is

sn

im­port

ant

research

p

aper

proposes

using

Tucker

decomposition

to

compress

convolutional

neural

network

in

low-

level

visu al

experiments

in

this

p

aper

prove

the

effectiveness

of

Tucker

decomposition

in

compressing

the

model

in

th

at

the

denoising

neural

network

D;CNN|the

model

p

arameters

are

reduced

by

85%~88%,a;d

the

number

of

floating

point

operations

(FLOPs)

is

reduced

by

85%~88%.In

the

super-resolution

neural

network

VDSR,the

p

arameters

of

the

model

ue

reduced

by

85%|a;d

the

number

of

floating-point

operations

is

reduced

by

85%.Keywords:co;volutio;

al

neural

networMCNNLTucker

decompositio;|model

p

arameter|FLOPS|CNN

compression卷积神经网络的发展给计算机视觉任务提供了多种解决方

法[1-2],在移动设备上部署CNN进行计算机视觉任务得到了广

是矩阵奇异值分解(SVD)的高阶推广。Tuckar分解将原始张量

分解为核心张量和;个;模矩阵,如图1所示。:7泛的关注。对于移动设备应用程序,CNN的训练通常是在服务

器上完成的,推理过程则是在移动设备上完成。然而,CNN在移

动设备应用程序中部署的最关键的问题就是:移动设备的计算

能力和内存容量。因此,若是想在移动设备上部署CNN,必须对

CNN模型进行压缩。深度神经网络有过参数的性质袁

这使得网络在训练过程中

JD.—旺1_I

I

KJW

D,可以收敛到损失函数的局部最小值[3-4]遥为了提高移动设备上的

测试性能,在网络性能没有大幅下降的情况下,剔除训练过的网

络中的冗余参数。文献[5]使用了

Tuckar分解压缩了

AlexNet、

VGG-S、GoogLeNet和VGG-16网络,四个网络都是用于解决

高级视觉任务(图像识别与分类),但是在视觉低级任务中,如去

2本文方法图1

Tucker分解及张量矩阵化噪和高分辨率等任务,Tucker分解用以压缩该任务中相关网络

本文分三步对卷积神经网络进行压缩:①Tuckar分解;②秩

的选择;③网络微调。本文首先利用全局解析变分贝叶斯矩阵分

的有效性尚未被验证过。本文利用Tuckar分解,对视觉低级任

务中的网络进行压缩,并通过实验证实了其有效性。1相关理论1.1

CNN压缩与加速解,分析了各层核张量的模3和模4矩阵分解的主子空间遥然后

在每一层的核张量上根据第一步所选择的秩进行塔克分解。最

后,使用反向传播微调整个网络。2.1核张量上的塔克分解大量的工作文献[6-11]已证实可以通过压缩来加速神经

网络的推理速度。量化[12-14]和特殊的卷积实现[15-18]可以加速神

卷积核张量:在CNN中,卷积运算使用以下线性映射将大

小为HxWxT的输入张量X映射为大小为H1XW1XT1的输岀张

经网络。张量分解[5,19-21]的方法将权值分解为轻量块,例如文献

Y:Yh,,憎,

,t,=KiF躁4,

=

1

j

=

1

F

1[22-24]提岀了用截断奇异值分解加速全连接层的方法;文献

[25]提岀将层分解为1伊3和3伊1;文献[26]提岀将层分解为

3x3和1伊1

;通道修剪0切从特征映射中删除冗余通道。1.2张量分解张量是多维数组。例如,向量是一维张量,矩阵是二维张量。

CANDECOMP/PARAFAC模型和Tuckar模型是两种常用的张

S

s

T•XhiWjhi

=

(h1

-1

)A+i-P,wj=(w1

-1

)A+j-P

(1)其中,K是一个SxSxTxT的四维核张量,△是卷积操作的

步长,P是卷积操作中zaro-padding的大小遥四维核张量的秩为(R1,

R2,

R3,

R4)的张量分解有如下形式:量分解模型。在本文中,利用Tuckar模型对卷积神经网络的参

数进行压缩。Tuckar分解——计算张量不同模态的正交空间,

心防移移移移CWF”•M,•M;•M则1

=1则2=1则3

=1则4=1R1

R2

R3

R4ttWF•Ma:《工业控制计算机》2021年第34卷第4期其中,C是一个大小为R1xR2xR3xR4的核张量‘MaM^M®、

M(4)分别是大小为SxRf、SxR2、TxR3、TfxR4的因子矩阵。在塔克分解中,并不是每一模都必须被分解。在卷积神经网

络中,对卷积核张量的模1和模2进行塔克分解并不能显著减

少模型的参数,因为通常这两个维度的大小是比较小的,例如当

卷积操作中的kernel

size为3或者5的时候。所以,我们可以

采用Tucker-2分解的,核张量将会被分解为如下形式:3

R4%山=移移RC=,sM2•“::;,

(2)r3

=1r4

11其中,C是一个大小为SxSxR3xR4的核张量,将(2)式代入(1)式并整理得到卷积操作的近似计算:T3Zh,w,r3=^移

*Mt,

'Xh,w,t忆 S

S

RZh,,w,,r4

=

Zhi

w,ri

=

1 j

j

1

r

移i,j,r3,r<=

1

CR

)

Yh,

'憎,t

=

Mt ,

r/ZIY

,憎忆山r4移

11

(4其中,Z和Z‘分别是大小为HxWxR3、H'xW'xR4的中间张量。复杂度分析:式(1)中的卷积操作包含S2TT1个参数和

S^TTM忆W忆的乘积-累加(multiplication-addition)操作遥在

Tucker分解的作用下,压缩率(compression

ratio)RC和加速率

(speed-up

ratio)Rs可以表示为如下形式:R

s2tt’

r

S2TT1H'W,__________C

TR2

S

TR23+S

R3R4+T1R4

3HW+S

R3R4H'W'+T1

R4H'W'2.2秩的选择秩(砸3,砸4)的选择,对于性能(内存、模型推理速度)提升和

模型精度损失显得尤为重要,是模型压缩中的一个超参数。本文

中通过变分贝叶斯矩阵分解(VBMF,

variational

Bayesian

ma­trix

factorizatio

n)[32]来对秩(砸3,砸4)做一次性决定,而不是通过

耗时的人工试验来决定。VBMF的全局解析解在Tucker分解中

的秩的选择中非常有效,因为它能求岀噪声的方差、秩,甚至为

完美秩的恢复品提供了理论条件。本文中,分别对核张量的模-3矩阵化结果和模-4的矩阵

化结果使用VBMF的解析解来决定秩砸3和砸4。2.3 模型微调由于Tucker分解只是将核张量的重构误差降到最小,而不

包含深度神经网络中的非线性响应

所以整个压缩后的网络的

精度会明显降低。但是,本文发现,使用模型微调,以压缩前的网

络的训练参数重新对网络进行训练,经过10个epoch后,网络

精度能接近于原始的精度。3实验我们使用两个有代表性的网络DnCNN^和VDSR[2]

,

DnCNN

是经典的去噪神经网络,VDSR是早期使用深度学习做超分辨

率任务的神经网络。在DnCNN中有17个卷积层,本文不压缩第一层和最后一

层卷积层,因为前者的input_channel为1,而后者的out-

put_channel为1,对他们进行压缩显得意义不大。所以,本文只

是对其中的15个卷积层的参数进行压缩如表1~表3所示。从上述结果可以看岀

在对网络精度没有太大影响的情况

下,DnCNN模型的参数量减少了

85%~88%,浮点运算次数表1

DnCNN原始精度轧t碍

需厉Sii:ni;i卩sr-;r:SS1VSir-iiiiiPSK1?SS1U31.71i?i).9&rqh29.20■2255C26.215i:iU.«T7595表2

DnCNN压缩后的精度W曲i;ji

n:irs-'-.l

I

Tl

l;1T'SNRqsiw旳鹉I52?24.:JZO.-SS'ij1

?65432-J1:.:'.

1

£5:JWUl502-5.7UC.86K

表3

DnCNN压缩前后对比Ni^nid彌!l

;.前.;・娄歎.hl

(前)

i:'Id)15汁::>;yi:i:'vi

1

:)::.M55^-.JLl!:■:jM伍IkS'jfiV

11::.MFLOPs 减少了

85%~88%。在

VDSR

员8

个卷积层

对整个网络进行压缩

即对

18个卷积层的参数都进行压缩。如表4、表5所示。表4

VDSR压缩前后精度比较DntHNetScfJcTJSRVDETL-Dtlfih

1

kinmL

FJ55R.-SS1MrsMi-ssiMw77:■:.■;

i:就忙K.4:?H;•防i.l.

"::;32

66Sell--却冬::••:.

5428

■::■«.27

72■:.■:1

-=.b;131

:;'::■28祐28

61A?

iO:it

•■:z?

-:.i■n

•:■•:■00X42?.242^.74表5

VDSR压缩前后参数量和FLOPs比较替數量(id替款■

Ch口

仆1“

Ldi.J2;.;•?沁..ii从上述结果可以看岀

在对网络精度没有太大影响的情况

下,VDSR模型的参数量减少了

85%,浮点运算次数FLOPs减

少了

85%。4

结束语基于Tucker分解在高级视觉任务中的神经网络中的有效

性,本文提岀在低级视觉任务中使用Tucker分解对卷积神经网

络的参数进行压缩,并使用典型卷积网络DnCNN和VDSR在

文献中使用的数据集中进行了广泛实验。实验验证了

Tucker分

解在低级视觉任务中的有效性

本文方法在网络精度没有太大

影响的情况下,能使模型的参数量和浮点运算次数减少85%左

右遥在下一步工作中,将研究压缩层数对压缩效果的影响以及如

何补偿网络的精度损失。参考文献[1

]Zhang

K,

Zuo

W,

Chen

Y,

et

al.

Beyond

a

gaussian

denois-

er:Residual

learning

of

deep

cnn

for

image

denoising[J].IEEE

transactions

on

image

processing,

2017,

26(7):

3142-3155[2]

Kim

J,

Kwon

Lee

J,

Mu

Lee

K.

Accurate

image

super-reso­lution

using

yery

deep

conyolutional

networks [C]//Proceed-

ings

of

the

IEEE

conference

on

computer

yision

nnd

pattern

recognition,20f6:f646-f654[3]

Hinton

G

E,Sriyastaya

N,

Krizheysky

A,

et

tl.

Improying

neu­ral

networks

by

preyenting

co-adaptation

of

feature

detec-

tors[J].

.rXiy

preprint

trXiy:

1207.0580,

2012[4]

Denil

M,

Shakibi

B,

Dinh

L,

etl.

Predicting

parameters

in

deep

learning[J].

.rXiy

preprint

trXiy:1306.0543,

2013[5]

Kim

Y

D,

Park

E,

Yoo

S,

et

tl.

Compression

of

deep

conyo­lutional

neural

networks

for

fast

and

low

power

mobile

appli-

cations[J].

arXiy

preprint

arXiy:f5f

1.06530,

2015[6]

Han

S,

Pool

J,

Tran

J,

et

al.

Learning

both

weights

and

con-96nections

for

efficient

neural

networks

[J].arXiv

preprint

arXiv:

1506.02626,

2015[7]

Han

S,

Mao

H,

Dally

W

J.

Deep

compression:

Compressing

视觉低级任务中的CNN压缩研究tion[J].

arXiv

preprint

arXiv:1412.6553,

2014[20]Gong

Y,

Liu

L,

Yang

M,

et

al.

Compressing

deep

convolu­tional

networks

using

vector

quantization

[J].arXiv

preprint

deep

neural

networks

with

pruning,

trained

quantization

and

huffman

coding[J].

arXiv

preprint

arXiv:1510.00149,

2015[8]

Luo

o

H,

Wu

J,

Lin

W.

Thinet:

A

filterlevel pruning

method

arXiv:1412.6115,

2014[21

]Masana

M,van

de

Weijer

J,Herranz

L,et

-adaptive

deep

network

compression[C]//Proceedings

of

the

IEEE

In­ternational

Conference

on

Computer

Vision,2017:4289-4297[22]

Xue

J,

Li

J,

Gong

Y.

Restructuring

of

deep

neural

network

for

deep

neural

network

compression[C]//Proceedings

of

the

IEEE

international

conference

on

computer

vision,2017:5058-

5066[9]

Dong

X,Huang

J,Yang

Y,et

is

less:

A

more

compli­acoustic

models

with

singular

value

decomposition[C]//ln-

terspeech,2013:

2365-2369[23]

Denton

E,

Zaremba

W,

Bruna

J,

et

al.

Exploiting

linear

cated

network

with

less

inference

compIexity[C]//Proceedings

of the

IEEE

Conference

on

Computer

Vision

and

Pattern

structure

within

convolutional

networks

for

efficient

evaluation

Recognition,2017:5840-5848[10]

Han

S,

Liu

X,

Mao

H,

et

al.

EIE:

Efficient

inference

engine

[J].

arXiv

preprint

arXiv:1404.0736,

2014[24]

Girshick

r-cnn[C]//Proceedings

of

the

IEEE

interna­on

compressed

deep

neural

network

[J].ACM

SIGARCH

tional

conference

on

computer

vision,2015:

1440-1448[25]

Jaderberg

M,

Vedaldi

A,

Zisserman

A.

Speeding

up

convo­Computer

Architecture

News,

2016,

44(3):

243-254[11

]Han

S,

Kang

J,

Mao

H,

et

al.

Ese:

Efficient

speech

recog­lutional

neural

networks

with

low

rank

expansions

[J].arXiv

nition

engine

with

sparse

Istm

on

fpga

[C]//Proceedings

of

preprint

arXiv:1405.3866,

2014[26]

Zhang

X, Zou

J,

He

K,

et

al.

Accelerating

very

deep

con­the

2017

ACM/SIGDA

International

Symposium

on

Field

-

Programmable

Gate

Arrays,2017:

75-84[12]

Zhu

C,

Han

S,

Mao

H, et

al.

Trained

ternary

quantizationvolutional

networks

for

classification

and

detection

[J].IEEE

transactions

on

pattern

analysis

and

machine

intelligence,

[J].

arXiv

preprint

arXiv:1612.01064,

2016[13]

Courbariaux

M,

Hubara

I,

Soudry

D,

et

al.

Binarized

neural

2015,38(10):

1943-1955[27]

Polyak

A,

Wolf

L.

Channel-level

acceleration

of

deep

face

networks:Training

deep

neural

networks

with

weights

and

representations[J],

IEEE

Access,

2015

(3):

2163-2175[28]

Hu

H,

Peng

R,

Tai

Y

W,

et

al.

Network

trimming:

A

data-

activations

constrained

to+

1

or-1

[J].arXiv

preprint

arXiv:

1602.02830,

2016[14]

Rastegari

M,

Ordonez

V,

Redmon

J,

et

al.

Xnor-net:

Ima-

driven

neuron

pruning

approach

towards

efficient

deep

ar-

chitectures[J].

arXiv

preprint

arXiv:1607.03250,

2016[29]

Anwar

S,

Sung

W.

Compact

deep

convolutional

neural

net­genet

classification

using

binary

convolutional

neural

net­works

[C]//European

conference

on

computer

vision.

works

with

coarse

pruning[J].arXiv

preprint

arXiv:1610.09639,

Springer,Cham,

2016:

525-542[15]

Mathieu

M,

Henaff

M,LeCun

Y.

Fast

training

of

convolutional

2016[30]

Molchanov

P,

Tyree

S,

Karras

T,

et

al.

Pruning

convolutional

networks

through

ffts[J].arXiv

preprint

arXiv:1312.5851,

2013[16]

VasiIache

N,

Johnson

J,

Mathieu

M,

et

al.

Fast

convolution­neural

networks

for

resource

efficient

transfer

learning [J].

arXiv

preprint

arXiv:1611.06440,

2016,

3[31

]Tucker

L

R.

Some

mathematical

notes

on

three-mode

fac­al

nets

with

fbfft:A

GPU

performance

evaluation

[J].

arXiv

preprint

arXiv:1412.7580,

2014[17]

Lavin

A,Gray

S.

Fast

algorithms

for

convolutional

neural

net-

tor

anaIysis[J].

Psychometrika,

1966,

31(3):

279-311[32]

Nakajima

S,

Sugiyama

M,

Babacan

S

D,

et

al.

Global

ana­works[C]//Proceedings

of

the

IEEE

Conference

on

Comput­er

Vision

and

Pattern

Recognition,2016:4013-4021[18]

Bagherinezhad

H,Farhadi

A,Rastegari

-based

con­lytic

solution

of

fully

-observed

variational

Bayesian

matrix

factorization[J].JournaI

of

Machine

Learning

Research,

2013,

14(Jan):

1-37[33]

Nakajima

S,

Tomioka

R,

Sugiyama

M,

et

al.

Perfect

dimen­volutional

neural

network:

U.S.

Patent

10,691,975[P].

2020-

6-23[19]

Lebedev

V,

Ganin

Y,

Rakhuba

M,

et

al.

Speeding-up

con­sionality

recovery

by

variational

Bayesian PCA

[J].Advances

in

Neural

Information

Processing

Systems,2012,25:971-979[收稿日期:2021.1.27]volutional

neural

networks

using

fine-tuned

cp-decomposi-(上接第93页)engineering

of

Japan,

2018,

51(8):695-703参考文献[1

]Chang

S,Zhuo

J,Meng

S,et

Coal

Technologies

in

[5]

白建云,朱竹军,张培华•基于BP神经网络的循环流化床锅炉生成

NOx质量浓度在线软测量[J].热力发电,2016,45(12):78-83[6]

易正明,邓植丹,覃佳卓,等•基于RBF-BP混合神经网络的烧结烟

China:

Current

Status

and

Future

Perspectives[J].

Engineer­ing,

2016,2(4):447-459[2]

Zhao

Y,Wang

G,Hu

Q,et

blending

optimization

model

气NOx预测[J].钢铁研究学报,2020,32(7):639-646[7]

李鹏辉,刘冉,余廷芳•基于支持向量机和BP神经网络的燃煤锅炉

NOx

排放预测[J].热能动力工程,2016,31(10):104-108,129-130[8]

魏乐,胡晓东,尹诗•基于优化XGBoost的发电机前轴承故障预警

[J/OL].系统仿真学报:1-8

[2021

-01

-05]./

for

reducing

pollutant

emission

costs

based

on

Support

Vector

Machine[J].

IOP

Conference

Series:Earth

and

Environ­mental

Science,

2019,

300(3):032086[3]

Lv

Y

,

Liu

J

,

Yang

T

,

et

al.

A

novel

least

squares

support

10.16182/.20-0538[9]

Dietterich

T

le

Methods

in

Machine

Learning

[C]^/

vector

machine

ensemble

model

for

NOx

emission

prediction

of

a

coal-fired

boiIer[J].

Energy,

2013,

55(15):319-329[4]

Tang

Z

,

Wu

X

,

Cao

S

et

al.

Modeling

of

the

Boiler

NOx

International

Workshop

on

Multiple

Classifier

er,

Berlin,

Heidelberg,

2000[收稿日期:2021.1.7]Emission

with

a

Data

Driven

Algorithm

[J].JournaI

of

chemical