CV / ArcFace

ArcFace MobileFaceNet

reComputer R Series (CM5 + Hailo-10H)

ArcFace 人脸识别(2.04M 参数,LFW 99.4%),支持 reComputer R Series 搭配 Hailo-8 或 Hailo-10H。

59 次下载
大小
3.91 MB
内存
4GB+
精度
Hailo HEF / HailoRT

选择你正在使用的设备,设置指南和文档将相应更新。

快速开始

部署
sudo docker run --rm \
  --name cm5-hailo-arcface \
  --privileged \
  --net=host \
  -e PYTHONUNBUFFERED=1 \
  --device /dev/hailo0:/dev/hailo0 \
  -v /usr/lib/libhailort.so.5.1.1:/usr/lib/libhailort.so.5.1.1:ro \
  -v /usr/lib/libhailort.so:/usr/lib/libhailort.so:ro \
  ghcr.io/seeed-projects/recomputer-hailo10h-cv/arcface_mobilefacenet:latest \
  python web_detection.py --model_path model/arcface_mobilefacenet.hef --video_path video/test.mp4

REST API

使用 REST API 进行推理。复制以下命令。

Curl
curl -X POST "http://<Board_IP>:8000/api/models/arcface_mobilefacenet/predict" \
  -F "file=@face.jpg"
Python
import requests
resp = requests.post(
    "http://<Board_IP>:8000/api/models/arcface_mobilefacenet/predict",
    files={"file": open("face.jpg", "rb")},
    timeout=30,
)
print(resp.json())

模型详情

reComputer R Series (CM5 + Hailo-10H)

ArcFace MobileFaceNet 在 reComputer R Series(CM5 + Hailo-10H)上运行

ArcFace 搭配 MobileFaceNet 骨干网络,通过 HailoRT 在 Hailo-10H 上提取 512 维人脸特征向量。特征向量用于人脸验证与识别,比对本身由客户端使用余弦相似度完成。

本页面向搭载 PCIe Hailo-10H 加速器的 reComputer R Series(CM5 + Hailo-10H)。

模型信息

属性值
架构ArcFace(MobileFaceNet 骨干网络)
任务人脸识别(特征向量提取)
输入112x112x3 RGB(letterbox,归一化已编译进 HEF)
输出512 维人脸特征向量
参数量2.04M
LFW 准确率99.4%(Hailo Model Zoo 参考值)
HEFHailo Model Zoo v5.4.0,Hailo-10H

该准确率来自 Hailo Model Zoo 参考值,不是在 CM5 上实测的结果。

硬件与主机设置

项目值
开发板reComputer R Series 搭配 Raspberry Pi CM5
加速器Hailo-10H(PCIe 接口),以 /dev/hailo0 暴露
运行时HailoRT 5.1.1
容器内 Python3.13, aarch64

在主机上安装 Hailo-10H 软件包,并在启动容器前确认驱动与设备就绪:

bash
sudo apt update
sudo apt install hailo-h10-all -y
sudo reboot

# 重启后
hailortcli --version
hailortcli fw-control identify
ls -l /dev/hailo0

使用演示视频运行

bash
sudo docker run --rm \
  --name cm5-hailo-arcface \
  --privileged \
  --net=host \
  -e PYTHONUNBUFFERED=1 \
  --device /dev/hailo0:/dev/hailo0 \
  -v /usr/lib/libhailort.so.5.1.1:/usr/lib/libhailort.so.5.1.1:ro \
  -v /usr/lib/libhailort.so:/usr/lib/libhailort.so:ro \
  ghcr.io/seeed-projects/recomputer-hailo10h-cv/arcface_mobilefacenet:latest \
  python web_detection.py --model_path model/arcface_mobilefacenet.hef --video_path video/test.mp4

打开 http://<Board_IP>:8000 查看网页预览。每帧会标注特征向量维度,REST API 返回完整的 512 维向量。

USB 摄像头模式

bash
sudo docker run --rm \
  --name cm5-hailo-arcface \
  --privileged \
  --net=host \
  -e PYTHONUNBUFFERED=1 \
  --device /dev/hailo0:/dev/hailo0 \
  --device /dev/video0:/dev/video0 \
  -v /usr/lib/libhailort.so.5.1.1:/usr/lib/libhailort.so.5.1.1:ro \
  -v /usr/lib/libhailort.so:/usr/lib/libhailort.so:ro \
  ghcr.io/seeed-projects/recomputer-hailo10h-cv/arcface_mobilefacenet:latest \
  python web_detection.py --model_path model/arcface_mobilefacenet.hef --camera_id 0

REST API

text
POST http://<Board_IP>:8000/api/models/arcface_mobilefacenet/predict
bash
curl -X POST "http://<Board_IP>:8000/api/models/arcface_mobilefacenet/predict" \
  -F "file=@face.jpg"
json
{
  "success": true,
  "source": "uploaded image",
  "embedding": [0.023, -0.156, 0.089, "..."],
  "dimension": 512,
  "image": { "width": 1280, "height": 720 }
}
接口方法用途
/GET网页预览界面
/api/models/arcface_mobilefacenet/predictPOST人脸特征向量(JSON)
/api/video_feedGETMJPEG 预览流
/api/configGET / POST读取或修改运行时阈值
/api/video/uploadPOST上传源视频
/api/video/analyzePOST开始离线视频分析
/api/video/statusGET读取分析进度
/api/video/download/{filename}GET下载标注结果

人脸验证不单独提供接口:请在客户端对两个返回向量做余弦相似度比较(先做 L2 归一化)。

HEF 文件

HEF大小说明
arcface_mobilefacenet.hef2,666,496 bytes面向 Hailo-10H 编译,Model Zoo v5.4.0

实现说明

  • HEF 内含归一化层,因此应用把画面 letterbox 到 112x112、BGR 转 RGB 后直接送入 uint8 像素。
  • 当 vstream 名称可见时,特征向量取自 fc1 输出;否则使用第一个输出张量。首次推理会打印全部 vstream 名称和 shape,便于在实机上核对映射。
  • 空向量或包含非有限值的向量会被拒绝,不会当作有效结果返回。

开发说明

  • 源码模块:src/hailo10h_arcface_mobilefacenet/
  • Dockerfile:docker/hailo10h/arcface_mobilefacenet.dockerfile
  • 镜像:ghcr.io/seeed-projects/recomputer-hailo10h-cv/arcface_mobilefacenet:latest
  • 模块使用 HailoRT 5.1.1 InferModel API 与面向 Hailo-10H 编译的 HEF。

输入与输出

输入:图像(112x112 RGB)。输出:512 维人脸特征向量;人脸比对由客户端完成。