Skip to content

Commit 3586c1b

Browse files
committed
Add archive diagram
1 parent baab7e3 commit 3586c1b

2 files changed

Lines changed: 158 additions & 3 deletions

File tree

docs/guides/arch.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# InspireFace Architecture
22

3-
TODO
3+
InspireFace SDK adopts a layered modular architecture design that provides high-performance face recognition capabilities across diverse hardware platforms. The system is structured into five main layers: Client Interface, Session Management, Core Services, Engine Layer, and Platform Support.
4+
5+
![](https://inspireface-1259028827.cos.ap-singapore.myqcloud.com/docs%2Fmem_model.drawio.png)
6+
7+
At the top level, the **Client Interface Layer** provides a unified C API that abstracts complex implementations, allowing developers to easily integrate face detection, recognition, and liveness detection functionalities. The **Session Management Layer** serves as the core processing unit, supporting multiple concurrent Session instances with independent configurations and resource isolation, alongside comprehensive image codec and processing capabilities for various formats (RGB, BGR, YUV).
8+
9+
The **Core Services Layer** encompasses two global services: App Context for SDK lifecycle and resource management, and Feature Hub for centralized face feature vector storage, search, and comparison with support for both memory and persistent storage modes.
10+
11+
The **Engine Layer** represents the performance cornerstone, featuring a **multi-backend heterogeneous neural network inference architecture** that intelligently selects optimal backends including ONNX Runtime, TensorRT, CoreML, and MNN based on available hardware resources.
12+
13+
The **Hardware Support Layer** provides comprehensive acceleration across multiple platforms. **GPU acceleration** includes full CUDA support for NVIDIA hardware with Tensor Core optimization, OpenCL compatibility for AMD devices, and native Metal framework support for Apple platforms. **Embedded NPU support** encompasses ARM Mali NPU, Rockchip NPU, and Apple NPU Engine(**ANE**) architectures. **CPU optimization** leverages ARM NEON SIMD instructions, Intel AVX/SSE extensions, and OpenMP-based multi-threading. Additionally, **2D image processing acceleration** utilizes hardware engines like ARM Mali GPU, Rockchip RGA for efficient format conversion, scaling, and geometric transformations with DMA-optimized zero-copy memory management.
14+
15+
This architecture ensures optimal performance through intelligent hardware detection and resource scheduling while maintaining cross-platform compatibility and easy integration across Linux, Windows, Android, and iOS environments.

docs/using-with/c-cpp.md

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,153 @@ if (ret != HSUCCEED) {
202202
// Not in use need to release
203203
HFReleaseFaceFeature(&feature);
204204
```
205+
## Face Embedding Database
205206

206-
## Face Feature Management
207+
We provide a lightweight face embedding vector database (**FeatureHub**) storage solution that includes basic functions such as adding, deleting, modifying, and searching, while supporting both **memory** and **persistent** storage modes.
207208

208-
TODO
209+
Before starting FeatureHub, you need to be familiar with the following parameters:
210+
211+
- **primaryKeyMode**: Primary key mode, with two modes available. It's recommended to use HF_PK_AUTO_INCREMENT by default
212+
- HF_PK_AUTO_INCREMENT: Auto-increment mode for primary keys
213+
- HF_PK_MANUAL_INPUT: Manual input mode for primary keys, requiring users to avoid duplicate primary keys themselves
214+
- **enablePersistence**: Whether to enable persistent database storage mode
215+
- If true: The database will write to local files for persistent storage during usage
216+
- If false: High-speed memory management mode, dependent on program lifecycle
217+
- **persistenceDbPath**: Storage path required only for persistent mode, defined by the user. If the input is a folder rather than a file, the system default file naming will be used
218+
- **searchThreshold**: Face search threshold, using floating-point numbers. During search, only embeddings above the threshold are searched. Different models and scenarios require manual threshold settings
219+
- **searchMode**: Search mode, **effective only when searching for top-1 face**, with EAGER and EXHAUSTIVE modes (**this feature is temporarily disabled in the current version**)
220+
- HF_SEARCH_MODE_EAGER: Complete search immediately upon encountering the first face above the threshold
221+
- HF_SEARCH_MODE_EXHAUSTIVE: Search all similar faces and return the one with the highest similarity
222+
223+
### Enable/Disable FeatureHub
224+
225+
Using thread-safe singleton pattern design, it has global scope and only needs to be opened once:
226+
227+
```c
228+
// When you need to enable global storage
229+
HFFeatureHubConfiguration configuration;
230+
configuration.primaryKeyMode = HF_PK_AUTO_INCREMENT; // Recommended to use auto increment
231+
configuration.enablePersistence = 1; // If the memory mode is set to 0
232+
configuration.persistenceDbPath = db_path;
233+
configuration.searchMode = HF_SEARCH_MODE_EXHAUSTIVE;
234+
configuration.searchThreshold = 0.48f;
235+
ret = HFFeatureHubDataEnable(configuration);
236+
if (ret != HSUCCEED) {
237+
HFLogPrint(HF_LOG_ERROR, "Enable feature hub error: %d", ret);
238+
return ret;
239+
}
240+
241+
// .....
242+
243+
// You can manually close it when you don't need to use it, or ignore it until the program ends
244+
HFFeatureHubDataDisable();
245+
```
246+
247+
### Insert Face Embedding
248+
249+
Insert a face embedding feature vector into FeatureHub. If in HF_PK_AUTO_INCREMENT mode, the input feature.id will be ignored. If in HF_PK_MANUAL_INPUT mode, the input feature.id is the ID the user expects to insert, and the actual inserted face ID is returned through result_id.
250+
251+
```c
252+
// Insert face feature into the hub
253+
HFFaceFeatureIdentity featureIdentity;
254+
featureIdentity.feature = &feature;
255+
featureIdentity.id = -1;
256+
HFaceId result_id;
257+
ret = HFFeatureHubInsertFeature(featureIdentity, &result_id);
258+
if (ret != HSUCCEED) {
259+
HFLogPrint(HF_LOG_ERROR, "Insert feature error: %d", ret);
260+
return ret;
261+
}
262+
```
263+
264+
### Search Most Similar Face
265+
266+
Input a face embedding to be queried and search for a face ID from FeatureHub that is above the threshold (Cosine similarity).
267+
268+
```c
269+
// Search face feature
270+
HFFaceFeatureIdentity query_featureIdentity;
271+
query_featureIdentity.feature = &query_feature;
272+
query_featureIdentity.id = -1;
273+
HFloat confidence;
274+
ret = HFFeatureHubFaceSearch(query_feature, &confidence, &query_featureIdentity);
275+
276+
if (ret != HSUCCEED) {
277+
HFLogPrint(HF_LOG_ERROR, "Search feature error: %d", ret);
278+
return ret;
279+
}
280+
```
281+
282+
### Search Top-K Faces
283+
284+
Search for the top K faces with the highest similarity. Note that the data obtained by the `HFFeatureHubFaceSearchTopK` interface is cached data, and you need to retrieve all the result data you need before the next call, otherwise the next call will overwrite the historical data.
285+
286+
```c
287+
// Create HFSearchTopKResults to store search results
288+
HFSearchTopKResults results;
289+
ret = HFFeatureHubFaceSearchTopK(feature, topK, &results);
290+
if (ret != HSUCCEED) {
291+
HFLogPrint(HF_LOG_ERROR, "The search for the top k vectors failed: %d", ret);
292+
return ret;
293+
}
294+
295+
// Get all the results
296+
for (int i = 0; i < results.size; i++) {
297+
HFloat score = results.confidence[i];
298+
HPFaceId id = results.ids[i];
299+
}
300+
```
301+
302+
### Delete Face Embedding
303+
304+
Specify a face ID to delete that face from FeatureHub.
305+
306+
```c
307+
// Remove face feature
308+
ret = HFFeatureHubFaceRemove(result_id);
309+
if (ret != HSUCCEED) {
310+
HFLogPrint(HF_LOG_ERROR, "Remove feature error: %d", ret);
311+
return ret;
312+
}
313+
HFLogPrint(HF_LOG_INFO, "Remove feature result: %d", result_id);
314+
```
315+
316+
### Update Face Embedding
317+
318+
```C
319+
// Create HFFaceFeatureIdentity
320+
HFFaceFeatureIdentity updateIdentity;
321+
updateIdentity.id = old_id;
322+
updateIdentity.feature = &feature;
323+
324+
// Update feature
325+
ret = HFFeatureHubFaceUpdate(updateIdentity);
326+
if (ret != HSUCCEED) {
327+
HFLogPrint(HF_LOG_ERROR, "Update feature error: %d", ret);
328+
return ret;
329+
}
330+
```
331+
332+
### Get Face Embedding from ID
333+
334+
You can quickly obtain FaceFeatureIdentity related information through a face ID.
335+
336+
```c
337+
// Create HFFaceFeatureIdentity
338+
HFFaceFeatureIdentity identity;
339+
auto result = HFFeatureHubGetFaceIdentity(id, &identity);
340+
if (result != HSUCCEED) {
341+
return nullptr;
342+
}
343+
```
344+
345+
### Dynamic Search Threshold Adjustment
346+
347+
You can dynamically modify FeatureHub's search threshold in different scenarios.
348+
349+
```c
350+
HFFeatureHubFaceSearchThresholdSetting(0.5f);
351+
```
209352
210353
## Other Feature
211354

0 commit comments

Comments
 (0)