tf.cond()点,提示了为什么在tensorflow中需要tf.cond(),这个函数
tf.nn.moments()
import tensorflow as tf
img = tf.Variable(tf.random_normal([128, 32, 32, 64]))
axis = list(range(len(img.get_shape()) - 1))
axis=[0]
mean, variance = tf.nn.moments(img, axis)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
mean_=mean.eval()
这里axis=0代表,取每个batch的平均值,一般都是用axis=[0,1,2],这时候生成的mean为(64,)代表输入的每一个通道取平均
执行以下代码,
import tensorflow as tf
is_traing = tf.placeholder(dtype=tf.bool)
x = tf.ones([1, 2, 2, 3])
x_norm = tf.layers.batch_normalization(x, training=is_traing)
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
会出现以下图片
整个batchnorm看这个网址