我想在Tensorflow中建立一个广义的批量标准化函数。尺寸批量标准化
我在这个article学习批量标准化,我发现很亲切。
我与规模和的β变量的尺寸的问题:在我的情况下批标准化被施加到每个卷积层的每个激活,因此,如果我有作为卷积层一个的输出与尺寸tersor:
[57,57,96]
我需要规模和测试具有相同的尺寸卷积层输出,是否正确?
这里是我的功能,该程序的作品,但我不知道是否是正确的
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