Skip to Content
Mastering Computer Vision with TensorFlow 2.x
book

Mastering Computer Vision with TensorFlow 2.x

by Krishnendu Kar
May 2020
Beginner to intermediate
430 pages
10h 39m
English
Packt Publishing
Content preview from Mastering Computer Vision with TensorFlow 2.x

Inputting a test image and converting it into a tensor

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() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Computer Vision with TensorFlow 2

Hands-On Computer Vision with TensorFlow 2

Benjamin Planche, Eliot Andres

Publisher Resources

ISBN: 9781838827069Supplemental Content