返回模型
说明文档
license: other license_name: insightface-non-commercial license_link: https://github.com/deepinsight/insightface#license tags:
- face-detection
- face-recognition
- scrfd
- arcface
- onnx
- batch-inference
- tensorrt library_name: onnx pipeline_tag: image-classification
InsightFace 批量优化模型(最大批次 32)
重新导出的 InsightFace 模型,支持真正的动态批次且无跨帧污染。
版本对比
| 仓库 | 最大批次 | 建议 |
|---|---|---|
| 本仓库 | 1-32 | ✅ 推荐 - 最佳性能 |
| alonsorobots/scrfd_320_batched_64 | 1-64 | 用于实验 |
批次=32 是最佳选择。 在 RTX 5090 上的测试表明,批次=64 没有提供额外的吞吐量提升。
为什么选择这些模型?
原始的 InsightFace ONNX 模型在批量推理方面存在问题:
buffalo_l检测模型:硬编码批次=1buffalo_l_batch检测模型:有问题 - 由于重塑操作扁平化了批次维度,存在跨帧污染
这些重新导出的模型修复了 ONNX 图中的 dynamic_axes,实现了真正的批量推理。
模型
| 模型 | 任务 | 输入形状 | 输出 | 批次 | 加速比 |
|---|---|---|---|---|---|
scrfd_10g_320_batch.onnx |
人脸检测 | [N, 3, 320, 320] |
边界框, 关键点 | 1-32 | 6× |
arcface_w600k_r50_batch.onnx |
人脸嵌入 | [N, 3, 112, 112] |
512维向量 | 1-32 | 10× |
性能(TensorRT FP16,RTX 5090)
SCRFD 人脸检测
| 批次大小 | FPS | 毫秒/帧 |
|---|---|---|
| 1 | 867 | 1.15 |
| 16 | 5,498 | 0.18 |
ArcFace 嵌入
| 批次大小 | FPS | 毫秒/嵌入 |
|---|---|---|
| 1 | 292 | 3.4 |
| 16 | 3,029 | 0.33 |
使用方法
import numpy as np
import onnxruntime as ort
# 加载模型
sess = ort.InferenceSession("scrfd_10g_320_batch.onnx",
providers=["TensorrtExecutionProvider", "CUDAExecutionProvider"])
# 批量推理
batch = np.random.randn(16, 3, 320, 320).astype(np.float32)
outputs = sess.run(None, {"input.1": batch})
# outputs[0-2]: 每个FPN层级的分数(步长 8, 16, 32)
# outputs[3-5]: 每个FPN层级的边界框
# outputs[6-8]: 每个FPN层级的关键点
已验证:无批次污染
# 单独处理同一帧 vs 在批次中处理 = 完全相同的结果
single_output = sess.run(None, {"input.1": frame[np.newaxis, ...]})
batch[7] = frame
batch_output = sess.run(None, {"input.1": batch})
max_diff = np.max(np.abs(single_output[0] - batch_output[0][7]))
# max_diff < 1e-5 ✓
重新导出过程
这些模型是使用 MMDetection 从 InsightFace 的 PyTorch 源代码重新导出的,并设置了正确的 dynamic_axes:
dynamic_axes = {
"input.1": {0: "batch"},
"score_8": {0: "batch"},
"score_16": {0: "batch"},
# ... 所有输出
}
详情请参阅 SCRFD_320_EXPORT_INSTRUCTIONS.md。
许可证
仅限非商业研究用途 - 根据 InsightFace 许可证。
如需商业许可,请联系:recognition-oss-pack@insightface.ai
致谢
- 原始模型:InsightFace,作者 Jia Guo 等人
- SCRFD 论文:Sample and Computation Redistribution for Efficient Face Detection
- ArcFace 论文:ArcFace: Additive Angular Margin Loss for Deep Face Recognition
alonsorobots/scrfd_320_batched
作者 alonsorobots
image-classification
onnx
↓ 0
♥ 0
创建时间: 2025-12-02 10:56:05+00:00
更新时间: 2025-12-02 20:27:55+00:00
在 Hugging Face 上查看文件 (4)
.gitattributes
README.md
arcface_w600k_r50_batch.onnx
ONNX
scrfd_10g_320_batch.onnx
ONNX