This repository contains our MSML/MSAI 605 face-verification project built around the Labeled Faces in the Wild (LFW) dataset. The codebase keeps the deterministic data-preparation backbone from Milestone 1, the evaluation and experiment-tracking workflow from Milestone 2, and the current embedding-based inference components added for Milestone 3 work.
The repository currently includes:
- deterministic LFW ingestion from a local dataset directory
- deterministic identity-level train/val/test splitting
- deterministic positive/negative pair generation saved to disk
- vectorized scoring and benchmarking utilities from the earlier baseline pipeline
- typed evaluation configs, validation checks, threshold sweeps, tracked runs, and error-slice extraction
- embedding, pair-inference, confidence, Docker, and load-test utilities that are being used for Milestone 3 development
src/lfw_verif/: package code for ingestion, pair generation, evaluation, plotting, tracking, embeddings, confidence, and inferencescripts/: runnable entrypoints for ingestion, pair generation, evaluation, tracked runs, error slicing, pair inference, and load testingconfigs/: milestone configs for ingestion, evaluation, benchmarking, and current inference settingstests/: unit, integration, determinism, and smoke testsoutputs/: generated Milestone 1 artifacts such as manifests, splits, pairs, and benchmarksartifacts/real_eval/: committed pair CSVs used for evaluation workartifacts/runs/: tracked evaluation runs generated locallyreports/: report figures, comparison tables, and exported report assets
The main project flow is still organized around a deterministic backbone:
flowchart LR
A[LFW image directory] --> B[scripts/ingest_lfw.py]
B --> C[outputs/lfw_manifest.json + outputs/splits.json]
C --> D[scripts/make_pairs.py]
D --> E[pair CSVs with train/val/test rows]
E --> F[scripts/evaluate_pairs.py]
F --> G[scores.json + metrics.json + threshold_sweep.json]
F --> H[roc.png + confusion_matrix.png]
E --> I[scripts/run_tracked_eval.py]
I --> J[artifacts/runs/<run_id>/...]
J --> K[scripts/extract_error_slices.py]
E --> L[scripts/infer_pairs.py]
E --> M[scripts/load_test.py]
The current inference code path is structured as:
- deterministic image preprocessing
- embedding generation
- cosine similarity scoring
- threshold-based decision
- confidence computation
- latency measurement
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .The current dependency set includes the embedding runtime used by the inference modules (torch, torchvision, and facenet-pytorch) in addition to the Milestone 1 and 2 project requirements.
Set --lfw_root to your local LFW directory.
$LFW_ROOT="C:\path\to\lfw_or_lfw_funneled"
python scripts/ingest_lfw.py --lfw_root "$LFW_ROOT" --out_dir outputs --config configs/m1.yaml
python scripts/make_pairs.py --manifest outputs/lfw_manifest.json --splits outputs/splits.json --out_dir outputs --config configs/m1.yaml
python scripts/bench_similarity.py --out_dir outputs --config configs/m1.yamlThe real LFW evaluation pair files staged in the repository are:
artifacts/real_eval/baseline_eval_pairs.csvartifacts/real_eval/improved_eval_pairs.csv
Run the tracked baseline evaluation with:
$env:PYTHONPATH="src"
python scripts/run_tracked_eval.py --pairs artifacts/real_eval/baseline_eval_pairs.csv --config configs/m2_baseline.yaml --image-size 32 32Run the tracked improved evaluation with:
$env:PYTHONPATH="src"
python scripts/run_tracked_eval.py --pairs artifacts/real_eval/improved_eval_pairs.csv --config configs/m2_improved.yaml --image-size 32 32Each tracked run writes a directory under artifacts/runs/ containing:
scores.jsonmetrics.jsonthreshold_sweep.jsonroc.pngconfusion_matrix.pngrun.json
Generate error slices from any tracked run directory with:
python scripts/extract_error_slices.py --run-dir artifacts/runs/<run_id> --output-dir reports/error_slices/<label> --max-examples 2Milestone 3 upgrades the face verification system from a weak placeholder representation to an embedding-based pipeline, packages it in Docker, and measures runtime behavior under concurrent usage.
- FaceNet (InceptionResnetV1, pretrained on VGGFace2) embedding stage (512-dim vectors)
- Cosine similarity scoring from embeddings
- Calibrated confidence output (linear threshold scaling, range [0.0, 1.0])
- CLI inference interface (single pair and batch modes)
- Docker packaging for reproducible deployment
- Concurrency load test with throughput and p95 latency reporting
- Image A + Image B
- Preprocess (resize 160x160, normalize [-1,1])
- Embed (FaceNet InceptionResnetV1, 512-dim)
- Cosine Similarity Score
- Threshold Decision (threshold in configs/m3_inference.yaml)
- Calibrated Confidence
- Output: score, decision, confidence, latency
Confidence is computed via linear scaling around the operating threshold:
- At threshold → 0.5 (maximum uncertainty)
- Score = 1.0 → 1.0 (maximum SAME confidence)
- Score = -1.0 → 0.0 (maximum DIFFERENT confidence)
- Above 0.5 = SAME, below 0.5 = DIFFERENT
- Embedding model: FaceNet InceptionResnetV1 pretrained on VGGFace2 (512-dim)
- Threshold: 0.6 (selected on val split using balanced-accuracy rule)
- Confidence: Linear threshold scaling — score at threshold = 0.5, scales to 0.0 and 1.0 at extremes
python -m venv .venv
# Windows
.\.venv\Scripts\Activate.ps1
# Mac/Linux
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install facenet-pytorch --no-deps
pip install -e . --no-deps
pip install requests tqdm# Build
docker build -t faceoff-m3 .
# Single pair inference
docker run --rm faceoff-m3 python scripts/infer_pairs.py \
--image-a path/to/face_a.jpg \
--image-b path/to/face_b.jpg
# Batch inference
docker run --rm faceoff-m3 python scripts/infer_pairs.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--output-json reports/infer_results.json# Single pair
python scripts/infer_pairs.py --image-a path/to/a.jpg --image-b path/to/b.jpg
# Batch
python scripts/infer_pairs.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--output-json reports/infer_results.jsonpython scripts/load_test.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--num-workers 4 \
--num-requests 20 \
--output-json reports/load_test_results.jsonpython -m pytest -q- Inference config:
configs/m3_inference.yaml - CLI script:
scripts/infer_pairs.py - Load test script:
scripts/load_test.py - Sample pairs:
artifacts/real_eval/m3_sample_pairs.csv - Load test results:
reports/load_test_results.json - Sample inference results:
reports/infer_results.json
v0.3
The repository now also includes current Milestone 3 development utilities:
src/lfw_verif/embeddings.pysrc/lfw_verif/confidence.pysrc/lfw_verif/inference.pyscripts/infer_pairs.pyscripts/load_test.pyconfigs/m3_inference.yamlDockerfile
These files are the current inference-facing entrypoints in the repo and are intended to be used with the embedding-based verification path.
Example CLI help:
**MSML/MSAI 605 — Face Verification on the Labeled Faces in the Wild Dataset**
This repository contains our MSML/MSAI 605 face-verification project built around the Labeled Faces in the Wild (LFW) dataset. The codebase keeps the deterministic data-preparation backbone from Milestone 1, the evaluation and experiment-tracking workflow from Milestone 2, and the embedding-based deployable inference system added in Milestone 3.
---
## What Each Milestone Contributes
| Milestone | Main Contribution |
|---|---|
| Milestone 1 | Deterministic LFW ingestion, identity-level splitting, pair generation, vectorized scoring |
| Milestone 2 | Threshold calibration, tracked runs, error analysis, data-centric iteration, validation checks |
| **Milestone 3** | **Embedding-based inference, Docker packaging, CLI interface, concurrency load testing** |
---
## Repository Layout
src/lfw_verif/ ← core package (ingestion, pairs, similarity, evaluation, embeddings, inference, confidence) scripts/ ← CLI entrypoints (ingest, make_pairs, evaluate, tracked runs, infer, load test) configs/ ← YAML configs for all milestones tests/ ← unit, integration, determinism, and smoke tests artifacts/real_eval/ ← committed pair CSVs used for evaluation artifacts/runs/ ← tracked evaluation run outputs (generated locally) reports/ ← figures, comparison tables, and report assets outputs/ ← Milestone 1 manifests, splits, pairs, benchmarks
---
## Environment Setup
### Windows PowerShell
```powershell
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install facenet-pytorch --no-deps
pip install requests tqdm
pip install -e . --no-deps
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install facenet-pytorch --no-deps
pip install requests tqdm
pip install -e . --no-deps$LFW_ROOT="C:\path\to\lfw"
python scripts/ingest_lfw.py --lfw_root "$LFW_ROOT" --out_dir outputs --config configs/m1.yaml
python scripts/make_pairs.py --manifest outputs/lfw_manifest.json --splits outputs/splits.json --out_dir outputs --config configs/m1.yaml
python scripts/bench_similarity.py --out_dir outputs --config configs/m1.yamlStaged pair files:
artifacts/real_eval/baseline_eval_pairs.csvartifacts/real_eval/improved_eval_pairs.csv
$env:PYTHONPATH="src"
python scripts/run_tracked_eval.py --pairs artifacts/real_eval/baseline_eval_pairs.csv --config configs/m2_baseline.yaml --image-size 32 32
python scripts/run_tracked_eval.py --pairs artifacts/real_eval/improved_eval_pairs.csv --config configs/m2_improved.yaml --image-size 32 32Each tracked run writes to artifacts/runs/<run_id>/ containing scores.json, metrics.json, threshold_sweep.json, roc.png, confusion_matrix.png, and run.json.
python scripts/extract_error_slices.py --run-dir artifacts/runs/<run_id> --output-dir reports/error_slices/<label> --max-examples 2Milestone 3 upgrades the verifier from a weak placeholder representation to a full embedding-based inference system, packaged in Docker and characterized under concurrent load.
| File | Purpose |
|---|---|
src/lfw_verif/embeddings.py |
FaceNet preprocessing and embedding extraction |
src/lfw_verif/inference.py |
Full pair-level inference pipeline with stage separation |
src/lfw_verif/confidence.py |
Calibrated confidence computation |
scripts/infer_pairs.py |
CLI entrypoint — single pair and batch inference |
scripts/load_test.py |
Concurrency load test with throughput and p95 latency |
configs/m3_inference.yaml |
Inference config — model, threshold, load test settings |
Dockerfile |
Reproducible container build |
tests/test_inference.py |
Unit tests for similarity, threshold, confidence |
tests/test_smoke.py |
End-to-end smoke test for inference pipeline |
Image A + Image B
→ Preprocess (resize 160x160, normalize [-1, 1])
→ FaceNet InceptionResnetV1 (512-dim embeddings, pretrained VGGFace2)
→ Cosine Similarity Score
→ Threshold Decision (threshold: 0.6, selected on val split)
→ Calibrated Confidence
→ Output: score, decision, confidence, latency
- Embedding model: FaceNet InceptionResnetV1 pretrained on VGGFace2, 512-dim output
- Threshold: 0.6 — selected on validation split using balanced accuracy maximization (same procedure as Milestone 2)
- Confidence: Computed as a linear transformation of the similarity score relative to the threshold:
confidence = (score - threshold + 1) / 2
Range: [0, 1]
Interpretation:
- Values close to 1 → high confidence in SAME prediction
- Values close to 0 → high confidence in DIFFERENT prediction
# Build
docker build -t faceoff-m3 .
# Single pair inference
docker run --rm faceoff-m3 python scripts/infer_pairs.py \
--image-a path/to/face_a.jpg \
--image-b path/to/face_b.jpg
# Batch inference
docker run --rm faceoff-m3 python scripts/infer_pairs.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--output-json reports/infer_results.json# Single pair
python scripts/infer_pairs.py --image-a path/to/a.jpg --image-b path/to/b.jpg
# Batch
python scripts/infer_pairs.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--output-json reports/infer_results.jsonpython scripts/load_test.py \
--pairs-csv artifacts/real_eval/m3_sample_pairs.csv \
--num-workers 4 \
--num-requests 20 \
--output-json reports/load_test_results.json- Total requests processed
- Throughput (requests/second)
- Average latency
- p95 latency (tail latency)
- Failure count (if any)
Loading embedder: facenet
Running inference on 5 pairs...
[1/5] ------------------------------------------------------------
Image A : lfw-deepfunneled/Jane_Fonda/Jane_Fonda_0002.jpg
Image B : lfw-deepfunneled/Jane_Fonda/Jane_Fonda_0001.jpg
Score : 0.076105
Threshold : 0.6
Decision : DIFFERENT
Confidence : 0.3363
Latency : 0.2238s
------------------------------------------------------------
[2/5] ------------------------------------------------------------
Image A : lfw-deepfunneled/George_Tenet/George_Tenet_0001.jpg
Image B : lfw-deepfunneled/George_Tenet/George_Tenet_0002.jpg
Score : 0.670348
Threshold : 0.6
Decision : SAME
Confidence : 0.5879
Latency : 0.1126s
------------------------------------------------------------
| Artifact | Path |
|---|---|
| Inference config | configs/m3_inference.yaml |
| CLI script | scripts/infer_pairs.py |
| Load test script | scripts/load_test.py |
| Sample pairs | artifacts/real_eval/m3_sample_pairs.csv |
| Sample inference output | reports/infer_results.json |
| Load test results | reports/load_test_results.json |
Milestone 2 report outputs live in reports/, including:
Milestone2_report.pdfreal_run_comparison.csvreal_run_comparison.mdreport_manifest.json- ROC and confusion-matrix figures
Tracked evaluation outputs are written under artifacts/runs/.
# Full test suite
python -m pytest -q
# Milestone 3 inference tests only
python -m pytest tests/test_inference.py tests/test_smoke.py -v| Tag | Milestone |
|---|---|
v0.1 |
Milestone 1 — Data pipeline |
v0.2 |
Milestone 2 — Evaluation and tracking |
v0.3 |
Milestone 3 — Embedding inference and Docker |
python scripts/infer_pairs.py --help python scripts/load_test.py --help
## Docker
A Docker build path is defined in `Dockerfile`.
Build the image with:
```powershell
docker build -t lfw-verification .
The container currently installs the project dependencies and the embedding runtime used by the inference modules.
Milestone 2 report outputs live in reports/, including:
Milestone2_report.pdfreal_run_comparison.csvreal_run_comparison.mdreport_manifest.json- ROC and confusion-matrix figures
Tracked evaluation outputs are written under artifacts/runs/.
Run the full test suite with:
python -m pytest -qIf you only want the newer inference-related tests:
python -m pytest tests/test_inference.py tests/test_smoke.py -qMilestone 4 finalizes the system with a responsible audit, hardware-aware profiling, and a clean reproducible release.
| Addition | Location |
|---|---|
| Profiling script (stage-wise latency + batch sensitivity) | scripts/profile_inference.py |
| System Card (intended use, limits, fairness risks, metrics) | reports/system_card.md |
| Reproducibility checklist (exact commands + artifact paths) | reports/reproducibility_checklist.md |
| Profiling results (CPU baseline, batch sensitivity) | reports/profiling_results.json |
| Stage | Latency | % of Total |
|---|---|---|
| Preprocessing | ~7ms | 3.76% |
| Embedding (×2) | ~89ms | 96.18% |
| Scoring | <1ms | 0.06% |
| End-to-end | ~186ms | 100% |
Embedding generation dominates latency. Preprocessing and scoring are negligible.
| Batch Size | Avg Latency | Throughput |
|---|---|---|
| 1 | 187.5ms | 5.33 rps |
| 2 | 147.3ms | 6.79 rps |
| 4 | 143.4ms | 6.97 rps |
| 8 | 151.2ms | 6.61 rps |
| 16 | 163.9ms | 6.10 rps |
Optimal throughput at batch size 4 (~7 rps). Larger batches show slight degradation on CPU due to memory overhead.
v1.0-final
| Artifact | Path |
|---|---|
| System Card | reports/system_card.md |
| Reproducibility checklist | reports/reproducibility_checklist.md |
| Profiling results | reports/profiling_results.json |
| Inference config | configs/m3_inference.yaml |
| Sample inference output | reports/infer_results.json |
| Load test results | reports/load_test_results.json |