Skip to content

Instantly share code, notes, and snippets.

@imironhead
Created December 8, 2017 14:24
Show Gist options
  • Save imironhead/af2dc12a953cc953bed6e1c5f3c3d2dc to your computer and use it in GitHub Desktop.
Save imironhead/af2dc12a953cc953bed6e1c5f3c3d2dc to your computer and use it in GitHub Desktop.
def instance_norm(flow):
"""
arXiv:1607.08022v2
"""
with tf.variable_scope('inst_norm'):
depth = flow.get_shape()[3]
scale = tf.get_variable(
'scale',
[depth],
initializer=tf.random_normal_initializer(1.0, 0.02))
shift = tf.get_variable(
'shift',
[depth],
initializer=tf.constant_initializer(0.0))
mean, variance = tf.nn.moments(flow, axes=[1, 2], keep_dims=True)
flow = (flow - mean) / tf.sqrt(variance + 1e-5)
return scale * flow + shift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment