<jupyter_start><jupyter_text>Find the K Nearest Neighbors for a particular imageHere we find the k-nearest neighbors based on image features. We load the pickles dictionary and find the nearest neighbors from that portion of the dataset.<jupyter_code>import sys
sys.path.append("../main/")
from image_utils import find_k_closest, get_k_nearest_neighbor_image
%load_ext autoreload
%autoreload 2

import random
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>load the pickle file with feature vectors<jupyter_code>import pickle
with open('../main/data/features_dict.pickle', 'rb') as handle:
    features_dict = pickle.load(handle)<jupyter_output><empty_output><jupyter_text>examples of finding the k nearest neighbors for a few randomly selected images<jupyter_code># we take an objectid to run nearest-neighbors on
# this means that the leftmost image will be the object itself
# the remaining 4 (left to right) are most similar

features_dict_as_list = list(features_dict.items())

for i in range(5):
    objectid, this_vec = random.choice(features_dict_as_list)
    print("Example #{}: object id = {}".format(i, objectid))
    
    k_closest_list = find_k_closest(this_vec, features_dict)
    image = get_k_nearest_neighbor_image(k_closest_list)
    plt.imshow(image)
    plt.show()<jupyter_output>Example #0: object id = 465
{'fraction_non_alphanumeric': 0.0808448652585579, 'fraction_numerical': 0.005098324836125273, 'mean_word_length': 5.835820895522388, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '297409', 'license': 'MIT', 'n_tokens_mistral': 448, 'n_tokens_neox': 438, 'n_words': 132, 'path': 'notebooks/3_FindNearestNeighbors.ipynb', 'repo_name': 'Bhaskers-Blu-Org2/HoloLens-Art-Recommendations', 'size': '1373'}