def _instance_norm(input):
""" Instance Normalization
"""
with tf.variable_scope("instance_norm"):
depth = input.get_shape()[3]
scale = _weights("scale", [depth], mean=1.0)
offset = _biases("offset", [depth])
mean, variance = tf.nn.moments(input, axes=[1,2], keep_dims=True)
epsilon = 1e-5
inv = tf.rsqrt(variance + epsilon)
normalized = (input-mean)*inv
return scale*normalized + offset
评论列表
文章目录