text: #! pip3 install cloudmesh-installer
  #! pip3 install cloudmesh-common
  #! pip3 install tensorflow-gpu==1.14.0
  
  import tensorflow as tf
  from keras.layers import Dense, Input
  from keras.layers import Conv2D, Flatten
  from keras.layers import Reshape, Conv2DTranspose
  from keras.models import Model
  from keras.datasets import mnist
  from keras.utils import plot_model
  from keras import backend as K
  
  import numpy as np
  import matplotlib.pyplot as plt
  
  (x_train, y_train), (x_test, y_test) = mnist.load_data()
  
  image_size = x_train.shape[1]
  x_train = np.reshape(x_train, [-1, image_size, image_size, 1])
  x_test = np.reshape(x_test, [-1, image_size, image_size, 1])
  x_train = x_train.astype('float32') / 255
  x_test = x_test.astype('float32') / 255
  
  input_shape = (image_size, image_size, 1)
  batch_size = 32
  kernel_size = 3
  latent_dim = 16
  hidden_units = [32, 64]
  
  
  inputs = Input(shape=input_shape, name='encoder_input')
  x = inputs
  x = Dense(hidden_units[0], activation='relu')(x)
  x = Dense(hidden_units[1], activation='relu')(x)
  
  shape = K.int_shape(x)
  print(shape,"----")
  
  # generate latent vector
  x = Flatten()(x)
  latent = Dense(latent_dim, name='latent_vector')(x)
  
  # instantiate encoder model
  encoder = Model(inputs,
                  latent,
                  name='encoder')
  encoder.summary()
  plot_model(encoder,
             to_file='encoder.png',
             show_shapes=True)
  
  
  latent_inputs = Input(shape=(latent_dim,), name='decoder_input')
  x = Dense(shape[1] * shape[2] * shape[3])(latent_inputs)
  x = Reshape((shape[1], shape[2], shape[3]))(x)
  x = Dense(hidden_units[0], activation='relu')(x)
  x = Dense(hidden_units[1], activation='relu')(x)
  
  outputs = Dense(1, activation='relu')(x)
  
  decoder = Model(latent_inputs, outputs, name='decoder')
  decoder.summary()
  plot_model(decoder, to_file='decoder.png', show_shapes=True)
  
  autoencoder = Model(inputs,
                      decoder(encoder(inputs)),
                      name='autoencoder')
  autoencoder.summary()
  plot_model(autoencoder,
             to_file='autoencoder.png',
             show_shapes=True)
  
  autoencoder.compile(loss='mse', optimizer='adam')
  
  
  autoencoder.fit(x_train,
                  x_train,
                  validation_data=(x_test, x_test),
                  epochs=1,
                  batch_size=batch_size)
  
  x_decoded = autoencoder.predict(x_test)
  
  imgs = np.concatenate([x_test[:8], x_decoded[:8]])
  imgs = imgs.reshape((4, 4, image_size, image_size))
  imgs = np.vstack([np.hstack(i) for i in imgs])
  plt.figure()
  plt.axis('off')
  plt.title('Input: 1st 2 rows, Decoded: last 2 rows')
  plt.imshow(imgs, interpolation='none', cmap='gray')
  plt.savefig('input_and_decoded.png')
  plt.show()
  
  
  
  """# REFERENCES
  
  1. [Adavnced Keras Deep Learning Book](https://github.com/PacktPublishing/Advanced-Deep-Learning-with-Keras)
  """
  
  