Created
July 13, 2019 08:00
-
-
Save gautham20/f53b6a1c6e05af5252be33e8384a6c0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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