(mean, variance, is_training)
Use accumulated statistics for moments during inference.

  After training the user is responsible for filling the accumulators with the
  actual values. See _UpdateBnAccumulators() in eval_gan_lib.py for an example.

  Args:
    mean: Tensor of shape [num_channels] with the mean of the current batch.
    variance: Tensor of shape [num_channels] with the variance of the current
      batch.
    is_training: Boolean, wheather to construct ops for training or inference
      graph.

  Returns:
    Tuple of (mean, variance) to use. This can the same as the inputs.
Use accumulated statistics for moments during inference.
Use accumulated statistics for moments during inference .
def _accumulated_moments_for_inference(mean, variance, is_training):
  """Use accumulated statistics for moments during inference.

  After training the user is responsible for filling the accumulators with the
  actual values. See _UpdateBnAccumulators() in eval_gan_lib.py for an example.

  Args:
    mean: Tensor of shape [num_channels] with the mean of the current batch.
    variance: Tensor of shape [num_channels] with the variance of the current
      batch.
    is_training: Boolean, wheather to construct ops for training or inference
      graph.

  Returns:
    Tuple of (mean, variance) to use. This can the same as the inputs.
  """
  variable_collections = [
      tf.GraphKeys.MODEL_VARIABLES, tf.GraphKeys.GLOBAL_VARIABLES,
  ]
  with tf.variable_scope("accu", values=[mean, variance]):
    # Create variables for accumulating batch statistic and use them during
    # inference. The ops for filling the accumulators must be created and run
    # before eval. See docstring above.
    accu_mean = tf.get_variable(
        "accu_mean",
        shape=mean.shape,
        initializer=tf.zeros_initializer(),
        trainable=False,
        collections=variable_collections)
    accu_variance = tf.get_variable(
        "accu_variance",
        shape=variance.shape,
        initializer=tf.zeros_initializer(),
        trainable=False,
        collections=variable_collections)
    accu_counter = tf.get_variable(
        "accu_counter",
        shape=[],
        initializer=tf.initializers.constant(1e-12),
        trainable=False,
        collections=variable_collections)
    update_accus = tf.get_variable(
        "update_accus",
        shape=[],
        dtype=tf.int32,
        initializer=tf.zeros_initializer(),
        trainable=False,
        collections=variable_collections)

    mean = tf.identity(mean, "mean")
    variance = tf.identity(variance, "variance")

    if is_training:
      return mean, variance

    logging.debug("Using accumulated moments.")
    # Return the accumulated batch statistics and add current batch statistics
    # to accumulators if update_accus variables equals 1.
    def update_accus_fn():
      return tf.group([
          tf.assign_add(accu_mean, mean),
          tf.assign_add(accu_variance, variance),
          tf.assign_add(accu_counter, 1),
      ])
    dep = tf.cond(
        tf.equal(update_accus, 1),
        update_accus_fn,
        tf.no_op)
    with tf.control_dependencies([dep]):
      return accu_mean / accu_counter, accu_variance / accu_counter
def _accumulated_moments_for_inference ( mean , variance , is_training ) : variable_collections = [ tf . GraphKeys . MODEL_VARIABLES , tf . GraphKeys . GLOBAL_VARIABLES , ] with tf . variable_scope ( "accu" , values = [ mean , variance ] ) : # Create variables for accumulating batch statistic and use them during # inference. The ops for filling the accumulators must be created and run # before eval. See docstring above. accu_mean = tf . get_variable ( "accu_mean" , shape = mean . shape , initializer = tf . zeros_initializer ( ) , trainable = False , collections = variable_collections ) accu_variance = tf . get_variable ( "accu_variance" , shape = variance . shape , initializer = tf . zeros_initializer ( ) , trainable = False , collections = variable_collections ) accu_counter = tf . get_variable ( "accu_counter" , shape = [ ] , initializer = tf . initializers . constant ( 1e-12 ) , trainable = False , collections = variable_collections ) update_accus = tf . get_variable ( "update_accus" , shape = [ ] , dtype = tf . int32 , initializer = tf . zeros_initializer ( ) , trainable = False , collections = variable_collections ) mean = tf . identity ( mean , "mean" ) variance = tf . identity ( variance , "variance" ) if is_training : return mean , variance logging . debug ( "Using accumulated moments." ) # Return the accumulated batch statistics and add current batch statistics # to accumulators if update_accus variables equals 1. def update_accus_fn ( ) : return tf . group ( [ tf . assign_add ( accu_mean , mean ) , tf . assign_add ( accu_variance , variance ) , tf . assign_add ( accu_counter , 1 ) , ] ) dep = tf . cond ( tf . equal ( update_accus , 1 ) , update_accus_fn , tf . no_op ) with tf . control_dependencies ( [ dep ] ) : return accu_mean / accu_counter , accu_variance / accu_counter