Normalization

 

Normalization

local_response_normalization

local_response_normalization出现在论文”ImageNet Classification with deep Convolutional Neural Networks”中,论文中说,这种normalization对于泛化是有好处的.

bix,y=aix,y(k+α∑min(0,i+n/2)j=max(0,i−n/2)(ajx,y)2)β

经过了一个conv2d或pooling后,我们获得了[batch_size, height, width, channels]这样一个tensor.现在,将channels称之为层,不考虑batch_size

  • i代表第i层
  • aix,y就代表 第i层的 (x,y)位置所对应的值
  • n个相邻feature maps.
  • k...α...n...β是hyper parameters
  • 可以看出,这个函数的功能就是, aix,y需要用他的相邻的map的同位置的值进行normalization
    在alexnet中, k=2,n=5,α=10−4,β=0.75
tf.nn.local_response_normalization(input, depth_radius=None, bias=None, alpha=None, beta=None, name=None)
'''
Local Response Normalization.
The 4-D input tensor is treated as a 3-D array of 1-D vectors (along the last dimension), and each vector is normalized independently. Within a given vector, each component is divided by the weighted, squared sum of inputs within depth_radius. In detail,
'''
"""
input: A Tensor. Must be one of the following types: float32, half. 4-D.
depth_radius: An optional int. Defaults to 5. 0-D. Half-width of the 1-D normalization window.
bias: An optional float. Defaults to 1. An offset (usually positive to avoid dividing by 0).
alpha: An optional float. Defaults to 1. A scale factor, usually positive.
beta: An optional float. Defaults to 0.5. An exponent.
name: A name for the operation (optional).
"""
  • depth_radius: 就是公式里的n/2
  • bias : 公式里的k
  • input: 将conv2d或pooling 的输出输入就行了[batch_size, height, width, channels]
  • return :[batch_size, height, width, channels], 正则化后

batch_normalization

论文地址
batch_normalization, 故名思意,就是以batch为单位进行normalization
- 输入:mini_batch: In={x1,x2,..,xm}
- γ,β,需要学习的参数,都是向量
- ϵ: 一个常量
- 输出: Out={y1,y2,...,ym}
算法如下:
(1)mini_batch mean:

μIn←1m∑i=1mxi

(2)mini_batch variance

σ2In=1m∑i=1m(xi−μIn)2

(3)Normalize

x^i=xi−μInσ2In+ϵ−−−−−−√

(4)scale and shift

yi=γx^i+β

可以看出,batch_normalization之后,数据的维数没有任何变化,只是数值发生了变化
Out作为下一层的输入
函数:
tf.nn.batch_normalization()

def batch_normalization(x,
mean,
variance,
offset,
scale,
variance_epsilon,
name=None):

Args:

  • x: Input Tensor of arbitrary dimensionality.
  • mean: A mean Tensor.
  • variance: A variance Tensor.
  • offset: An offset Tensor, often denoted β in equations, or None. If present, will be added to the normalized tensor.
  • scale: A scale Tensor, often denoted γ in equations, or None. If present, the scale is applied to the normalized tensor.
  • variance_epsilon: A small float number to avoid dividing by 0.
  • name: A name for this operation (optional).
  • Returns: the normalized, scaled, offset tensor.
    对于卷积,x:[bathc,height,width,depth]
    对于卷积,我们要feature map中共享 γi 和 βi ,所以 γ,β的维度是[depth]

现在,我们需要一个函数 返回mean和variance, 看下面.

tf.nn.moments()

def moments(x, axes, shift=None, name=None, keep_dims=False):
# for simple batch normalization pass `axes=[0]` (batch only).

对于卷积的batch_normalization, x 为[batch_size, height, width, depth],axes=[0,1,2],就会输出(mean,variance), mean 与 variance 均为标量。

local_response_normalization 和 batch_normalization的更多相关文章

  1. tensorflow中的batch_normalization实现

    tensorflow中实现batch_normalization的函数主要有两个: 1)tf.nn.moments 2)tf.nn.batch_normalization tf.nn.moments主 ...

  2. Tensorflow BatchNormalization详解:4_使用tf.nn.batch_normalization函数实现Batch Normalization操作

    使用tf.nn.batch_normalization函数实现Batch Normalization操作 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 吴恩达deeplearnin ...

  3. 批量归一化batch_normalization

    为了解决在深度神经网络训练初期降低梯度消失/爆炸问题,Sergey loffe和Christian Szegedy提出了使用批量归一化的技术的方案,该技术包括在每一层激活函数之前在模型里加一个操作,简 ...

  4. 请问batch_normalization做了normalization后为什么要变回来?

    请问batch_normalization做了normalization后为什么要变回来? 请问batch_normalization做了normalization后为什么要变回来? - 莫驚蟄的回答 ...

  5. tensorflow 的 Batch Normalization 实现(tf.nn.moments、tf.nn.batch_normalization)

    tensorflow 在实现 Batch Normalization(各个网络层输出的归一化)时,主要用到以下两个 api: tf.nn.moments(x, axes, name=None, kee ...

  6. Key in_hidden/batch_normalization/beta not found in checkpoint

    可能原因:不同参数的结果保存到了同一文件夹下 解决方法:不同参数结果放在不同的checkpoints tf.train.Saver().save(sess, self.checkpoint_dir + ...

  7. CTPN项目部分代码学习

    上次拜读了CTPN论文,趁热打铁,今天就从网上找到CTPN 的tensorflow代码实现一下,这里放出大佬的github项目地址:https://github.com/eragonruan/text ...

  8. TensorFlow 神经网络相关函数

    TensorFlow 激活函数 激活操作提供用于神经网络的不同类型的非线性.这些包括平滑的非线性(sigmoid,tanh,elu,softplus,和softsign),连续的,但不是到处可微函数( ...

  9. TensorFlow NormLization

    local_response_normalization local_response_normalization出现在论文”ImageNet Classification with deep Con ...

随机推荐

  1. Prime算法生成最小生成树

    虽说是生成树,但我只将生成的边输出了.至于怎么用这些边来创建树...我不知道_(:з」∠)_ //Prime方法生成最小生成树 void GraphAdjacencyListWeight::Gener ...

  2. 获取qq音乐json数据---某课网音乐app学习

    移动端qq音乐地址:https://m.y.qq.com/ .抓取QQ音乐数据 请求首页时,有如下链接,回调了jsonp https://c.y.qq.com/splcloud/fcgi-bin/p. ...

  3. HDU_Reward_拓扑排序

    Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  4. Redis 之持久化(rdb、aof)

    Redis的持久化有2种方式   1快照  2是日志 测试aof:

  5. DECLARE_DYNAMIC

    DECLARE_DYNAMIC(class_name) DECLARE_DYNCREATE 包含了DECLARE_DYNAMIC的功能,并且可以在运行过程中动态创建对象.如果需要动态创建类对象,需要使 ...

  6. 环状序列(Circular Sequence, ACM/ICPC Seoul 2004, UVa1584)

    长度为n的环状串有n种表示法,分别为从某 个位置开始顺时针得到.例如,图3-4的环状串 有10种表示: CGAGTCAGCT,GAGTCAGCTC,AGTCAGCTCG等. 在这些表示法中,字典序最小 ...

  7. (C/C++学习)8.C++ Lambda

    一.生成随机数字 假设我们有一个vector<int>容器,想用100以内的随机数初始化它,其中一个办法是通过generate函数生成,如代码1所示.generate函数接受三个参数,前两 ...

  8. Python - 面对对象(进阶)

    目录 Python - 面对对象(进阶) 类的成员 一. 字段 二. 方法 三. 属性 类的修饰符 类的特殊成员 Python - 面对对象(进阶) 类的成员 一. 字段 字段包括:普通字段和静态字段 ...

  9. 第十二节:pandas缺失数据处理

    1.isnull():检查是否含有确实数据 2.fillna():填充缺失数据 3.dropna() :删除缺失值 4.replace():替换值

  10. 第十节:pandas之loc()、iloc()与ix()索引