Skip to content

armgit / facex

Public Imported from GitHub
0

Full face stack that runs entirely in the browser. Detection, 576-point 3D mesh, recognition, anti-spoof, smile — all WebAssembly, zero server. Apache 2.0.

4.4 KB
Raw Blame

Exact search at cluster boundaries, compact decisions and concurrent gallery work

Three research prototypes share the workload from bench_gallery_groups.py. Fifteen fixture photos provide model embeddings for eight enrollment crops and a ninth held-out crop. The 65535 enrollment vectors are generated by perturbing those eight views per group. The 45 distinct queries are the held-out views, normalized midpoints toward another group, and random directions (15 each). Random directions are a mathematical stress test. They do not represent unknown people. Identity group labels are known at enrollment.

Spherical caps for exact top five

Within each group choose up to eight farthest-first prototypes from a seeded random sample of 128 rows. Assign every enrollment row to its nearest prototype. In each resulting cell choose the enrollment row closest in angle to the mean as a witness. Store its unit axis and the smallest dot product between the axis and any assigned unit vector. Reorder the on-disk rows by cell, retaining original IDs. A fixed-stride enrollment sample can alias with periodic data and miss entire views.

If the query makes angle A with the axis and the cell's half-angle is B, the upper cosine score is cos(max(0,A-B)). The implementation evaluates this without trigonometric functions and adds numerical slack. Search promising cells first, refine using existing float64 cosine scoring and stop below the current fifth score. Within each cell the original row order resolves ties, and across cells the final sort uses the original row ID.

Probe type CompactGallery p50 / p95 ms Cap search p50 / p95 ms
Held-out crop 9.72 / 11.09 0.98 / 1.80
Between two groups 9.55 / 13.32 1.79 / 5.06
Random direction 9.83 / 18.64 22.25 / 56.60

All five IDs and all five scores matched CompactGallery on every probe and repeat. End-of-run process RSS was about 34 MiB for cap search and 161 MiB for CompactGallery. The packed original rows still occupy approximately 128 MiB of backing storage. These are warm-file results on tmpfs. RSS excludes host file cache, model inference and offline building. The candidate screen in this prototype is scoped to the ordinary nonzero norms in this workload.

Threshold decisions from enrolled witnesses

For each identity the maximum witness dot gives a lower bound on its best enrolled score, and the maximum cap upper bound gives an upper bound. Award a match only when its lower bound clears the threshold and exceeds every rival upper bound by the required margin. Reject when every upper bound lies below the threshold. Other cases require exact lookup. These statements concern agreement with an exact gallery decision for the chosen thresholds.

The decision worker reads 493440 bytes of index arrays (axes, radii encoded as cosines, identity owners) and never reads original enrollment rows. For evaluation it also reads reference labels and scores. At threshold 0.85 and margin 0.05 it resolved 36 of 45 probes: 15 crop matches, six midpoint rejections and 15 random-direction rejections. Nine midpoint cases required fallback. At threshold 0.65 and the same margin it resolved 31 of 45. All resolved decisions matched the exhaustive per-identity reference and all oracle identity scores were inside their computed intervals. The thresholds are illustrative and need independent calibration.

Eight ready queries on one CPU

The batched screen evaluates eight float32 queries against one gallery matrix and refines finalists per query in float64. On groups of eight already available queries, median completion time fell from 77.37 to 50.90 ms, and p95 from 87.98 to 53.49 ms. IDs and scores were equal for both implementations. This tests gallery computation only. Request arrival timing, HTTP queues and concurrent model inference are outside the experiment.

Reproduction

Use Linux, NumPy, Pillow and the project C compiler. Make sufficient temporary space available (at least 400 MiB). Each search method runs in its own pinned process with one BLAS thread. Single-query timings use three measured passes after one warm pass, 45 samples per probe type. The batch benchmark alternates method order between passes and times 20 batches per method after warmup. Results are machine and cache dependent.

mkdir -p data
bash download_weights.sh
make cli
OPENBLAS_NUM_THREADS=1 PYTHONPATH=python python tests/bench_gallery_caps.py data/edgeface_xs_fp32.bin