May 2020
Beginner to intermediate
430 pages
10h 39m
English
So far, we've developed an image directory and prepared and trained the model. In this section, we'll convert the image into a tensor. We develop a tensor from an image by converting the image into an array and then use NumPy's expand_dims() function to expand the shape of the array. Subsequently, we preprocess the input to prepare the image so that it's in the format the model requires:
img_path = 'furniture_images/test/chair/testchair.jpg'img = image.load_img(img_path, target_size=(150, 150))img_tensor = image.img_to_array(img)img_tensor = np.expand_dims(img_tensor, axis=0)img_tensor = preprocess_input(img_tensor)featuremap = model.predict(img_tensor)
Finally, we use the Keras model.predict() ...