tensorflow - 在 TensorFlow 中,如何查看批量归一化参数?

标签 tensorflow machine-learning neural-network python-3.6

我在网络中使用tf.layers.batch_normalization层。如您所知,批量归一化对该层中的每个单元 u_i 使用可训练参数 gamma 和 beta,为各种输入 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 - 在 TensorFlow 中,如何查看批量归一化参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53282439/

相关文章:

python - 使用 scikit-learn 时,如何找到我的树 split 的属性?

machine-learning - 具有梯度下降误差的逻辑回归

c++ - OpenCV 机器学习函数需要 CvFileStorage* 而不是 cv::FileStorage*

machine-learning - 卷积神经网络中的 "linear projection"是什么

tensorflow - tf.Session() 上的段错误(核心转储)

tensorflow - 原因: image not found tensorflow GPU

TensorFlow。当我运行 cifar10_train.py 时,CIFAR10 示例中的代码更改没有反射(reflect)出来

machine-learning - tensorflow 中embedding_rnn_seq2seq模型中的output_projection参数是什么?

python - 您最初选择机器学习算法/进行初始设置的经验法则是什么?

python - VGG16 Keras 微调 : low accuracy