Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: insightface-non-commercial
|
| 4 |
+
license_link: https://github.com/deepinsight/insightface#license
|
| 5 |
+
tags:
|
| 6 |
+
- face-detection
|
| 7 |
+
- face-recognition
|
| 8 |
+
- scrfd
|
| 9 |
+
- arcface
|
| 10 |
+
- onnx
|
| 11 |
+
- batch-inference
|
| 12 |
+
- tensorrt
|
| 13 |
+
library_name: onnx
|
| 14 |
+
pipeline_tag: image-classification
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# InsightFace Batch-Optimized Models
|
| 18 |
+
|
| 19 |
+
Re-exported InsightFace models with **proper dynamic batch support** and **no cross-frame contamination**.
|
| 20 |
+
|
| 21 |
+
## Why These Models?
|
| 22 |
+
|
| 23 |
+
The original InsightFace ONNX models have issues with batch inference:
|
| 24 |
+
- `buffalo_l` detection model: hardcoded batch=1
|
| 25 |
+
- `buffalo_l_batch` detection model: **broken** - has cross-frame contamination due to reshape operations that flatten the batch dimension
|
| 26 |
+
|
| 27 |
+
These re-exports fix the `dynamic_axes` in the ONNX graph for **true batch inference**.
|
| 28 |
+
|
| 29 |
+
## Models
|
| 30 |
+
|
| 31 |
+
| Model | Task | Input Shape | Output | Batch | Speedup |
|
| 32 |
+
|-------|------|-------------|--------|-------|---------|
|
| 33 |
+
| `scrfd_10g_320_batch.onnx` | Face Detection | `[N, 3, 320, 320]` | boxes, landmarks | 1-32 | **6×** |
|
| 34 |
+
| `arcface_w600k_r50_batch.onnx` | Face Embedding | `[N, 3, 112, 112]` | 512-dim vectors | 1-32 | **10×** |
|
| 35 |
+
|
| 36 |
+
## Performance (TensorRT FP16, RTX 5090)
|
| 37 |
+
|
| 38 |
+
### SCRFD Face Detection
|
| 39 |
+
| Batch Size | FPS | ms/frame |
|
| 40 |
+
|------------|-----|----------|
|
| 41 |
+
| 1 | 867 | 1.15 |
|
| 42 |
+
| 16 | **5,498** | 0.18 |
|
| 43 |
+
|
| 44 |
+
### ArcFace Embeddings
|
| 45 |
+
| Batch Size | FPS | ms/embedding |
|
| 46 |
+
|------------|-----|--------------|
|
| 47 |
+
| 1 | 292 | 3.4 |
|
| 48 |
+
| 16 | **3,029** | 0.33 |
|
| 49 |
+
|
| 50 |
+
## Usage
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
import numpy as np
|
| 54 |
+
import onnxruntime as ort
|
| 55 |
+
|
| 56 |
+
# Load model
|
| 57 |
+
sess = ort.InferenceSession("scrfd_10g_320_batch.onnx",
|
| 58 |
+
providers=["TensorrtExecutionProvider", "CUDAExecutionProvider"])
|
| 59 |
+
|
| 60 |
+
# Batch inference
|
| 61 |
+
batch = np.random.randn(16, 3, 320, 320).astype(np.float32)
|
| 62 |
+
outputs = sess.run(None, {"input.1": batch})
|
| 63 |
+
|
| 64 |
+
# outputs[0-2]: scores per FPN level (stride 8, 16, 32)
|
| 65 |
+
# outputs[3-5]: bboxes per FPN level
|
| 66 |
+
# outputs[6-8]: keypoints per FPN level
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Verified: No Batch Contamination
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
# Same frame processed alone vs in batch = identical results
|
| 73 |
+
single_output = sess.run(None, {"input.1": frame[np.newaxis, ...]})
|
| 74 |
+
batch[7] = frame
|
| 75 |
+
batch_output = sess.run(None, {"input.1": batch})
|
| 76 |
+
|
| 77 |
+
max_diff = np.max(np.abs(single_output[0] - batch_output[0][7]))
|
| 78 |
+
# max_diff < 1e-5 ✓
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
## Re-export Process
|
| 82 |
+
|
| 83 |
+
These models were re-exported from InsightFace's PyTorch source using MMDetection with proper `dynamic_axes`:
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
dynamic_axes = {
|
| 87 |
+
"input.1": {0: "batch"},
|
| 88 |
+
"score_8": {0: "batch"},
|
| 89 |
+
"score_16": {0: "batch"},
|
| 90 |
+
# ... all outputs
|
| 91 |
+
}
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
See [SCRFD_320_EXPORT_INSTRUCTIONS.md](https://github.com/deepinsight/insightface/issues/1573) for details.
|
| 95 |
+
|
| 96 |
+
## License
|
| 97 |
+
|
| 98 |
+
**Non-commercial research purposes only** - per [InsightFace license](https://github.com/deepinsight/insightface#license).
|
| 99 |
+
|
| 100 |
+
For commercial licensing, contact: `recognition-oss-pack@insightface.ai`
|
| 101 |
+
|
| 102 |
+
## Credits
|
| 103 |
+
|
| 104 |
+
- Original models: [InsightFace](https://github.com/deepinsight/insightface) by Jia Guo et al.
|
| 105 |
+
- SCRFD paper: [Sample and Computation Redistribution for Efficient Face Detection](https://arxiv.org/abs/2105.04714)
|
| 106 |
+
- ArcFace paper: [ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://arxiv.org/abs/1801.07698)
|
| 107 |
+
|