code: def update_bn_ema(
      xn,
      batch_mean,
      batch_var,
      moving_mean,
      moving_var,
      decay,
      internal_update,
  ):
      update_op1 = moving_averages.assign_moving_average(
          moving_mean,
          batch_mean,
          decay,
          zero_debias=False,
          name="mean_ema_op",
      )
      update_op2 = moving_averages.assign_moving_average(
          moving_var,
          batch_var,
          decay,
          zero_debias=False,
          name="var_ema_op",
      )
  
      if internal_update:
          with tf.control_dependencies([update_op1, update_op2]):
              return tf.identity(xn, name="output")
      else:
          tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_op1)
          tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_op2)
          return tf.identity(xn, name="output")
  
file_path: tensorpack/tensorpack/models/_old_batch_norm.py
imports: import tensorflow
  from tensorflow.contrib.framework import add_model_variable
  from tensorflow.python.training import moving_averages
  from ..tfutils.common import get_tf_version_tuple
  from ..tfutils.tower import get_current_tower_context
  from ..utils import logger
  from ..utils.argtools import get_data_format
  from .common import VariableHolder, layer_register
  from .tflayer import convert_to_tflayer_args
label_desc: Use image node_id 2 for calling a global function with example usage: update_bn_ema(xn, batch_mean, batch_var, moving_mean, moving_var, decay, internal_update) and returns: tf, tf