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

Predicting the class of all images

The following function imports the necessary packages to get files from the directory and the similarity calculation. We then specify which folder to target based on the input class of the uploaded image:

import osfrom scipy.spatial import distance as distfrom sklearn.metrics.pairwise import cosine_similarityif y_classes == [0]:    path = 'furniture_images/val/bed'elif y_classes == [1]:    path = 'furniture_images/val/chair'else:    path = 'furniture_images/val/sofa'

The following function loops through each image in the test directory and converts the image into an array, which is then used to predict the feature vector using the trained model:

mindist=10000maxcosine =0i=0for filename in os.listdir(path): image_train ...
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