tensorflow中的lrn函数详解
来源:互联网 发布:java类的主方法是啥 编辑:程序博客网 时间:2024/06/06 03:57
LRN函数类似DROPOUT和数据增强作为relu激励之后防止数据过拟合而提出的一种处理方法,全称是 local response normalization--局部响应标准化。这个函数很少使用,基本上被类似DROPOUT这样的方法取代,具体原理还是值得一看的
函数原型
def lrn(input, depth_radius=None, bias=None, alpha=None, beta=None, name=None):官方文档给的解释如下,这些官方文档看了没啥卵用,越看越糊涂
sqr_sum[a, b, c, d] = sum(input[a, b, c, d - depth_radius : d + depth_radius + 1] ** 2)output = input / (bias + alpha * sqr_sum) ** beta见最早的出处AlexNet论文对它的定义, 《ImageNet Classification with Deep ConvolutionalNeural Networks》
i:代表下标,你要计算像素值的下标,从0计算起
j:平方累加索引,代表从j~i的像素值平方求和
x,y:像素的位置,公式中用不到
a:代表feature map里面的 i 对应像素的具体值
N:每个feature map里面最内层向量的列数
k:超参数,由原型中的blas指定
α:超参数,由原型中的alpha指定
n/2:超参数,由原型中的deepth_radius指定
β:超参数,由原型中的belta指定
看一个栗子,理解上诉的参数,进而理解rln函数
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 1批次 2x2x8的feature map a = tf.reshape(a, [1, 2, 2, 8]) normal_a=tf.nn.lrn(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,N=8
第一行第一个数来说:i = 0
a = 1,min(N-1, i+n/2) = min(7, 2)=2,j = max(0, i - k)=max(0, 0)=0,下标从0~2个数平方求和, b=1/(1^2 + 2^2 + 3^2)=1/14 = 0.071428571
同理,第一行第四个数来说:i = 3
a = 4,min(N-1, i+n/2) = min(7, 5 )=5, j = max(0,1) = 1,下标从1~5进行平方求和,b = 4/(2^2 + 3^2 + 4^2 + 5^2 + 6^2) = 4/90=0.044444444
再来一个,第二行第一个数来说: i = 0
a = 8, min(N-1, i+n/2) = min(7, 2) = 2, j=max(0,0)=0, 下标从0~2的3个数平方求和,b = 8/(8^2 + 7^2 + 6^2)=8/149=0.053691275
其他的也是类似操作
参考文献
【TensorFlow】tf.nn.local_response_normalization详解,lrn正则法如何计算?
TensorFlow之深入理解AlexNet
Tensorflow的LRN是怎么做的
ImageNet Classification with Deep ConvolutionalNeural Networks
- tensorflow中的lrn函数详解
- 【TensorFlow】tf.nn.local_response_normalization详解,lrn正则法如何计算?
- tensorflow下的局部响应归一化函数tf.nn.lrn
- LRN在caffe和tensorflow中的不同实现
- Tensorflow的LRN是怎么做的
- tensorflow 实现AlexNet(附lrn API介绍)
- LRN
- Tensorflow argmax函数详解
- tensorflow中的优化函数
- tensorflow中的激活函数
- ImageNet中的LRN(Local Response Normalization)
- tensorflow中的一些重要函数
- Tensorflow中的变量初始化函数
- tensorflow中的pad函数解释
- 8、TensorFlow 中的激活函数
- 9、TensorFLow 中的决策函数
- 10、TensorFLow 中的损失函数
- Tensorflow -- tf.nn.conv2d() 函数详解
- JSON转换成JSONArray数组
- MVC设计思想
- XMAN2017选拔赛Crypto-Caesar
- Java GC 专家系列3:GC调优实践
- eclipse运行maven web项目
- tensorflow中的lrn函数详解
- 加快QT工程编译速度
- Eclipse问题集
- 【数据结构】拾遗(一):图的邻接矩阵创建以及其深广度遍历C++实现
- 垃圾回收的算法与实现 pdf
- Contains Duplicate II
- Java GC专家系列1:理解Java垃圾回收
- Android_Framework_WindowManagerService_总述
- Python 爬虫简单实战之CSDN