code: def make_decoder(base_depth, activation, input_size, output_shape):
      """Creates the decoder function.
  
      Args:
        base_depth: Layer base depth in decoder net.
        activation: Activation function in hidden layers.
        input_size: The flattened latent input shape as an int.
        output_shape: The output image shape as a list.
  
      Returns:
        decoder: A `callable` mapping a `Tensor` of encodings to a
          `tfd.Distribution` instance over images.
      """
      deconv = functools.partial(
          tf_keras.layers.Conv2DTranspose,
          padding="SAME",
          activation=activation,
      )
      conv = functools.partial(
          tf_keras.layers.Conv2D, padding="SAME", activation=activation
      )
      decoder_net = tf_keras.Sequential(
          [
              tf_keras.layers.Reshape((1, 1, input_size)),
              deconv(2 * base_depth, 7, padding="VALID"),
              deconv(2 * base_depth, 5),
              deconv(2 * base_depth, 5, 2),
              deconv(base_depth, 5),
              deconv(base_depth, 5, 2),
              deconv(base_depth, 5),
              conv(output_shape[-1], 5, activation=None),
              tf_keras.layers.Reshape(output_shape),
          ]
      )
  
      def decoder(codes):
          """Builds a distribution over images given codes.
  
          Args:
            codes: A `Tensor` representing the inputs to be decoded, of shape `[...,
              code_size]`.
  
          Returns:
            decoder_distribution: A multivariate `Bernoulli` distribution.
          """
          logits = decoder_net(codes)
          return tfd.Independent(
              tfd.Bernoulli(logits=logits),
              reinterpreted_batch_ndims=len(output_shape),
              name="decoder_distribution",
          )
  
      return decoder
  
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 2 for calling a global function with example usage: make_decoder(base_depth, activation, input_size, output_shape) and returns: decoder, tfd