Skip to main content

Real-time face recognition library: detection, embedding, tracking and matching.

Project description

FaceHub

Real-time face recognition library — detection, embedding, tracking, and matching.

Python License: MIT Tests

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: DetectorProtocol lets 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

Full API docs (English / 中文) are in the docs/ directory and can be served with:

pip install mkdocs mkdocs-material
cd docs && mkdocs serve

License

The FaceHub code is released under the MIT License.

⚠️ The pre-trained buffalo_l model 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 文档位于 docs/ 目录,可通过 MkDocs 本地预览。

许可

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

face_hub-1.0.4.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

face_hub-1.0.4-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file face_hub-1.0.4.tar.gz.

File metadata

  • Download URL: face_hub-1.0.4.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for face_hub-1.0.4.tar.gz
Algorithm Hash digest
SHA256 4e6a9271e7d93ce8ea04df6e10d72d3a1197c2daccb904684eb013969e52034f
MD5 2668929096e322f852d49d5e050e7d59
BLAKE2b-256 da7a887e4153cde5fd6abb2982919ace3a84f4676e73885ef593fa8075f13be3

See more details on using hashes here.

Provenance

The following attestation bundles were made for face_hub-1.0.4.tar.gz:

Publisher: publish.yml on allen902/face-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file face_hub-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: face_hub-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for face_hub-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a582a52d2369a14a207f7411e33393424550cdbeb6f31ad07df3901724f57b6c
MD5 9eb872e7bd7f62f55c81aff30c75264f
BLAKE2b-256 c97462af1df5546f58a9184c5a468de21671a45609a8c26f022a0021eabc16ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for face_hub-1.0.4-py3-none-any.whl:

Publisher: publish.yml on allen902/face-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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