Skip to main content

Face Similarity

Project description

JaviFace 🎯

Accurate face comparison — selfie vs selfie, selfie vs ID, ID vs ID.

PyPI version Python License: MIT


What is JaviFace?

JaviFace is a lightweight Python library for face verification. Given two face images, it tells you whether they belong to the same person — with scenario-specific thresholds calibrated for selfie and ID document comparisons.

Under the hood it runs two models:

Component Format Role
RetinaFace (ResNet-50) TensorFlow H5 Face detection, alignment & crop
FaceVerifier ONNX 512-dim embedding + cosine similarity

FaceVerifier runs on CUDA, CoreML, or CPU — automatically selected based on your hardware.


Install

pip install javiface

or

poetry add javiface

Required: tensorflow for RetinaFace detection. On TF ≥ 2.16 also install:

pip install tf-keras

GPU acceleration (NVIDIA CUDA): replace the default onnxruntime with onnxruntime-gpu:

pip uninstall onnxruntime
pip install "onnxruntime-gpu>=1.22.0"

Quick Start

from PIL import Image
from javiface import JaviFace, RetinaFace as rf

# Load models
model = rf.build_model("retinaface.h5")
verifier = JaviFace("javi_face_v1.onnx")

# Load images
img1 = Image.open("selfie.jpg")
img2 = Image.open("id_photo.jpg")

# Crop & align faces (PIL in → PIL out)
face1 = rf.get_face(img1, model)
face2 = rf.get_face(img2, model)

# Compare
# threshold = 0.2621 -> Selfie vs Selfie [default]
# threshold = 0.1838 -> Selfie vs ID document
# threshold = 0.1990 -> ID document vs ID document
result = verifier.compare(face1, face2, threshold=0.2621)

print(result)
# {'similarity': 0.214, 'same_person': False}

Model Metadata

Parameter Value
Embedding dim 512
Input size 224 × 224
Similarity metric Cosine
Normalize mean [0.485, 0.456, 0.406]
Normalize std [0.229, 0.224, 0.225]

Model Cards

retinaface.h5 — Face Detector

Field Value
Architecture ResNet-50 + FPN + SSH heads
Framework TensorFlow / Keras
Output Bounding boxes + 5 face landmarks
Primary use Face detection, alignment & crop

javi_face_v1.onnx — Face Verifier

ResNet-50 backbone + ArcFace head, trained from scratch on ~860 K face images across 94 K identities.

Field Value
Architecture ResNet-50 + ArcFace (m=0.5, s=64)
Embedding dim 512 — L2-normalized (unit hypersphere)
Training data 861 597 images · 94 261 identities
Export format ONNX (CUDA / CoreML / CPU)
Primary use KYC — selfie vs ID document verification

Performance

Scenario ROC-AUC EER Precision Recall
Selfie vs Selfie 0.9993 0.485 % 99.54 % 99.33 %
Selfie vs ID document 0.9951 1.862 % 97.31 % 97.47 %
ID vs ID 0.9930 2.228 % 97.60 % 97.08 %

Similarity Distribution — Selfie vs Selfie

Similarity Distribution

Full training details and evaluation breakdown → MODEL_CARD.md


Thresholds

Choose the threshold that matches your use case. A similarity ≥ threshold means same person.

Scenario Threshold Use when
Selfie vs Selfie 0.2621 Comparing two live photos
Selfie vs ID document 0.1838 KYC / onboarding flows
ID vs ID 0.1990 Document deduplication

Lower threshold → stricter match. ID photos have less variation than selfies, so the bar is lower.


Hardware Acceleration

FaceVerifier (ONNX) automatically selects the best available provider:

FaceVerifier loaded — provider: CoreML   # macOS
FaceVerifier loaded — provider: CUDA     # NVIDIA GPU
FaceVerifier loaded — provider: CPU      # fallback

RetinaFace (TensorFlow) uses whatever device TF has available. Set TF_FORCE_GPU_ALLOW_GROWTH=true (already set internally) to avoid reserving all VRAM.


Author

Javier Daza · javierjdaza@gmail.com · GitHub


MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

javiface-0.1.7.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

javiface-0.1.7-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file javiface-0.1.7.tar.gz.

File metadata

  • Download URL: javiface-0.1.7.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for javiface-0.1.7.tar.gz
Algorithm Hash digest
SHA256 c654ac8a733a587e39d4fa555c47885c763ece1add86b6969eef44ac0eb0e446
MD5 57ab015f8fae341b4ce4cc46e8964120
BLAKE2b-256 5375141ecf65b27958aaedf80d01b56a4680d4cd1793c953fc54e8e194b215ea

See more details on using hashes here.

File details

Details for the file javiface-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: javiface-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for javiface-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b26cf9489b1dd883c36e4444123c9c0ee5aa8b12ff427cd847cfe763bf960087
MD5 d0bc14b49655f737bf51e1d00ec9f9f3
BLAKE2b-256 6ed6ff365fdc4c1ed04f3ec6737b1ae86db94919b891f02fa9ff3012e8485836

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page