Search 100 Million Identities in Less Than One Second with the Trueface SDK: A Tutorial

Cyrus Behroozi
Trueface
Published in
5 min readJun 3, 2020
Made using the Trueface SDK

Two questions we often get asked by clients wanting to use our technology are how accurate is it, and how fast can it run? Today, I will be touching on the second question. As a member of the C++ team at Trueface, I have been involved in migrating all the core technology from the Python SDK to the new C++ SDK. The C++ SDK offers all the same great features as the Python SDK but also exhibits significant speed improvements — not only is C++ a much faster language (compiled vs interpreted), but our team has also spent countless hours benchmarking and optimizing our code implementations. This hard work paid off on our first submission to the National Institute of Standards and Technology (NIST) Face Recognition Vendors Test (FRVT) where we scored top 10 for genuine match speed. The C++ SDK has also been compiled for multiple CPU architectures including X86_64 and ARM, and offers python bindings making it easy to start deploying computer vision applications on any platform.

What exactly is 1 to N matching?

To explain 1 to N matching, I’ll first explain what 1 to 1 matching is. In 1 to 1 matching, we compare two different face images to obtain a match probability describing the likelihood that the two faces belong to the same identity. With 1 to N matching, we compare a single face image against a collection of face images (stored in the form of face templates) to see if there is a match. For example, the collection could contain face templates belonging to all the employees who are authorized to enter a building. When someone approaches the security camera by the door, 1 to N matching can be used to quickly determine if said person is authorized to enter the building.

Theoretically, it’s possible to use the 1 to 1 module to perform a pseudo 1 to N search. However, the 1 to N module in the C++ SDK utilizes multiple advanced optimizations to offer much faster search speeds. Additionally, the C++ SDK 1 to N module offers utility functions that help to manage and store face templates in collections. Face templates can be stored in memory only (will disappear once the program ends), can be stored locally on the device with SQLite, or can be stored on a fully-fledged SQL database (this last option is still in development).

Speed Benchmarks

The SDK currently supports two methods for running a 1 to N search: identifyTopCandidate and batchIdentifyTopCandidate . The second method can perform multiple searches concurrently which increases throughput and provides a performance increase on devices with many available CPU cores.

The X86_64 benchmarks reported below were performed on Dual Intel Xeon CPU E5-2630 v4 @2.20GHz, 128GB Ram, Ubuntu 18.04 . This is the exact same CPU used by NIST in their FRVT tests. For the testing, the collection was populated using templates generated from the Labeled Faces in the Wild dataset using the FULL model with the frVectorCompression flag enabled.

As can be seen, a collection of 100 million templates can be searched in just under 1 second. With the batchIdentifyTopCandidate function, the average search time per probe template is even less, at 382 ms. So what do these numbers mean in practice? Let’s say, hypothetically, you’re in Germany (population 83 Million) and you are tasked with identifying a missing person amongst the entire population. Traditionally this would take thousands of man-hours and the results may not be accurate. The Trueface C++ SDK can identify the same missing person in less than one second.

At a conservative average, a template and corresponding metadata are ~1Kb in size. Therefore, a collection size of 1 million — already an immense number of identities — only requires 1GB of Ram.

While this performance is impressive, we must remember that this benchmark was run on a dual server-grade CPU with a whopping 20 cores total. How does the SDK perform on a lightweight embedded device such as a Raspberry Pi? To answer this, I ran the same benchmark on a Raspberry Pi 4 with 4GB of Ram running AArch64. Due to RAM limitations, I used a collection size of 1 million. On average, the call to identifyTopCandidate took 66 ms. Hence, we can still perform impressively fast 1 to N searches even on embedded devices.

Sample Code — Python

I will demonstrate how easy it is to build an application using the Trueface C++ SDK python bindings to run 1 to N identification using the webcam or a video on disk. For the sake of the demo, I will split the application into two parts — the first will demonstrate how to create and save templates to a collection, and the second will load the stored templates from disk and run a 1 to N search. To run the demo, you will need to have opencv-python installed on your system. For the demo, I will only be enrolling a few identities. However, you can enroll millions of identities as required for your use case.

Start by navigating to the C++ SDK releases page and download the correct SDK for your target device. You will have to obtain an SDK token and can do so by contacting sales@trueface.ai.

Creating a new collection and populating it with templates:

Load the templates from disk and run a 1 to N search:

If all goes well, you should end up with something like this:

The bottom left image was the only image enrolled in the collection.

And there you have it. The next time you are tasked with quickly identifying a needle in a haystack, you’ll know what tool to reach for.

--

--