Browse Source

Upload files to ''

Added the scripts for accessing the database
ayan.ghoshal-patch-1
ayan.ghoshal 6 days ago
parent
commit
3fd33539d5
2 changed files with 102 additions and 0 deletions
  1. +32
    -0
      faissChecking.py
  2. +70
    -0
      pickleChecking.py

+ 32
- 0
faissChecking.py View File

@ -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")

+ 70
- 0
pickleChecking.py View File

@ -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")

Loading…
Cancel
Save