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

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

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).
"""

举例子:
import tensorflow as tf a = tf.constant([
[[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0],
[8.0, 7.0, 6.0, 5.0],
[4.0, 3.0, 2.0, 1.0]],
[[4.0, 3.0, 2.0, 1.0],
[8.0, 7.0, 6.0, 5.0],
[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0]]
])
#reshape a,get the feature map [batch:1 height:2 width:2 channels:8]
a = tf.reshape(a, [1, 2, 2, 8]) normal_a=tf.nn.local_response_normalization(a,2,0,1,1)
with tf.Session() as sess:
print("feature map:")
image = sess.run(a)
print (image)
print("normalized feature map:")
normal = sess.run(normal_a)
print (normal)
feature map:
[[[[ 1. 2. 3. 4. 5. 6. 7. 8.]
[ 8. 7. 6. 5. 4. 3. 2. 1.]] [[ 4. 3. 2. 1. 8. 7. 6. 5.]
[ 1. 2. 3. 4. 5. 6. 7. 8.]]]]
normalized feature map:
[[[[ 0.07142857 0.06666667 0.05454545 0.04444445 0.03703704 0.03157895
0.04022989 0.05369128]
[ 0.05369128 0.04022989 0.03157895 0.03703704 0.04444445 0.05454545
0.06666667 0.07142857]] [[ 0.13793103 0.10000001 0.0212766 0.00787402 0.05194805 0.04
0.03448276 0.04545454]
[ 0.07142857 0.06666667 0.05454545 0.04444445 0.03703704 0.03157895
0.04022989 0.05369128]]]]
这里我取了n/2=2,k=0,α=1,β=1,举个例子,比如对于一通道的第一个像素“1”来说,我们把参数代人公式就是1/(1^2+2^2+3^2)=0.07142857,对于四通道的第一个像素“4”来说,公式就是4/(2^2+3^2+4^2+5^2+6^2)=0.04444445,以此类推
注意:这里的feature_map为【1,2,2,8】,其中1代表图像的数量,2X2代表图像的长宽,8代表图像的层数(map),NRL主要是利用map去计算,然后计算的值为图像的长宽(像素),与图像的数量无关!
我们可以这么理解,feature_map分割为直观的图像,第一个通道[1,8,4,1],第二个通道[2,7,3,2],第三个通道[3,6,2,3],以此类推。。。
那么求解的过程和上面就一一对应了,其中在边角达不到n的时候,那就省略。
能感觉到这种方法不好吗?效果肯定有的,因为对像素归一化了,有利于计算。但是对于一整幅图像来说反而没有什么太大的作用,因为归一化的种类不同,造成部分特征体现不出来,有时候反而不好。
batch_normalization
为什么有batch?上面结尾已经做了初步分析,也已经大概引出来对批量的图像做归一化,对单个图像做的归一化效果不好!

可以看出,batch_normalization之后,数据的维数没有任何变化,只是数值发生了变化
OutOut作为下一层的输入
函数:
tf.nn.batch_normalization()
def batch_normalization(x,
mean,
variance,
offset,
scale,
variance_epsilon,
name=None):
Args:
- x: Input
Tensorof 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, orNone. 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 和 β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 均为标量。
参考:
https://blog.csdn.net/mao_xiao_feng/article/details/53488271
https://www.jianshu.com/p/c06aea337d5d
https://blog.csdn.net/u012436149/article/details/52985303
TensorFlow NormLization的更多相关文章
- Tensorflow&CNN:验证集预测与模型评价
版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90480140 - 写在前面 本科毕业设计终于告一段落了.特 ...
- Tensorflow&CNN:裂纹分类
版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90478551 - 写在前面 本科毕业设计终于告一段落了.特 ...
- Tensorflow 官方版教程中文版
2015年11月9日,Google发布人工智能系统TensorFlow并宣布开源,同日,极客学院组织在线TensorFlow中文文档翻译.一个月后,30章文档全部翻译校对完成,上线并提供电子书下载,该 ...
- tensorflow学习笔记二:入门基础
TensorFlow用张量这种数据结构来表示所有的数据.用一阶张量来表示向量,如:v = [1.2, 2.3, 3.5] ,如二阶张量表示矩阵,如:m = [[1, 2, 3], [4, 5, 6], ...
- 用Tensorflow让神经网络自动创造音乐
#————————————————————————本文禁止转载,禁止用于各类讲座及ppt中,违者必究————————————————————————# 前几天看到一个有意思的分享,大意是讲如何用Ten ...
- tensorflow 一些好的blog链接和tensorflow gpu版本安装
pading :SAME,VALID 区别 http://blog.csdn.net/mao_xiao_feng/article/details/53444333 tensorflow实现的各种算法 ...
- tensorflow中的基本概念
本文是在阅读官方文档后的一些个人理解. 官方文档地址:https://www.tensorflow.org/versions/r0.12/get_started/basic_usage.html#ba ...
- kubernetes&tensorflow
谷歌内部--Borg Google Brain跑在数十万台机器上 谷歌电商商品分类深度学习模型跑在1000+台机器上 谷歌外部--Kubernetes(https://github.com/kuber ...
- tensorflow学习
tensorflow安装时遇到gcc: error trying to exec 'as': execvp: No such file or directory. 截止到2016年11月13号,源码编 ...
随机推荐
- RAID的详细配置
一.RAID 1.RAID机制通过使用多硬盘并行工作的方式来提高硬盘的IO性能 2.RAID分为多种,称之为RAID level,RAID共有7级:RAID0~RAID6 3.常用的RAID级别有:R ...
- 【Java集合系列一】ArrayList解析
一.基础简介 1.ArrayList继承关系 2.底层用数组来存储数据,数据会在ArrayList创建的时候一并初始化.如果创建ArrayList的时候,没有设置容量,则会delay到第一次add数据 ...
- overload(重载)和override(覆盖)的注意点
使用overload(重载)的几个注意点: 在使用重载时只能通过不同的参数形式.例如:不同的参数类型,不同的参数个数,不同的参数顺序,当然,同一个方法内的几个参数类型必须不一样.例如可以是fun(in ...
- Core Json 序列化相关问题
//返回json 大小写 配置 services.AddMvc() .AddJsonOptions( op => op.Serial ...
- WebView性能、体验分析与优化
育新 徐宏 嘉洁 ·2017-06-09 20:03 在App开发中,内嵌WebView始终占有着一席之地.它能以较低的成本实现Android.iOS和Web的复用,也可以冠冕堂皇的突破苹果对热更新的 ...
- java学习笔记39(sql事物)
在之前的学习中,我们学习了使用PreparedStatement类,使用这个类消除了sql注入的隐患,可是,还有些一些其他的隐患,这里以银行转账业务为例, 假设 一个银行,张三在里面存了1000元, ...
- Oracle(二)在 Mysql 的基础上学习 Oracle
毕竟我是先学的mysql,对数据库的一切认知都会有一个先入为主的思想在里面,如果不搞清楚其中的异同,我感觉Oracle我是学不会 了,甚至会把它们混淆.那么,不会mysql的没必要往下看了. 下边第一 ...
- SpringMVC + MyBatis分库分表方案
mybatis作为流行的ORM框架,项目实际使用过程中可能会遇到分库分表的场景.mybatis在分表,甚至是同主机下的分库都可以说是完美支持的,只需要将表名或者库名作为动态参数组装sql就能够完成.但 ...
- MyCat配置详解
MyCAT 配置解析 server.xml Mycat的配置文件,设置账号.参数等schema.xml Mycat对应的物理数据库和数据库表的配置rule.xml Mycat分片(分库分表)规则 一 ...
- PythonStudy——名称空间 Name space
# 名称空间:就是名字与地址的对应关系,可以被Python解释器遍历查找,采用堆栈存储方式 # 三种名称空间# Built-in:内置名称空间:系统级,一个:随解释器执行而产生,解释器停止而销毁# G ...