title: Prediction with ANN are most of the time false
body: <p>my probleme is that my ANN predicts only about 2 times out of 10 the right digit but when the ANN was fitted it tells me about 98% accuarcy. I'm quit a starter with ANNS and I don't know if I'm missing something abvious or why it is like it is.
  For testing I use a tabel with 81 digits (allways in a row from 1 to 9).
  I would be grateful if someone can help me :)</p>
  <p>Training the ANN</p>
  <pre><code>import tensorflow as tf
  import tensorflow_datasets as tfds
  from tensorflow.keras.models import save_model
  
  # See available datasets
  print(tfds.list_builders())
  
  # Construct a tf.data.Dataset
  dataset = tfds.load(name=&quot;mnist&quot;, split=tfds.Split.TRAIN)
  
  # Build your input pipeline
  dataset = dataset.shuffle(1024).batch(32).prefetch(tf.data.experimental.AUTOTUNE)
  for features in dataset.take(1):
    image, label = features[&quot;image&quot;], features[&quot;label&quot;]
  
  # tfds works in both Eager and Graph modes
  
  
  # See available datasets
  print(tfds.list_builders())
  
  # Construct a tf.data.Dataset
  dataset = tfds.load(name=&quot;mnist&quot;, split=tfds.Split.TRAIN)
  
  # Build your input pipeline
  dataset = dataset.shuffle(1024).batch(32).prefetch(tf.data.experimental.AUTOTUNE)
  for features in dataset.take(1):
    image, label = features[&quot;image&quot;], features[&quot;label&quot;]
  
    mnist = tf.keras.datasets.mnist
  
  # Aufteilung in Training- und Testset
  (x_train, y_train),(x_test, y_test) = mnist.load_data()
  x_train, x_test = x_train / 255.0, x_test / 255.0
  print(x_test[0])
  # TF Bilderkennungsmodell
  model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(512, activation=tf.nn.relu),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=tf.nn.softmax)
  ])
  
  # Crossentropy für die 10 Zahlen Klassen
  model.compile(optimizer='adam',
                loss='sparse_categorical_crossentropy',
                metrics=['accuracy'])
  
  # Modellfitting und Evaluation
  model.fit(x_train, y_train, epochs=50)
  model.evaluate(x_test, y_test)
  
  filepath = './saved_model2'
  save_model(model, filepath)
  </code></pre>
  <p>For testing with my table:</p>
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  from tensorflow.keras.models import load_model
  import cv2
  import PIL
  
  
  # Model configuration
  img_width, img_height = 28, 28
  batch_size = 250
  no_epochs = 25
  no_classes = 10
  validation_split = 0.2
  verbosity = 1
  
  
  filepath = './saved_model2'
  
  model = load_model(filepath, compile=True)
  img = PIL.Image.open(&quot;Dataset/raster.jpg&quot;)
  bilder = []
  
  i= 0
  for x in range(0,224,28):
      img1 = img.crop([0,x,28,x+28])
      img2 = img.crop([28,x,56,x+28])
      img3 = img.crop([56,x,84,x+28])
      img4 = img.crop([84,x,112,x+28])
      img5 = img.crop([112,x,140,x+28])
      img6 = img.crop([140,x,168,x+28])
      img7 = img.crop([168,x,196,x+28])
      img8 = img.crop([196,x,224,x+28])
      img9 = img.crop([224,x,252,x+28])
      img1.save(&quot;Dataset/eigeneBilder/&quot;+str(i+1)+&quot;.jpg&quot;)
      img2.save(&quot;Dataset/eigeneBilder/&quot;+str(i+2)+&quot;.jpg&quot;)
      img3.save(&quot;Dataset/eigeneBilder/&quot;+str(i+3)+&quot;.jpg&quot;)
      img4.save(&quot;Dataset/eigeneBilder/&quot;+str(i+4)+&quot;.jpg&quot;)
      img5.save(&quot;Dataset/eigeneBilder/&quot;+str(i+5)+&quot;.jpg&quot;)
      img6.save(&quot;Dataset/eigeneBilder/&quot;+str(i+6)+&quot;.jpg&quot;)
      img7.save(&quot;Dataset/eigeneBilder/&quot;+str(i+7)+&quot;.jpg&quot;)
      img8.save(&quot;Dataset/eigeneBilder/&quot;+str(i+8)+&quot;.jpg&quot;)
      img9.save(&quot;Dataset/eigeneBilder/&quot;+str(i+9)+&quot;.jpg&quot;)
      i += 9
  print(bilder)
  
  samples_to_predict = []
  for i in range(1,81,1):
      # Generate a plot
      sample = cv2.imread(&quot;Dataset/eigeneBilder/&quot;+str(i)+&quot;.jpg&quot;)
      img = cv2.bitwise_not(sample)
      sample = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      reshaped_image = sample.reshape((img_width, img_height,1))
      plt.imshow(reshaped_image)
      reshaped_image/255
      # Add sample to array for prediction
      samples_to_predict.append(reshaped_image)
  
  samples_to_predict = np.array(samples_to_predict)
  
  print(samples_to_predict[0])
  predictions = model.predict(samples_to_predict)
  classes = np.argmax(predictions, axis=1)
  print(samples_to_predict)
  print(classes)
  </code></pre>