code: def actnorm_scale(name, x, logscale_factor=3., reverse=False, init=False):
    
    x_shape = common_layers.shape_list(x)
    with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
  
      # Variance initialization logic.
      assert len(x_shape) == 2 or len(x_shape) == 4
      if len(x_shape) == 2:
        x_var = tf.reduce_mean(x**2, [0], keepdims=True)
        logdet_factor = 1
        var_shape = (1, x_shape[1])
      elif len(x_shape) == 4:
        x_var = tf.reduce_mean(x**2, [0, 1, 2], keepdims=True)
        logdet_factor = x_shape[1]*x_shape[2]
        var_shape = (1, 1, 1, x_shape[3])
  
      init_value = tf.log(1.0 / (tf.sqrt(x_var) + 1e-6)) / logscale_factor
      logs = get_variable_ddi("logs", var_shape, initial_value=init_value,
                              init=init)
      logs = logs * logscale_factor
  
      # Function and reverse function.
      if not reverse:
        x = x * tf.exp(logs)
      else:
        x = x * tf.exp(-logs)
  
      # Objective calculation, h * w * sum(log|s|)
      dlogdet = tf.reduce_sum(logs) * logdet_factor
      if reverse:
        dlogdet *= -1
      return x, dlogdet
docs: Per-channel scaling of x.