97
Introduction of Convolution Neural Network 汇报人:赵子健 2016年9月3日 智能机器人与测控技术实验室

Tutorial of cnn 赵子健9.16

Embed Size (px)

Citation preview

Page 1: Tutorial of cnn 赵子健9.16

Introduction of Convolution Neural Network

汇报人:赵子健

2016年9月3日

智能机器人与测控技术实验室

Page 2: Tutorial of cnn 赵子健9.16

2目录

数字图像,神经网络1

基础篇——数字图像与神经网络1

卷积,池化,全连接1

强化篇——卷积神经网络2

结构,常见CNN,超深度CNN1

提高篇——ConvNet结构与实例3

Page 3: Tutorial of cnn 赵子健9.16

3目录

数字图像,神经网络1

基础篇——数字图像与神经网络1

卷积,池化,全连接1

强化篇——卷积神经网络2

结构,常见CNN,超深度CNN1

提高篇——ConvNet结构与实例3

Page 4: Tutorial of cnn 赵子健9.16

数字图像 4

模拟图像→采样→量化→数字图像

Page 5: Tutorial of cnn 赵子健9.16

数字图像 5

二值图

1 bit/pixel

0/1

灰度图

1 byte/pixel

0-255

彩色图

3 byte/pixel

R:0-255 G:0-255 B:0-255

Page 6: Tutorial of cnn 赵子健9.16

神经网络 6

Page 7: Tutorial of cnn 赵子健9.16

神经网络 7

Page 8: Tutorial of cnn 赵子健9.16

神经网络 8

Page 9: Tutorial of cnn 赵子健9.16

神经网络 9

Page 10: Tutorial of cnn 赵子健9.16

神经网络 10

Page 11: Tutorial of cnn 赵子健9.16

神经网络 11

Page 12: Tutorial of cnn 赵子健9.16

神经网络 12

Page 13: Tutorial of cnn 赵子健9.16

神经网络——Activation Functions 13

其他激活函数:Leaky ReLU , Maxout , ELU , etc.

(Rectified Linear Unit)

梯度弥散(饱和)

非0中心

exp( )计算量大

梯度弥散(饱和)

tanh( )计算量不小

绝对抑制(前/反)

缩放至[0,1]

dσ简单: σ(1-σ)

缩放至[-1,1]

0中心

不弥散

计算量小

收敛快6

Page 14: Tutorial of cnn 赵子健9.16

神经网络——Activation Functions 14

其他激活函数:Leaky ReLU , Maxout , ELU , etc.

(Rectified Linear Unit)

缩放至[0,1]

dσ简单: σ(1-σ)

缩放至[0,1]

0中心

不弥散

计算量小

收敛快6

Page 15: Tutorial of cnn 赵子健9.16

神经网络——Activation Functions 15

(Rectified Linear Unit) (Parametric Rectified Linear Unit)

PReLU

Page 16: Tutorial of cnn 赵子健9.16

神经网络——Gradient Descent 16

Have some function

Want

Outline:

• Start with some

• Keep changing to reduce until we hopefully

end up at a minimum

Page 17: Tutorial of cnn 赵子健9.16

神经网络——Gradient Descent 17

1

0

J(0,1)

Page 18: Tutorial of cnn 赵子健9.16

神经网络——Backpropagation 18

反向传播算法(Backpropagation)是目前用来训练人工神经网络(ANN)

的最常用且最有效的算法。其主要思想是:

(1)将训练集数据输入到ANN的输入层,经过隐藏层,最后达到输出层

并输出结果,这是ANN的前向传播过程;

(2)由于ANN的输出结果与实际结果有误差,则计算估计值与实际值之

间的误差,并将该误差从输出层向隐藏层反向传播,直至传播到输入层;

(3)在反向传播的过程中,根据误差调整参数的值;不断迭代上述过

程,直至收敛。

Page 19: Tutorial of cnn 赵子健9.16

神经网络——Backpropagation——变量定义 19

上图是一个三层人工神经网络,layer1至layer3分别是输入层、隐藏层和输出层。

如图,先定义一些变量:

表示第l层的第k个神经元连接到第j层的第个神经元的权重;

表示第l层的第j个神经元的偏置;

表示第l层的第j个神经元的输入,即:

表示第l层的第j个神经元的输出,即:

其中 表示激活函数。

Page 20: Tutorial of cnn 赵子健9.16

神经网络——Backpropagation——代价函数 20

代价函数被用来计算ANN输出值与实际值之间的误差。常用的代价函数是二次

代价函数(Quadratic cost function):

其中,x表示输入的样本,y表示实际的分类,L表示神经网络的最大层数,aL 表

示预测的输出。

Page 21: Tutorial of cnn 赵子健9.16

神经网络——Backpropagation——公式及推导 21

首先,将第l层第j个神经元中产生的误差(即实际值与预测值之间的误差)定义为:

以一个输入样本为例进行说明,此时代价函数表示为:

公式1(计算最后一层神经网络产生的错误) 公式2(由后往前,计算每一层神经网络产生的错误)

公式3(计算权重的梯度) 公式4(计算偏置的梯度)

Page 22: Tutorial of cnn 赵子健9.16

神经网络——Backpropagation——算法 22

前向传播:

输出层误差:

反向传播误差:

梯度下降,参数更新:

Page 23: Tutorial of cnn 赵子健9.16

23目录

数字图像,神经网络1

基础篇——数字图像与神经网络1

卷积,池化,全连接1

强化篇——卷积神经网络2

结构,常见CNN,超深度CNN1

提高篇——ConvNet结构与实例3

Page 24: Tutorial of cnn 赵子健9.16

卷积神经网络 24

1981年诺贝尔医学奖

Hubel & Wiesel @ John Hopkins University

Page 25: Tutorial of cnn 赵子健9.16

卷积神经网络 25

Page 26: Tutorial of cnn 赵子健9.16

卷积神经网络 26

LeNet-5 by LeCun in 1998

LeCun, Yann, et al. "Gradient-based learning applied to document

recognition." Proceedings of the IEEE 86.11 (1998): 2278-2324.

Page 27: Tutorial of cnn 赵子健9.16

卷积神经网络 27

Page 28: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 28

彩色图

3 byte/pixel

R:0-255 G:0-255 B:0-255

Page 29: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 29

卷积 Convolution 在图像处理中,对图像用一个卷积核进行卷积运算,实际上是一个滤波的过

程。下面是卷积的数学表示:

Page 30: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 30

假设有6组卷积核

并行地互不干涉地进行

同样的操作,得到:

Page 31: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 31

这实际上就完成了一层卷积运算

Page 32: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 32

这实际上就完成了一层卷积运算

那么不断加层,就构成了初步的深度神经网络…

输入图片 特征图 特征图

Page 33: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 33

Page 34: Tutorial of cnn 赵子健9.16

Convolution layer 卷积运算 34

参数: F(filter size), S(stride)

Page 35: Tutorial of cnn 赵子健9.16

35

卷积运算演示

Page 36: Tutorial of cnn 赵子健9.16

36

卷积运算演示

Page 37: Tutorial of cnn 赵子健9.16

37

卷积运算演示

Page 38: Tutorial of cnn 赵子健9.16

38

卷积运算演示

Page 39: Tutorial of cnn 赵子健9.16

39

卷积运算演示

Page 40: Tutorial of cnn 赵子健9.16

40

卷积运算演示

Page 41: Tutorial of cnn 赵子健9.16

41

卷积运算演示

Page 42: Tutorial of cnn 赵子健9.16

42

卷积运算演示

Page 43: Tutorial of cnn 赵子健9.16

43

卷积运算演示

Page 44: Tutorial of cnn 赵子健9.16

44

卷积运算演示

Page 45: Tutorial of cnn 赵子健9.16

45

卷积运算演示

Page 46: Tutorial of cnn 赵子健9.16

46

卷积运算演示

Page 47: Tutorial of cnn 赵子健9.16

47

卷积运算演示

Page 48: Tutorial of cnn 赵子健9.16

48

卷积运算演示

Page 49: Tutorial of cnn 赵子健9.16

49

卷积运算演示

Page 50: Tutorial of cnn 赵子健9.16

50

卷积运算演示

Page 51: Tutorial of cnn 赵子健9.16

51

卷积运算演示

Page 52: Tutorial of cnn 赵子健9.16

52

卷积运算演示

Page 53: Tutorial of cnn 赵子健9.16

卷积运算 53

千里之行,已迈出重要一步!

Wait aaaa moment!

Page 54: Tutorial of cnn 赵子健9.16

卷积运算 54

Output size: (N - F) / stride + 1

(224-11)/4+1=54.25 ≠ 25

Alex God was wrong?

Hinton Big God was wrong?

Page 55: Tutorial of cnn 赵子健9.16

卷积运算 55

Output size: (N - F) / stride + 1

(224-11)/4+1=54.25 ≠ 25

Alex God was wrong?

Hinton Big God was wrong?

Page 56: Tutorial of cnn 赵子健9.16

卷积运算 56

Zero Pad

Page 57: Tutorial of cnn 赵子健9.16

卷积运算 57

Zero Pad

CONV layers with stride 1, filters of size FxF,

P = (F-1)/2

有三个参数: F(filter size), S(stride), P(pad)

有时,想由(N - F) / stride + 1得出整数不容易

pad的数量未必四边对称

Page 58: Tutorial of cnn 赵子健9.16

卷积运算 58

Output size: (N - F) / stride + 1

(224-11)/4+1=54.25 ≠ 25

Alex God was wrong?

Hinton Big God was wrong?

我并不认为两位大神在这里出错,

很有可能他们使用了pad,224→227

Page 59: Tutorial of cnn 赵子健9.16

卷积运算 59

Zero Padding 是一个很小但又有用的trick

Page 60: Tutorial of cnn 赵子健9.16

卷积运算 60

[From Andrej Karpathy’s Notes]

Page 61: Tutorial of cnn 赵子健9.16

Pooling layer (池化层/降采样层) 61

降低特征图平面空间尺度(降低矩阵大小),提高后续可操作性

Page 62: Tutorial of cnn 赵子健9.16

Pooling layer (池化层/降采样层) 62

Max Pooling

Page 63: Tutorial of cnn 赵子健9.16

Pooling layer (池化层/降采样层) 63

[From Andrej Karpathy’s Notes] Max Pooling

与卷积尺寸计算方法的不同?

F=3, S=2 (有重叠)

F=2, S=2

· mean pooling

· stochastic pooling (probabilistic pooling)

· probability weighted pooling

Page 64: Tutorial of cnn 赵子健9.16

神经网络—— Batch Normalization 64

开始讲解算法前,先来思考一个问题:我们知道在神经网络训练开始前,都要对输入数据做一个归一化处理,那么具体为什么需要归一化呢?归一化后有什么好处呢?原因在于神经网络学习过程本质就是为了学习数据分布,一旦训练数据与测试数据的分布不同,那么网络的泛化能力也大大降低;另外一方面,一旦每批训练数据的分布各不相同(batch 梯度下降),那么网络就要在每次迭代都去学习适应不同的分布,这样将会大大降低网络的训练速度,这也正是为什么我们需要对数据都要做一个归一化预处理的原因。

Page 65: Tutorial of cnn 赵子健9.16

65神经网络—— Batch Normalization

Page 66: Tutorial of cnn 赵子健9.16

66神经网络—— Batch Normalization

Page 67: Tutorial of cnn 赵子健9.16

67神经网络—— Batch Normalization

Page 68: Tutorial of cnn 赵子健9.16

68神经网络—— Batch Normalization

Page 69: Tutorial of cnn 赵子健9.16

69神经网络—— Batch Normalization

Page 70: Tutorial of cnn 赵子健9.16

70

批归一化(Batch Normalization)[Loffe & Szegedy, JMLR 2015]:

非常有用的技术,更高层的归一化能进一步提升性能。可以分四步进行:

(a):在应用非线性之前在每个隐藏层上进行归一化。

(b):在训练中,为每个 minibatch 计算出均值和标准差。

(c):在反向传播中,我们应该考虑前向通过过程中的归一化。也就是说,反向传

播过程中应该进行一个换算和移位运算(shift operation)。换算和移位参数也应

该被学习,因为考虑到隐藏层的衍生物也将取决于它们。

(d):在测试时间,使用全局均值和标准差,这里说的不是为每个 minibatch 计算

出的那些。

http://blog.csdn.net/hjimce/article/details/50866313

神经网络—— Batch Normalization

Page 71: Tutorial of cnn 赵子健9.16

全连接层 71

Fully-connected layer

跟普通神经网络基本一样

Page 72: Tutorial of cnn 赵子健9.16

72目录

数字图像,神经网络,1

基础篇——数字图像与神经网络1

卷积,池化,全连接1

强化篇——卷积神经网络2

结构,常见CNN,超深度CNN1

提高篇——ConvNet结构与实例3

Page 73: Tutorial of cnn 赵子健9.16

常见网络结构 73

普通单向卷积神经网络结构:

代表有:LeNet, AlexNet, ZF Net, VGGNet

复杂多向卷积神经网络结构:

代表有:GoogLeNet, ResNet (及其衍生网络)

Page 74: Tutorial of cnn 赵子健9.16

常见网络结构——LeNet 74

共7层 FC7为输出层,经典叫法

LeCun, Yann, et al. "Gradient-based learning applied to document

recognition." Proceedings of the IEEE 86.11 (1998): 2278-2324.[5453]

Page 75: Tutorial of cnn 赵子健9.16

常见网络结构——AlexNet 75

Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton.

"Imagenet classification with deep convolutional neural networks."

Advances in neural information processing systems. 2012.[2593]

INPUT -> [[CONV -> RELU] -> POOL]*2 -> [CONV -> RELU] ->[CONV -> RELU] ] -> POOL

-> [FC -> RELU]*2 -> FC

Page 76: Tutorial of cnn 赵子健9.16

常见网络结构——AlexNet 76

Full (simplified) AlexNet architecture:

[227x227x3] INPUT

[55x55x96] CONV1: 96 11x11 filters at stride 4, pad 0

[27x27x96] MAX POOL1: 3x3 filters at stride 2

[27x27x96] NORM1: Normalization layer

[27x27x256] CONV2: 256 5x5 filters at stride 1, pad 2

[13x13x256] MAX POOL2: 3x3 filters at stride 2

[13x13x256] NORM2: Normalization layer

[13x13x384] CONV3: 384 3x3 filters at stride 1, pad 1

[13x13x384] CONV4: 384 3x3 filters at stride 1, pad 1

[13x13x256] CONV5: 256 3x3 filters at stride 1, pad 1

[6x6x256] MAX POOL3: 3x3 filters at stride 2

[4096] FC6: 4096 neurons

[4096] FC7: 4096 neurons

[1000] FC8: 1000 neurons (class scores)

Details/Retrospectives:

- first use of ReLU

- used Norm layers (not common anymore)

- heavy data augmentation

- dropout 0.5

- batch size 128

- SGD Momentum 0.9

- Learning rate 1e-2, reduced by 10

manually when val accuracy plateaus

- L2 weight decay 5e-4

- 7 CNN ensemble: 18.2% -> 15.4%

Page 77: Tutorial of cnn 赵子健9.16

常见网络结构——ZFNet 77

在AlexNet上调整超参数,使得表现有所提高。

进而说明了经典结构参数并不一定是当前结构下的最优超参数。

Page 78: Tutorial of cnn 赵子健9.16

常见网络结构——VGGNet 78

Page 79: Tutorial of cnn 赵子健9.16

常见网络结构——VGGNet 79

2014年ILSVRC冠军

Top 5 error:11.2->7.3

Page 80: Tutorial of cnn 赵子健9.16

复杂卷积网络——GoogLeNet 80

Page 81: Tutorial of cnn 赵子健9.16

复杂卷积网络——GoogLeNet 81

Page 82: Tutorial of cnn 赵子健9.16

复杂卷积网络——GoogLeNet 82

相对中间的网络产生的特征辨识力很强因而也应当充分加以利用。故在这

些层中增加一些额外的分类器(softmax0和softmax1),能够增加BP的梯

度信号并提供额外的正则化。

位置:将小的卷积网络(1*1)放在4a和4d的输出上。

在训练过程中,损失会考虑3个分类器根据权重叠加,进行BP权重更新;

而在测试过程,只使用最终的分类器softmax2。

4a 块 4b 块

Page 83: Tutorial of cnn 赵子健9.16

更复杂网络——ResNet 83

MSRA深度残差网络在2015年ImageNet和COCO共5个领域取得第一名:ImageNet recognition, ImageNet detection, ImageNet localization,

COCO detection, and COCO segmentation。

CVPR 2009 best paper:

“Single Image Haze Removal

Using Dark Channel Prior”

“基于暗通道的图像去雾算法”

CVPR 2016 best paper:

Page 84: Tutorial of cnn 赵子健9.16

更复杂网络——ResNet 84

基本残差式:

维度调整式:

Page 85: Tutorial of cnn 赵子健9.16

更复杂网络——ResNet 85

Page 86: Tutorial of cnn 赵子健9.16

86

Page 87: Tutorial of cnn 赵子健9.16

更复杂网络——ResNet 87

building block for ResNet-34 building block for ResNet-50/101/152

Page 88: Tutorial of cnn 赵子健9.16

更复杂网络——ResNet 88

物体定位

ImageNet Locolization

物体检测

ImageNet Detection

图像分类

ImageNet Classification

Page 89: Tutorial of cnn 赵子健9.16

ResNet变体——Stochastic Depth 89

Deep Networks with Stochastic Depth //preprint arXiv

Gao Huang @ Cornell University Date: 2016.4.4 Cited by 19

测试结果CIFAR-100: 24.58

Page 90: Tutorial of cnn 赵子健9.16

ResNet变体——Stochastic Depth 90

bl=1 :

bl=0 :

bl=1和bl=0如何选取? pl(bl=1) = pl

作者提出一个线性衰减规则:从输入层 p0 = 1 到最后的残差块 pL 有:

Page 91: Tutorial of cnn 赵子健9.16

ResNet变体——Stochastic Depth 91

在训练过程中,有效的残差块数估计期望值为

新添超参数 pL

在该线性衰减规则下,取 pL=0.5,

当深度网络的残差块数很多(L大)时,

测试端也要做出相应改变:

Page 92: Tutorial of cnn 赵子健9.16

ResNet变体——Fractal Network 92

FractalNet: Ultra-Deep Neural Networks without Residuals //preprint arXiv

Gustav Larsson @ University of Chicago Date: 2016.5.24

测试结果CIFAR-100: 22.85

该文章不同与第一篇drop layer,它提出了分形网络(fractal network)的概念,

基于fractal network的基础上,采用drop path来进行训练。

左图展示了分型网络原理

fc代表某单一类型网络

参数C代表分支路径数

本例中 C=4

参数B代表分型块的数量

本例中 B=5

两块之间用pooling降采样

若以卷基层来衡量深度,则有

深度 = B·2C

Page 93: Tutorial of cnn 赵子健9.16

ResNet变体——Fractal Network 93

文章提出了的drop path方法如下:

(1) local:join模块一定概率丢弃(drop)每条通路,但确保每个join上至少1条通路;

(2) global:对分形网络(fractal network)只留下一条路径。

优点:在训练过程中,针对不同的mini-batch使用不同的子网络(subnetworks), 可以避免

并行路径以及不同层次路径之间的相互适应。

Page 94: Tutorial of cnn 赵子健9.16

ResNet变体——Identity Mapping 94

Identity Mappings in Deep Residual Networks //preprint arXiv

Kaiming He @ Microsoft Research Date: 2016.4.12 Cited by 19

测试结果CIFAR-100: 22.71

该文章主要对原文Deep Residual Learning for Image Recognition的残差单元做了两方面做了

详尽的实验:1. shortcut类型 2. 激活函数顺序。

CIFAR-10测试集上进行测试

结果证明还是原始的shortcut类型表现最好

Page 95: Tutorial of cnn 赵子健9.16

ResNet变体——Identity Mapping 95

实验二

激活函数顺序

full pre-activiation

表现最好

ResNet的自我提升

Page 96: Tutorial of cnn 赵子健9.16

96Acknowledgement (致谢)

CS231n by Fei-Fei Li & Andrej Karpathy & Justin Johnson

Excellent course,本slide很多内容引用该课程的slides,坚持跟完,建议不用字幕

Page 97: Tutorial of cnn 赵子健9.16

97致谢

Q&A

谢谢!