文件最后提交记录最后更新时间
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
update: add support for Buffalo_l model based on InsightFace Co-authored-by: XiyangLiu233<liuxiyang10@huawei.com> # message auto-generated for no-merge-commit merge: !7538 merge master into master update: add support for Buffalo_l model based on InsightFace Created-by: frankliu233 Commit-by: frankliu233;XiyangLiu233 Merged-by: ascend-robot Description: ## Motivation Add support for Buffalo_l model based on InsightFace ## Modification Add Buffalo model support code. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!753819 天前
README.md

Buffalo_l模型-推理指导

概述

Buffalo_l是Insightface团队开发的工业级人脸分析模型,专为高精度人脸检测、关键点定位、人脸特征提取和属性分析设计,支持遮挡、低质、侧脸等复杂场景,提供开箱即用的多任务人脸处理能力。它由以下五个小模型组成。

模型名称 模型文件 模型功能
SCRFD-10GF det_10g.onnx 人脸检测
2d106 2d106det.onnx 106个2D人脸关键点的定位
3d68 1k3d68 68个3D人脸关键点的定位
ResNet50@WebFace600K w600k_r50.onnx 人脸特征提取
Gender&Age genderage.onnx 性别和年龄预测

模型输入与输出

  • 输入数据
模型名称 输入数据 数据类型 大小 数据排布格式
SCRFD-10GF input.1 FLOAT32 1 x 3 x height x width NCHW
2d106 data FLOAT32 batchsize x 3 x 192 x 192 NCHW
3d68 data FLOAT32 batchsize x 3 x 192 x 192 NCHW
ResNet50@WebFace600K input.1 FLOAT32 batchsize x 3 x 112 x 112 NCHW
Gender&Age data FLOAT32 batchsize x 3 x 96 x 96 NCHW
  • 输出数据
模型名称 输出数据 输出数据含义 数据类型 大小 数据排布格式
SCRFD-10GF 448 stride=8 尺度的置信度 FLOAT32 12800 x 1 ND
SCRFD-10GF 471 stride=16 尺度的置信度 FLOAT32 3200 x 1 ND
SCRFD-10GF 494 stride=32 尺度的置信度 FLOAT32 800 x 1 ND
SCRFD-10GF 451 stride=8 尺度的边界框偏移量 FLOAT32 12800 x 4 ND
SCRFD-10GF 474 stride=16 尺度的边界框偏移量 FLOAT32 3200 x 4 ND
SCRFD-10GF 497 stride=32 尺度的边界框偏移量 FLOAT32 800 x 4 ND
SCRFD-10GF 454 stride=8 尺度的关键点偏移量 FLOAT32 12800 x 10 ND
SCRFD-10GF 477 stride=16 尺度的关键点偏移量 FLOAT32 3200 x 10 ND
SCRFD-10GF 500 stride=32 尺度的关键点偏移量 FLOAT32 800 x 10 ND
2d106 fc1 106个2D关键点的坐标 FLOAT32 1 x 212 ND
3d68 fc1 3D人脸重建参数 FLOAT32 1 x 3309 ND
ResNet50@WebFace600K 683 512维人脸特征向量 FLOAT32 1 x 512 ND
Gender&Age fc1 性别概率和年龄上下限 FLOAT32 1 x 3 ND

推理环境准备

  • 该模型需要以下插件与驱动

    表 1 版本配套表

    配套 版本 环境准备指导
    固件与驱动 25.3.RC1 Pytorch框架推理环境准备
    CANN 8.3.RC2 -
    Python 3.11.6 -
    PyTorch 2.1.0 -
    说明:请以CANN版本选择实际固件与驱动版本。 \ \

快速上手

获取源码

git clone https://gitcode.com/ascend/ModelZoo-PyTorch.git
cd ModelZoo-PyTorch/ACL_PyTorch/built-in/cv/Buffalo_l

安装依赖

# openeuler系统
yum install -y g++
yum install -y patch
yum install -y cmake

# ubuntu系统
apt-get install -y g++
apt-get install -y patch
apt-get install -y cmake

pip install -r requirements.txt

git clone https://gitee.com/Ronnie_zheng/MagicONNX
cd MagicONNX && git checkout master
pip install .
cd ..

下载权重

创建权重路径

mkdir -p ~/.insightface/models/

https://modelscope.cn/models/fireicewolf/buffalo_l 下载好后将权重放入~/.insightface/models/目录下

下载数据集

本模型采用 LFW(Labled Faces in Wild) ,解压到 ModelZoo-PyTorch/ACL_PyTorch/built-in/cv/Buffalo_l/data 目录下(如没有则需要自己创建)。另外,精度验证依赖pairs.txt文件,下载:百度网盘,提取码:iwyk,下载到ModelZoo-PyTorch/ACL_PyTorch/built-in/cv/Buffalo_l/data目录下。

数据目录结构请参考:

data
└── pairs.txt
└── lfw
 ├── AJ_Cook
 ├── AJ_Lamas
 └── ...

调整ONNX文件

cd ~/.insightface/models/buffalo_l

python -m onnxruntime.tools.make_dynamic_shape_fixed --input_name data --input_shape 1,3,192,192 1k3d68.onnx 1k3d68.fix.onnx

python -m onnxruntime.tools.make_dynamic_shape_fixed --input_name data --input_shape 1,3,192,192 2d106det.onnx 2d106det.fix.onnx

python -m onnxruntime.tools.make_dynamic_shape_fixed --input_name input.1 --input_shape 1,3,640,640 det_10g.onnx det_10g.fix.onnx

python -m onnxruntime.tools.make_dynamic_shape_fixed --input_name data --input_shape 1,3,96,96 genderage.onnx genderage.fix.onnx

python -m onnxruntime.tools.make_dynamic_shape_fixed --input_name input.1 --input_shape 1,3,112,112 w600k_r50.onnx w600k_r50.fix.onnx

rm -f 1k3d68.onnx
rm -f 2d106det.onnx
rm -f det_10g.onnx
rm -f genderage.onnx
rm -f w600k_r50.onnx

# 回到modelzoo工作目录
cd /path_to_modelzoo_workspace/ModelZoo-PyTorch/ACL_PyTorch/built-in/cv/Buffalo_l

ONNX文件优化

python fix_name.py ~/.insightface/models/buffalo_l/2d106det.fix.onnx ~/.insightface/models/buffalo_l/2d106det.fix_name.onnx

python fix_prelu.py ~/.insightface/models/buffalo_l/2d106det.fix_name.onnx ~/.insightface/models/buffalo_l/2d106det.opt.onnx

python fix_prelu.py ~/.insightface/models/buffalo_l/w600k_r50.fix.onnx ~/.insightface/models/buffalo_l/w600k_r50.opt.onnx

cd ~/.insightface/models/buffalo_l/

rm -f 2d106det.fix.onnx
rm -f 2d106det.fix_name.onnx
rm -f w600k_r50.fix.onnx

模型转换

  1. 配置环境变量。
source /usr/local/Ascend/ascend-toolkit/set_env.sh

说明: 该脚本中环境变量仅供参考,请以实际安装环境配置环境变量。详细介绍请参见《环境变量列表》。

  1. 执行命令查看芯片名称(${chip_name})。
npu-smi info
# 回显如下
+---------------------------+---------------+------------------------------------------------+
| NPU   Name            | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                  | Bus-Id        | AICore(%)   Memory-Usage(MB)  XXX-Usage(MB)        |
+===========================+===============+================================================+
| 0     xxx             | OK            | 95.0        36                0    / 0             |
| 0                     | 0000:C1:00.0  | 0           0    / 0          3447 / 65536         |
+===========================+===============+================================================+
| 1     xxx             | OK            | 93.7        37                0    / 0             |
| 0                     | 0000:C2:00.0  | 0           0    / 0          3447 / 65536         |
+===========================+===============+================================================+
# 根据实际芯片名称填入
chip_name=xxx
  1. 执行ATC命令。
atc --model=1k3d68.fix.onnx --framework=5 --output=1k3d68 --input_format=NCHW --input_shape="data:1,3,192,192" --log=error --soc_version=Ascend${chip_name} --precision_mode=must_keep_origin_dtype

atc --model=2d106det.opt.onnx --framework=5 --output=2d106det --input_format=NCHW --input_shape="data:1,3,192,192" --log=error --soc_version=Ascend${chip_name} --precision_mode=must_keep_origin_dtype

atc --model=det_10g.fix.onnx --framework=5 --output=det_10g --input_format=NCHW --input_shape="input.1:1,3,640,640" --log=error --soc_version=Ascend${chip_name} --precision_mode=must_keep_origin_dtype

atc --model=genderage.fix.onnx --framework=5 --output=genderage --input_format=NCHW --input_shape="data:1,3,96,96" --log=error --soc_version=Ascend${chip_name}

atc --model=w600k_r50.opt.onnx --framework=5 --output=w600k_r50 --input_format=NCHW --input_shape="input.1:1,3,112,112" --log=error --soc_version=Ascend${chip_name} --precision_mode=must_keep_origin_dtype

cd -
  • atc命令参数说明:
    • --model:ONNX模型文件
    • --framework:5代表ONNX模型
    • --output:输出的OM模型
    • --input_format:输入数据的格式
    • --input_shape:输入数据的shape
    • --log:日志级别
    • --soc_version:处理器型号
    • --precision_mode: 精度模型,must_keep_origin_dtype表示保持模型原有精度

安装ais_bench推理工具

请访问ais_bench推理工具代码仓,根据readme文档进行工具安装。

模型推理

  1. 修改代码
python insightface_patch.py
  1. 执行模型推理
python face_analysis_test.py --device 0 --image /path_to_image/test_image.jpg --output ./ouptput_image.jpg
  • 命令参数说明:
    • --device:设备ID,这里以0卡为例
    • --image:输入图片路径
    • --output:输出图片路径
  1. 推理结果展示

9971a0bd-751b-486d-80ad-0e881780c56f.png

以insightface库自带的测试图片t1.jpg(该图片路径在insightface安装路径下的data/images下)为例,推理时间为0.147s,端到端时间为0.157s。

性能测试

cd ~/.insightface/models/buffalo_l/
source /usr/local/Ascend/ascend-toolkit/set_env.sh

python3 -m ais_bench --model ./1k3d68.om --batchsize 1 --device 0
python3 -m ais_bench --model ./2d106det.om --batchsize 1 --device 0
python3 -m ais_bench --model ./det_10g.om --batchsize 1 --device 0
python3 -m ais_bench --model ./genderage.om --batchsize 1 --device 0
python3 -m ais_bench --model ./w600k_r50.om --batchsize 1 --device 0

cd -
  • 参数说明:
    • --model:om模型路径
    • --batchsize:模型batch大小
    • --device: 设备ID

精度测试

模型官方没有提供精度测试的方法,使用自定义的脚本在LFW数据集上测试模型的召回率和正确率,并与CPU上的相关结果进行对比。

python acc_eval.py --device 0
  • 命令参数说明:
    • --device:设备ID,这里以0卡为例

模型推理性能

模型 机器型号 Batch Size 数据集 性能 (FPS)
SCRFD-10GF Atlas 800I A2 1 随机构造 445
2d106 Atlas 800I A2 1 随机构造 1610
3d68 Atlas 800I A2 1 随机构造 322
ResNet50@WebFace600K Atlas 800I A2 1 随机构造 745
Gender&Age Atlas 800I A2 1 随机构造 3012

模型推理精度

设备 数据集 召回率 正确率
Atlas 800I A2 LFW 99.64% 98.54%
CPU LFW 99.64% 98.54%