【发布时间】:2017-04-14 13:29:19
【问题描述】:
我正在尝试在 Tensorflow 中构建一个通用的批量标准化函数。
我在这个article 中学习批量标准化,我觉得这很亲切。
我对 scale 和 beta 变量的维度有疑问:在我的情况下,批量标准化应用于每个卷积层的每个激活,因此如果我有作为卷积层的输出一个尺寸为:
[57,57,96]
我需要 scale 和 beta 具有与卷积层输出相同的维度,对吗?
这是我的功能,程序可以运行,但我不知道是否正确
def batch_normalization_layer(batch):
# Calculate batch mean and variance
batch_mean, batch_var = tf.nn.moments(batch, axes=[0, 1, 2])
# Apply the initial batch normalizing transform
scale = tf.Variable(tf.ones([batch.get_shape()[1],batch.get_shape()[2],batch.get_shape()[3]]))
beta = tf.Variable(tf.zeros([batch.get_shape()[1],batch.get_shape()[2],batch.get_shape()[3]]))
normalized_batch = tf.nn.batch_normalization(batch, batch_mean, batch_var, beta, scale, 0.0001)
return normalized_batch
【问题讨论】:
标签: python-2.7 tensorflow conv-neural-network batch-normalization