In [1]:
import graphlab
Load dataset with photos and their deep features:
In [2]:
photos = graphlab.SFrame('photos_deep_features.gl')
Show a few first rows of dataset:
In [3]:
photos
Out[3]:
Train a nearest neighbors model on deep features of photos
In [4]:
nn_model = graphlab.nearest_neighbors.create(photos, features=['deep_features'], label='path')
Print information about the model:
In [5]:
nn_model
Out[5]:
Show 12 nearest photos for first 10 photos in the dataset:
In [6]:
graphlab.canvas.set_target('ipynb')
n = 12 # number of nearest neighbors
for i in xrange(10):
query = nn_model.query(photos[i:i+1],k=n)
nearest_neighbors = photos.filter_by(query['reference_label'], 'path')
nearest_neighbors['image'].show()
This notebook is inspired by one of the notebooks in the following Coursera course: https://www.coursera.org/learn/ml-foundations