Merge branch 'develop' of https://github.com/PaddlePaddle/FastDeploy into huawei

This commit is contained in:
yunyaoXYY
2022-12-29 09:22:26 +00:00
8 changed files with 67 additions and 35 deletions

View File

@@ -62,7 +62,7 @@ if(PADDLEINFERENCE_DIRECTORY)
execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/copy_directory.py ${PADDLEINFERENCE_DIRECTORY} ${THIRD_PARTY_PATH}/install/paddle_inference)
else()
set(PADDLEINFERENCE_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/")
set(PADDLEINFERENCE_VERSION "2.4-dev3")
set(PADDLEINFERENCE_VERSION "2.4-dev4")
if(WIN32)
if (WITH_GPU)
set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.zip")

View File

@@ -23,4 +23,4 @@ ONNX模型不能直接调用RK芯片中的NPU进行运算需要把ONNX模型
| 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 | -/92 |
| Classification | [ResNet](../../../../examples/vision/classification/paddleclas/rknpu2/README.md) | ResNet50_vd | -/33 |

View File

@@ -3,7 +3,8 @@
# Linux上C++部署
1. 编译完成运行,提示找不到.so文件
1. 编译完成运行,提示找不到.so文件 "cannot open shared object file: No such file or directory"
在执行二进制文件时需要能够在环境变量中找到FastDeploy相关的库文件。FastDeploy提供了辅助脚本来帮助完成。

View File

@@ -3,6 +3,7 @@
## 转换模型
下面以 ResNet50_vd为例子教大家如何转换分类模型到RKNN模型。
### 导出ONNX模型
```bash
# 安装 paddle2onnx
pip install paddle2onnx
@@ -17,7 +18,7 @@ paddle2onnx --model_dir ResNet50_vd_infer \
--params_filename inference.pdiparams \
--save_file ResNet50_vd_infer/ResNet50_vd_infer.onnx \
--enable_dev_version True \
--opset_version 12 \
--opset_version 10 \
--enable_onnx_checker True
# 固定shape注意这里的inputs得对应netron.app展示的 inputs 的 name有可能是image 或者 x
@@ -26,25 +27,50 @@ python -m paddle2onnx.optimize --input_model ResNet50_vd_infer/ResNet50_vd_infer
--input_shape_dict "{'inputs':[1,3,224,224]}"
```
### 编写模型导出配置文件
### 编写模型导出配置文件
以转化RK3588的RKNN模型为例子我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml来转换ONNX模型到RKNN模型。
默认的 mean=0, std=1是在内存做normalize如果你需要在NPU上执行normalize操作请根据你的模型配置normalize参数例如:
如果你需要在NPU上执行normalize操作请根据你的模型配置normalize参数例如:
```yaml
model_path: ./ResNet50_vd_infer.onnx
output_folder: ./
target_platform: RK3588
normalize:
mean: [[0.485,0.456,0.406]]
std: [[0.229,0.224,0.225]]
outputs: []
outputs_nodes: []
model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx
output_folder: ./ResNet50_vd_infer
mean:
-
- 123.675
- 116.28
- 103.53
std:
-
- 58.395
- 57.12
- 57.375
outputs_nodes:
do_quantization: False
dataset:
dataset: "./ResNet50_vd_infer/dataset.txt"
```
**在CPU上做normalize**可以参考以下yaml
```yaml
model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx
output_folder: ./ResNet50_vd_infer
mean:
-
- 0
- 0
- 0
std:
-
- 1
- 1
- 1
outputs_nodes:
do_quantization: False
dataset: "./ResNet50_vd_infer/dataset.txt"
```
这里我们选择在NPU上执行normalize操作.
# ONNX模型转RKNN模型
### ONNX模型转RKNN模型
```shell
python tools/rknpu2/export.py \
--config_path tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml \

View File

@@ -57,7 +57,7 @@ bool PaddleClasPreprocessor::BuildPreprocessPipelineFromConfig() {
int height = op.begin()->second["size"].as<int>();
processors_.push_back(std::make_shared<CenterCrop>(width, height));
} else if (op_name == "NormalizeImage") {
if (!disable_normalize) {
if (!disable_normalize_) {
auto mean = op.begin()->second["mean"].as<std::vector<float>>();
auto std = op.begin()->second["std"].as<std::vector<float>>();
auto scale = op.begin()->second["scale"].as<float>();
@@ -67,7 +67,7 @@ bool PaddleClasPreprocessor::BuildPreprocessPipelineFromConfig() {
processors_.push_back(std::make_shared<Normalize>(mean, std));
}
} else if (op_name == "ToCHWImage") {
if (!disable_permute) {
if (!disable_permute_) {
processors_.push_back(std::make_shared<HWC2CHW>());
}
} else {
@@ -83,14 +83,14 @@ bool PaddleClasPreprocessor::BuildPreprocessPipelineFromConfig() {
}
void PaddleClasPreprocessor::DisableNormalize() {
this->disable_normalize = true;
this->disable_normalize_ = true;
// the DisableNormalize function will be invalid if the configuration file is loaded during preprocessing
if (!BuildPreprocessPipelineFromConfig()) {
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;
}
}
void PaddleClasPreprocessor::DisablePermute() {
this->disable_permute = true;
this->disable_permute_ = true;
// the DisablePermute function will be invalid if the configuration file is loaded during preprocessing
if (!BuildPreprocessPipelineFromConfig()) {
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;

View File

@@ -59,9 +59,9 @@ class FASTDEPLOY_DECL PaddleClasPreprocessor {
// GPU device id
int device_id_ = -1;
// for recording the switch of hwc2chw
bool disable_permute = false;
bool disable_permute_ = false;
// for recording the switch of normalize
bool disable_normalize = false;
bool disable_normalize_ = false;
// read config file
std::string config_file_;
};

View File

@@ -3,6 +3,6 @@ requests
tqdm
numpy
opencv-python
fastdeploy-tools>=0.0.1
fastdeploy-tools>=0.0.2
pyyaml
fastapi

View File

@@ -1,10 +1,15 @@
model_path: ./ResNet50_vd_infer.onnx
output_folder: ./
target_platform: RK3588
normalize:
mean: [[0, 0, 0]]
std: [[1, 1, 1]]
outputs: []
outputs_nodes: []
model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx
output_folder: ./ResNet50_vd_infer
mean:
-
- 123.675
- 116.28
- 103.53
std:
-
- 58.395
- 57.12
- 57.375
outputs_nodes:
do_quantization: False
dataset:
dataset: "./ResNet50_vd_infer/dataset.txt"