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. [Android]异常6-TextView setText延迟显示

    背景:Thread和Handler显示数据到界面 解决办法有: 解决一>界面使用了ListView.GridView等,把高度和宽度调整为固定值或者match_parent 解决二>某处U ...

  2. JS高级——变量提升

    JS执行过程 1.首先是预解析:预解析过程最重要的是提升,在JavaScript代码在预解析阶段,会对以var声明的变量名,和function开头的语句块,进行提升操作 2.执行操作 全局中解析和执行 ...

  3. Python 之数据类型

    # Numbers(数字) # int(有符号整型) # long(长整型[也可以代表八进制和十六进制]) # float(浮点型) # complex(复数) # String(字符串) # Lis ...

  4. jdbcUrl is required with driverClassName错误解决

    jdbcUrl is required with driverClassName springboot2.0配置多数据源: spring.datasource.primary.url=jdbc:mys ...

  5. profiler-gpu分析记录

    查看 Android 手机芯片信息下面以 夜神模拟器为例 D:\cmderλ adb devices # 1. 列出安卓设备List of devices attached127.0.0.1:6200 ...

  6. 转载:python 日期,季度,年份

    # 这个data_matrix[:,dimen] <= thresh_val 内标会返回data_matrix当中的值符合条件的,返回为True # ret_array 中就会返回 下标为Tru ...

  7. swift--Xcode7 使用Alamofire框架发送HTTP请求报错

    控制台打印的错误信息: Application Transport Security has blocked a cleartext HTTP (http://) resource load sinc ...

  8. CF17E Palisection (回文自动机+DP)

    题目传送门 题目大意:给你一个字符串,让你求出有多少对相交的回文子串 啊啊啊啊降智了,我怎么又忘了正难则反! 求相交会很难搞.把问题转化成求互不相交的回文子串再减一下就行了 先利用$PAM$求出以每个 ...

  9. [pytorch学习]1.pytorch ubuntu安装

    看完了Deep Learning with Python,尝试了部分Keras的demo代码. 感觉Keras虽然容易上手,能够快速搭建出一个通用的模型,但是缺乏对底层的控制. 同时,在使用了自己编译 ...

  10. centOS防火墙

    默认防火墙firewall #停止firewall systemcl stop firewall.service #禁止firewall开机启动 systemctl disable firewall. ...