Search code examples
databasealgorithmdatabase-designdatabase-schemaface-recognition

How to store FaceNet data efficiently?


I am using the Facenet algorithm for face recognition. I want to create application based on this, but the problem is the Facenet algorithm returns an array of length 128, which is the face embedding per person.

For person identification, I have to find the Euclidian difference between two persons face embedding, then check that if it is greater than a threshold or not. If it is then the persons are same; if it is less then persons are different.

Let's say If I have to find person x in the database of 10k persons. I have to calculate the difference with each and every person's embeddings, which is not efficient.

Is there any way to store this face embedding efficiently and search for the person with better efficiency?

I guess reading this blog will help the others.

It's in detail and also covers most aspects of implementation.

Face recognition on 330 million faces at 400 images per second


Solution

  • Recommend you to store them in redis or cassandra. They will overperform than relational databases.

    Those key-value stores can store multidimensional vector as a value.

    You can find embedding vectors with deepface. I shared a sample code snippet below.

    #!pip install deepface
    from deepface import DeepFace
    img_list = ["img1.jpg", "img2.jpg", ...]
    
    model = DeepFace.build_model("Facenet")
    for img_path in img_list:
        img_embedding = DeepFace.represent(img_path, model = model)
        #store img_embedding into the redis here