title: Keras, multi-layer autoencoder, the same accuracy for different amount of hidden layers
body: <p>I'm currently trying to implement a multi-layer autoencoder using Keras, but I'm starting to believe that my implementation is wrong, since I don't get any difference in accuracy nor variance by using 2 or 3 hidden layers. I tried using two hidden layers with 400/180 and then I tried using three hidden layers with nodes of 400/180/30 and I practically get the exact same result. My code is currently looking like this:</p>
  
  <pre><code>from keras.layers import Input, Dense, initializers
  import numpy as np
  from Dataset import Dataset
  import matplotlib.pyplot as plt
  from keras.models import Sequential
  from keras.optimizers import Adam
  import time
  
  #global variables
  d = Dataset()
  num_features = d.X_train.shape[1]
  #input = [784, 400, 100, 10, 100, 400]
  #output = [400, 100, 10, 100, 400, 784]
  #names = ['hidden1', 'hidden2', 'hidden3', 'hidden4', 'hidden5', 'hidden6']
  
  list_of_nodes = [784, 400, 180]
  
  def generate_hidden_nodes(list_of_nodes):
      input = []
      for j in range(len(list_of_nodes)):
          input.append(list_of_nodes[j])
      for i in range(len(list_of_nodes)-2):
          input.append(list_of_nodes[-2-i])
      output = input[::-1]
      return input, output
  
  input,output = generate_hidden_nodes(list_of_nodes)
  
  
  
  
  
  def autoencoder(epochs):
      w = initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None)
      model = Sequential()
      input, output = generate_hidden_nodes(list_of_nodes)
      for j in range(len(input)):
          if j == (len(input)-1):
              model.add(Dense(output[j], activation='sigmoid', kernel_initializer=w, input_dim=input[j]))
              #model.add(Dropout(0.45))
          else:
              model.add(Dense(output[j], activation='relu', kernel_initializer=w, input_dim=input[j],
                              ))
              #model.add(Dropout(0.45))
      model.compile(optimizer=Adam(lr=0.001), loss='binary_crossentropy', metrics=['acc'])
      history = model.fit(d.X_train, d.X_train,
                          epochs=epochs,
                          batch_size=50,
                          shuffle=True,
                          validation_split = 0.2)
                          #validation_data=(d.X_test, d.X_test))
      #print(history.history.keys())
      #plt.plot(history.history['val_acc'])
      #print(history.history['val_acc'])
      plt.show()
      return model
  
  def cv():
      accuracy = 0
      size = 5
      epochs = 20
      variance = 0
      storage = np.zeros((size, epochs))
      for j in range(size):
          ae = autoencoder(epochs)
          #print(ae.history.history['val_acc'])
          storage[j] = ae.history.history['val_acc']
      for i in range(size):
          accuracy += storage[i][-1]
      mean = accuracy/size
      for k in range(size):
          variance += ((storage[k][-1] - mean)**2)
      variance = variance/size
      return mean, variance
  
  mean, variance = cv()
  print(mean)
  print(variance)
  time.sleep(10)
  
  def finding_index():
      elements, index = np.unique(d.Y_test, return_index=True)
      return elements, index
  
  def plotting():
      ae = autoencoder(20)
      elements, index = finding_index()
      y_proba = ae.predict(d.X_test)
      plt.figure(figsize=(20, 4))
      # size = 20
      for i in range(len(index)):
          ax = plt.subplot(2, len(index), i + 1)
          plt.imshow(d.X_test[index[i]].reshape(28, 28))
          plt.gray()
          ax.get_xaxis().set_visible(False)
          ax.get_yaxis().set_visible(False)
  
          ax = plt.subplot(2, len(index), i + 1 + len(index))
          plt.imshow(y_proba[index[i]].reshape(28, 28))
          plt.gray()
          ax.get_xaxis().set_visible(False)
          ax.get_yaxis().set_visible(False)
      plt.show()
  
  
  plotting()
  </code></pre>
  
  <p>I was expecting a significant difference by sending it down to only 30 nodes in the end (and the decoding it back). Is there an obvious mistake in my code, the dataset I'm currently using is the Mnist dataset (handwritten digits). Thanks in advance!</p>