def instance_norm(x, name='instance_norm', reuse=False):
with tf.variable_scope(name, reuse=reuse):
depth = x.get_shape()[3]
scale = tf.get_variable('scale', [depth], initializer=tf.random_normal_initializer(1.0, 0.02))
offset = tf.get_variable('offset', [depth], initializer=tf.constant_initializer(0.0))
mean, variance = tf.nn.moments(x, axes=[1, 2], keep_dims=True)
inv = tf.rsqrt(variance + 1e-5)
normalized = (x - mean) * inv
return scale * normalized + offset
评论列表
文章目录