title: How to interpret expand_dims while predicting a uploaded image in tensorflow
body: <p>These days I am getting familiar with CNN &amp; tensorflow (via cat/dog classification problem) and while writing the predict function, I realize that the code uses expand_dims, which I am not able to interpret [1].</p>
  <p>When I am able to get the desired (150, 150, 3) array of uploaded image, why cant I feed it to the predict function? the images I trained/validated were also of the same size (150, 150, 3). What exactly adding this additional (1, 150, 150, 3) helping???</p>
  <p>Many thanks in advance,</p>
  <p>[1]</p>
  <pre><code>import numpy as np
  
  from google.colab import files
  from keras.preprocessing import image
  
  uploaded=files.upload()
  
  for fn in uploaded.keys():
   
    # predicting images
    path='/content/' + 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])
    
    classes = model.predict(images, batch_size=10)
    
    print(classes[0])
    
    if classes[0]&gt;0.5:
      print(fn + &quot; is a dog&quot;)
      
    else:
      print(fn + &quot; is a cat&quot;)
  </code></pre>