def actnorm_center(name, x, reverse=False, init=False):
  """Add a bias to x.

  Initialize such that the output of the first minibatch is zero centered
  per channel.

  Args:
    name: scope
    x: 2-D or 4-D Tensor.
    reverse: Forward or backward operation.
    init: data-dependent initialization.

  Returns:
    x_center: (x + b), if reverse is True and (x - b) otherwise.
  """
  shape = common_layers.shape_list(x)
  with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
    assert len(shape) == 2 or len(shape) == 4
    if len(shape) == 2:
      x_mean = tf.reduce_mean(x, [0], keepdims=True)
      b = get_variable_ddi("b", (1, shape[1]), initial_value=-x_mean,
                           init=init)
    elif len(shape) == 4:
      x_mean = tf.reduce_mean(x, [0, 1, 2], keepdims=True)
      b = get_variable_ddi(
          "b", (1, 1, 1, shape[3]), initial_value=-x_mean, init=init)

    if not reverse:
      x += b
    else:
      x -= b
    return x
def actnorm_center ( name , x , reverse = False , init = False ) : shape = common_layers . shape_list ( x ) with tf . variable_scope ( name , reuse = tf . AUTO_REUSE ) : assert len ( shape ) == 2 or len ( shape ) == 4 if len ( shape ) == 2 : x_mean = tf . reduce_mean ( x , [ 0 ] , keepdims = True ) b = get_variable_ddi ( "b" , ( 1 , shape [ 1 ] ) , initial_value = - x_mean , init = init ) elif len ( shape ) == 4 : x_mean = tf . reduce_mean ( x , [ 0 , 1 , 2 ] , keepdims = True ) b = get_variable_ddi ( "b" , ( 1 , 1 , 1 , shape [ 3 ] ) , initial_value = - x_mean , init = init ) if not reverse : x += b else : x -= b return x
Add a bias to x.

  Initialize such that the output of the first minibatch is zero centered
  per channel.

  Args:
    name: scope
    x: 2-D or 4-D Tensor.
    reverse: Forward or backward operation.
    init: data-dependent initialization.

  Returns:
    x_center: (x + b), if reverse is True and (x - b) otherwise.