class_docstr: Defines the ImageVAE model.
class_docstr_tok: ["Defines","the","ImageVAE","model","."]
code: def bottleneck(self, x):
      z_size = self.hparams.bottleneck_bits
      x_shape = common_layers.shape_list(x)
      with tf.variable_scope("bottleneck", reuse=tf.AUTO_REUSE):
          mu = x[..., : self.hparams.bottleneck_bits]
          if self.hparams.mode != tf_estimator.ModeKeys.TRAIN:
              return mu, 0.0  # No sampling or kl loss on eval.
          log_sigma = x[..., self.hparams.bottleneck_bits :]
          epsilon = tf.random_normal(x_shape[:-1] + [z_size])
          z = mu + tf.exp(log_sigma / 2) * epsilon
          kl = 0.5 * tf.reduce_mean(
              tf.exp(log_sigma) + tf.square(mu) - 1.0 - log_sigma,
              axis=-1,
          )
          # This is the 'free bits' trick mentioned in Kingma et al. (2016)
          free_bits = self.hparams.free_bits
          kl_loss = tf.reduce_mean(tf.maximum(kl - free_bits, 0.0))
      return z, kl_loss * self.hparams.kl_beta
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from magenta.models.image_stylization import ops
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  import tensorflow_probability
label_desc: Use image node_id 6 for calling the ImageVAE obj's underlying member method code with example usage: obj.bottleneck(x) and returns: z,  unknown, mu,  int