import tensorflow as tf

    """
    Virtual Batch Normalization
    """

    def __init__(self, x, name, epsilon=1e-5):
        """
        x is the reference batch
        """
        assert isinstance(epsilon, float)

        shape = x.get_shape().as_list()
        with tf.variable_scope(name) as scope:
            self.epsilon = epsilon
            self.name = name
            self.mean = tf.reduce_mean(x, [0, 1, 2], keep_dims=True)
            self.mean_sq = tf.reduce_mean(tf.square(x), [0, 1, 2], keep_dims=True)
            self.batch_size = int(x.get_shape()[0])
            assert x is not None
            assert self.mean is not None
            assert self.mean_sq is not None
            out = tf.nn.relu(self._normalize(x, self.mean, self.mean_sq, "reference"))
            self.reference_output = out

    def __call__(self, x, update=False):
        with tf.variable_scope(self.name) as scope:
            if not update:
                new_coeff = 1. / (self.batch_size + 1.)
                old_coeff = 1. - new_coeff
