From 3fd33539d5a82f3df72fba2e83ced3c99e1199f3 Mon Sep 17 00:00:00 2001 From: "ayan.ghoshal" Date: Wed, 29 Jan 2025 02:40:14 +0100 Subject: [PATCH] Upload files to '' Added the scripts for accessing the database --- faissChecking.py | 32 ++++++++++++++++++++++ pickleChecking.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 faissChecking.py create mode 100644 pickleChecking.py diff --git a/faissChecking.py b/faissChecking.py new file mode 100644 index 0000000..5c6c0cc --- /dev/null +++ b/faissChecking.py @@ -0,0 +1,32 @@ + + +# import faiss + +# # Load the FAISS index +# index = faiss.read_index("face_index.faiss") + +# # Print information about the index +# print(f"Number of vectors in the index: {index.ntotal}") +# print(index) + +import faiss +import numpy as np + +# Load the FAISS index +index = faiss.read_index("face_index.faiss") + +# Check the total number of vectors in the index +total_vectors = index.ntotal +print(f"Number of vectors in the index: {total_vectors}") + +# Reconstruct vectors one by one +vectors = [] +for i in range(total_vectors): + vectors.append(index.reconstruct(i)) + +# Convert the list of vectors to a NumPy array +vectors_array = np.array(vectors) + +# Save the array to a text file for inspection +np.savetxt("faiss_vectors.txt", vectors_array, fmt="%.6f") +print("Vectors saved to faiss_vectors.txt") diff --git a/pickleChecking.py b/pickleChecking.py new file mode 100644 index 0000000..f7671ca --- /dev/null +++ b/pickleChecking.py @@ -0,0 +1,70 @@ +# import pickle + +# # Load the pickle file +# with open("face_store.pkl", "rb") as f: +# data = pickle.load(f) + +# # Print the data for inspection +# print(data) + + +# import json +# import numpy as np + +# def convert_ndarray(obj): +# """Recursively convert numpy.ndarray to list in a data structure.""" +# if isinstance(obj, np.ndarray): +# return obj.tolist() +# elif isinstance(obj, list): +# return [convert_ndarray(item) for item in obj] +# elif isinstance(obj, dict): +# return {key: convert_ndarray(value) for key, value in obj.items()} +# else: +# return obj + +# # Assuming `data` contains numpy arrays +# # data = { +# # "name": "example", +# # "embedding": np.array([1.0, 2.0, 3.0]), +# # "nested": { +# # "another_array": np.array([4.0, 5.0]) +# # } +# # } + +# # Convert `data` to JSON-serializable format +# data_serializable = convert_ndarray(data) + +# # Save as JSON +# with open("data.json", "w") as json_file: +# json.dump(data_serializable, json_file, indent=4) + +# print("JSON file saved successfully!") + + +import pickle +import json +import numpy as np + +# Function to convert non-serializable objects (like numpy arrays) to a serializable format +def convert_to_serializable(data): + if isinstance(data, np.ndarray): + return data.tolist() # Convert ndarray to list + elif isinstance(data, dict): # If data is a dictionary, recursively convert values + return {key: convert_to_serializable(value) for key, value in data.items()} + elif isinstance(data, list): # If data is a list, recursively convert items + return [convert_to_serializable(item) for item in data] + else: + return data # For other types, return as is + +# Load the pickle file +with open("face_store.pkl", "rb") as f: + data = pickle.load(f) + +# Convert the data to a JSON-serializable format +data_serializable = convert_to_serializable(data) + +# Save to a JSON file +with open("face_store.json", "w") as json_file: + json.dump(data_serializable, json_file, indent=4) + +print("Data has been saved to face_store.json")