Whats the best way to sort and search for similar embeddings for facial recognition

259 Views Asked by At

I'm planning on making a rather large database of faces/embeddings. I want to know whats the best way to sort my list of embeddings and I also want to know what's the best way to search my list for the most similar face. I'm using deepface for my facial recognition and identification.

1

There are 1 best solutions below

0
On

Assume df['embeddings'] has a collection of all the embeddings you want to match against

face_embedding is the one you're finding the nearest match to

Define the distance function

def find_distance(x):
  if x is not None:
    return distance.euclidean(x.detach().numpy(), face_embedding.detach().numpy())
  else:
    return None

Apply the distance function to the 'embeddings' column of the dataframe

df['distance'] = df['embeddings'].apply(find_distance)

Find the index of the closest match

closest_index = df['distance'].idxmin()

return closest_index