These days I am getting familiar with CNN & 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].
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???
Many thanks in advance,
[1]
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]>0.5:
print(fn + " is a dog")
else:
print(fn + " is a cat")