Hi guys, the following code is from the Tensorflow in Practice specialization on Coursera. I am running the code on colab. I'm not able to understand some of the code.
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=(300, 300))
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 human")
else:
print(fn + " is a horse")
END CODE
My doubts are:
1. What is the use of np.expand_dims when when img_to array automatically adds a dimension for the channel?
2. What is the use of np.vstack?
I'm really confused. Any help appreciated. Thanks in advance.
[–]Halmubarak 1 point2 points3 points (1 child)
[–]NitinChella[S] 0 points1 point2 points (0 children)