In [1]:
import graphlab
In [2]:
image_train = graphlab.SFrame('image_train_data/')
In [3]:
image_train.head(1)
Out[3]:
In [4]:
knn_model = graphlab.nearest_neighbors.create(image_train, features=['deep_features'], label='id')
In [10]:
cat = image_train[18:19]
In [11]:
graphlab.canvas.set_target('ipynb')
In [12]:
cat['image'].show()
In [13]:
knn_model.query(cat)
Out[13]:
In [17]:
def get_images_from_ids(query_result):
return image_train.filter_by(query_result['reference_label'], 'id')
In [19]:
cat_neighbours = get_images_ids(knn_model.query(cat))
In [20]:
cat_neighbours['image'].show()
In [21]:
car = image_train[8:9]
In [22]:
car['image'].show()
In [23]:
get_images_from_ids(knn_model.query(car))['image'].show()
In [24]:
show_neighbours = lambda i: get_images_from_ids(knn_model.query(image_train[i:i+1]))['image'].show()
In [25]:
show_neighbours(8)
In [29]:
show_neighbours(2000)
In [39]:
dog_sframe = image_train[image_train['label'] == 'dog']
In [40]:
len(dog_sframe)
Out[40]:
In [37]:
cat_sframe = image_train[image_train['label'] == 'cat']
In [38]:
len(cat_sframe)
Out[38]:
In [41]:
bird_sframe = image_train[image_train['label'] == 'bird']
In [42]:
len(bird_sframe)
Out[42]:
In [43]:
automobile_sframe = image_train[image_train['label'] == 'automobile']
In [45]:
len(automobile_sframe)
Out[45]:
In [53]:
print len(image_train)
print 509 * 3 + 478
In [54]:
dog_only_knn_model = graphlab.nearest_neighbors.create(dog_sframe, features=['deep_features'], label='id')
In [55]:
cat_only_knn_model = graphlab.nearest_neighbors.create(cat_sframe, features=['deep_features'], label='id')
In [56]:
bird_only_knn_model = graphlab.nearest_neighbors.create(bird_sframe, features=['deep_features'], label='id')
In [57]:
automobile_only_knn_model = graphlab.nearest_neighbors.create(automobile_sframe, features=['deep_features'], label='id')
In [58]:
image_test = graphlab.SFrame('image_test_data/')
In [59]:
image_test[0:1]['image'].show()
In [73]:
q2 = cat_only_knn_model.query(image_test[0:1])
In [74]:
q2 = q2['rank' == 1]
# Filter
cat_neighbors = image_train.filter_by(q2['reference_label'],'id')
# Get the image
cat_neighbors['image'].show()
In [79]:
q3 = dog_only_knn_model.query(image_test[0:1])
In [80]:
q3 = q3['rank' == 1]
# Filter
dog_neighbors = image_train.filter_by(q3['reference_label'], 'id')
# Get the image
dog_neighbors['image'].show()
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: