def condition_batch_norm(x, z, is_training=True, scope="batch_norm"):
    """
    Hierarchical Embedding (without class-conditioning).
    Input latent vector z is linearly projected to produce per-sample gain and bias for batchnorm

    Note: Each instance has (2 x len(z) x n_feature) parameters
    """
    with tf.variable_scope(scope):
        _, _, _, c = x.get_shape().as_list()
        decay = 0.9
        epsilon = 1e-05

        test_mean = tf.get_variable(
            "pop_mean", shape=[c], dtype=tf.float32, initializer=tf.constant_initializer(0.0), trainable=False
        )
        test_var = tf.get_variable(
            "pop_var", shape=[c], dtype=tf.float32, initializer=tf.constant_initializer(1.0), trainable=False
        )

        beta = linear(z, c, name="beta")
        gamma = linear(z, c, name="gamma")

        beta = tf.reshape(beta, shape=[-1, 1, 1, c])
        gamma = tf.reshape(gamma, shape=[-1, 1, 1, c])

        if is_training:
            batch_mean, batch_var = tf.nn.moments(x, [0, 1, 2])
            ema_mean = tf.assign(test_mean, test_mean * decay + batch_mean * (1 - decay))
            ema_var = tf.assign(test_var, test_var * decay + batch_var * (1 - decay))

            with tf.control_dependencies([ema_mean, ema_var]):
                return tf.nn.batch_normalization(x, batch_mean, batch_var, beta, gamma, epsilon)
        else:
            return tf.nn.batch_normalization(x, test_mean, test_var, beta, gamma, epsilon)

    Hierarchical Embedding (without class-conditioning).
    Input latent vector z is linearly projected to produce per-sample gain and bias for batchnorm

    Note: Each instance has (2 x len(z) x n_feature) parameters
    
examples/inverse_gan_author_utils.py