Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6cfb59f
更新交叉编译
Zheng-Bicheng Jan 9, 2023
478f975
更新交叉编译
Zheng-Bicheng Jan 9, 2023
11081c4
更新交叉编译
Zheng-Bicheng Jan 9, 2023
8337768
更新交叉编译
Zheng-Bicheng Jan 10, 2023
f7d2ea9
更新交叉编译
Zheng-Bicheng Jan 10, 2023
d2eaaec
更新交叉编译
Zheng-Bicheng Jan 10, 2023
77e71c7
更新交叉编译
Zheng-Bicheng Jan 10, 2023
1d91da6
更新交叉编译
Zheng-Bicheng Jan 10, 2023
6575184
Merge branch 'develop' into test
Zheng-Bicheng Jan 10, 2023
be5efbc
Merge remote-tracking branch 'upstream/develop' into test
Zheng-Bicheng Jan 10, 2023
983837b
Merge remote-tracking branch 'origin/test' into test
Zheng-Bicheng Jan 10, 2023
00eab71
更新交叉编译
Zheng-Bicheng Jan 10, 2023
3e02c37
Update issues.md
jiangjiajun Jan 10, 2023
9e9687e
Update fastdeploy_init.sh
jiangjiajun Jan 10, 2023
64dc564
更新交叉编译
Zheng-Bicheng Jan 10, 2023
355a6e0
更新insightface系列模型的rknpu2支持
Zheng-Bicheng Jan 11, 2023
c3f899c
Merge branch 'develop' into test
Zheng-Bicheng Jan 11, 2023
c35787d
更新insightface系列模型的rknpu2支持
Zheng-Bicheng Jan 11, 2023
b637ba1
Merge remote-tracking branch 'origin/test' into test
Zheng-Bicheng Jan 11, 2023
0693c59
更新说明文档
Zheng-Bicheng Jan 11, 2023
da14acb
Merge branch 'develop' into test
jiangjiajun Jan 12, 2023
aa7aee4
更新insightface
Zheng-Bicheng Jan 12, 2023
027b762
Merge remote-tracking branch 'origin/test' into test
Zheng-Bicheng Jan 12, 2023
dcc6ac2
尝试解决pybind问题
Zheng-Bicheng Jan 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions docs/cn/faq/rknpu2/rknpu2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ ONNX模型不能直接调用RK芯片中的NPU进行运算,需要把ONNX模型
* ARM CPU使用ONNX框架进行测试
* NPU均使用单核进行测试

| 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) |
|----------------|------------------------------------------------------------------------------------------|--------------------------|--------------------|
| Detection | [Picodet](../../../../examples/vision/detection/paddledetection/rknpu2/README.md) | Picodet-s | 162/112 |
| Detection | [RKYOLOV5](../../../../examples/vision/detection/rkyolo/README.md) | YOLOV5-S-Relu(int8) | -/57 |
| Detection | [RKYOLOX](../../../../examples/vision/detection/rkyolo/README.md) | - | -/- |
| Detection | [RKYOLOV7](../../../../examples/vision/detection/rkyolo/README.md) | - | -/- |
| Segmentation | [Unet](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | Unet-cityscapes | -/- |
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | portrait(int8) | 133/43 |
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | human(int8) | 133/43 |
| Face Detection | [SCRFD](../../../../examples/vision/facedet/scrfd/rknpu2/README.md) | SCRFD-2.5G-kps-640(int8) | 108/42 |
| Classification | [ResNet](../../../../examples/vision/classification/paddleclas/rknpu2/README.md) | ResNet50_vd | -/33 |
| 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) |
|----------------------|------------------------------------------------------------------------------------------|--------------------------|--------------------|
| Detection | [Picodet](../../../../examples/vision/detection/paddledetection/rknpu2/README.md) | Picodet-s | 162/112 |
| Detection | [RKYOLOV5](../../../../examples/vision/detection/rkyolo/README.md) | YOLOV5-S-Relu(int8) | -/57 |
| Detection | [RKYOLOX](../../../../examples/vision/detection/rkyolo/README.md) | - | -/- |
| Detection | [RKYOLOV7](../../../../examples/vision/detection/rkyolo/README.md) | - | -/- |
| Segmentation | [Unet](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | Unet-cityscapes | -/- |
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | portrait(int8) | 133/43 |
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | human(int8) | 133/43 |
| Face Detection | [SCRFD](../../../../examples/vision/facedet/scrfd/rknpu2/README.md) | SCRFD-2.5G-kps-640(int8) | 108/42 |
| Face FaceRecognition | [InsightFace](../../../../examples/vision/faceid/insightface/rknpu2/README_CN.md) | ms1mv3_arcface_r18(int8) | 81/12 |
| Classification | [ResNet](../../../../examples/vision/classification/paddleclas/rknpu2/README.md) | ResNet50_vd | -/33 |

## 预编译库下载

为了方便大家进行开发,这里提供1.0.2版本的FastDeploy给大家使用

- [FastDeploy RK356X c++ SDK](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-rk356X-1.0.2.tgz)
- [FastDeploy RK3588 c++ SDK](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-rk3588-1.0.2.tgz)
2 changes: 0 additions & 2 deletions examples/vision/faceid/insightface/cpp/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ VPL模型加载和初始化,其中model_file为导出的ONNX模型格式。
通过InsightFaceRecognitionPreprocessor::SetAlpha(std::vector<float>& alpha)来进行修改
> > * **beta**(vector&lt;float&gt;): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f],
通过InsightFaceRecognitionPreprocessor::SetBeta(std::vector<float>& beta)来进行修改
> > * **permute**(bool): 预处理是否将BGR转换成RGB,默认true,
通过InsightFaceRecognitionPreprocessor::SetPermute(bool permute)来进行修改

#### InsightFaceRecognitionPostprocessor成员变量(后处理参数)
> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false,
Expand Down
1 change: 0 additions & 1 deletion examples/vision/faceid/insightface/python/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式
> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112]
> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5]
> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f]
> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True

#### AdaFacePostprocessor的成员变量
以下变量为AdaFacePostprocessor的成员变量
Expand Down
3 changes: 0 additions & 3 deletions examples/vision/faceid/insightface/python/infer_arcface.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def build_option(args):
face1 = cv2.imread(args.face_positive)
face2 = cv2.imread(args.face_negative) # 0,2 不同的人

# 设置 l2 normalize
model.postprocessor.l2_normalize = True

# 预测图片检测结果
result0 = model.predict(face0)
result1 = model.predict(face1)
Expand Down
3 changes: 0 additions & 3 deletions examples/vision/faceid/insightface/python/infer_cosface.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def build_option(args):
face1 = cv2.imread(args.face_positive)
face2 = cv2.imread(args.face_negative) # 0,2 不同的人

# 设置 l2 normalize
model.postprocessor.l2_normalize = True

# 预测图片检测结果
result0 = model.predict(face0)
result1 = model.predict(face1)
Expand Down
3 changes: 0 additions & 3 deletions examples/vision/faceid/insightface/python/infer_partial_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def build_option(args):
face1 = cv2.imread(args.face_positive)
face2 = cv2.imread(args.face_negative) # 0,2 不同的人

# 设置 l2 normalize
model.postprocessor.l2_normalize = True

# 预测图片检测结果
result0 = model.predict(face0)
result1 = model.predict(face1)
Expand Down
3 changes: 0 additions & 3 deletions examples/vision/faceid/insightface/python/infer_vpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def build_option(args):
face1 = cv2.imread(args.face_positive)
face2 = cv2.imread(args.face_negative) # 0,2 不同的人

# 设置 l2 normalize
model.postprocessor.l2_normalize = True

# 预测图片检测结果
result0 = model.predict(face0)
result1 = model.predict(face1)
Expand Down
54 changes: 54 additions & 0 deletions examples/vision/faceid/insightface/rknpu2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[English](README.md) | 简体中文
# InsightFace RKNPU准备部署模型

本教程提供InsightFace模型在RKNPU2环境下的部署,模型的详细介绍已经ONNX模型的下载请查看[模型介绍文档](../README.md)。

## 支持模型列表
目前FastDeploy支持如下模型的部署
- ArcFace
- CosFace
- PartialFC
- VPL

## 下载预训练ONNX模型

为了方便开发者的测试,下面提供了InsightFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于InsightFace中对各模型的介绍,详情各参考InsightFace中的说明

| 模型 | 大小 | 精度 (AgeDB_30) |
|:-------------------------------------------------------------------------------------------|:------|:--------------|
| [CosFace-r18](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r18.onnx) | 92MB | 97.7 |
| [CosFace-r34](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r34.onnx) | 131MB | 98.3 |
| [CosFace-r50](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r50.onnx) | 167MB | 98.3 |
| [CosFace-r100](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r100.onnx) | 249MB | 98.4 |
| [ArcFace-r18](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r18.onnx) | 92MB | 97.7 |
| [ArcFace-r34](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r34.onnx) | 131MB | 98.1 |
| [ArcFace-r50](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r50.onnx) | 167MB | - |
| [ArcFace-r100](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx) | 249MB | 98.4 |
| [ArcFace-r100_lr0.1](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_r100_lr01.onnx) | 249MB | 98.4 |
| [PartialFC-r34](https://bj.bcebos.com/paddlehub/fastdeploy/partial_fc_glint360k_r50.onnx) | 167MB | - |
| [PartialFC-r50](https://bj.bcebos.com/paddlehub/fastdeploy/partial_fc_glint360k_r100.onnx) | 249MB | - |


## 转换为RKNPU模型

```bash
wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r18.onnx

python -m paddle2onnx.optimize --input_model ./ms1mv3_arcface_r18/ms1mv3_arcface_r18.onnx \
--output_model ./ms1mv3_arcface_r18/ms1mv3_arcface_r18.onnx \
--input_shape_dict "{'data':[1,3,112,112]}"

python /Path/To/FastDeploy/tools/rknpu2/export.py \
--config_path tools/rknpu2/config/arcface_unquantized.yaml \
--target_platform rk3588
```

## 详细部署文档

- [Python部署](python)
- [C++部署](cpp)


## 版本说明

- 本版本文档和代码基于[InsightFace CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) 编写
13 changes: 13 additions & 0 deletions examples/vision/faceid/insightface/rknpu2/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PROJECT(infer_demo C CXX)
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)

# 指定下载解压后的fastdeploy库路径
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")

include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)

# 添加FastDeploy依赖头文件
include_directories(${FASTDEPLOY_INCS})

add_executable(infer_arcface_demo ${PROJECT_SOURCE_DIR}/infer_arcface.cc)
target_link_libraries(infer_arcface_demo ${FASTDEPLOY_LIBS})
135 changes: 135 additions & 0 deletions examples/vision/faceid/insightface/rknpu2/cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[English](README.md) | 简体中文
# InsightFace C++部署示例

FastDeploy支持在RKNPU上部署包括ArcFace\CosFace\VPL\Partial_FC在内的InsightFace系列模型。

本目录下提供`infer_arcface.cc`快速完成InsighFace模型包括ArcFace在CPU/RKNPU加速部署的示例。


在部署前,需确认以下两个步骤:

1. 软硬件环境满足要求
2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库

以上步骤请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)实现

在本目录执行如下命令即可完成编译测试

```bash
mkdir build
cd build
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j

# 下载官方转换好的ArcFace模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r18.onnx
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip
unzip face_demo.zip

# CPU推理
./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 0
# RKNPU推理
./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 1
```

运行完成可视化结果如下图所示

<div width="700">
<img width="220" float="left" src="https://user-images.githubusercontent.com/67993288/184321537-860bf857-0101-4e92-a74c-48e8658d838c.JPG">
<img width="220" float="left" src="https://user-images.githubusercontent.com/67993288/184322004-a551e6e4-6f47-454e-95d6-f8ba2f47b516.JPG">
<img width="220" float="left" src="https://user-images.githubusercontent.com/67993288/184321622-d9a494c3-72f3-47f1-97c5-8a2372de491f.JPG">
</div>

以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)

## InsightFace C++接口

### ArcFace类

```c++
fastdeploy::vision::faceid::ArcFace(
const string& model_file,
const string& params_file = "",
const RuntimeOption& runtime_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX)
```

ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式。

### CosFace类

```c++
fastdeploy::vision::faceid::CosFace(
const string& model_file,
const string& params_file = "",
const RuntimeOption& runtime_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX)
```

CosFace模型加载和初始化,其中model_file为导出的ONNX模型格式。

### PartialFC类

```c++
fastdeploy::vision::faceid::PartialFC(
const string& model_file,
const string& params_file = "",
const RuntimeOption& runtime_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX)
```

PartialFC模型加载和初始化,其中model_file为导出的ONNX模型格式。

### VPL类

```c++
fastdeploy::vision::faceid::VPL(
const string& model_file,
const string& params_file = "",
const RuntimeOption& runtime_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX)
```

VPL模型加载和初始化,其中model_file为导出的ONNX模型格式。
**参数**

> * **model_file**(str): 模型文件路径
> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可
> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式

#### Predict函数

> ```c++
> ArcFace::Predict(cv::Mat* im, FaceRecognitionResult* result)
> ```
>
> 模型预测接口,输入图像直接输出检测结果。
>
> **参数**
>
> > * **im**: 输入图像,注意需为HWC,BGR格式
> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceRecognitionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/)

### 修改预处理以及后处理的参数
预处理和后处理的参数的需要通过修改InsightFaceRecognitionPostprocessor,InsightFaceRecognitionPreprocessor的成员变量来进行修改。

#### InsightFaceRecognitionPreprocessor成员变量(预处理参数)
> > * **size**(vector&lt;int&gt;): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112],
通过InsightFaceRecognitionPreprocessor::SetSize(std::vector<int>& size)来进行修改
> > * **alpha**(vector&lt;float&gt;): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5],
通过InsightFaceRecognitionPreprocessor::SetAlpha(std::vector<float>& alpha)来进行修改
> > * **beta**(vector&lt;float&gt;): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f],
通过InsightFaceRecognitionPreprocessor::SetBeta(std::vector<float>& beta)来进行修改

#### InsightFaceRecognitionPostprocessor成员变量(后处理参数)
> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false,
InsightFaceRecognitionPostprocessor::SetL2Normalize(bool& l2_normalize)来进行修改

- [模型介绍](../../../)
- [Python部署](../python)
- [视觉模型预测结果](../../../../../../docs/api/vision_results/README.md)
- [如何切换模型推理后端引擎](../../../../../../docs/cn/faq/how_to_change_backend.md)
Loading