title: Seemingly good results with training a CNN but bad when testing
body: <p>I have trained a cnn model which classifies currency. At the end of training, it seems that the model was performing very good at training and validation data sets. The final accuracies were:</p>
  <pre><code>Epoch 00020: saving model to model_weights.h5
  112/112 [==============================] - 243s 2s/step - loss: 0.3176 - accuracy: 0.8881 - val_loss: 0.3223 - val_accuracy: 0.9014
  </code></pre>
  <p>The training accuracy was 88.81% and validation accuracy was 90.14%.
  But when testing time came, the model performed terrible. It can't classify even a single correct image. For every image, the prediction was:</p>
  <pre><code>[0. 0. 0. 0. 0. 0. 0. 1.]
  </code></pre>
  <p>There was 8 classes. And for every image, only this was predicting. The code I used was the code for testing was the code I copied from Tensorflow specialization at Coursera. The target size is also  correct.</p>
  <pre><code>for fn in uploaded.keys():
    path = fn
    img = image.load_img(path, target_size=(150, 150))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
  
    images = np.vstack([x])
    print (images.shape)
    classes = model.predict(images, batch_size=10)
    print(fn)
    print(classes.squeeze())
  </code></pre>
  <p>The result array should be in order:</p>
  <pre><code>['10', '100', '20', '200', '2000', '50', '500', 'Background']
  </code></pre>
  <p>According to model, it is classifying all images 'Background'.</p>
  <p>Here are some of the images I used during testing:
  <a href="https://i.stack.imgur.com/QhpwQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QhpwQ.jpg" alt="Rs. 10" /></a>
  <a href="https://i.stack.imgur.com/XqkDE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XqkDE.jpg" alt="Rs. 20" /></a>
  <a href="https://i.stack.imgur.com/1gmzu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1gmzu.jpg" alt="Rs. 50" /></a>
  Can anyone help me explain why this is happening. It would be really appreciated.
  P.S. These are Indian currency.</p>