code: def make_encoder(base_depth, activation, latent_size, code_size):
      """Creates the encoder function.
  
      Args:
        base_depth: Layer base depth in encoder net.
        activation: Activation function in hidden layers.
        latent_size: The number of latent variables in the code.
        code_size: The dimensionality of each latent variable.
  
      Returns:
        encoder: A `callable` mapping a `Tensor` of images to a `Tensor` of shape
          `[..., latent_size, code_size]`.
      """
      conv = functools.partial(
          tf_keras.layers.Conv2D, padding="SAME", activation=activation
      )
  
      encoder_net = tf_keras.Sequential(
          [
              conv(base_depth, 5, 1),
              conv(base_depth, 5, 2),
              conv(2 * base_depth, 5, 1),
              conv(2 * base_depth, 5, 2),
              conv(4 * latent_size, 7, padding="VALID"),
              tf_keras.layers.Flatten(),
              tf_keras.layers.Dense(
                  latent_size * code_size, activation=None
              ),
              tf_keras.layers.Reshape([latent_size, code_size]),
          ]
      )
  
      def encoder(images):
          """Encodes a batch of images.
  
          Args:
            images: A `Tensor` representing the inputs to be encoded, of shape `[...,
              channels]`.
  
          Returns:
            codes: A `float`-like `Tensor` of shape `[..., latent_size, code_size]`.
              It represents latent vectors to be matched with the codebook.
          """
          images = 2 * tf.cast(images, dtype=tf.float32) - 1
          codes = encoder_net(images)
          return codes
  
      return encoder
  
imports: import functools
  import os
  import time
  from absl import flags
  from matplotlib import cm
  from matplotlib import figure
  from matplotlib.backends import backend_agg
  import numpy
  from six.moves import urllib
  import tensorflow.compat.v1
  from tensorflow_probability import distributions
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow.contrib.learn.python.learn.datasets import mnist
  from tensorflow.python.training import moving_averages
label_desc: Use image node_id 1 for calling a global function with example usage: make_encoder(base_depth, activation, latent_size, code_size) and returns: encoder, codes