For the complete documentation index, see llms.txt. This page is also available as Markdown.

Example: Best Face-ID Vector from Walk-Bys

Keep one face-ID vector per person walking past a camera, from the frame that shows their face best

A camera at an office entrance sees people walk in and out all day, and many of them more than once. In this example you build a Pop that detects and tracks every person on every frame, picks the frame where each person's face is seen best, and computes a face-ID vector from that one frame. Comparing the vectors then recognizes who came back, even when they changed their clothes.

The example video shows ten walk-bys of eight people, the way an entrance sees them: people come in through the center door or the doors on the left and walk on past the camera without stopping, most of them alone, some in a pair, and one group of three, a few steps apart. Two of them come back later in different clothes: one in a navy blazer instead of a yellow rain jacket and backpack, the other in a trench coat instead of a green cardigan.

The complete, runnable example is in the Python SDK repository, under examples/temporal_context, together with the video. The steps below build it piece by piece.

The example video, played at three times its speed: people walk in through the doors of an office lobby and on past the camera, alone, in pairs and in a group of three
The example video at 3× speed. Everyone in it is generated.

Before you start

  • Python SDK 3.24.0 or newer, and an API key in EYEPOP_API_KEY.

  • The example code and video:

Step 1: Detect and track people

The efficient side of the Pop runs on every frame. eyepop.person.medium:latest finds people, and a tracking component with eyepop.person.reid:latest follows each one by appearance as well as motion, so a person keeps their trackId when they cross paths with someone else:

Step 2: Select the frame where the face is seen best

A person's box alone says little about their face: the largest view of someone walking away shows the back of their head. A relevancy model fixes that. With a face detector as the relevancy model, a frame is only as relevant as the face found in it, and a person whose face is never found is never selected:

minTrackLengthSeconds=2.0 ignores tracks shorter than two seconds. A walk-by through the lobby takes longer than that, but when a group comes in through the doors together, the tracker can briefly start a second track on one of them before it settles; that fragment is never selected.

The relevancy model runs on every tracked person of every frame, so it should be small and fast. The short-range face detector is both, and it is made for faces close to the camera: the views a face-ID model compares best. Without intervalSeconds, each person is selected once, when they leave the frame — the right choice for walk-bys, which last seconds.

See Select Operators for exactly how relevance and timing work.

Ten walk-bys from the example video, each cropped from the frame the select operator chose: close to the camera and facing it
The ten selections from the example video: for each walk-by, the frame where the face detector found the face best. #3 and #5 are the same person, and so are #4 and #9. Everyone in the video is generated.

Step 3: Detect, align and embed the face

The selection forwards a crop of the person from the selected frame. Three stages turn it into a vector:

  1. The face detector finds the face inside the person crop.

  2. CropForward cuts it out with some margin, and orientationTargetAngle=-90 rotates it upright, using the eye line the detector reports. Face-ID models compare best on aligned faces.

  3. eyepop.face-id.large:latest embeds the aligned face as a 512-dimensional vector.

These stages run once per person instead of on every frame, which is what makes the large face-ID model affordable on a busy entrance.

Step 4: Read the vectors

Selected predictions carry the result, one per person. The vector is attached to the face object nested under the selected person, as a tensor named embedding:

The vectors are not normalized. Normalize them before storing them in a vector database that expects unit vectors.

Step 5: Compare walk-bys

Two vectors of the same face point in nearly the same direction, so their cosine similarity is high. Grouping walk-bys by similarity counts the people behind them, and shows who walked by more than once. A walk-by joins a group only when it is alike to every walk-by already in it, so one borderline match cannot chain two different people together:

The threshold trades missed matches against false ones. Tune it on your own cameras, with the script's --threshold: lighting, distance and angle all move it.

Face-ID compares faces, not outfits. In the example video, the two people who come back are matched to their first walk-by with a cosine similarity of 0.42 and 0.29, although both changed their clothes. No two different people score higher than 0.16, so a threshold of 0.25 sits between the two.

Run the example

It prints one line per person as their selection arrives, writes every vector to faces.jsonl, and ends with how many different people walked by, each repeat visit with its lowest similarity to the rest of its group:

The face crops of the two people who walked by twice, side by side: #3 and #5 with a cosine similarity of 0.42, and #4 and #9 with 0.29
The face crops face-ID embedded for the two people who came back, in different clothes. Everyone in the video is generated.

Every walk-by is selected exactly once, while the live predictions cover every frame of the video, and the two people who came back are recognized by their faces alone.

Point --video at an rtsp:// camera instead of the file to run the same Pop on a live entrance.

Next steps

Last updated