From 08a521dc39e20513989b2cdde31cd2a6a47c5e2c Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Mon, 4 Nov 2024 03:13:21 +0000 Subject: [PATCH 1/8] update example/vision/face_detection/README.md. Signed-off-by: Zheng-Bicheng --- example/vision/face_detection/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/vision/face_detection/README.md b/example/vision/face_detection/README.md index b634fed..b67800d 100644 --- a/example/vision/face_detection/README.md +++ b/example/vision/face_detection/README.md @@ -31,7 +31,11 @@ 在深度学习中,RetinaFace是一种高效的人脸检测模型,旨在准确识别图像中的人脸及其关键点。该模型结合了特征金字塔网络(FPN)和单阶段检测方法,能够在不同尺度下进行人脸检测,从而提高了对小型和远距离人脸的检测能力。RetinaFace不仅能够检测人脸位置,还能提供人脸的五个关键点(如眼睛、鼻子和嘴巴)的坐标,适用于多种人脸识别和分析应用。 -## 2 在凌智视觉模块上部署模型 +## 2 运行前的准备 + +* 请确保你已经下载了 [凌智视觉模块人脸检测模型](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LZ-DigitHandRecog.rknn) + +## 3 在凌智视觉模块上部署模型 训练完模型后,请参考以下教程在凌智视觉模块上部署检测模型例程: -- Gitee From 6dc6b78230779c63036ff60d00237df6b1837157 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Mon, 4 Nov 2024 03:14:10 +0000 Subject: [PATCH 2/8] update example/vision/face_detection/README.md. Signed-off-by: Zheng-Bicheng --- example/vision/face_detection/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/vision/face_detection/README.md b/example/vision/face_detection/README.md index b67800d..2f6ac58 100644 --- a/example/vision/face_detection/README.md +++ b/example/vision/face_detection/README.md @@ -2,7 +2,7 @@ 发布版本:V0.0.0 -日期:2024-09-11 +日期:2024-11-04 文件密级:□绝密 □秘密 □内部资料 ■公开 @@ -25,7 +25,7 @@ | **日期** | **版本** | **作者** | **修改说明** | | :--------- | -------- | -------- | ------------ | -| 2024/09/11 | 0.0.0 | 郑必城 | 初始版本 | +| 2024/11/04 | 0.0.0 | 郑必城 | 初始版本 | ## 1 简介 -- Gitee From 3861ff709a37e49c4c66028ba7a99ad15cab9faf Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Mon, 4 Nov 2024 03:14:25 +0000 Subject: [PATCH 3/8] update example/vision/face_detection/python/README.md. Signed-off-by: Zheng-Bicheng --- example/vision/face_detection/python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/vision/face_detection/python/README.md b/example/vision/face_detection/python/README.md index 4eb920b..8d8e744 100644 --- a/example/vision/face_detection/python/README.md +++ b/example/vision/face_detection/python/README.md @@ -2,7 +2,7 @@ 发布版本:V0.0.0 -日期:2024-09-11 +日期:2024-11-04 文件密级:□绝密 □秘密 □内部资料 ■公开 @@ -25,7 +25,7 @@ | **日期** | **版本** | **作者** | **修改说明** | | :--------- | -------- | -------- | ------------ | -| 2024/09/11 | 0.0.0 | 郑必城 | 初始版本 | +| 2024/11/04 | 0.0.0 | 郑必城 | 初始版本 | ## 1 简介 -- Gitee From f7533dc9ad620600824186242b33e136b2f36f10 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Thu, 7 Nov 2024 17:47:19 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E6=A3=80=E6=B5=8B/=E8=AF=86=E5=88=AB=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 ++++++++- configs/LZ-ArcFace.yaml | 26 ++++++++++++++++++++++++++ docs/models/arcface.md | 34 ++++++++++++++++++++++++++++++++++ docs/models/retinaface.md | 24 ++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 configs/LZ-ArcFace.yaml create mode 100644 docs/models/arcface.md create mode 100644 docs/models/retinaface.md diff --git a/.gitignore b/.gitignore index f7704e1..b33e012 100644 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,15 @@ Temp dataset.txt # Model +*.pdiparams +*.pdiparams.info +*.pdmodel *.onnx *.rknn # Picture -*.jpg \ No newline at end of file +*.jpg + +# Zip +*.tar +*.zip diff --git a/configs/LZ-ArcFace.yaml b/configs/LZ-ArcFace.yaml new file mode 100644 index 0000000..869c4ad --- /dev/null +++ b/configs/LZ-ArcFace.yaml @@ -0,0 +1,26 @@ +config: + mean: + - 0.406 + - 0.456 + - 0.485 + std: + - 0.225 + - 0.224 + - 0.229 + type: "fp32" + +load_onnx: + inputs: + - x + input_size_list: + - + - 1 + - 3 + - 224 + - 224 + outputs: + - save_infer_model/scale_0.tmp_1 + +build: + do_quantization: True + dataset: ./dataset.txt \ No newline at end of file diff --git a/docs/models/arcface.md b/docs/models/arcface.md new file mode 100644 index 0000000..c001857 --- /dev/null +++ b/docs/models/arcface.md @@ -0,0 +1,34 @@ +```bash +cd /path/to/LockzhinerVisionModule + +rm -rf mobileface_v1.0_infer.tar +wget https://paddle-model-ecology.bj.bcebos.com/model/insight-face/mobileface_v1.0_infer.tar +tar -xvf mobileface_v1.0_infer.tar + +rm LZ-ArcFace.onnx +paddle2onnx --model_dir mobileface_v1.0_infer \ + --model_filename inference.pdmodel \ + --params_filename inference.pdiparams \ + --save_file LZ-ArcFace.onnx \ + --deploy_backend rknn + +rm face_demo.zip +rm face_0.jpg +rm face_1.jpg +rm face_2.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip +unzip face_demo.zip + +rm dataset.txt +touch dataset.txt +echo face_0.jpg > dataset.txt +echo face_1.jpg > dataset.txt +echo face_2.jpg > dataset.txt + +rm LZ-ArcFace.rknn +python utils/export.py \ + --config_path=./configs/LZ-ArcFace.yaml \ + --model_load_path=./LZ-ArcFace.onnx \ + --model_save_path=./LZ-ArcFace.rknn \ + --target_platform=RV1106 +``` \ No newline at end of file diff --git a/docs/models/retinaface.md b/docs/models/retinaface.md new file mode 100644 index 0000000..89f77f5 --- /dev/null +++ b/docs/models/retinaface.md @@ -0,0 +1,24 @@ +```bash +cd /path/to/LockzhinerVisionModule + +rm RetinaFace_mobile320.onnx +wget https://ftrg.zbox.filez.com/v2/delivery/data/95f00b0fc900458ba134f8b180b3f7a1/examples/RetinaFace/RetinaFace_mobile320.onnx + +rm LZ-RetinaFace.onnx +mv RetinaFace_mobile320.onnx LZ-RetinaFace.onnx + +rm test.jpg +# 下载不了去 https://github.com/airockchip/rknn_model_zoo/blob/main/examples/RetinaFace/model/test.jpg 下载 +wget -O test.jpg https://s21.ax1x.com/2024/11/07/pAyN4VU.jpg + +rm dataset.txt +touch dataset.txt +echo test.jpg > dataset.txt + +rm LZ-RetinaFace.rknn +python utils/export.py \ + --config_path=./configs/LZ-RetinaFace.yaml \ + --model_load_path=./LZ-RetinaFace.onnx \ + --model_save_path=./LZ-RetinaFace.rknn \ + --target_platform=RV1106 +``` \ No newline at end of file -- Gitee From 25cc1f6500527a16a6254fbf954459cc74df39ab Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Thu, 7 Nov 2024 18:12:52 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/LZ-ArcFace.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/LZ-ArcFace.yaml b/configs/LZ-ArcFace.yaml index 869c4ad..1ad745f 100644 --- a/configs/LZ-ArcFace.yaml +++ b/configs/LZ-ArcFace.yaml @@ -16,8 +16,8 @@ load_onnx: - - 1 - 3 - - 224 - - 224 + - 112 + - 112 outputs: - save_infer_model/scale_0.tmp_1 -- Gitee From d1f7e8d8508eca01b7309c4678b47d251f782208 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Thu, 7 Nov 2024 19:01:43 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/LZ-ArcFace.yaml | 9 +++++---- configs/LZ-MobileNetV3.yaml | 1 + configs/LZ-Picodet.yaml | 1 + configs/LZ-Picodet_fp32.yaml | 1 + configs/LZ-RetinaFace.yaml | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configs/LZ-ArcFace.yaml b/configs/LZ-ArcFace.yaml index 1ad745f..789cdb1 100644 --- a/configs/LZ-ArcFace.yaml +++ b/configs/LZ-ArcFace.yaml @@ -1,12 +1,13 @@ config: + # RGB mean: - - 0.406 - - 0.456 - 0.485 + - 0.456 + - 0.406 std: - - 0.225 - - 0.224 - 0.229 + - 0.224 + - 0.225 type: "fp32" load_onnx: diff --git a/configs/LZ-MobileNetV3.yaml b/configs/LZ-MobileNetV3.yaml index 6a42da0..3020477 100644 --- a/configs/LZ-MobileNetV3.yaml +++ b/configs/LZ-MobileNetV3.yaml @@ -1,4 +1,5 @@ config: + # BGR mean: - 0.406 - 0.456 diff --git a/configs/LZ-Picodet.yaml b/configs/LZ-Picodet.yaml index d69b926..ce39f0e 100644 --- a/configs/LZ-Picodet.yaml +++ b/configs/LZ-Picodet.yaml @@ -1,4 +1,5 @@ config: + # BGR mean: - 0.406 - 0.456 diff --git a/configs/LZ-Picodet_fp32.yaml b/configs/LZ-Picodet_fp32.yaml index 1ceb394..8071fd3 100644 --- a/configs/LZ-Picodet_fp32.yaml +++ b/configs/LZ-Picodet_fp32.yaml @@ -1,4 +1,5 @@ config: + # BGR mean: - 0.406 - 0.456 diff --git a/configs/LZ-RetinaFace.yaml b/configs/LZ-RetinaFace.yaml index 3eacb28..e51314c 100644 --- a/configs/LZ-RetinaFace.yaml +++ b/configs/LZ-RetinaFace.yaml @@ -1,4 +1,5 @@ config: + # RGB mean: - -104 - -117 -- Gitee From 3f178e9be344483f749005649dc6bd8d515a295f Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Fri, 8 Nov 2024 09:30:38 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + example/vision/face_detection/README.md | 6 +- .../vision/face_detection/python/README.md | 2 +- example/vision/face_recognition/README.md | 55 ++++++ .../vision/face_recognition/python/README.md | 182 ++++++++++++++++++ .../face_recognition/python/test_arc_face.py | 24 +++ 6 files changed, 266 insertions(+), 4 deletions(-) create mode 100644 example/vision/face_recognition/README.md create mode 100644 example/vision/face_recognition/python/README.md create mode 100644 example/vision/face_recognition/python/test_arc_face.py diff --git a/README.md b/README.md index 237e34b..47d502a 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ Lockzhiner Vision Module 拥有丰富的 IO 接口,其接口图片如下图所 * [凌智视觉模块二维码检测与识别部署指南](./example/special/qr_code_recognition) * [凌智视觉模块条码检测与识别部署指南](./example/special/bar_code_recognition) * [凌智视觉模块人脸检测部署指南](example/vision/face_detection) +* [凌智视觉模块人脸识别部署指南](example/vision/face_recognition) ## 🐛 Bug反馈 diff --git a/example/vision/face_detection/README.md b/example/vision/face_detection/README.md index 2f6ac58..784ae33 100644 --- a/example/vision/face_detection/README.md +++ b/example/vision/face_detection/README.md @@ -29,11 +29,11 @@ ## 1 简介 -在深度学习中,RetinaFace是一种高效的人脸检测模型,旨在准确识别图像中的人脸及其关键点。该模型结合了特征金字塔网络(FPN)和单阶段检测方法,能够在不同尺度下进行人脸检测,从而提高了对小型和远距离人脸的检测能力。RetinaFace不仅能够检测人脸位置,还能提供人脸的五个关键点(如眼睛、鼻子和嘴巴)的坐标,适用于多种人脸识别和分析应用。 +在深度学习中,RetinaFace 是一种高效的人脸检测模型,旨在准确识别图像中的人脸及其关键点。该模型结合了特征金字塔网络(FPN)和单阶段检测方法,能够在不同尺度下进行人脸检测,从而提高了对小型和远距离人脸的检测能力。RetinaFace 不仅能够检测人脸位置,还能提供人脸的五个关键点(如眼睛、鼻子和嘴巴)的坐标,适用于多种人脸识别和分析应用。 ## 2 运行前的准备 -* 请确保你已经下载了 [凌智视觉模块人脸检测模型](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LZ-DigitHandRecog.rknn) +* 请确保你已经下载了 [凌智视觉模块人脸检测模型](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LZ-RetinaFace.rknn) ## 3 在凌智视觉模块上部署模型 @@ -46,6 +46,6 @@ 以下测试数据为模型执行 Predict 函数运行 1000 次耗时的平均时间 -| 检测模型 | FPS(帧/s) | 精度(%) | +| 人脸检测模型 | FPS(帧/s) | 精度(%) | |:-------:|:----:|:----:| |LZ-RetinaFace| 38 | - | \ No newline at end of file diff --git a/example/vision/face_detection/python/README.md b/example/vision/face_detection/python/README.md index 8d8e744..fc693f3 100644 --- a/example/vision/face_detection/python/README.md +++ b/example/vision/face_detection/python/README.md @@ -31,7 +31,7 @@ 接下来让我们基于 Python 来部署 RetinaFace 人脸检测模型。在开始本章节前: -- 请确保你已经参考 [凌智视觉模块检测模型部署指南](../README.md) 对模型进行了充分训练。 +- 请确保你已经参考 [凌智视觉模块人脸检测模型部署指南](../README.md) 正确下载了凌智视觉模块人脸检测模型。 - 请确保你已经按照 [开发环境搭建指南](../../../../docs/introductory_tutorial/python_development_environment.md) 正确配置了开发环境。 ## 2 Python API 文档 diff --git a/example/vision/face_recognition/README.md b/example/vision/face_recognition/README.md new file mode 100644 index 0000000..801af0f --- /dev/null +++ b/example/vision/face_recognition/README.md @@ -0,0 +1,55 @@ +

凌智视觉模块人脸识别模型部署指南

+ +发布版本:V0.0.0 + +日期:2024-11-04 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/11/04 | 0.0.0 | 郑必城 | 初始版本 | + +## 1 简介 + +ArcFace 是一种基于深度学习的人脸识别模型,专注于在人脸特征向量(即嵌入)上实现更高的区分度。其核心在于 **角度间隔 (Angular Margin)** 的思想,通过将类间距离投影到角度空间进行学习,使得模型能够更精确地将不同类别(人脸)的特征分离开来。 + +在实际应用中, ArcFace 通过改进传统的 Softmax 损失函数,引入角度间隔损失来优化人脸的嵌入特征。具体而言,该模型将人脸特征映射到一个单位圆上,并在不同类别之间引入一个固定的角度间隔,从而保证不同人脸类别的特征向量在角度空间上更加分离。这一方法使得模型在区分相似人脸或小样本人脸方面更加有效。 + +ArcFace 的应用领域广泛,尤其在需要高度准确的身份验证、访问控制和智能安防等场景中展现出显著的性能优势。其优势在于模型能够在多样化和大规模的人脸识别任务中保持高效,同时也具有良好的泛化能力。 + +## 2 运行前的准备 + +* 请确保你已经下载了 [凌智视觉模块人脸识别模型](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LZ-ArcFace.rknn) + +## 3 在凌智视觉模块上部署模型 + +训练完模型后,请参考以下教程在凌智视觉模块上部署检测模型例程: + + +* [凌智视觉模块人脸识别模型 Python 部署指南](./python) + +## 4 各模型性能指标 + +以下测试数据为模型执行 Predict 函数运行 1000 次耗时的平均时间 + +| 人脸识别模型 | FPS(帧/s) | 精度(%) | +|:-------:|:----:|:----:| +|LZ-ArcFace| 120 | - | \ No newline at end of file diff --git a/example/vision/face_recognition/python/README.md b/example/vision/face_recognition/python/README.md new file mode 100644 index 0000000..6e8603c --- /dev/null +++ b/example/vision/face_recognition/python/README.md @@ -0,0 +1,182 @@ +

凌智视觉模块人脸识别模型 Python 部署指南

+ +发布版本:V0.0.0 + +日期:2024-11-04 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/11/04 | 0.0.0 | 郑必城 | 初始版本 | + +## 1 简介 + +接下来让我们基于 Python 来部署 ArcFace 人脸识别模型。在开始本章节前: + +- 请确保你已经参考 [凌智视觉模块人脸识别模型部署指南](../README.md) 正确下载了凌智视觉模块人脸识别模型。 +- 请确保你已经按照 [开发环境搭建指南](../../../../docs/introductory_tutorial/python_development_environment.md) 正确配置了开发环境。 + +## 2 Python API 文档 + +```python +class FaceRecognitionResult: + """ + 人脸识别结果类,用于封装和处理人脸识别结果数据。 + + 该类主要提供了一个包装层,用于访问和管理由视觉模块产生的人脸识别结果。 + """ + + def __init__(self): + self.face_recognition_result = vision.FaceRecognitionResult() + + @property + def feature(self): + """ + 获取人脸识别结果的特征信息 + + Returns: + list(float): 特征信息 + """ + return self.face_recognition_result.feature + +class ArcFace: + """ + ArcFace 类 - 用于人脸识别的 ArcFace 模型封装。 + + 该类封装了 InsightFace 框架下的 ArcFace 人脸识别模型,提供了初始化和预测的方法。 + """ + + def __init__(self): + """ + 构造函数 - 初始化 PaddleDet 对象。 + """ + self.model = vision.ArcFace() + + def initialize(self, model_path): + """ + 初始化模型 - 加载预训练的 ArcFace 模型。 + + Args: + model_path (str): 模型文件的路径。 + + Returns: + bool: 初始化是否成功。 + """ + return self.model.initialize(model_path) + + def predict(self, input_mat): + """ + 进行预测 - 使用加载的模型对输入数据进行分类预测。 + + Args: + input_mat (cv2.Mat): 输入的图像数据,通常是一个 cv2.Mat 变量。 + + Returns: + FaceRecognitionResult: 人脸识别结果,包含了 128 维度的人脸特征 + """ + return self.model.predict(input_mat) +``` + +## 3 项目介绍 + +为了方便大家入手,我们做了一个简易的人脸识别例程。该程序可以使用摄像头进行端到端推理。 + +```python +from lockzhiner_vision_module.cv2 import VideoCapture +from lockzhiner_vision_module.vision import RetinaFace, visualize +from lockzhiner_vision_module.edit import Edit +import time +import sys + +if __name__ == "__main__": + args = sys.argv + if len(args) != 2: + print("Need model path. Example: python test_retina_face.py LZ-RetinaFace.rknn") + exit(1) + + edit = Edit() + edit.start_and_accept_connection() + + model = RetinaFace() + if model.initialize(args[1]) is False: + print("Failed to initialize RetinaFace") + exit(1) + + video_capture = VideoCapture() + if video_capture.open(0) is False: + print("Failed to open capture") + exit(1) + + while True: + read_index = 0 + total_time_ms = 0 + for i in range(30): + ret, mat = video_capture.read() + if ret is False: + continue + + start_time = time.time() + results = model.predict(mat) + end_time = time.time() + total_time_ms += end_time - start_time + read_index += 1 + + print(f"result size is {len(results)}") + for result in results: + box = result.box + score = result.score + label_id = result.label_id + print( + f"(x,y,w,h,score): [{box.x},{box.y},{box.width},{box.height},{score}]" + ) + vis_mat = visualize(mat, results) + edit.print(vis_mat) + print(f"FPS is {1.0 / (total_time_ms/read_index)}") +``` + +## 4 上传并测试 Python 程序 + +参考 [连接设备指南](../../../../docs/introductory_tutorial/connect_device_using_ssh.md) 正确连接 Lockzhiner Vision Module 设备。 + +![](../../../../docs/introductory_tutorial/images/connect_device_using_ssh/ssh_success.png) + +请使用 Electerm Sftp 依次上传以下两个文件: + +- 进入存放 **test_retina_face.py** 脚本文件的目录,将 **test_retina_face.py** 上传到 Lockzhiner Vision Module +- 进入存放 **LZ-RetinaFace.rknn(也可能是其他模型)** 模型存放的目录(模型存放在训练模型后下载的 output 文件夹内),将 **LZ-RetinaFace.rknn** 上传到 Lockzhiner Vision Module + +![](images/stfp_0.png) + +![](images/stfp_1.png) + +请使用 Electerm Ssh 并在命令行中执行以下命令: + +```bash +python test_retina_face.py LZ-RetinaFace.rknn +``` + +运行程序后,屏幕上开始打印矩形框信息和置信度,并在一段时间后输出 FPS 值 + +![alt text](result_0.png) + + + + diff --git a/example/vision/face_recognition/python/test_arc_face.py b/example/vision/face_recognition/python/test_arc_face.py new file mode 100644 index 0000000..ff1e5af --- /dev/null +++ b/example/vision/face_recognition/python/test_arc_face.py @@ -0,0 +1,24 @@ +from lockzhiner_vision_module.cv2 import imread +from lockzhiner_vision_module.vision import ArcFace, cosine_similarity +import time +import sys + +if __name__ == "__main__": + args = sys.argv + if len(args) != 4: + print("Need model path. Example: python test_arc_face.py LZ-ArcFace.rknn image_path_0 image_path_1") + exit(1) + + model = ArcFace() + if model.initialize(args[1]) is False: + print("Failed to initialize ArcFace") + exit(1) + + input_mat_0 = imread(args[2]) + result_0 = model.predict(input_mat_0) + + input_mat_1 = imread(args[3]) + result_1 = model.predict(input_mat_1) + + + print(f"Similarity is {cosine_similarity(result_0, result_1)}") \ No newline at end of file -- Gitee From bc03c442343fab0c2c53be1f8b76424bad60f8fa Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Fri, 8 Nov 2024 09:34:18 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vision/face_recognition/python/README.md | 58 +++++-------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/example/vision/face_recognition/python/README.md b/example/vision/face_recognition/python/README.md index 6e8603c..b0ec275 100644 --- a/example/vision/face_recognition/python/README.md +++ b/example/vision/face_recognition/python/README.md @@ -100,56 +100,30 @@ class ArcFace: 为了方便大家入手,我们做了一个简易的人脸识别例程。该程序可以使用摄像头进行端到端推理。 ```python -from lockzhiner_vision_module.cv2 import VideoCapture -from lockzhiner_vision_module.vision import RetinaFace, visualize -from lockzhiner_vision_module.edit import Edit +from lockzhiner_vision_module.cv2 import imread +from lockzhiner_vision_module.vision import ArcFace, cosine_similarity import time import sys if __name__ == "__main__": args = sys.argv - if len(args) != 2: - print("Need model path. Example: python test_retina_face.py LZ-RetinaFace.rknn") + if len(args) != 4: + print("Need model path. Example: python test_arc_face.py LZ-ArcFace.rknn image_path_0 image_path_1") exit(1) - edit = Edit() - edit.start_and_accept_connection() - - model = RetinaFace() + model = ArcFace() if model.initialize(args[1]) is False: - print("Failed to initialize RetinaFace") + print("Failed to initialize ArcFace") exit(1) - video_capture = VideoCapture() - if video_capture.open(0) is False: - print("Failed to open capture") - exit(1) + input_mat_0 = imread(args[2]) + result_0 = model.predict(input_mat_0) + + input_mat_1 = imread(args[3]) + result_1 = model.predict(input_mat_1) + - while True: - read_index = 0 - total_time_ms = 0 - for i in range(30): - ret, mat = video_capture.read() - if ret is False: - continue - - start_time = time.time() - results = model.predict(mat) - end_time = time.time() - total_time_ms += end_time - start_time - read_index += 1 - - print(f"result size is {len(results)}") - for result in results: - box = result.box - score = result.score - label_id = result.label_id - print( - f"(x,y,w,h,score): [{box.x},{box.y},{box.width},{box.height},{score}]" - ) - vis_mat = visualize(mat, results) - edit.print(vis_mat) - print(f"FPS is {1.0 / (total_time_ms/read_index)}") + print(f"Similarity is {cosine_similarity(result_0, result_1)}") ``` ## 4 上传并测试 Python 程序 @@ -160,8 +134,8 @@ if __name__ == "__main__": 请使用 Electerm Sftp 依次上传以下两个文件: -- 进入存放 **test_retina_face.py** 脚本文件的目录,将 **test_retina_face.py** 上传到 Lockzhiner Vision Module -- 进入存放 **LZ-RetinaFace.rknn(也可能是其他模型)** 模型存放的目录(模型存放在训练模型后下载的 output 文件夹内),将 **LZ-RetinaFace.rknn** 上传到 Lockzhiner Vision Module +- 进入存放 **test_arc_face.py** 脚本文件的目录,将 **test_arc_face.py** 上传到 Lockzhiner Vision Module +- 进入存放 **LZ-ArcFace.rknn(也可能是其他模型)** 模型存放的目录(模型存放在训练模型后下载的 output 文件夹内),将 **LZ-ArcFace.rknn** 上传到 Lockzhiner Vision Module ![](images/stfp_0.png) @@ -170,7 +144,7 @@ if __name__ == "__main__": 请使用 Electerm Ssh 并在命令行中执行以下命令: ```bash -python test_retina_face.py LZ-RetinaFace.rknn +python test_arc_face.py LZ-ArcFace.rknn image_path_0 image_path_1 ``` 运行程序后,屏幕上开始打印矩形框信息和置信度,并在一段时间后输出 FPS 值 -- Gitee