CNN Layers

Layers and Implements

CNN网络主要包括卷积层、池化层、全连接层等。

在这里插入图片描述

Convolution Layers

Single channel

1.No padding

在这里插入图片描述

给定一张5X5的单通道的灰度图像和一个3X3的卷积核,从左上角开始将对应位置的数字相乘再求和,kernel 依次滑动stride=1,计算得到右侧的结果;

输入输出的尺寸关系为:
W i d t h o u t = ⌊ W i d t h i n − W i d t h k e r n e l s t r i d + 1 ⌋ Width_{out} = \left \lfloor \frac{Width_{in}-Width_{kernel}}{strid} +1 \right \rfloor Widthout=stridWidthinWidthkernel+1
代码实现:

2.Padding
在这里插入图片描述

给定同样的一张5X5的单通道的灰度图像和一个3X3的卷积核,首先在图像边缘添加零值像素得到padding后的图像。

一般情况下:
p a d d i n g = ⌊ W i d t h k e r n e l 2 ⌋ padding=\left \lfloor \frac{Width_{kernel}}{2} \right \rfloor padding=2Widthkernel
从左上角开始将对应位置的数字相乘再求和,kernel 依次滑动stride=1,计算得到右侧的结果;

输入输出的尺寸关系为:
W i d t h o u t = ⌊ W i d t h i n + 2 ∗ p a d d i n g − W i d t h k e r n e l s t r i d + 1 ⌋ Width_{out} = \left \lfloor \frac{Width_{in}+2 *padding -Width_{kernel}}{strid} +1 \right \rfloor Widthout=stridWidthin+2paddingWidthkernel+1

Multi channel

在这里插入图片描述

对应与多通道的输入图像,就需要多通道的卷积核来分别对各个通道进行卷积计算然后再将三通道数据相加,输出仍为单通道,即一个卷积核对应一个输出。

要获得多个输出,就需要使用多个卷积核来对图像进行卷积计算。

在这里插入图片描述

Pooling Layers

pooling的目的是在尽量保留关键信息的情况下缩小feature map的尺寸,从而减少运算量。

在这里插入图片描述

取前面卷积的输出中的一个channel为例进行大小为 2x2 的 maxpooling,即每四个元素中选出最大值。pooling前后的尺寸关系:
W i d t h o u t = ⌊ W i d t h i n W i d t h p o o l i n g ⌋ Width_{out} =\left \lfloor \frac{Width_{in}}{Width_{pooling}} \right \rfloor Widthout=WidthpoolingWidthin
除了 max pooling 外,还有average pooling、medium pooling 等。

Fully Connection Layers

在这里插入图片描述

全连接层就是与传统的神经网络一样,输入为一个特征向量,然后经过一系列的前向传播计算得到预测向量。因此卷积操作获得的feature map 要经过flatten操作转换为特征向量,然后再与参数weights进行相乘。

Function Layers

Dropout

在全连接层中,特征向量的长度往往都是非常大的。这样在进行计算时就会有非常大的计算量,与此同时,在进行batch training时计算量就会很容易达到一个不能接受的程度。

为了降低训练时的计算负担,引入了dropout的方法,即在训练时随机的选取一部分参数(可采用将一部分参数置零的方式)进行训练。但是在进行预测时需要将所有参数计入计算范围。

Batch Normalization

图像数据的数据量一般都很大,为了改良数据的分布在一个batch 中对每一张图片进行normalization。

normalization的过程:
I n p u t :   B a t c h   v a l u e   o f   X i n : { x 1 , x 2 , x 3 , . . . } B a t c h   m e a n :   μ = 1 m ⋅ ∑ i = 1 m x i B a t c h   v a r i a n c e :   σ 2 = 1 m ⋅ ∑ i = 1 m ( x i − μ ) 2 N o r m a l i z e   X :   x i h a t = x i − μ σ O u t p u t : s c a l e   a n d   s h i f t   X o u t : x i o u t = γ x i + β Input:\ Batch \ value \ of\ X^{in}: \{x_1,x_2,x_3,...\}\\Batch\ mean:\ \mu =\frac{1}{m}\cdot \sum_{i=1}^{m}x_i\\Batch\ variance:\ \sigma^2 =\frac{1}{m}\cdot \sum_{i=1}^{m}(x_i- \mu)^2\\Normalize\ X:\ x_i^{hat}=\frac{x_i-\mu}{\sigma}\\Output: scale\ and\ shift\ X^{out}:x_i^{out}=\gamma x_i+\beta\\ Input: Batch value of Xin:{x1,x2,x3,...}Batch mean: μ=m1i=1mxiBatch variance: σ2=m1i=1m(xiμ)2Normalize X: xihat=σxiμOutput:scale and shift Xout:xiout=γxi+β

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值