title: How to get an autoencoder to work on a small image dataset
body: <p>I have a dataset of three images. When I create an autoencoder to train on those three images, the output I get is the exact same for each image, and it looks like a blend of all three images.</p>
  
  <p>My result looks like this:</p>
  
  <p>Input image 1:
  <a href="https://i.stack.imgur.com/omrBI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/omrBI.png" alt="enter image description here"></a></p>
  
  <p>Output image 1:
  <a href="https://i.stack.imgur.com/VH4MN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VH4MN.png" alt="enter image description here"></a></p>
  
  <p>Input image 2:
  <a href="https://i.stack.imgur.com/RYbn4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RYbn4.png" alt="enter image description here"></a></p>
  
  <p>Output image 2:
  <a href="https://i.stack.imgur.com/NLq5F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NLq5F.png" alt="enter image description here"></a></p>
  
  <p>Input image 3:
  <a href="https://i.stack.imgur.com/OII1n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OII1n.png" alt="enter image description here"></a></p>
  
  <p>Output image 3:
  <a href="https://i.stack.imgur.com/SmYpU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SmYpU.png" alt="enter image description here"></a></p>
  
  <p>So you can see that the output is giving the exact same thing for each of the inputs, and while it matches each relatively well, it's not perfect.</p>
  
  <p>This is a three image dataset - it should be perfect (or at least different for each of the images).</p>
  
  <p>I'm concerned about this three image dataset because when I do the 500 image dataset, all I get back is a white blank screen, because that's the best average of all the images.</p>
  
  <p>I'm using Keras, and the code is really simple.</p>
  
  <pre><code>from keras.models                   import Sequential
  from keras.layers                   import Dense, Flatten, Reshape
  import numpy as np
  
  # returns a numpy array with shape (3, 24, 32, 1)
  # there are 3 images that are each 24x32 and are black and white (1 color channel)
  x_train = get_data()
  
  # this is the size of our encoded representations
  # encode down to two numbers (I have tested using 3; I still have the same issue)
  encoding_dim = 2
  # the shape without the batch amount
  input_shape = x_train.shape[1:]
  # how many output neurons we need to create an image
  input_dim = np.prod(input_shape)
  
  # simple feedforward network
  # I've also tried convolutional layers; same issue
  autoencoder = Sequential([
                Flatten(), # flatten
                Dense(encoding_dim), # encode
                Dense(input_dim), # decode
                Reshape(input_shape) # reshape decoding
  ])
  
  # adadelta optimizer works better than adam, same issue with both
  autoencoder.compile(optimizer='adadelta', loss='mse')
  
  # train it to output the same thing it gets as input
  # I've tried epochs up to 30000 with no improvement;
  # still predicts the same image for all three inputs
  autoencoder.fit(x_train, x_train,
              epochs=10,
              batch_size=1,
              verbose=1)
  
  out = autoencoder.predict(x_train)
  </code></pre>
  
  <p>I then take the outputs (<code>out[0]</code>, <code>out[1]</code>, <code>out[2]</code>) and convert them back into images. You can see the output images above.</p>
  
  <p>I'm worried because this shows that the autoencoder isn't preserving any information about the input image, which is not how an encoder should perform.</p>
  
  <p>How can I get the encoder to show differences in outputs based on the input images?</p>
  
  <p>EDIT:</p>
  
  <p>One of my coworkers had the suggestion of not even using an autoencoder, but a 1 layer feedforward neural network. I tried this, and the same thing happened, until I set the batch size to 1 and trained for 1400 epochs, and then it worked perfectly. This leads me to think that <a href="https://github.com/keras-team/keras/issues/6447#issuecomment-328903943" rel="nofollow noreferrer">more epochs</a> would solve this issue, but I'm not sure yet.</p>
  
  <p>EDIT:</p>
  
  <p>Training for 10,000 epochs (with batch-size 3) made the second image look different than the first and third on the encoder, which is exactly what happened on the non-encoder version when running for around 400 epochs (also with batch-size 3) providing further evidence that training for more epochs may be the solution.</p>
  
  <p>Going to test using batch size 1, and see if that helps even more, and then try training for very many epochs and see if that completely solves the issue.</p>