我想在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