您可以获取批处理规范化层范围内的所有变量并打印它们。例子:
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.]