# How to improve Face matching time

I'm working on a project that aims to detect each person's face while entering to a public space and store entering time and the person's image (array format) in Elasticsearch, and then detect each exiting face, loop over the Elasticsearch index relative to people who have entered in that day, pass to my model two images (detected exiting face and faces stored in Elasticsearch), match the two faces and return enter time, exit time and total duration.

For face matching/Face re-identification I'm using a VGG model that takes ~1sec to compare two faces. This model takes two parameters and returns a value between 0 and 1. I loop over all faces, I append accuracy to a list, and the appropriate face is which has the minimum value returned. So that, if I have 100 entered person in that day, while looping to find one face, the program will take more than 100sec, but in my use case the program needs to run in real-time.

Any propositions for that ? Am I working with a wrong approach ?

This is a Screenshot of my code where I'm calling the model:

• have your profiled where the 1 second is coming from? is it in the network itself? is it related to pure python plumbing? is it relatws to copies from the cpu to the gpu? 1 second seems like a very long time. is this being run on a gpu or a cpu? Basically, I would do some more granular profiling if you can. Using a neural network to do what you're proposing should take on the order of a couple milliseconds, not one second. Jun 2 at 12:21
• I'm not sure what framework you're using, but you might be falling into the trap of building your computational graph on every invocation of your call to verifyFace Jun 2 at 12:27
• Show us the code for verifyFace so we don't have to make wild guesses. Like @juicedatom said, maybe you are running on a CPU and should be using a GPU. Which are you using? Jun 3 at 11:15