Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse filesFiles changed (13)
- .gitattributes+1
- Dockerfile+3-2
- README.md+71
- images/Densities.pngAdded
- images/ROC.pngAdded
- images/[Originals]/ROC.pngAdded
- images/[Originals]/confusion_matrix.pngAdded
- images/confusion_matrix.pngAdded
- images/faceverification_demo.gifAdded
- pyproject.toml+7-3
- requirements.txt+2-26
- src/faceverification/config.py+1-1
- uv.lock+14-6
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textimages/faceverification_demo.gif filter=lfs diff=lfs merge=lfs -text
7 unmodified lines891011121314151617181920217 unmodified linesWORKDIR /appRUN apt-get update && apt-get install -y --no-install-recommends \libgl1 \libglib2.0-0 \&& rm -rf /var/lib/apt/lists/*COPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip setuptools "wheel>=0.46.2"RUN pip install --no-cache-dir -r requirements.txtCOPY pyproject.toml README.md ./COPY src ./src7 unmodified lines89101112131415161718192021227 unmodified linesWORKDIR /appRUN apt-get update && apt-get upgrade -y \&& apt-get install -y --no-install-recommends \libgl1 \libglib2.0-0 \&& rm -rf /var/lib/apt/lists/*COPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip setuptools "wheel>=0.46.2"RUN pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txtCOPY pyproject.toml README.md ./COPY src ./src
22 unmodified lines2324252627283 unmodified lines32333435363722 unmodified linesThe app lets users add known people to a local embeddings database and verify whether a new face image matches one of the stored identities.## Features- Face detection and preprocessing from uploaded images3 unmodified lines- FastAPI interface for containerized API deployments- Docker-based Hugging Face Space deployment## Tech Stack- Python22 unmodified lines2324252627282930313233343536373839403 unmodified lines444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710822 unmodified linesThe app lets users add known people to a local embeddings database and verify whether a new face image matches one of the stored identities.This demo was built to show that FaceNet, despite being an older architecture,is still a strong and practical baseline for face embedding workflows. Itsmoderate runtime footprint also makes it an interesting candidate for constraineddeployments, including edge-style scenarios when hardware, latency, and accuracyrequirements are compatible.The project is also intended as a reusable AI engineering template: the samestructure can be adapted to build CI/CD pipelines for other models, or extendedfrom image uploads into a video pipeline for near real-time face recognition.## Features- Face detection and preprocessing from uploaded images3 unmodified lines- FastAPI interface for containerized API deployments- Docker-based Hugging Face Space deployment## Architecture```mermaidflowchart LRA[Upload] --> B[MTCNN]B --> C[Crop]C --> D[FaceNet]D --> E[Normalize]E --> F[ChromaDB]F --> G[Threshold]G --> H[Match]```Images are first passed through MTCNN for face detection and cropping. FaceNetthen produces an embedding, which is L2-normalized before being stored orqueried in ChromaDB. Verification compares the nearest stored embedding againstthe calibrated distance threshold.## Model EvaluationThe verification threshold was calibrated with a small study on the`bitmind/lfw` dataset, a Hugging Face version of Labeled Faces in the Wild(LFW). The study builds same-person and different-person image pairs, splitsthem into calibration and held-out evaluation sets, and evaluates L2 distancebetween L2-normalized FaceNet embeddings.For this demo, the selected threshold is:```textsame person if L2 distance <= 1.0764different person if L2 distance > 1.0764```This value was chosen on the calibration split because it maximized balancedaccuracy while staying below the distance region where different-person pairsstart to dominate. The held-out evaluation split contains 720 same-person and720 different-person pairs.Held-out evaluation results:| Metric | Value || --- | ---: || AUC-ROC | 0.9838 || Accuracy | 0.9653 || FAR | 0.0097 || FRR | 0.0597 || TPR | 0.9403 || Calibrated threshold | 1.0764 || Calibration EER threshold | 1.1857 |These metrics are intended to justify the threshold for this demo dataset, notas a production biometric benchmark.## Tech Stack- Python
13 unmodified lines1415161718192021222324252633 unmodified lines60616213 unmodified lines"pydantic>=2.11.10,<=2.12.5","pydantic-settings>=2.14.1","chromadb>=1.5.9","pytest>=9.0.3","pytest-cov>=7.1.0","fastapi>=0.136.1","pyjwt>=2.10.1","python-multipart>=0.0.28","uvicorn[standard]>=0.46.0","ruff>=0.15.13","torch>=2.12.0","torchvision>=0.27.0",]33 unmodified lines[tool.ruff.lint]select = ["E", "F", "I", "B", "UP", "SIM"]13 unmodified lines1415161718192021222333 unmodified lines5758596061626364656613 unmodified lines"pydantic>=2.11.10,<=2.12.5","pydantic-settings>=2.14.1","chromadb>=1.5.9","fastapi>=0.136.1","pyjwt>=2.10.1","python-multipart>=0.0.28","uvicorn[standard]>=0.46.0","torch>=2.12.0","torchvision>=0.27.0",]33 unmodified lines[tool.ruff.lint]select = ["E", "F", "I", "B", "UP", "SIM"][dependency-groups]dev = ["pytest>=9.0.3","pytest-cov>=7.1.0","ruff>=0.15.13",]
123456743 unmodified lines515253545556575859606176 unmodified lines13813914014114214314414572 unmodified lines2182192202212222232243 unmodified lines22822923023123223323423523623723 unmodified lines26126226326426526626726826927027127227327427527627727827928028137 unmodified lines31932032132232332432532616 unmodified lines343344345346347348349350# This file was autogenerated by uv via the following command:# uv --cache-dir .uv-cache export --locked --no-hashes --no-emit-project --format requirements.txt --output-file requirements.txt--find-links https://download.pytorch.org/whl/cpu/torch/--find-links https://download.pytorch.org/whl/cpu/torchvision/aiohappyeyeballs==2.6.1# via aiohttpaiohttp==3.13.543 unmodified lines# via# build# click# pytest# tqdm# uvicorncoverage==7.14.0# via pytest-covdatasets==4.8.5# via faceverificationdill==0.4.176 unmodified lines# via opentelemetry-apiimportlib-resources==7.1.0# via chromadbiniconfig==2.3.0# via pytestjinja2==3.1.6# via# gradio72 unmodified lines# gradio-client# huggingface-hub# onnxruntime# pytestpandas==3.0.2# via# datasets3 unmodified lines# facenet-pytorch# gradio# torchvisionpluggy==1.6.0# via# pytest# pytest-covpropcache==0.5.2# via# aiohttp23 unmodified linespydub==0.25.1# via gradiopygments==2.20.0# via# pytest# richpyjwt==2.12.1# via faceverificationpypika==0.51.1# via chromadbpyproject-hooks==1.2.0# via buildpytest==9.0.3# via# faceverification# pytest-covpytest-cov==7.1.0# via faceverificationpython-dateutil==2.9.0.post0# via# kubernetes37 unmodified lines# via# jsonschema# referencingruff==0.15.13# via faceverificationsafehttpx==0.1.7# via gradiosemantic-version==2.10.016 unmodified lines# via chromadbtokenizers==0.23.1# via chromadbtomli==2.4.1 ; python_full_version <= '3.11'# via coveragetomlkit==0.14.0# via gradiotorch==2.12.0 ; sys_platform == 'darwin'1234543 unmodified lines495051525354555676 unmodified lines13313413513613713872 unmodified lines2112122132142152163 unmodified lines22022122222322422523 unmodified lines24925025125225325425525625725825926026137 unmodified lines29930030130230330416 unmodified lines321322323324325326# This file was autogenerated by uv via the following command:# uv --cache-dir .uv-cache export --locked --no-dev --no-hashes --no-emit-project --format requirements.txt --index https://download.pytorch.org/whl/cpu --output-file requirements.txtaiohappyeyeballs==2.6.1# via aiohttpaiohttp==3.13.543 unmodified lines# via# build# click# tqdm# uvicorndatasets==4.8.5# via faceverificationdill==0.4.176 unmodified lines# via opentelemetry-apiimportlib-resources==7.1.0# via chromadbjinja2==3.1.6# via# gradio72 unmodified lines# gradio-client# huggingface-hub# onnxruntimepandas==3.0.2# via# datasets3 unmodified lines# facenet-pytorch# gradio# torchvisionpropcache==0.5.2# via# aiohttp23 unmodified linespydub==0.25.1# via gradiopygments==2.20.0# via richpyjwt==2.12.1# via faceverificationpypika==0.51.1# via chromadbpyproject-hooks==1.2.0# via buildpython-dateutil==2.9.0.post0# via# kubernetes37 unmodified lines# via# jsonschema# referencingsafehttpx==0.1.7# via gradiosemantic-version==2.10.016 unmodified lines# via chromadbtokenizers==0.23.1# via chromadbtomlkit==0.14.0# via gradiotorch==2.12.0 ; sys_platform == 'darwin'
10 unmodified lines1112131415161710 unmodified linesvector_db_collection: str = "face_embeddings"vector_db_persist_directory: str | None = Nonevector_db_n_results: int = 5face_match_threshold: float = 1.08device: Literal["auto", "cpu", "cuda"] = "auto"mtcnn_thresholds: tuple[float, float, float] = (0.6, 0.7, 0.95)10 unmodified lines1112131415161710 unmodified linesvector_db_collection: str = "face_embeddings"vector_db_persist_directory: str | None = Nonevector_db_n_results: int = 5face_match_threshold: float = 1.0764device: Literal["auto", "cpu", "cuda"] = "auto"mtcnn_thresholds: tuple[float, float, float] = (0.6, 0.7, 0.95)
567 unmodified lines5685695705715725735745755765775781 unmodified line5805815825835845856 unmodified lines592593594595596597598599600601602603604605606607567 unmodified lines{ name = "pydantic" },{ name = "pydantic-settings" },{ name = "pyjwt" },{ name = "pytest" },{ name = "pytest-cov" },{ name = "python-dotenv" },{ name = "python-multipart" },{ name = "ruff" },{ name = "torch", version = "2.12.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform == 'darwin'" },{ name = "torch", version = "2.12.0+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform != 'darwin'" },{ name = "torchvision", version = "0.27.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform == 'darwin'" },1 unmodified line{ name = "uvicorn", extra = ["standard"] },][package.metadata]requires-dist = [{ name = "chromadb", specifier = ">=1.5.9" },6 unmodified lines{ name = "pydantic", specifier = ">=2.11.10,<=2.12.5" },{ name = "pydantic-settings", specifier = ">=2.14.1" },{ name = "pyjwt", specifier = ">=2.10.1" },{ name = "pytest", specifier = ">=9.0.3" },{ name = "pytest-cov", specifier = ">=7.1.0" },{ name = "python-dotenv", specifier = ">=1.2.2" },{ name = "python-multipart", specifier = ">=0.0.28" },{ name = "ruff", specifier = ">=0.15.13" },{ name = "torch", specifier = ">=2.12.0", index = "https://download.pytorch.org/whl/cpu" },{ name = "torchvision", specifier = ">=0.27.0", index = "https://download.pytorch.org/whl/cpu" },{ name = "uvicorn", extras = ["standard"], specifier = ">=0.46.0" },][[package]]name = "fastapi"version = "0.136.1"567 unmodified lines5685695705715725735745751 unmodified line5775785795805815825835845855865875885896 unmodified lines596597598599600601602603604605606607608609610611612613614615567 unmodified lines{ name = "pydantic" },{ name = "pydantic-settings" },{ name = "pyjwt" },{ name = "python-dotenv" },{ name = "python-multipart" },{ name = "torch", version = "2.12.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform == 'darwin'" },{ name = "torch", version = "2.12.0+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform != 'darwin'" },{ name = "torchvision", version = "0.27.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "sys_platform == 'darwin'" },1 unmodified line{ name = "uvicorn", extra = ["standard"] },][package.dev-dependencies]dev = [{ name = "pytest" },{ name = "pytest-cov" },{ name = "ruff" },][package.metadata]requires-dist = [{ name = "chromadb", specifier = ">=1.5.9" },6 unmodified lines{ name = "pydantic", specifier = ">=2.11.10,<=2.12.5" },{ name = "pydantic-settings", specifier = ">=2.14.1" },{ name = "pyjwt", specifier = ">=2.10.1" },{ name = "python-dotenv", specifier = ">=1.2.2" },{ name = "python-multipart", specifier = ">=0.0.28" },{ name = "torch", specifier = ">=2.12.0", index = "https://download.pytorch.org/whl/cpu" },{ name = "torchvision", specifier = ">=0.27.0", index = "https://download.pytorch.org/whl/cpu" },{ name = "uvicorn", extras = ["standard"], specifier = ">=0.46.0" },][package.metadata.requires-dev]dev = [{ name = "pytest", specifier = ">=9.0.3" },{ name = "pytest-cov", specifier = ">=7.1.0" },{ name = "ruff", specifier = ">=0.15.13" },][[package]]name = "fastapi"version = "0.136.1"
.gitattributes+1
Dockerfile+3-2
README.md+71
images/Densities.pngAdded

images/ROC.pngAdded

images/[Originals]/ROC.pngAdded

images/[Originals]/confusion_matrix.pngAdded

images/confusion_matrix.pngAdded

images/faceverification_demo.gifAdded

Large File Pointer Details
- SHA256: 656e8b4d2d98ee7150e76be63b548064dc0a36cd4346fd2ca1c8ea77a4f88094
- Pointer size: 131 Bytes
- Size of remote file: 162 kB
pyproject.toml+7-3
requirements.txt+2-26
src/faceverification/config.py+1-1
uv.lock+14-6