在TensorFlow中,如何查看批处理规范化参数?

在TensorFlow中,如何查看批处理规范化参数?,tensorflow,machine-learning,neural-network,python-3.6,Tensorflow,Machine Learning,Neural Network,Python 3.6,我正在网络中使用tf.layers.batch\u规范化层。如您所知,批量标准化将可训练参数gamma和beta应用于该层中的每个单位u_i,为各种输入x选择其自身的标准偏差和u_i(x)的平均值。通常,gamma初始化为1,beta初始化为0 我感兴趣的是窥探各个单位正在学习的gamma和beta值,以收集关于网络训练后它们最终走向的统计数据。如何在每个训练实例中查看它们的当前值?您可以获取批处理规范化层范围内的所有变量并打印它们。例如: import tensorflow as tf tf

我正在网络中使用
tf.layers.batch\u规范化
层。如您所知,批量标准化将可训练参数gamma和beta应用于该层中的每个单位u_i,为各种输入x选择其自身的标准偏差和u_i(x)的平均值。通常,gamma初始化为1,beta初始化为0


我感兴趣的是窥探各个单位正在学习的gamma和beta值,以收集关于网络训练后它们最终走向的统计数据。如何在每个训练实例中查看它们的当前值?

您可以获取批处理规范化层范围内的所有变量并打印它们。例如:

import tensorflow as tf

tf.reset_default_graph()
x = tf.constant(3.0, shape=(3,))
x = tf.layers.batch_normalization(x)

print(x.name) # batch_normalization/batchnorm/add_1:0

variables = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                              scope='batch_normalization')
print(variables)

#[<tf.Variable 'batch_normalization/gamma:0' shape=(3,) dtype=float32_ref>,
# <tf.Variable 'batch_normalization/beta:0' shape=(3,) dtype=float32_ref>,
# <tf.Variable 'batch_normalization/moving_mean:0' shape=(3,) dtype=float32_ref>,
#  <tf.Variable 'batch_normalization/moving_variance:0' shape=(3,) dtype=float32_ref>]

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    gamma = sess.run(variables[0])
    print(gamma) # [1. 1. 1.]
将tensorflow导入为tf
tf.reset_default_graph()
x=tf.常数(3.0,形状=(3,))
x=tf.layers.batch_归一化(x)
打印(x.name)#批次标准化/批次标准化/添加1:0
变量=tf.get_集合(tf.GraphKeys.GLOBAL_变量,
scope='batch_normalization')
打印(变量)
#[,
# ,
# ,
#  ]
使用tf.Session()作为sess:
sess.run(tf.global\u variables\u initializer())
gamma=sess.run(变量[0])
打印(伽马)#[1.1.1]

谢谢!我推测范围
批处理规范化
是由层自动添加的?