title: Preparing an array for model.predict() In tensorflow
body: <p>I have been trying to predict dog versus cats in my trained model. In my code, I load my trained model and load the images from a directory on my computer, and images load without an issue. In my small test set there are 5 cat and 5 dog images</p>
  
  <p>When I run this code, It always predicts dog, but I can assure you there is not a problem in my model, It has 97% accuracy, which is pretty great. And by the way, when I explicitly test a cat image with directly putting the image.jpg in <code>model.predict()</code>, It predicts it right. I think the issue is that I put <code>resized_img</code> in <code>model.predict()</code>, I don't know how to put an array in <code>model.predict()</code>. </p>
  
  <p>I am a complete newbie, I don't know if I am doing it right. </p>
  
  <p>Any tip would be really helpful. Thanks!</p>
  
  <pre class="lang-py prettyprint-override"><code>import cv2
  import tensorflow as tf
  import matplotlib.pyplot as plt
  import numpy as np
  import glob
  
  CATEGORIES = ["Dog", "Cat"]
  IMG_SIZE = 200
  TEST_DIR = r"C:\mydir\*.*"
  model = tf.keras.models.load_model("catsvsdogspredict.model")
  
  
  for file in glob.glob(TEST_DIR):
      img = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
      resized_img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))
      resized_img = resized_img.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
      prediction = model.predict(resized_img)
      plt.grid(False)
      plt.imshow(img, cmap="gray")
      plt.title("Prediction: " + CATEGORIES[np.argmax(prediction)])
      plt.show()
  
  </code></pre>
  
  <p>Here is how I read the training images.</p>
  
  <pre class="lang-py prettyprint-override"><code>training_data = []
  def create_training_data():
      for category in CATEGORIES:
          path = os.path.join(DATADIR, category) #path to cats or dogs dir, string matching with file name
          class_num = CATEGORIES.index(category)
          for img in os.listdir(path):
              try:
                  img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
                  new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
                  training_data.append([new_array, class_num])
              except Exception as e:
                  pass
  
  create_training_data()
  print(len(training_data))
  random.shuffle(training_data)
  # creating arrays
  X = []
  y = []
  for features, label in training_data:
      X.append(features)
      y.append(label)
  X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
  y = np.array(y)
  
  </code></pre>