code: def actnorm_scale(
      name, x, logscale_factor=3.0, reverse=False, init=False
  ):
      """Per-channel scaling of x."""
      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
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import numpy
  import scipy
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import common_video
  from tensor2tensor.utils import contrib
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  import tensorflow_probability
label_desc: Use image node_id 15 for calling a global function with example usage: actnorm_scale(name, x, logscale_factor, reverse, init) and returns: x,  dlogdet