简体   繁体   中英

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

Sounds like you want a nearest neighbour search. You could have a look at the various space partitioning data structures like kd-trees

First make a dictionary with 10000 face encodings as it is shown at Face_recognition sample, then store it as pickle-file. While loaded in memory it will take a sacond to find distance between X face encoding and that 10000 pre-encoded ones. take a look how it works I'm operating with millions of faces in such way.

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

which solution did you finally adopt? I'm also thinking about it, looking forward to you response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM