From 0401580264fd015e60cc0024694871406e3599f2 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng <58363586+Zheng-Bicheng@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:13:55 +0800 Subject: [PATCH 1/4] [Bug Fix] Fixed Ppclas Bugs (#1009) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更新ppclas * 更新ppclas * 更新ppclas * 更新ppclas --- docs/cn/faq/rknpu2/rknpu2.md | 2 +- .../paddleclas/rknpu2/README.md | 58 ++++++++++++++----- .../classification/ppcls/preprocessor.cc | 8 +-- .../classification/ppcls/preprocessor.h | 4 +- .../rknpu2/config/ResNet50_vd_infer_rknn.yaml | 23 +++++--- 5 files changed, 63 insertions(+), 32 deletions(-) diff --git a/docs/cn/faq/rknpu2/rknpu2.md b/docs/cn/faq/rknpu2/rknpu2.md index e0384e051..fcd3e7c35 100644 --- a/docs/cn/faq/rknpu2/rknpu2.md +++ b/docs/cn/faq/rknpu2/rknpu2.md @@ -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 | diff --git a/examples/vision/classification/paddleclas/rknpu2/README.md b/examples/vision/classification/paddleclas/rknpu2/README.md index bd4305dc0..d61e6c570 100644 --- a/examples/vision/classification/paddleclas/rknpu2/README.md +++ b/examples/vision/classification/paddleclas/rknpu2/README.md @@ -3,6 +3,7 @@ ## 转换模型 下面以 ResNet50_vd为例子,教大家如何转换分类模型到RKNN模型。 +### 导出ONNX模型 ```bash # 安装 paddle2onnx pip install paddle2onnx @@ -17,34 +18,59 @@ 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 python -m paddle2onnx.optimize --input_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ --output_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ --input_shape_dict "{'inputs':[1,3,224,224]}" -``` +``` - ### 编写模型导出配置文件 -以转化RK3588的RKNN模型为例子,我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml,来转换ONNX模型到RKNN模型。 +### 编写模型导出配置文件 +以转化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 \ @@ -54,4 +80,4 @@ python tools/rknpu2/export.py \ ## 其他链接 - [Cpp部署](./cpp) - [Python部署](./python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) \ No newline at end of file +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/fastdeploy/vision/classification/ppcls/preprocessor.cc b/fastdeploy/vision/classification/ppcls/preprocessor.cc index ef8d8f20e..aa4314cf8 100644 --- a/fastdeploy/vision/classification/ppcls/preprocessor.cc +++ b/fastdeploy/vision/classification/ppcls/preprocessor.cc @@ -57,7 +57,7 @@ bool PaddleClasPreprocessor::BuildPreprocessPipelineFromConfig() { int height = op.begin()->second["size"].as(); processors_.push_back(std::make_shared(width, height)); } else if (op_name == "NormalizeImage") { - if (!disable_normalize) { + if (!disable_normalize_) { auto mean = op.begin()->second["mean"].as>(); auto std = op.begin()->second["std"].as>(); auto scale = op.begin()->second["scale"].as(); @@ -67,7 +67,7 @@ bool PaddleClasPreprocessor::BuildPreprocessPipelineFromConfig() { processors_.push_back(std::make_shared(mean, std)); } } else if (op_name == "ToCHWImage") { - if (!disable_permute) { + if (!disable_permute_) { processors_.push_back(std::make_shared()); } } 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; diff --git a/fastdeploy/vision/classification/ppcls/preprocessor.h b/fastdeploy/vision/classification/ppcls/preprocessor.h index 2162ac095..06b586d63 100644 --- a/fastdeploy/vision/classification/ppcls/preprocessor.h +++ b/fastdeploy/vision/classification/ppcls/preprocessor.h @@ -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_; }; diff --git a/tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml b/tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml index d47075090..72c27a18a 100644 --- a/tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml +++ b/tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml @@ -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: \ No newline at end of file +dataset: "./ResNet50_vd_infer/dataset.txt" From 51d81f6b432807ca3dcced17da1de280cb10792c Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 29 Dec 2022 14:23:19 +0800 Subject: [PATCH 2/4] Update requirements.txt --- python/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/requirements.txt b/python/requirements.txt index 3c463f4bb..f50f053a9 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -3,6 +3,6 @@ requests tqdm numpy opencv-python -fastdeploy-tools>=0.0.1 +fastdeploy-tools>=0.0.2 pyyaml fastapi From d58e352e70d39eb7f9d9d39dd7d331bb08326fb9 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 29 Dec 2022 14:42:34 +0800 Subject: [PATCH 3/4] Update use_sdk_on_linux.md --- docs/cn/faq/use_sdk_on_linux.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/cn/faq/use_sdk_on_linux.md b/docs/cn/faq/use_sdk_on_linux.md index 0ceb5ca0c..ccf46f5e0 100644 --- a/docs/cn/faq/use_sdk_on_linux.md +++ b/docs/cn/faq/use_sdk_on_linux.md @@ -3,7 +3,8 @@ # Linux上C++部署 -1. 编译完成运行,提示找不到.so文件 +1. 编译完成运行,提示找不到.so文件 "cannot open shared object file: No such file or directory" + 在执行二进制文件时,需要能够在环境变量中找到FastDeploy相关的库文件。FastDeploy提供了辅助脚本来帮助完成。 From 9795a5287d4e2d8dab2ec434c0a8d4e9ea09901f Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Thu, 29 Dec 2022 15:50:45 +0800 Subject: [PATCH 4/4] [Backend] Update paddle inference version (#990) 2.4-dev3 -> 2.4-dev4 --- cmake/paddle_inference.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/paddle_inference.cmake b/cmake/paddle_inference.cmake index 3ab45454a..3822f9ac3 100644 --- a/cmake/paddle_inference.cmake +++ b/cmake/paddle_inference.cmake @@ -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")