face-hub 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
face_hub-1.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Allen Deng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: face-hub
3
+ Version: 1.0.1
4
+ Summary: Real-time face recognition library: detection, embedding, tracking and matching.
5
+ Author: AllenDeng
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/allen902/face_hub
8
+ Project-URL: Documentation, https://allen902.github.io/face_hub
9
+ Project-URL: Repository, https://github.com/allen902/face_hub
10
+ Project-URL: Issues, https://github.com/allen902/face_hub/issues
11
+ Keywords: face-recognition,insightface,retinaface,arcface,computer-vision
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: opencv-python>=4.8.0
26
+ Requires-Dist: insightface>=0.7.3
27
+ Requires-Dist: onnxruntime>=1.18.0
28
+ Requires-Dist: numpy>=1.24.0
29
+ Requires-Dist: Pillow>=10.0.0
30
+ Provides-Extra: gpu-win
31
+ Requires-Dist: onnxruntime-directml>=1.24.0; extra == "gpu-win"
32
+ Provides-Extra: gpu-linux
33
+ Requires-Dist: onnxruntime-gpu>=1.18.0; extra == "gpu-linux"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0; extra == "dev"
36
+ Requires-Dist: build>=0.10; extra == "dev"
37
+ Requires-Dist: twine>=4.0; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # FaceHub
41
+
42
+ > Real-time face recognition library — detection, embedding, tracking, and matching.
43
+
44
+ [![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
46
+ [![Tests](https://github.com/allen902/face_hub/actions/workflows/publish.yml/badge.svg)](https://github.com/allen902/face_hub/actions/workflows/publish.yml)
47
+
48
+ ## Features
49
+
50
+ - **Detection**: insightface RetinaFace with GPU auto-detection (CUDA / DirectML) and CPU fallback.
51
+ - **Embedding**: ArcFace 512-dim L2-normalized features.
52
+ - **Recognition**: 1:N cosine-similarity matching with a versioned encoding cache.
53
+ - **Tracking**: IoU-based multi-face tracker with majority-vote identity smoothing.
54
+ - **Camera**: cross-platform capture thread (Windows DShow, macOS AVFoundation, Linux V4L2).
55
+ - **Protocol**: `DetectorProtocol` lets you plug in your own detector (YOLO, MediaPipe, etc.).
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install face-hub
61
+ ```
62
+
63
+ Optional GPU backends:
64
+
65
+ ```bash
66
+ # Windows DirectML
67
+ pip uninstall -y onnxruntime
68
+ pip install face-hub[gpu-win]
69
+
70
+ # Linux NVIDIA CUDA
71
+ pip uninstall -y onnxruntime
72
+ pip install face-hub[gpu-linux]
73
+ ```
74
+
75
+ ## Quick Start
76
+
77
+ ```python
78
+ from face_hub import (
79
+ FaceHubPipeline, FaceDetector, FaceRecognizer,
80
+ FaceTracker, FaceDatabase, CameraThread,
81
+ )
82
+
83
+ # 1. Initialize components
84
+ db = FaceDatabase(db_path="face_db.json")
85
+ detector = FaceDetector(device="auto", det_size=640)
86
+ recognizer = FaceRecognizer(tolerance=0.45)
87
+ tracker = FaceTracker(smooth_frames=5)
88
+ camera = CameraThread(camera_id=0, width=640, height=360)
89
+
90
+ # 2. Assemble the pipeline
91
+ pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
92
+ pipeline.start()
93
+
94
+ # 3. Loop
95
+ try:
96
+ while True:
97
+ result = pipeline.process_frame()
98
+ if result is None:
99
+ continue
100
+ for face in result.known_faces:
101
+ print(f"{face.name} ({face.confidence:.0%})")
102
+ finally:
103
+ pipeline.stop()
104
+ ```
105
+
106
+ ## Custom Detector
107
+
108
+ Any object satisfying `DetectorProtocol` can be plugged into the pipeline:
109
+
110
+ ```python
111
+ from face_hub import DetectorProtocol, DetectionWithEmbedding, BBox
112
+
113
+ class MyYoloDetector:
114
+ def detect_with_embeddings(self, frame):
115
+ boxes = self.yolo_model(frame)
116
+ return [
117
+ DetectionWithEmbedding(
118
+ bbox=BBox(x1=b.x1, y1=b.y1, x2=b.x2, y2=b.y2),
119
+ confidence=b.conf,
120
+ embedding=self.embedder(frame[b.y1:b.y2, b.x1:b.x2]),
121
+ quality_pass=True,
122
+ )
123
+ for b in boxes
124
+ ]
125
+
126
+ pipeline = FaceHubPipeline(camera, MyYoloDetector(), recognizer, tracker, db)
127
+ ```
128
+
129
+ ## Documentation
130
+
131
+ Full API docs (English / 中文) are in the `docs/` directory and can be served with:
132
+
133
+ ```bash
134
+ pip install mkdocs mkdocs-material
135
+ cd docs && mkdocs serve
136
+ ```
137
+
138
+ ## License
139
+
140
+ The FaceHub **code** is released under the [MIT License](LICENSE).
141
+
142
+ > ⚠️ 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.
143
+
144
+ ---
145
+
146
+ # FaceHub(中文)
147
+
148
+ > 实时人脸识别库 — 检测、特征提取、追踪、匹配。
149
+
150
+ ## 特性
151
+
152
+ - **检测**:insightface RetinaFace,自动检测 CUDA / DirectML GPU 并回退 CPU。
153
+ - **特征**:ArcFace 512 维 L2 归一化特征向量。
154
+ - **识别**:1:N 余弦相似度匹配,带版本号缓存。
155
+ - **追踪**:基于 IoU 的多目标追踪 + 多数投票身份平滑。
156
+ - **摄像头**:跨平台采集线程(Windows DShow、macOS AVFoundation、Linux V4L2)。
157
+ - **协议**:`DetectorProtocol` 允许接入自定义检测器(YOLO、MediaPipe 等)。
158
+
159
+ ## 安装
160
+
161
+ ```bash
162
+ pip install face-hub
163
+ ```
164
+
165
+ 可选 GPU 后端:
166
+
167
+ ```bash
168
+ # Windows DirectML
169
+ pip uninstall -y onnxruntime
170
+ pip install face-hub[gpu-win]
171
+
172
+ # Linux NVIDIA CUDA
173
+ pip uninstall -y onnxruntime
174
+ pip install face-hub[gpu-linux]
175
+ ```
176
+
177
+ ## 快速开始
178
+
179
+ ```python
180
+ from face_hub import (
181
+ FaceHubPipeline, FaceDetector, FaceRecognizer,
182
+ FaceTracker, FaceDatabase, CameraThread,
183
+ )
184
+
185
+ # 1. 初始化组件
186
+ db = FaceDatabase(db_path="face_db.json")
187
+ detector = FaceDetector(device="auto", det_size=640)
188
+ recognizer = FaceRecognizer(tolerance=0.45)
189
+ tracker = FaceTracker(smooth_frames=5)
190
+ camera = CameraThread(camera_id=0, width=640, height=360)
191
+
192
+ # 2. 组装流水线
193
+ pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
194
+ pipeline.start()
195
+
196
+ # 3. 循环处理
197
+ try:
198
+ while True:
199
+ result = pipeline.process_frame()
200
+ if result is None:
201
+ continue
202
+ for face in result.known_faces:
203
+ print(f"{face.name} ({face.confidence:.0%})")
204
+ finally:
205
+ pipeline.stop()
206
+ ```
207
+
208
+ ## 自定义检测器
209
+
210
+ 任何满足 `DetectorProtocol` 的对象都可以接入流水线,示例见上文英文部分。
211
+
212
+ ## 文档
213
+
214
+ 完整中英 API 文档位于 `docs/` 目录,可通过 MkDocs 本地预览。
215
+
216
+ ## 许可
217
+
218
+ FaceHub **代码** 采用 [MIT License](LICENSE)。
219
+
220
+ > ⚠️ insightface 自动下载的 `buffalo_l` 预训练模型受其模型许可约束,默认仅供非商用研究使用;商业使用需单独获取授权。详见文档。
@@ -0,0 +1,181 @@
1
+ # FaceHub
2
+
3
+ > Real-time face recognition library — detection, embedding, tracking, and matching.
4
+
5
+ [![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+ [![Tests](https://github.com/allen902/face_hub/actions/workflows/publish.yml/badge.svg)](https://github.com/allen902/face_hub/actions/workflows/publish.yml)
8
+
9
+ ## Features
10
+
11
+ - **Detection**: insightface RetinaFace with GPU auto-detection (CUDA / DirectML) and CPU fallback.
12
+ - **Embedding**: ArcFace 512-dim L2-normalized features.
13
+ - **Recognition**: 1:N cosine-similarity matching with a versioned encoding cache.
14
+ - **Tracking**: IoU-based multi-face tracker with majority-vote identity smoothing.
15
+ - **Camera**: cross-platform capture thread (Windows DShow, macOS AVFoundation, Linux V4L2).
16
+ - **Protocol**: `DetectorProtocol` lets you plug in your own detector (YOLO, MediaPipe, etc.).
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install face-hub
22
+ ```
23
+
24
+ Optional GPU backends:
25
+
26
+ ```bash
27
+ # Windows DirectML
28
+ pip uninstall -y onnxruntime
29
+ pip install face-hub[gpu-win]
30
+
31
+ # Linux NVIDIA CUDA
32
+ pip uninstall -y onnxruntime
33
+ pip install face-hub[gpu-linux]
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```python
39
+ from face_hub import (
40
+ FaceHubPipeline, FaceDetector, FaceRecognizer,
41
+ FaceTracker, FaceDatabase, CameraThread,
42
+ )
43
+
44
+ # 1. Initialize components
45
+ db = FaceDatabase(db_path="face_db.json")
46
+ detector = FaceDetector(device="auto", det_size=640)
47
+ recognizer = FaceRecognizer(tolerance=0.45)
48
+ tracker = FaceTracker(smooth_frames=5)
49
+ camera = CameraThread(camera_id=0, width=640, height=360)
50
+
51
+ # 2. Assemble the pipeline
52
+ pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
53
+ pipeline.start()
54
+
55
+ # 3. Loop
56
+ try:
57
+ while True:
58
+ result = pipeline.process_frame()
59
+ if result is None:
60
+ continue
61
+ for face in result.known_faces:
62
+ print(f"{face.name} ({face.confidence:.0%})")
63
+ finally:
64
+ pipeline.stop()
65
+ ```
66
+
67
+ ## Custom Detector
68
+
69
+ Any object satisfying `DetectorProtocol` can be plugged into the pipeline:
70
+
71
+ ```python
72
+ from face_hub import DetectorProtocol, DetectionWithEmbedding, BBox
73
+
74
+ class MyYoloDetector:
75
+ def detect_with_embeddings(self, frame):
76
+ boxes = self.yolo_model(frame)
77
+ return [
78
+ DetectionWithEmbedding(
79
+ bbox=BBox(x1=b.x1, y1=b.y1, x2=b.x2, y2=b.y2),
80
+ confidence=b.conf,
81
+ embedding=self.embedder(frame[b.y1:b.y2, b.x1:b.x2]),
82
+ quality_pass=True,
83
+ )
84
+ for b in boxes
85
+ ]
86
+
87
+ pipeline = FaceHubPipeline(camera, MyYoloDetector(), recognizer, tracker, db)
88
+ ```
89
+
90
+ ## Documentation
91
+
92
+ Full API docs (English / 中文) are in the `docs/` directory and can be served with:
93
+
94
+ ```bash
95
+ pip install mkdocs mkdocs-material
96
+ cd docs && mkdocs serve
97
+ ```
98
+
99
+ ## License
100
+
101
+ The FaceHub **code** is released under the [MIT License](LICENSE).
102
+
103
+ > ⚠️ 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.
104
+
105
+ ---
106
+
107
+ # FaceHub(中文)
108
+
109
+ > 实时人脸识别库 — 检测、特征提取、追踪、匹配。
110
+
111
+ ## 特性
112
+
113
+ - **检测**:insightface RetinaFace,自动检测 CUDA / DirectML GPU 并回退 CPU。
114
+ - **特征**:ArcFace 512 维 L2 归一化特征向量。
115
+ - **识别**:1:N 余弦相似度匹配,带版本号缓存。
116
+ - **追踪**:基于 IoU 的多目标追踪 + 多数投票身份平滑。
117
+ - **摄像头**:跨平台采集线程(Windows DShow、macOS AVFoundation、Linux V4L2)。
118
+ - **协议**:`DetectorProtocol` 允许接入自定义检测器(YOLO、MediaPipe 等)。
119
+
120
+ ## 安装
121
+
122
+ ```bash
123
+ pip install face-hub
124
+ ```
125
+
126
+ 可选 GPU 后端:
127
+
128
+ ```bash
129
+ # Windows DirectML
130
+ pip uninstall -y onnxruntime
131
+ pip install face-hub[gpu-win]
132
+
133
+ # Linux NVIDIA CUDA
134
+ pip uninstall -y onnxruntime
135
+ pip install face-hub[gpu-linux]
136
+ ```
137
+
138
+ ## 快速开始
139
+
140
+ ```python
141
+ from face_hub import (
142
+ FaceHubPipeline, FaceDetector, FaceRecognizer,
143
+ FaceTracker, FaceDatabase, CameraThread,
144
+ )
145
+
146
+ # 1. 初始化组件
147
+ db = FaceDatabase(db_path="face_db.json")
148
+ detector = FaceDetector(device="auto", det_size=640)
149
+ recognizer = FaceRecognizer(tolerance=0.45)
150
+ tracker = FaceTracker(smooth_frames=5)
151
+ camera = CameraThread(camera_id=0, width=640, height=360)
152
+
153
+ # 2. 组装流水线
154
+ pipeline = FaceHubPipeline(camera, detector, recognizer, tracker, db)
155
+ pipeline.start()
156
+
157
+ # 3. 循环处理
158
+ try:
159
+ while True:
160
+ result = pipeline.process_frame()
161
+ if result is None:
162
+ continue
163
+ for face in result.known_faces:
164
+ print(f"{face.name} ({face.confidence:.0%})")
165
+ finally:
166
+ pipeline.stop()
167
+ ```
168
+
169
+ ## 自定义检测器
170
+
171
+ 任何满足 `DetectorProtocol` 的对象都可以接入流水线,示例见上文英文部分。
172
+
173
+ ## 文档
174
+
175
+ 完整中英 API 文档位于 `docs/` 目录,可通过 MkDocs 本地预览。
176
+
177
+ ## 许可
178
+
179
+ FaceHub **代码** 采用 [MIT License](LICENSE)。
180
+
181
+ > ⚠️ insightface 自动下载的 `buffalo_l` 预训练模型受其模型许可约束,默认仅供非商用研究使用;商业使用需单独获取授权。详见文档。
@@ -0,0 +1,84 @@
1
+ """
2
+ FaceHub — Real-time Face Recognition Library
3
+
4
+ Usage:
5
+ from face_hub import (
6
+ FaceHubPipeline, FaceDetector, FaceRecognizer,
7
+ CameraThread, FaceTracker, FaceDatabase,
8
+ )
9
+ from face_hub.types import UNKNOWN_SENTINEL, PipelineResult, TrackedFace
10
+ """
11
+
12
+ __version__ = "1.0.1"
13
+ __author__ = "AllenDeng"
14
+
15
+ # When installed as a package, prefer the metadata version (pyproject.toml).
16
+ # Falls back to the hardcoded value above during local development.
17
+ try:
18
+ from importlib.metadata import version as _pkg_version
19
+
20
+ __version__ = _pkg_version("face-hub")
21
+ except Exception:
22
+ pass
23
+
24
+ # ── Core components (from engine subpackage) ─────────────────
25
+ from face_hub.engine.camera import CameraThread
26
+ from face_hub.engine.face_detector import FaceDetector
27
+ from face_hub.engine.face_recognizer import FaceRecognizer
28
+ from face_hub.engine.face_tracker import FaceTracker
29
+ from face_hub.engine.face_database import FaceDatabase
30
+
31
+ # ── Pipeline (from face_hub/ main package) ─────────────────────
32
+ from face_hub.pipeline import FaceHubPipeline
33
+ from face_hub.detector_protocol import DetectorProtocol
34
+
35
+ # ── Types ──────────────────────────────────────────────────────
36
+ from face_hub.types import (
37
+ UNKNOWN_SENTINEL,
38
+ BBox,
39
+ DetectionResult,
40
+ DetectionWithEmbedding,
41
+ TrackedFace,
42
+ PipelineResult,
43
+ )
44
+
45
+ # ── Exceptions ─────────────────────────────────────────────────
46
+ from face_hub.exceptions import (
47
+ FaceHubError,
48
+ ModelLoadError,
49
+ InferenceError,
50
+ CameraError,
51
+ DatabaseError,
52
+ RecognitionError,
53
+ )
54
+
55
+ # ── Config ─────────────────────────────────────────────────────
56
+ from face_hub.engine.config import DEFAULT_SETTINGS, get_default_settings
57
+
58
+ __all__ = [
59
+ # Core
60
+ "CameraThread",
61
+ "FaceDetector",
62
+ "FaceRecognizer",
63
+ "FaceTracker",
64
+ "FaceDatabase",
65
+ "FaceHubPipeline",
66
+ "DetectorProtocol",
67
+ # Types
68
+ "UNKNOWN_SENTINEL",
69
+ "BBox",
70
+ "DetectionResult",
71
+ "DetectionWithEmbedding",
72
+ "TrackedFace",
73
+ "PipelineResult",
74
+ # Exceptions
75
+ "FaceHubError",
76
+ "ModelLoadError",
77
+ "InferenceError",
78
+ "CameraError",
79
+ "DatabaseError",
80
+ "RecognitionError",
81
+ # Config
82
+ "DEFAULT_SETTINGS",
83
+ "get_default_settings",
84
+ ]
@@ -0,0 +1,67 @@
1
+ """
2
+ Detector protocol — abstract interface for face detection + embedding.
3
+
4
+ Built-in implementation: face_hub.engine.face_detector.FaceDetector (insightface).
5
+ Users can implement this protocol to plug in custom models (YOLO, MediaPipe,
6
+ commercial SDK, etc.) without modifying the rest of the pipeline.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Protocol, List, runtime_checkable
12
+ import numpy as np
13
+
14
+ from face_hub.types import DetectionResult, DetectionWithEmbedding
15
+
16
+
17
+ @runtime_checkable
18
+ class DetectorProtocol(Protocol):
19
+ """
20
+ Protocol for face detection and embedding extraction.
21
+
22
+ Any object implementing these three methods can be passed to
23
+ FaceHubPipeline as the detector.
24
+
25
+ Minimal implementation: just implement detect_with_embeddings().
26
+ detect() and reload_model() have default no-op fallbacks.
27
+ """
28
+
29
+ def detect(self, frame: np.ndarray) -> List[DetectionResult]:
30
+ """
31
+ Detect all faces in a BGR frame.
32
+
33
+ Args:
34
+ frame: BGR image as (H, W, 3) numpy array.
35
+
36
+ Returns:
37
+ List of DetectionResult, sorted by confidence descending.
38
+ """
39
+ ...
40
+
41
+ def detect_with_embeddings(
42
+ self, frame: np.ndarray
43
+ ) -> List[DetectionWithEmbedding]:
44
+ """
45
+ Detect faces and extract feature embeddings in one pass.
46
+
47
+ This is the primary method called by the pipeline. Implementations
48
+ should return embeddings that are L2-normalized 512-dim float32 vectors
49
+ (or set the confidence threshold in FaceRecognizer accordingly).
50
+
51
+ Args:
52
+ frame: BGR image as (H, W, 3) numpy array.
53
+
54
+ Returns:
55
+ List of DetectionWithEmbedding, sorted by confidence descending.
56
+ """
57
+ ...
58
+
59
+ def reload_model(self, det_size: int = None) -> None:
60
+ """
61
+ Reload the underlying model with new parameters (optional).
62
+
63
+ Called when the user changes detection resolution at runtime.
64
+ Default no-op is acceptable if the implementation doesn't support
65
+ hot-reload.
66
+ """
67
+ pass
@@ -0,0 +1 @@
1
+ """face_hub engine — core algorithms for detection, recognition, tracking."""