Skip to content

Instantly share code, notes, and snippets.

@gautham20
Created July 13, 2019 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gautham20/f53b6a1c6e05af5252be33e8384a6c0d to your computer and use it in GitHub Desktop.
Save gautham20/f53b6a1c6e05af5252be33e8384a6c0d to your computer and use it in GitHub Desktop.
def get_similar_images(img_index, n=10):
start = time.time()
base_img_id, base_vector, base_label = img_repr_df.iloc[img_index, [0, 1, 2]]
cosine_similarity = 1 - img_repr_df['img_repr'].apply(lambda x: cosine(x, base_vector))
similar_img_ids = np.argsort(cosine_similarity)[-11:-1][::-1]
end = time.time()
print(f'{end - start} secs')
return base_img_id, base_label, img_repr_df.iloc[similar_img_ids]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment