Professional geometric face recognition library with AI-powered matching
Project description
GFRAM - Geometric Face Recognition and Matching
Professional face recognition library based on geometric features and GeometricTransformer architecture โ lightweight, privacy-preserving, and highly accurate!
๐ Key Features
- ๐ท Pure Geometric Approach: 150 geometric features from 478 3D facial landmarks
- ๐ค Custom AI Architecture: GeometricTransformer with Multi-Head Self-Attention
- โก Lightweight: Only 1.3M parameters (50x smaller than ResNet-100)
- ๐ Privacy-Preserving: Only geometric vectors transmitted, not images
- ๐ High Performance: 99.52% accuracy on LFW, <100ms on CPU
- ๐ฆ Easy Installation:
pip install gfram - ๐ Cross-Platform: Windows, macOS, Linux, and mobile devices
๐ฏ Scientific Innovation
GFRAM introduces a novel hybrid approach combining geometric analysis with deep learning:
| Innovation | Description |
|---|---|
| 478 3D Landmarks | MediaPipe FaceMesh vs traditional 68 points (7x more data) |
| 150 Geometric Features | Distances, ratios, angles, areas, Delaunay, symmetry, Hu moments |
| GeometricTransformer | Self-attention on landmark relationships (1.3M params) |
| Hybrid Matching | 30% geometric + 70% semantic = 99.52% accuracy |
| Privacy by Design | Impossible to reconstruct face from geometric vector |
๐ Performance Comparison
| Model | LFW Acc | CFP-FP | Params | Speed (CPU) | Model Size |
|---|---|---|---|---|---|
| ArcFace-R100 | 99.83% | 98.27% | 65M | ~450ms | 249 MB |
| MobileFaceNet | 99.28% | 96.12% | 1M | ~35ms | 4.1 MB |
| GFRAM | 99.52% | 95.43% | 1.3M | <100ms | 5.8 MB |
GFRAM achieves competitive accuracy with significantly lower computational requirements
๐ฆ Installation
Basic Installation
pip install gfram
Full Installation (with all features)
pip install gfram[all]
From Source
git clone https://github.com/feruza-42h/gfram.git
cd gfram
pip install -e .
Requirements
- Python 3.8+
- PyTorch 1.9+
- MediaPipe 0.9+
- NumPy, SciPy, OpenCV
๐ Quick Start
Face Recognition in 5 Lines
from gfram import GFRAMRecognizer
# Initialize (model auto-downloads on first run)
recognizer = GFRAMRecognizer()
# Add people to database
recognizer.add_user("john_doe", ["john1.jpg", "john2.jpg", "john3.jpg"])
recognizer.add_user("jane_smith", ["jane1.jpg", "jane2.jpg"])
# Identify unknown face
result = recognizer.identify("unknown.jpg")
print(f"Identity: {result.user_id}, Confidence: {result.confidence:.2%}")
# Output: Identity: john_doe, Confidence: 98.45%
Face Verification (1:1 Matching)
from gfram import GFRAMRecognizer
recognizer = GFRAMRecognizer()
# Compare two faces
match = recognizer.verify("photo_a.jpg", "photo_b.jpg")
print(f"Same person: {match.match}, Score: {match.score:.3f}")
# Output: Same person: True, Score: 0.892
Extract Geometric Features Only
from gfram import GeometricExtractor
extractor = GeometricExtractor()
# Extract 150 geometric features
features = extractor.extract("face.jpg")
print(f"Feature vector shape: {features.shape}") # (150,)
print(f"Interocular distance: {features[0]:.4f}")
print(f"Face width/height ratio: {features[45]:.4f}")
Using GeometricTransformer Directly
import torch
from gfram.models import GeometricTransformer
# Create model
model = GeometricTransformer(
d_model=256,
nhead=8,
num_layers=4,
dim_feedforward=1024
)
# Forward pass with landmarks
landmarks = torch.randn(1, 478, 3) # (batch, points, xyz)
embedding = model(landmarks) # (1, 512)
print(f"Embedding shape: {embedding.shape}")
Real-time Recognition from Webcam
from gfram import GFRAMRecognizer
import cv2
recognizer = GFRAMRecognizer()
recognizer.load("my_database.gfram")
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Recognize faces in frame
results = recognizer.identify_frame(frame)
for face in results:
# Draw bounding box and name
x, y, w, h = face.bbox
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, f"{face.user_id}: {face.confidence:.1%}",
(x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
cv2.imshow("GFRAM Recognition", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
๐๏ธ Architecture
System Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GFRAM Pipeline โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Input Image โ
โ โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ RetinaFace โ โ โ MediaPipe โ โ โ 478 3D Landmarks โ โ
โ โ Detection โ โ FaceMesh โ โ (x, y, z) โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ Geometric Features โ โ GeometricTransformer โโ
โ โ G โ โยนโตโฐ โ โ E โ โโตยนยฒ โโ
โ โ (~6ms CPU) โ โ (~45ms CPU) โโ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Hybrid Similarity Matching โ โ
โ โ S = 0.3ยทsim_G + 0.7ยทsim_E โ โ
โ โ HNSW Index: O(log n) search โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ Identity + Confidence โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Geometric Features (150 total)
| Category | Count | Description | Invariance |
|---|---|---|---|
| Euclidean Distances | 45 | Key landmark distances | Rotation |
| Proportion Ratios | 35 | Normalized ratios, Golden ratio | Scale |
| Angles | 30 | Angles between landmark triplets | Scale, Translation |
| Areas | 15 | Triangle areas from landmarks | Rotation |
| Delaunay Features | 10 | Triangulation topology | Topological |
| Symmetry | 8 | Bilateral symmetry coefficients | Scale |
| Hu Moments | 7 | Shape invariants | Affine |
GeometricTransformer Architecture
Input: X โ โ^(478ร3) โ 3D Landmarks
โ
Linear Embedding: โยณ โ โยฒโตโถ (768 params)
โ
3D Positional Encoding (122K params)
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Transformer Encoder ร 4 โ
โ โโโ Multi-Head Self-Attention โ
โ โ (8 heads, d_k=32) โ
โ โโโ Add & LayerNorm โ
โ โโโ Feed-Forward (256โ1024โ256) โ
โ โโโ Add & LayerNorm โ
โ (1.05M params) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Global Average Pooling: โ^(478ร256) โ โยฒโตโถ
โ
Projection Head: โยฒโตโถ โ โโตยนยฒ (131K params)
โ
L2 Normalization
โ
Output: e โ โโตยนยฒ โ Normalized Embedding
Total: ~1.3M parameters
๐ API Reference
GFRAMRecognizer
class GFRAMRecognizer:
def __init__(
self,
model_version: str = "2.0.0",
device: str = "cpu", # or "cuda"
alpha: float = 0.3, # geometric weight
beta: float = 0.7, # semantic weight
threshold: float = 0.68
)
def add_user(self, user_id: str, images: List[str]) -> None
def remove_user(self, user_id: str) -> bool
def identify(self, image: str, k: int = 5) -> IdentifyResult
def verify(self, image1: str, image2: str) -> VerifyResult
def identify_frame(self, frame: np.ndarray) -> List[FaceResult]
def save(self, path: str) -> None
def load(self, path: str) -> None
def get_user_count(self) -> int
GeometricExtractor
class GeometricExtractor:
def extract(self, image: Union[str, np.ndarray]) -> np.ndarray
def extract_from_landmarks(self, landmarks: np.ndarray) -> np.ndarray
def get_feature_names(self) -> List[str]
GeometricTransformer
class GeometricTransformer(nn.Module):
def __init__(
self,
d_model: int = 256,
nhead: int = 8,
num_layers: int = 4,
dim_feedforward: int = 1024,
dropout: float = 0.1,
output_dim: int = 512
)
def forward(self, landmarks: torch.Tensor) -> torch.Tensor
๐ง Configuration
Environment Variables
# Model cache directory (default: ~/.gfram/models/)
export GFRAM_CACHE_DIR=/path/to/cache
# Server URL for model downloads
export GFRAM_SERVER_URL=https://gfram.uz
# Disable auto-update
export GFRAM_AUTO_UPDATE=0
Config File (~/.gfram/config.yaml)
model:
version: "2.0.0"
device: "cpu"
matching:
alpha: 0.3
beta: 0.7
threshold: 0.68
hnsw:
M: 16
ef_construction: 200
ef_search: 50
๐ฌ Research & Citation
If you use GFRAM in your research, please cite:
@article{gfram2024,
title={GFRAM: Geometric Face Recognition through Advanced Mathematical
Descriptors and Transformer Architecture},
author={Ortiqova, Feruza S.},
journal={arXiv preprint arXiv:2024.xxxxx},
year={2024},
institution={Tashkent University of Information Technologies}
}
Key Publications
- GeometricTransformer: Novel transformer architecture for landmark-based face recognition
- Hybrid Matching: Combining geometric and semantic embeddings for improved accuracy
- Privacy-Preserving FR: Geometric-only data transmission for GDPR compliance
๐ Project Structure
gfram/
โโโ __init__.py # Public API exports
โโโ core.py # GFRAMRecognizer main class
โโโ detectors/
โ โโโ retinaface.py # Face detection
โ โโโ mediapipe.py # 478 landmark extraction
โโโ geometry/
โ โโโ features.py # All 150 features
โ โโโ distances.py # Euclidean distances (45)
โ โโโ ratios.py # Proportions (35)
โ โโโ angles.py # Angles (30)
โ โโโ areas.py # Areas (15)
โ โโโ delaunay.py # Triangulation (10)
โ โโโ symmetry.py # Symmetry (8)
โ โโโ moments.py # Hu moments (7)
โ โโโ normalize.py # 3-step normalization
โโโ models/
โ โโโ transformer.py # GeometricTransformer
โ โโโ positional.py # 3D Positional Encoding
โ โโโ losses.py # ArcFace, Triplet, InfoNCE
โโโ matching/
โ โโโ hnsw.py # HNSW index wrapper
โ โโโ similarity.py # Hybrid similarity
โ โโโ memory.py # Prototype Memory Bank
โโโ utils/
โโโ visualization.py # Plotting utilities
โโโ io.py # File operations
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
git clone https://github.com/feruza-42h/gfram.git
cd gfram
pip install -e ".[dev]"
pytest # Run tests
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- MediaPipe team for excellent landmark detection
- PyTorch community for deep learning framework
- FAISS and hnswlib for efficient similarity search
- InsightFace for benchmark datasets and evaluation protocols
๐ Contact & Support
- Author: Ortiqova Feruza Sardor qizi
- Email: feruzaortiqova42@gmail.com
- GitHub: @feruza-42h
- Documentation: https://gfram.uz/docs
- Issues: GitHub Issues
Made with โค๏ธ in Tashkent for the research community
GFRAM โ Where Geometry Meets Intelligence
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gfram-3.0.0.tar.gz.
File metadata
- Download URL: gfram-3.0.0.tar.gz
- Upload date:
- Size: 61.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
718dac7072b49fb99872db1b1bf9028a5a57deb53280d9f7c67a5d18d0a4eb71
|
|
| MD5 |
2c3dbe00ba9ee63f52ff81b67ec5fb6d
|
|
| BLAKE2b-256 |
5ad8931de06bed91c7d04d52b667177f483c2e63d93544fc0ca4981ea80bb3f2
|
File details
Details for the file gfram-3.0.0-py3-none-any.whl.
File metadata
- Download URL: gfram-3.0.0-py3-none-any.whl
- Upload date:
- Size: 57.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f16a3902b8c88bee7ba232af2d0f8d1a679ba0832115badda150660f046eab16
|
|
| MD5 |
ea1f042e2d21c33985b11aed37a27628
|
|
| BLAKE2b-256 |
47b58f7019c9bddca31b4f32303972ff8e11aea63b65bbca9dadc42aafb7b054
|