Real-time face recognition library: detection, embedding, tracking and matching.
Project description
FaceHub
Real-time face recognition library — detection, embedding, tracking, and matching.
Features
- Detection: insightface RetinaFace with GPU auto-detection (CUDA / DirectML) and CPU fallback.
- Embedding: ArcFace 512-dim L2-normalized features.
- Recognition: 1:N cosine-similarity matching with a versioned encoding cache.
- Tracking: IoU-based multi-face tracker with majority-vote identity smoothing.
- Camera: cross-platform capture thread (Windows DShow, macOS AVFoundation, Linux V4L2).
- Protocol:
DetectorProtocollets you plug in your own detector (YOLO, MediaPipe, etc.).
Installation
pip install face-hub
Optional GPU backends:
# Windows DirectML
pip uninstall -y onnxruntime
pip install face-hub[gpu-win]
# Linux NVIDIA CUDA
pip uninstall -y onnxruntime
pip install face-hub[gpu-linux]
Quick Start
from face_hub import (
FaceHubPipeline, FaceDetector, FaceRecognizer,
FaceTracker, FaceDatabase, CameraThread,
)
# 1. Initialize components
db = FaceDatabase(db_path="face_db.json")
detector = FaceDetector(device="auto", det_size=640)
recognizer = FaceRecognizer(tolerance=0.45)
tracker = FaceTracker(smooth_frames=5)
camera = CameraThread(camera_id=0, width=640, height=360)
# 2. Assemble the pipeline
pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
pipeline.start()
# 3. Loop
try:
while True:
result = pipeline.process_frame()
if result is None:
continue
for face in result.known_faces:
print(f"{face.name} ({face.confidence:.0%})")
finally:
pipeline.stop()
Custom Detector
Any object satisfying DetectorProtocol can be plugged into the pipeline:
from face_hub import DetectorProtocol, DetectionWithEmbedding, BBox
class MyYoloDetector:
def detect_with_embeddings(self, frame):
boxes = self.yolo_model(frame)
return [
DetectionWithEmbedding(
bbox=BBox(x1=b.x1, y1=b.y1, x2=b.x2, y2=b.y2),
confidence=b.conf,
embedding=self.embedder(frame[b.y1:b.y2, b.x1:b.x2]),
quality_pass=True,
)
for b in boxes
]
pipeline = FaceHubPipeline(camera, MyYoloDetector(), recognizer, tracker, db)
Documentation
📖 Online Documentation — Full API reference in English & 中文
To preview locally:
pip install -r docs/requirements.txt
mkdocs serve -f docs/mkdocs.yml
License
The FaceHub code is released under the MIT License.
⚠️ The pre-trained
buffalo_lmodel downloaded automatically by insightface is subject to insightface's own model license and is for non-commercial research use unless separate authorization is obtained. See the documentation for details.
FaceHub(中文)
实时人脸识别库 — 检测、特征提取、追踪、匹配。
特性
- 检测:insightface RetinaFace,自动检测 CUDA / DirectML GPU 并回退 CPU。
- 特征:ArcFace 512 维 L2 归一化特征向量。
- 识别:1:N 余弦相似度匹配,带版本号缓存。
- 追踪:基于 IoU 的多目标追踪 + 多数投票身份平滑。
- 摄像头:跨平台采集线程(Windows DShow、macOS AVFoundation、Linux V4L2)。
- 协议:
DetectorProtocol允许接入自定义检测器(YOLO、MediaPipe 等)。
安装
pip install face-hub
可选 GPU 后端:
# Windows DirectML
pip uninstall -y onnxruntime
pip install face-hub[gpu-win]
# Linux NVIDIA CUDA
pip uninstall -y onnxruntime
pip install face-hub[gpu-linux]
快速开始
from face_hub import (
FaceHubPipeline, FaceDetector, FaceRecognizer,
FaceTracker, FaceDatabase, CameraThread,
)
# 1. 初始化组件
db = FaceDatabase(db_path="face_db.json")
detector = FaceDetector(device="auto", det_size=640)
recognizer = FaceRecognizer(tolerance=0.45)
tracker = FaceTracker(smooth_frames=5)
camera = CameraThread(camera_id=0, width=640, height=360)
# 2. 组装流水线
pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
pipeline.start()
# 3. 循环处理
try:
while True:
result = pipeline.process_frame()
if result is None:
continue
for face in result.known_faces:
print(f"{face.name} ({face.confidence:.0%})")
finally:
pipeline.stop()
自定义检测器
任何满足 DetectorProtocol 的对象都可以接入流水线,示例见上文英文部分。
文档
📖 在线文档 — 完整中英 API 文档
许可
FaceHub 代码 采用 MIT License。
⚠️ insightface 自动下载的
buffalo_l预训练模型受其模型许可约束,默认仅供非商用研究使用;商业使用需单独获取授权。详见文档。
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 face_hub-1.0.5.tar.gz.
File metadata
- Download URL: face_hub-1.0.5.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5bff9abc7c49db62cc80f62267a4bc3a14d5ba231b17d4ca7f98cd1f31f6b83
|
|
| MD5 |
c228ce0b7151519e329bebd6518b0969
|
|
| BLAKE2b-256 |
a8a768b0a5033865c0cc6d126f8f47dd3a72aba9c6e71ae0c5cea27520dc2fa7
|
Provenance
The following attestation bundles were made for face_hub-1.0.5.tar.gz:
Publisher:
publish.yml on allen902/face-hub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
face_hub-1.0.5.tar.gz -
Subject digest:
b5bff9abc7c49db62cc80f62267a4bc3a14d5ba231b17d4ca7f98cd1f31f6b83 - Sigstore transparency entry: 2167395604
- Sigstore integration time:
-
Permalink:
allen902/face-hub@ae73c1acd13144940554b9a04fc76fee24552ccb -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/allen902
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae73c1acd13144940554b9a04fc76fee24552ccb -
Trigger Event:
release
-
Statement type:
File details
Details for the file face_hub-1.0.5-py3-none-any.whl.
File metadata
- Download URL: face_hub-1.0.5-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf4804c0a5a1b0682af7b9146b468ec6cfe78b9d39f97e2a62245beeb4be5a1
|
|
| MD5 |
4452d1b9a94a74399e2bf56f5e5a5bfd
|
|
| BLAKE2b-256 |
3fe3549c4590f168704bf97e0010a1380db1a8d38601786b571b4fbef64c834c
|
Provenance
The following attestation bundles were made for face_hub-1.0.5-py3-none-any.whl:
Publisher:
publish.yml on allen902/face-hub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
face_hub-1.0.5-py3-none-any.whl -
Subject digest:
fbf4804c0a5a1b0682af7b9146b468ec6cfe78b9d39f97e2a62245beeb4be5a1 - Sigstore transparency entry: 2167395614
- Sigstore integration time:
-
Permalink:
allen902/face-hub@ae73c1acd13144940554b9a04fc76fee24552ccb -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/allen902
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae73c1acd13144940554b9a04fc76fee24552ccb -
Trigger Event:
release
-
Statement type: