Skip to content

feat(eval): face-matching evaluation harness and first results - #112

Draft
nisbenz wants to merge 7 commits into
MicroClub-USTHB:developfrom
nisbenz:eval/face-matching-harness
Draft

nisbenz wants to merge 7 commits into
MicroClub-USTHB:developfrom
nisbenz:eval/face-matching-harness

Conversation

@nisbenz

@nisbenz nisbenz commented Nov 30, 2026 •

Copy link
Copy Markdown

Part of #111. This adds an offline harness that measures how often the photo worker sends a photo to the wrong person (FPIR, misID) or misses the right one (FNIR), plus first results. No app code changes. The threshold and enrollment decisions are left for a follow-up, once we have labelled MicroClub data.

What's added

Path What it does
backend/eval/face_matching/ Open-set 1:N evaluation: dataset split, extraction, enrollment variants, metrics, report
backend/eval/face_matching/photos.py Detection stats on unlabelled event photos (faces per photo, face sizes, faces missed at 640 vs 1280)
backend/tests/unit/test_eval_face_matching.py 11 model-free tests (metrics, split, enroll/probe roles, extraction with a fake model). They run in make test
backend/docs/face-matching-eval.md Method, metric definitions, commands, results, open decisions

The harness isn't part of make test or CI, since it needs model weights and a dataset. Images, embeddings and results stay outside the repo; backend/eval/.gitignore is a second safety net.

How it measures

  • It runs the production code. Probe photos go through FaceEmbeddingService.detect_faces. Before any metric is computed, a parity check re-enrolls a sample of identities through the real compute_average_embedding and stops the run if the harness's template differs. It matched exactly (max |diff| = 0.0) on every run.
  • Open-set protocol. Each person enrolls from K = MIN_ENROLL_IMAGES = 3 photos. Their other photos are searched against a gallery of N members, and photos of people who aren't enrolled are searched too. The search uses exact cosine distance, identical to pgvector <=> (there's no ANN index on face_embedding). Results are the mean over 5 seeds, with 95% Wilson intervals.
  • Metrics:
    • FPIR (strangers matched to a member): the privacy metric.
    • misID (members matched to the wrong member).
    • FNIR, plus FNIR end-to-end (counting faces the detector missed).
    • FDR (share of matches that go to the wrong person), at assumed shares of member faces in real photos.
    • The threshold that meets each target FPIR, EER, rank-k, distance distributions, d′, and 1:1 TAR@FAR for comparison only.
    • Failure-to-enroll and detection-miss rates.
    • Everything split by single-face photos (auto-approved in production) and group photos.
  • Enrollment variants compared:
    • current (production): faces[0], mean of raw embeddings.
    • Largest face, most confident face, normalized mean, and keeping K vectors, plus combinations of these.

Results 1: LFW (public dataset, random subset)

The run used 4,556 images of 2,152 people, of whom 238 can be enrolled. That's the part extracted before the full run was paused; the subset is a seeded random sample of identities. Gallery sizes were 50 and 238.

Production method (current):

members threshold FPIR (stranger matched) misID (wrong member) FNIR (member missed)
50 0.5 (production) 0% 0% 1.44%
238 0.5 (production) 0.008% (1 face in ~12,000; CI 0.001–0.047%) 0% 1.35%
238 0.6 0.075% 0% 0.34%
238 0.612 (largest with FPIR ≤ 0.1%) 0.083% 0% 0.29%

Rank-1 is 99.99%, EER is 0.20%, failure-to-enroll is 0.17%, and detection misses are 0.07%.

image

Members' photos sit around 0.26 from their own template, and strangers' photos around 0.82 from the closest member. 0.5 sits well inside the gap, so on LFW it is conservative: about 1.4% of members' photos are missed.
image

The one false match at 0.5 is caused by faces[0] enrollment. One of Bob Hope's enrollment photos contains two faces, and faces[0] is Jane Russell's. His averaged template therefore partly contains her face, and her photo matches him at distance 0.495. On this data, 7.8% of multi-face photos have faces[0] ≠ the labelled person. In the app, the same thing happens when a selfie shows someone in the background.

image image
variant (238 members, threshold 0.5) FPIR FNIR
current (production) 0.008% 1.35%
normed mean 0.008% 1.38%
most confident 0.008% 1.35%
largest face 0.008% 1.87%
largest face + normalized mean 0% 1.95%
keep K vectors 0.108% 1.79%
largest face + keep K vectors 0.116% 1.99%
  • Largest face + normalized mean removes the poisoned-template match, at the cost of about 0.6 points more FNIR.
  • Normalizing alone makes no measurable difference.
  • Keeping K separate vectors is more than 10× worse on FPIR, because one bad enrollment vector is no longer diluted by the mean.

Results 2: MicroClub event photos (detection only)

These are 472 photos from one event camera folder ("Cam 250D", 6000×4000 JPEGs), used with members' written consent. They're unlabelled and no selfies were provided, so FPIR and FNIR weren't measured on this set. Only detection was analysed.
image

detector 640×640 (production) detector 1280×1280
faces found 1,300 1,392
photos with 0 / 1 / ≥ 2 faces 4 / 258 / 210 6 / 255 / 211
median face width at the detector 49 px 89 px
faces under 24 px at the detector 295 (23%) 154 (11%)
speed on CPU (this machine) 0.7 photos/s 0.5 photos/s
  • The production detector size misses 8.7% of faces (121 of 1,392), mostly small faces in crowd shots. Those people never get the photo.
  • Photos are shrunk about 9× before detection. At 640, 23% of faces are under 24 px wide, too small for reliable embeddings. They are the most likely source of wrong matches on real event photos; a labelled set is needed to confirm it.
  • 55% of photos have exactly one face, so they're auto-approved and the matched member is notified with no review.

What this doesn't decide yet

LFW is easy (frontal, well-lit celebrity photos), and 238 members is a small gallery. These results show the harness works and expose the faces[0] problem. They don't justify changing PHOTO_WORKER_SIMILARITY_THRESHOLD. Still open from #111:

  • FPIR/FNIR on a labelled MicroClub set (selfies plus event photos). Supported through labels.csv with role = enroll / probe
  • Threshold decision at our real gallery sizes
  • Single-face auto-approval decision
  • Enrollment method decision (the LFW results point to largest face + normalized mean)
  • Detector size decision (640 vs 1280)

How to reproduce

cd backend
# LFW, from the cached subset (drop --cached-only for the full 13,233 images, about 3 h on CPU)
uv run python -m eval.face_matching --data ~/face-eval/data/extracted/lfw \
  --out ~/face-eval/results/lfw-k3 --cache-dir ~/face-eval/cache \
  --k 3 --gallery-sizes 50,300,all --seeds 5 --strategies all \
  --providers CPUExecutionProvider --cached-only
# Event photo detection stats
uv run python -m eval.face_matching.photos stats --data "<photos>/Cam 250D" \
  --out ~/face-eval/results/microclub/stats --cache-dir ~/face-eval/cache-microclub \
  --det-sizes 640,1280 --providers CPUExecutionProvider

Each run writes report.md (every metric with a glossary), summary.json, per-seed JSON, CSVs and plots.

Testing

  • uv run ruff check . and uv run mypy . are clean.
  • uv run pytest tests/unit: 257 passed.
  • A real-model run on the cached LFW subset gives identical metrics before and after the final clean-up (4,242 values compared).

Nearest-member search by cosine distance (same as pgvector <=>) and the
metrics for open-set 1:N identification: FPIR, misID, FNIR, FDR, exact
threshold for a target FPIR, EER, CMC, distance distributions, d-prime,
1:1 TAR@FAR, Wilson intervals and per-identity counts. Pure numpy.

The eval/ folder ignores images, embeddings and results so personal data
can't be committed.
Load a <root>/<identity>/<image> dataset (optional labels.csv with face
boxes and enroll/probe roles) and split it into enrolled members, their
probe photos and strangers.

Every image goes through FaceEmbeddingService.detect_faces with the model
wrapped in a recorder, and is cached per image. A parity check re-enrolls
identities through the real compute_average_embedding and fails the run
if the harness's 'current' template differs.

Enrollment strategies: current (faces[0], mean of raw embeddings, as in
production), largest face, most confident face, normalized mean, and
keeping all K vectors.
Enroll the gallery with a strategy, pick each probe's labelled face (by
box, or nearest the centre) and search it. Failed enrollments make that
person a stranger, as in the app. Detection misses are counted for the
end-to-end FNIR.
python -m eval.face_matching runs the protocol over gallery sizes, seeds
and strategies, and writes report.md (with a metrics glossary),
summary.json, per-seed JSON, operating-point and DET CSVs and plots.

--checkpoint-every writes interim reports during long extractions,
identities are extracted in a seeded random order so each checkpoint is
a random sample, and --cached-only evaluates what is already cached.
python -m eval.face_matching.photos stats reports faces per photo, face
sizes in original and detector pixels, detector confidence, and the faces
the production detector size misses compared with a larger one.
Metrics against hand-computed cases (FPIR, FNIR, misID, FDR, exact
threshold, CMC, Wilson), strategy outputs, probe face selection, the
gallery/stranger split and enroll/probe roles, and extraction plus the
parity check with a fake insightface model.
Method, metric definitions, commands, and results on an LFW subset and
on detection stats for one set of event photos. Decisions on the
threshold, single-face auto-approval, enrollment method and detector size
are left open.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant