From 576b2e3cb0806fd8750cc94571cc8939754340dc Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Tue, 7 Feb 2023 09:06:06 +0000 Subject: [PATCH 01/20] Update PaddleSeg example directory --- docs/api/vision_results/README_CN.md | 3 + docs/api/vision_results/faq_CN.md | 25 ++++ .../vision_results/segmentation_result_CN.md | 2 + docs/cn/build_and_install/a311d.md | 10 ++ docs/cn/build_and_install/rv1126.md | 10 ++ .../segmentation/paddleseg/README_CN.md | 60 +++----- .../segmentation/paddleseg/a311d/README_CN.md | 12 -- .../paddleseg/{ => amlogic}/a311d/README.md | 4 +- .../paddleseg/amlogic/a311d/README_CN.md | 20 +++ .../{ => amlogic}/a311d/cpp/CMakeLists.txt | 0 .../{ => amlogic}/a311d/cpp/README.md | 0 .../{ => amlogic}/a311d/cpp/README_CN.md | 20 +-- .../{ => amlogic}/a311d/cpp/infer.cc | 6 +- .../{ => amlogic}/a311d/cpp/run_with_adb.sh | 0 .../paddleseg/cpu-gpu/README_CN.md | 48 +++++++ .../{ => cpu-gpu}/cpp/CMakeLists.txt | 0 .../paddleseg/{ => cpu-gpu}/cpp/README.md | 8 +- .../paddleseg/cpu-gpu/cpp/README_CN.md | 106 ++++++++++++++ .../paddleseg/cpu-gpu/cpp/infer.cc | 131 ++++++++++++++++++ .../paddleseg/{ => cpu-gpu}/python/README.md | 6 +- .../paddleseg/cpu-gpu/python/README_CN.md | 88 ++++++++++++ .../paddleseg/cpu-gpu/python/infer.py | 57 ++++++++ .../paddleseg/kunlun/README_CN.md | 48 +++++++ .../paddleseg/kunlun/cpp/CMakeLists.txt | 14 ++ .../paddleseg/kunlun/cpp/README.md | 96 +++++++++++++ .../paddleseg/{ => kunlun}/cpp/README_CN.md | 0 .../paddleseg/{ => kunlun}/cpp/infer.cc | 6 +- .../paddleseg/kunlun/python/README.md | 82 +++++++++++ .../{ => kunlun}/python/README_CN.md | 0 .../paddleseg/{ => kunlun}/python/infer.py | 0 .../{ => kunlun}/python/serving/README.md | 0 .../{ => kunlun}/python/serving/README_CN.md | 0 .../{ => kunlun}/python/serving/client.py | 0 .../{ => kunlun}/python/serving/server.py | 0 .../paddleseg/quantize/README_CN.md | 39 ++---- .../paddleseg/{ => rockchip}/rknpu2/README.md | 0 .../{ => rockchip}/rknpu2/README_CN.md | 0 .../{ => rockchip}/rknpu2/cpp/CMakeLists.txt | 2 +- .../{ => rockchip}/rknpu2/cpp/README.md | 2 +- .../{ => rockchip}/rknpu2/cpp/README_CN.md | 0 .../{ => rockchip}/rknpu2/cpp/infer.cc | 17 +-- .../{ => rockchip}/rknpu2/pp_humanseg.md | 2 +- .../{ => rockchip}/rknpu2/pp_humanseg_EN.md | 2 +- .../{ => rockchip}/rknpu2/python/README.md | 0 .../{ => rockchip}/rknpu2/python/README_CN.md | 0 .../{ => rockchip}/rknpu2/python/infer.py | 0 .../paddleseg/{ => rockchip}/rv1126/README.md | 2 +- .../{ => rockchip}/rv1126/README_CN.md | 0 .../{ => rockchip}/rv1126/cpp/CMakeLists.txt | 0 .../{ => rockchip}/rv1126/cpp/README.md | 0 .../{ => rockchip}/rv1126/cpp/README_CN.md | 0 .../{ => rockchip}/rv1126/cpp/infer.cc | 6 +- .../{ => rockchip}/rv1126/cpp/run_with_adb.sh | 0 .../paddleseg/serving/README_CN.md | 71 +--------- .../deploy.yaml | 0 .../{ => fastdeploy_serving}/README.md | 0 .../serving/fastdeploy_serving/README_CN.md | 86 ++++++++++++ .../models/paddleseg/1/README.md | 0 .../models/paddleseg/config.pbtxt | 0 .../models/postprocess/1/model.py | 0 .../models/postprocess/config.pbtxt | 0 .../models/preprocess/1/model.py | 0 .../models/preprocess/config.pbtxt | 0 .../models/runtime/1/README.md | 0 .../models/runtime/config.pbtxt | 0 .../paddleseg_grpc_client.py | 0 .../serving/simple_serving/README.md | 36 +++++ .../serving/simple_serving/README_CN.md | 32 +++++ .../serving/simple_serving/client.py | 23 +++ .../serving/simple_serving/server.py | 38 +++++ .../segmentation/paddleseg/sophgo/README.md | 9 +- .../paddleseg/sophgo/README_CN.md | 9 +- 72 files changed, 1050 insertions(+), 188 deletions(-) create mode 100644 docs/api/vision_results/faq_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/a311d/README_CN.md rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/README.md (78%) create mode 100644 examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/cpp/CMakeLists.txt (100%) rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/cpp/README.md (100%) rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/cpp/README_CN.md (70%) rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/cpp/infer.cc (95%) mode change 100755 => 100644 rename examples/vision/segmentation/paddleseg/{ => amlogic}/a311d/cpp/run_with_adb.sh (100%) create mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md rename examples/vision/segmentation/paddleseg/{ => cpu-gpu}/cpp/CMakeLists.txt (100%) rename examples/vision/segmentation/paddleseg/{ => cpu-gpu}/cpp/README.md (98%) create mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md create mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc rename examples/vision/segmentation/paddleseg/{ => cpu-gpu}/python/README.md (97%) create mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md create mode 100755 examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py create mode 100644 examples/vision/segmentation/paddleseg/kunlun/README_CN.md create mode 100644 examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt create mode 100755 examples/vision/segmentation/paddleseg/kunlun/cpp/README.md rename examples/vision/segmentation/paddleseg/{ => kunlun}/cpp/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/cpp/infer.cc (97%) mode change 100755 => 100644 create mode 100755 examples/vision/segmentation/paddleseg/kunlun/python/README.md rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/infer.py (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/serving/README.md (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/serving/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/serving/client.py (100%) rename examples/vision/segmentation/paddleseg/{ => kunlun}/python/serving/server.py (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/README.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/cpp/CMakeLists.txt (96%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/cpp/README.md (99%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/cpp/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/cpp/infer.cc (87%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/pp_humanseg.md (99%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/pp_humanseg_EN.md (99%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/python/README.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/python/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rknpu2/python/infer.py (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/README.md (92%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/cpp/CMakeLists.txt (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/cpp/README.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/cpp/README_CN.md (100%) rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/cpp/infer.cc (95%) mode change 100755 => 100644 rename examples/vision/segmentation/paddleseg/{ => rockchip}/rv1126/cpp/run_with_adb.sh (100%) rename examples/vision/segmentation/paddleseg/serving/{models/preprocess/1 => fastdeploy_serving/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer}/deploy.yaml (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/README.md (100%) create mode 100644 examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/paddleseg/1/README.md (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/paddleseg/config.pbtxt (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/postprocess/1/model.py (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/postprocess/config.pbtxt (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/preprocess/1/model.py (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/preprocess/config.pbtxt (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/runtime/1/README.md (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/models/runtime/config.pbtxt (100%) rename examples/vision/segmentation/paddleseg/serving/{ => fastdeploy_serving}/paddleseg_grpc_client.py (100%) create mode 100644 examples/vision/segmentation/paddleseg/serving/simple_serving/README.md create mode 100644 examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md create mode 100644 examples/vision/segmentation/paddleseg/serving/simple_serving/client.py create mode 100644 examples/vision/segmentation/paddleseg/serving/simple_serving/server.py diff --git a/docs/api/vision_results/README_CN.md b/docs/api/vision_results/README_CN.md index 94efce21e..a6ad2a808 100755 --- a/docs/api/vision_results/README_CN.md +++ b/docs/api/vision_results/README_CN.md @@ -16,3 +16,6 @@ FastDeploy根据视觉模型的任务类型,定义了不同的结构体(`fastd | OCRResult | [C++/Python文档](./ocr_result.md) | 文本框检测,分类和文本识别返回结果 | OCR系列模型等 | | MOTResult | [C++/Python文档](./mot_result.md) | 多目标跟踪返回结果 | pptracking系列模型等 | | HeadPoseResult | [C++/Python文档](./headpose_result.md) | 头部姿态估计返回结果 | FSANet系列模型等 | + +## 常见问题 +- [如何将视觉模型预测结果转换为numpy格式](./faq_CN.md) diff --git a/docs/api/vision_results/faq_CN.md b/docs/api/vision_results/faq_CN.md new file mode 100644 index 000000000..59ce781d8 --- /dev/null +++ b/docs/api/vision_results/faq_CN.md @@ -0,0 +1,25 @@ +[English](faq.md)| 简体中文 +# 视觉模型预测结果常见问题 + +## 将视觉模型预测结果转换为numpy格式 + +这里以[SegmentationResult](./segmentation_result_CN.md)为例,展示如何抽取SegmentationResult中的label_map或者score_map来转为numpy格式,同时也可以利用已有数据new SegmentationResult结构体 +``` +import fastdeploy as fd +import cv2 +import numpy as np + +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file) +im = cv2.imread(image) +result = model.predict(im) +# convert label_map and score_map to numpy format +numpy_label_map = np.array(result.label_map) +numpy_score_map = np.array(result.score_map) + +# create SegmentationResult object +result = fd.C.vision.SegmentationResult() +result.label_map = numpy_label_map.tolist() +result.score_map = numpy_score_map.tolist() +``` +>> **注意**: 以上为示例代码,具体请参考[PaddleSeg example](../../../examples/vision/segmentation/paddleseg/) diff --git a/docs/api/vision_results/segmentation_result_CN.md b/docs/api/vision_results/segmentation_result_CN.md index 5b393c6ea..0b3e22ee1 100644 --- a/docs/api/vision_results/segmentation_result_CN.md +++ b/docs/api/vision_results/segmentation_result_CN.md @@ -14,6 +14,7 @@ struct SegmentationResult { std::vector shape; bool contain_score_map = false; void Clear(); + void Free(); std::string Str(); }; ``` @@ -22,6 +23,7 @@ struct SegmentationResult { - **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`apply_softmax=True`) - **shape**: 成员变量,表示输出图片的shape,为H\*W - **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) ## Python 定义 diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md index 766be6954..7066ca9d5 100755 --- a/docs/cn/build_and_install/a311d.md +++ b/docs/cn/build_and_install/a311d.md @@ -2,6 +2,16 @@ # 晶晨 A311D 部署环境编译安装 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [交叉编译环境搭建](#交叉编译环境搭建) +* [基于 Paddle Lite 的 FastDeploy 交叉编译库编译](#基于-paddle-lite-的-fastdeploy-交叉编译库编译) +* [准备设备运行环境](#准备设备运行环境) +* [基于 FastDeploy 在 A311D 上的部署示例](#基于-fastdeploy-在-a311d-上的部署示例) + +## 简介以及编译选项 + FastDeploy 基于 Paddle Lite 后端支持在晶晨 NPU 上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md index 159ac00e4..090393e1d 100755 --- a/docs/cn/build_and_install/rv1126.md +++ b/docs/cn/build_and_install/rv1126.md @@ -2,6 +2,16 @@ # 瑞芯微 RV1126 部署环境编译安装 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [交叉编译环境搭建](#交叉编译环境搭建) +* [基于 Paddle Lite 的 FastDeploy 交叉编译库编译](#基于-paddle-lite-的-fastdeploy-交叉编译库编译) +* [准备设备运行环境](#准备设备运行环境) +* [基于 FastDeploy 在 RV1126 上的部署示例](#基于-fastdeploy-在-rv1126-上的部署示例) + +## 简介以及编译选项 + FastDeploy基于 Paddle Lite 后端支持在瑞芯微(Rockchip)Soc 上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 diff --git a/examples/vision/segmentation/paddleseg/README_CN.md b/examples/vision/segmentation/paddleseg/README_CN.md index 0b0cda349..28bdce086 100644 --- a/examples/vision/segmentation/paddleseg/README_CN.md +++ b/examples/vision/segmentation/paddleseg/README_CN.md @@ -1,47 +1,23 @@ -# PaddleSeg 模型部署 +# 使用FastDeploy部署PaddleSeg模型 -## 模型版本说明 +## FastDeploy介绍 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +FastDeploy是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg模型进行快速部署 -目前FastDeploy支持如下模型的部署 +## 详细文档 -- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/unet/README.md) -- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) -- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/contrib/PP-HumanSeg/README.md) -- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/fcn/README.md) -- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/deeplabv3/README.md) +- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU](cpu-gpu) +- [昆仑](kunlun) +- [升腾](ascend) +- [瑞芯微](rockchip) +- [晶晨](amlogic) +- [算能](sophgo) +- [Android ARM CPU部署](android) +- [服务化Serving部署](serving) +- [模型自动化压缩工具](quantize) +- [web部署](web) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting) - -## 准备PaddleSeg部署模型 - -PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -**注意** -- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 - -## 下载预训练模型 - -为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 -- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` -- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` - -开发者可直接下载使用。 - -| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | -| [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | -| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | -|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | -| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | -| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) +## 常见问题 +遇到问题可查看常见问题集合文档或搜索 FastDeploy issues,链接如下。若都无法解决,欢迎给 FastDeploy 提交新的issue +[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) +[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/paddleseg/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/a311d/README_CN.md deleted file mode 100644 index dad4f3924..000000000 --- a/examples/vision/segmentation/paddleseg/a311d/README_CN.md +++ /dev/null @@ -1,12 +0,0 @@ -[English](README.md) | 简体中文 -# PP-LiteSeg 量化模型在 A311D 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 A311D 上。 - -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) - - -## 详细部署文档 - -在 A311D 上只支持 C++ 的部署。 - -- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md similarity index 78% rename from examples/vision/segmentation/paddleseg/a311d/README.md rename to examples/vision/segmentation/paddleseg/amlogic/a311d/README.md index 07870aa59..db3e18110 100755 --- a/examples/vision/segmentation/paddleseg/a311d/README.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md @@ -1,6 +1,6 @@ English | [简体中文](README_CN.md) -# Deployment of PP-LiteSeg Quantification Model on A311D -Now FastDeploy allows deploying PP-LiteSeg quantization model to A311D based on Paddle Lite. +# Deployment of PP-LiteSeg Quantification Model on A311D +Now FastDeploy allows deploying PP-LiteSeg quantization model to A311D based on Paddle Lite. For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md new file mode 100644 index 000000000..ccb999450 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md @@ -0,0 +1,20 @@ +[English](README.md) | 简体中文 +# 在晶晨A311D上使用FastDeploy部署PaddleSeg模型 +晶晨A311D是一款先进的AI应用处理器。目前,FastDeploy支持在A311D上基于Paddle-Lite部署PaddleSeg相关模型 + +## 晶晨A311D支持的PaddleSeg模型 +由于晶晨A311D的NPU仅支持INT8量化模型的部署,因此所支持的量化模型如下: +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型,开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +>> **注意**: FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) + +## 详细部署文档 + +目前,A311D上只支持C++的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/a311d/cpp/README.md rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md similarity index 70% rename from examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md index a9528e940..4780a9110 100644 --- a/examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md @@ -1,31 +1,31 @@ [English](README.md) | 简体中文 # PP-LiteSeg 量化模型 C++ 部署示例 -本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 A311D 上的部署推理加速。 +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 晶晨A311D 上的部署推理加速。 ## 部署准备 ### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建) +1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#交叉编译环境搭建) ### 模型准备 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 +3. 模型需要异构计算,异构计算文件可以参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 -更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) +更多量化相关相关信息可查阅[模型量化](../../../quantize/README.md) ## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) 2. 将编译后的库拷贝到当前目录,可使用如下命令: ```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp ``` 3. 在当前路径下载部署所需的模型和示例图片: ```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp mkdir models && mkdir images wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz tar -xvf ppliteseg.tar.gz @@ -36,7 +36,7 @@ cp -r cityscapes_demo.png images 4. 编译部署示例,可使入如下命令: ```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. make -j8 @@ -47,7 +47,7 @@ make install 5. 基于 adb 工具部署 PP-LiteSeg 分割模型到晶晨 A311D,可使用如下命令: ```bash # 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp/build/install/ +cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/build/install/ # 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID ``` @@ -56,4 +56,4 @@ bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) +需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc old mode 100755 new mode 100644 similarity index 95% rename from examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc index 38f5f7168..4d2eb3f29 --- a/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc @@ -24,13 +24,13 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) { auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; auto subgraph_file = model_dir + sep + "subgraph.txt"; - fastdeploy::vision::EnableFlyCV(); + fastdeploy::vision::EnableFlyCV(); fastdeploy::RuntimeOption option; option.UseTimVX(); option.SetLiteSubgraphPartitionPath(subgraph_file); - + auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); assert(model.Initialized()); diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/run_with_adb.sh similarity index 100% rename from examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/run_with_adb.sh diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md new file mode 100644 index 000000000..a4ff4af5e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md @@ -0,0 +1,48 @@ +# 使用FastDeploy部署PaddleSeg模型 + +## 模型版本说明 + +- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) + +目前FastDeploy支持如下模型的部署 + +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | +| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | +|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/cpu-gpu/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md similarity index 98% rename from examples/vision/segmentation/paddleseg/cpp/README.md rename to examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md index 4c5be9f6c..bcccdd1cb 100755 --- a/examples/vision/segmentation/paddleseg/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md @@ -1,7 +1,7 @@ English | [简体中文](README_CN.md) # PaddleSeg C++ Deployment Example -This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. +This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. Before deployment, two steps require confirmation @@ -15,7 +15,7 @@ Taking the inference on Linux as an example, the compilation test can be complet ```bash mkdir build cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above 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 @@ -45,7 +45,7 @@ The visualized result after running is as follows The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: - [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PaddleSeg C++ Interface +## PaddleSeg C++ Interface ### PaddleSeg Class @@ -62,7 +62,7 @@ PaddleSegModel model loading and initialization, among which model_file is the e **Parameter** -> * **model_file**(str): Model file path +> * **model_file**(str): Model file path > * **params_file**(str): Parameter file path > * **config_file**(str): Inference deployment configuration file > * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md new file mode 100644 index 000000000..c5d39934b --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md @@ -0,0 +1,106 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/cpp-gpu/cpp + +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +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 + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + + +# CPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# GPU上TensorRT推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 2 +``` + +运行完成可视化结果如下图所示 +
+ +
+ +> **注意:** +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md) + +## PaddleSeg C++接口 + +### PaddleSeg类 + +```c++ +fastdeploy::vision::segmentation::PaddleSegModel( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PaddleSegModel::Predict(const cv::Mat &im, SegmentationResult *result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +## 快速链接 +- [PaddleSeg模型介绍](../../) +- [Python部署](../python) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc new file mode 100644 index 000000000..5269a0c2e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc @@ -0,0 +1,131 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "fastdeploy/vision.h" + +#ifdef WIN32 +const char sep = '\\'; +#else +const char sep = '/'; +#endif + +void CpuInfer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file, option); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::SegmentationResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +void GpuInfer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file, option); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::SegmentationResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +void TrtInfer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file, option); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::SegmentationResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +int main(int argc, char* argv[]) { + if (argc < 4) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppseg_model_dir ./test.jpeg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu; 2: run with gpu and use tensorrt backend; 3: run " + "with kunlunxin." + << std::endl; + return -1; + } + + if (std::atoi(argv[3]) == 0) { + CpuInfer(argv[1], argv[2]); + } else if (std::atoi(argv[3]) == 1) { + GpuInfer(argv[1], argv[2]); + } else if (std::atoi(argv[3]) == 2) { + TrtInfer(argv[1], argv[2]); + } + return 0; +} diff --git a/examples/vision/segmentation/paddleseg/python/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md similarity index 97% rename from examples/vision/segmentation/paddleseg/python/README.md rename to examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md index 95885a2f2..add5b053d 100755 --- a/examples/vision/segmentation/paddleseg/python/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md @@ -10,7 +10,7 @@ Before deployment, two steps require confirmation This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -# Download the deployment example code +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/segmentation/paddleseg/python @@ -34,7 +34,7 @@ The visualized result after running is as follows -## PaddleSegModel Python Interface +## PaddleSegModel Python Interface ```python fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) @@ -44,7 +44,7 @@ PaddleSeg model loading and initialization, among which model_file, params_file, **Parameter** -> * **model_file**(str): Model file path +> * **model_file**(str): Model file path > * **params_file**(str): Parameter file path > * **config_file**(str): Inference deployment configuration file > * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md new file mode 100644 index 000000000..1e31bd014 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) + +本目录下提供`infer.py`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/cpu-gpu/python + +# 下载Unet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# CPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PaddleSegModel Python接口 + +```python +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PaddleSegModel.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +## 其它文档 + +- [PaddleSeg 模型介绍](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py new file mode 100755 index 000000000..ba961159f --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py @@ -0,0 +1,57 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of PaddleSeg model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + parser.add_argument( + "--device", + type=str, + default='cpu', + help="Type of inference device, support 'kunlunxin', 'cpu' or 'gpu'.") + parser.add_argument( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], + [1, 3, 2048, 2048]) + return option + + +args = parse_arguments() + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +config_file = os.path.join(args.model, "deploy.yaml") +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片分割结果 +im = cv2.imread(args.image) +result = model.predict(im) +print(result) + +# 可视化结果 +vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) +cv2.imwrite("vis_img.png", vis_im) diff --git a/examples/vision/segmentation/paddleseg/kunlun/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/README_CN.md new file mode 100644 index 000000000..a4ff4af5e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/README_CN.md @@ -0,0 +1,48 @@ +# 使用FastDeploy部署PaddleSeg模型 + +## 模型版本说明 + +- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) + +目前FastDeploy支持如下模型的部署 + +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | +| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | +|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt new file mode 100644 index 000000000..93540a7e8 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +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_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md new file mode 100755 index 000000000..bcccdd1cb --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md @@ -0,0 +1,96 @@ +English | [简体中文](README_CN.md) +# PaddleSeg C++ Deployment Example + +This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. + +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) + +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. + +```bash +mkdir build +cd build +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above +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 + +# Download Unet model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + + +# CPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# TensorRT inference on GPU +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 +# kunlunxin XPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +``` + +The visualized result after running is as follows +
+ +
+ +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PaddleSeg C++ Interface + +### PaddleSeg Class + +```c++ +fastdeploy::vision::segmentation::PaddleSegModel( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +#### Predict Function + +> ```c++ +> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **im**: Input images in HWC or BGR format +> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` + +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/cpp/infer.cc b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc old mode 100755 new mode 100644 similarity index 97% rename from examples/vision/segmentation/paddleseg/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc index ae97c0406..e4d6e39d9 --- a/examples/vision/segmentation/paddleseg/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc @@ -48,7 +48,8 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file) { std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void KunlunXinInfer(const std::string& model_dir, const std::string& image_file) { +void KunlunXinInfer(const std::string& model_dir, + const std::string& image_file) { auto model_file = model_dir + sep + "model.pdmodel"; auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; @@ -170,7 +171,8 @@ int main(int argc, char* argv[]) { "e.g ./infer_model ./ppseg_model_dir ./test.jpeg 0" << std::endl; std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " - "with gpu; 2: run with gpu and use tensorrt backend; 3: run with kunlunxin." + "with gpu; 2: run with gpu and use tensorrt backend; 3: run " + "with kunlunxin." << std::endl; return -1; } diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/README.md new file mode 100755 index 000000000..add5b053d --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/python/README.md @@ -0,0 +1,82 @@ +English | [简体中文](README_CN.md) +# PaddleSeg Python Deployment Example + +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) + +This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +```bash +# Download the deployment example code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python + +# Download Unet model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# CPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True +# kunlunxin XPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +``` + +The visualized result after running is as follows +
+ +
+ +## PaddleSegModel Python Interface + +```python +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) for more information + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +### predict function + +> ```python +> PaddleSegModel.predict(input_image) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **input_image**(np.ndarray): Input data in HWC or BGR format + +> **Return** +> +> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax + +## Other Documents + +- [PaddleSeg Model Description](..) +- [PaddleSeg C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/python/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/python/README_CN.md rename to examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/python/infer.py b/examples/vision/segmentation/paddleseg/kunlun/python/infer.py similarity index 100% rename from examples/vision/segmentation/paddleseg/python/infer.py rename to examples/vision/segmentation/paddleseg/kunlun/python/infer.py diff --git a/examples/vision/segmentation/paddleseg/python/serving/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/README.md rename to examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md diff --git a/examples/vision/segmentation/paddleseg/python/serving/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/README_CN.md rename to examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/python/serving/client.py b/examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/client.py rename to examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py diff --git a/examples/vision/segmentation/paddleseg/python/serving/server.py b/examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/server.py rename to examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py diff --git a/examples/vision/segmentation/paddleseg/quantize/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/README_CN.md index a35f1d99d..a9b287754 100644 --- a/examples/vision/segmentation/paddleseg/quantize/README_CN.md +++ b/examples/vision/segmentation/paddleseg/quantize/README_CN.md @@ -5,33 +5,22 @@ FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工 ## FastDeploy一键模型自动化压缩工具 FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) -注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 +详细教程请见: [一键模型自动化压缩工具](https://github.com/PaddlePaddle/FastDeploy/tree/develop/tools/common_tools/auto_compression) +>> **注意**: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 -## 下载量化完成的PaddleSeg模型 +## 量化完成的PaddleSeg模型 用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. +| 模型 | 量化方式 | +| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) |量化蒸馏训练 | -#### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mIoU | INT8 mIoU | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 1138.04| 602.62 |None|None | 1.89 |77.37 | 71.62 |量化蒸馏训练 | +量化后模型的Benchmark比较,请参考[量化模型 Benchmark](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quantize.md) -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mIoU | INT8 mIoU | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 4726.65| 4134.91|None|None | 1.14 |77.37 | 71.62 |量化蒸馏训练 | - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) +## 支持部署量化模型的硬件 +FastDeploy 量化模型部署的过程大致都与FP32模型类似,只是模型量化与非量化的区别,如果硬件在量化模型部署过程有特殊处理,也会在文档中特别标明,因此量化模型部署可以参考如下硬件的链接 +- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU](../cpu-gpu) +- [昆仑](../kunlun) +- [升腾](../ascend) +- [瑞芯微](../rockchip) +- [晶晨](../amlogic) +- [算能](../sophgo) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/README.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md diff --git a/examples/vision/segmentation/paddleseg/rknpu2/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt similarity index 96% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt index 28161a83d..7fc1f6e22 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt @@ -33,4 +33,4 @@ file(GLOB PADDLETOONNX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddle2 install(PROGRAMS ${PADDLETOONNX_LIBS} DESTINATION lib) file(GLOB RKNPU2_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/rknpu2_runtime/RK3588/lib/*) -install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib) \ No newline at end of file +install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md similarity index 99% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md index 48c4646e2..1fe268f81 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md @@ -40,7 +40,7 @@ mkdir thirdpartys Please refer to [How to Build RKNPU2 Deployment Environment](../../../../../../docs/en/build_and_install/rknpu2.md) to compile SDK.After compiling, the fastdeploy-0.0.3 directory will be created in the build directory, please move it to the thirdpartys directory. ### Copy model and configuration files to folder Model -In the process of Paddle dynamic map model -> Paddle static map model -> ONNX mdoel, ONNX file and the corresponding yaml configuration file will be generated. Please move the configuration file to the folder model. +In the process of Paddle dynamic map model -> Paddle static map model -> ONNX mdoel, ONNX file and the corresponding yaml configuration file will be generated. Please move the configuration file to the folder model. After converting to RKNN, the model file also needs to be copied to folder model. Run the following command to download and use (the model file is RK3588. RK3568 needs to be [reconverted to PPSeg RKNN model](../README.md)). ### Prepare Test Images to folder image diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc similarity index 87% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc index f80d3fc8f..b501fc899 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc @@ -16,7 +16,8 @@ #include "fastdeploy/vision.h" void ONNXInfer(const std::string& model_dir, const std::string& image_file) { - std::string model_file = model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx"; + std::string model_file = + model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx"; std::string params_file; std::string config_file = model_dir + "/deploy.yaml"; auto option = fastdeploy::RuntimeOption(); @@ -43,13 +44,12 @@ void ONNXInfer(const std::string& model_dir, const std::string& image_file) { tc.PrintInfo("PPSeg in ONNX"); cv::imwrite("infer_onnx.jpg", vis_im); - std::cout - << "Visualized result saved in ./infer_onnx.jpg" - << std::endl; + std::cout << "Visualized result saved in ./infer_onnx.jpg" << std::endl; } void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) { - std::string model_file = model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn"; + std::string model_file = + model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn"; std::string params_file; std::string config_file = model_dir + "/deploy.yaml"; auto option = fastdeploy::RuntimeOption(); @@ -78,9 +78,7 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) { tc.PrintInfo("PPSeg in RKNPU2"); cv::imwrite("infer_rknn.jpg", vis_im); - std::cout - << "Visualized result saved in ./infer_rknn.jpg" - << std::endl; + std::cout << "Visualized result saved in ./infer_rknn.jpg" << std::endl; } int main(int argc, char* argv[]) { @@ -93,7 +91,6 @@ int main(int argc, char* argv[]) { } RKNPU2Infer(argv[1], argv[2]); -// ONNXInfer(argv[1], argv[2]); + // ONNXInfer(argv[1], argv[2]); return 0; } - diff --git a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md similarity index 99% rename from examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md index 2b14f6b9d..e0f458eb0 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md @@ -78,4 +78,4 @@ Deploy: - 144 type: Resize - type: Normalize -``` \ No newline at end of file +``` diff --git a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md similarity index 99% rename from examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md index 6870d32c7..312b9f7ae 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md @@ -78,4 +78,4 @@ Deploy: - 144 type: Resize - type: Normalize -``` \ No newline at end of file +``` diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/python/README.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/python/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/infer.py similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/python/infer.py rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/infer.py diff --git a/examples/vision/segmentation/paddleseg/rv1126/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md similarity index 92% rename from examples/vision/segmentation/paddleseg/rv1126/README.md rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md index dc9755272..7e4620b18 100755 --- a/examples/vision/segmentation/paddleseg/rv1126/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md @@ -1,6 +1,6 @@ English | [简体中文](README_CN.md) # Deployment of PP-LiteSeg Quantification Model on RV1126 -Now FastDeploy allows deploying PP-LiteSeg quantization model to RV1126 based on Paddle Lite. +Now FastDeploy allows deploying PP-LiteSeg quantization model to RV1126 based on Paddle Lite. For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/rv1126/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/README.md rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc old mode 100755 new mode 100644 similarity index 95% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc index d9f7c3311..513a03a01 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc @@ -24,13 +24,13 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) { auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; auto subgraph_file = model_dir + sep + "subgraph.txt"; - fastdeploy::vision::EnableFlyCV(); + fastdeploy::vision::EnableFlyCV(); fastdeploy::RuntimeOption option; option.UseTimVX(); option.SetLiteSubgraphPartitionPath(subgraph_file); - + auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); assert(model.Initialized()); diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/run_with_adb.sh b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/run_with_adb.sh similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/run_with_adb.sh rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/run_with_adb.sh diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/README_CN.md index 676272f2e..0c2e5194b 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/README_CN.md @@ -1,68 +1,9 @@ [English](README.md) | 简体中文 -# PaddleSegmentation 服务化部署示例 +# 使用 FastDeploy 服务化部署 PaddleSeg 模型 +## FastDeploy 服务化部署介绍 +在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving。simple_serving 基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 -在服务化部署前,需确认 +## 详细部署文档 -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) - - -## 启动服务 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/serving - -#下载yolov5模型文件 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz - -# 将模型文件放入 models/runtime/1目录下 -mv PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/model.pdmodel models/runtime/1/ -mv PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/model.pdiparams models/runtime/1/ - -# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) -# GPU镜像 -docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 -# CPU镜像 -docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 - -# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 -nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash - -# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) -CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models --backend-config=python,shm-default-byte-size=10485760 -``` ->> **注意**: 当出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改paddleseg_grpc_client.py中的请求端口号 - -服务启动成功后, 会有以下输出: -``` -...... -I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 -I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:8000 -I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 -``` - - -## 客户端请求 - -在物理机器中执行以下命令,发送grpc请求并输出结果 -``` -#下载测试图片 -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -#安装客户端依赖 -python3 -m pip install tritonclient[all] - -# 发送请求 -python3 paddleseg_grpc_client.py -``` - -发送请求成功后,会返回json格式的检测结果并打印输出: -``` - -``` - -## 配置修改 - -当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +- [fastdeploy serving](fastdeploy_serving) +- [simple serving](simple_serving) diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/1/deploy.yaml b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/deploy.yaml similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/1/deploy.yaml rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/deploy.yaml diff --git a/examples/vision/segmentation/paddleseg/serving/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/README.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md new file mode 100644 index 000000000..ac8965d75 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# PaddleSeg 服务化部署示例 + +在服务化部署前,需确认 + +- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README_CN.md) + + +## 启动服务 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving + +#下载PP-LiteSeg模型文件 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz + +# 将模型文件放入 models/runtime/1目录下 +mv PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/model.pdmodel models/runtime/1/ +mv PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/model.pdiparams models/runtime/1/ + +# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) +# GPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +# CPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 + +# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 +nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash + +# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models --backend-config=python,shm-default-byte-size=10485760 +``` +>> **注意**: 当出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改paddleseg_grpc_client.py中的请求端口号 + +服务启动成功后, 会有以下输出: +``` +...... +I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 +I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:8000 +I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 +``` + + +## 客户端请求 + +在物理机器中执行以下命令,发送grpc请求并输出结果 +``` +#下载测试图片 +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +#安装客户端依赖 +python3 -m pip install tritonclient[all] + +# 发送请求 +python3 paddleseg_grpc_client.py +``` + +发送请求成功后,会返回json格式的检测结果并打印输出: +``` +tm: name: "INPUT" +datatype: "UINT8" +shape: -1 +shape: -1 +shape: -1 +shape: 3 + +output_name: SEG_RESULT +Only print the first 20 labels in label_map of SEG_RESULT +{'label_map': [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 'score_map': [], 'shape': [1024, 2048], 'contain_score_map': False} +``` + +## 配置修改 + +当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/model_configuration.md) + +## 更多部署方式 +- [使用 VisualDL 进行 Serving 可视化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/vdl_management.md) + +## 常见问题 +- [如何编写客户端 HTTP/GRPC 请求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/client.md) +- [如何编译服务化部署镜像](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/compile.md) +- [服务化部署原理及动态Batch介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/demo.md) +- [模型仓库介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/model_repository.md) diff --git a/examples/vision/segmentation/paddleseg/serving/models/paddleseg/1/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/1/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/paddleseg/1/README.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/1/README.md diff --git a/examples/vision/segmentation/paddleseg/serving/models/paddleseg/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/paddleseg/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/postprocess/1/model.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/1/model.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/postprocess/1/model.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/1/model.py diff --git a/examples/vision/segmentation/paddleseg/serving/models/postprocess/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/postprocess/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/1/model.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/1/model.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/1/model.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/1/model.py diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/runtime/1/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/1/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/runtime/1/README.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/1/README.md diff --git a/examples/vision/segmentation/paddleseg/serving/models/runtime/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/runtime/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/paddleseg_grpc_client.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/paddleseg_grpc_client.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/paddleseg_grpc_client.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/paddleseg_grpc_client.py diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md new file mode 100644 index 000000000..da41a3a00 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md @@ -0,0 +1,36 @@ +English | [简体中文](README_CN.md) + +# PaddleSegmentation Python Simple Serving Demo + + +## Environment + +- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) + +Server: +```bash +# Download demo code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving + +# Download PP_LiteSeg model +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz + +# Launch server, change the configurations in server.py to select hardware, backend, etc. +# and use --host, --port to specify IP and port +fastdeploy simple_serving --app server:app +``` + +Client: +```bash +# Download demo code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving + +# Download test image +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# Send request and get inference result (Please adapt the IP and port if necessary) +python client.py +``` diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md new file mode 100644 index 000000000..d12bb9f2e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md @@ -0,0 +1,32 @@ +简体中文 | [English](README.md) + +# PaddleSeg Python轻量服务化部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) + +服务端: +```bash +# 下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving + +# 下载PP-LiteSeg模型文件 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz + +# 启动服务,可修改server.py中的配置项来指定硬件、后端等 +# 可通过--host、--port指定IP和端口号 +fastdeploy simple_serving --app server:app +``` + +客户端: +```bash +# 下载测试图片 +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# 请求服务,获取推理结果(如有必要,请修改脚本中的IP和端口号) +python client.py +``` diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/client.py b/examples/vision/segmentation/paddleseg/serving/simple_serving/client.py new file mode 100644 index 000000000..e652c4462 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/client.py @@ -0,0 +1,23 @@ +import requests +import json +import cv2 +import fastdeploy as fd +from fastdeploy.serving.utils import cv2_to_base64 + +if __name__ == '__main__': + url = "http://127.0.0.1:8000/fd/ppliteseg" + headers = {"Content-Type": "application/json"} + + im = cv2.imread("cityscapes_demo.png") + data = {"data": {"image": cv2_to_base64(im)}, "parameters": {}} + + resp = requests.post(url=url, headers=headers, data=json.dumps(data)) + if resp.status_code == 200: + r_json = json.loads(resp.json()["result"]) + result = fd.vision.utils.json_to_segmentation(r_json) + vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) + cv2.imwrite("visualized_result.jpg", vis_im) + print("Visualized result save in ./visualized_result.jpg") + else: + print("Error code:", resp.status_code) + print(resp.text) diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/server.py b/examples/vision/segmentation/paddleseg/serving/simple_serving/server.py new file mode 100644 index 000000000..2ae2df09c --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/server.py @@ -0,0 +1,38 @@ +import fastdeploy as fd +from fastdeploy.serving.server import SimpleServer +import os +import logging + +logging.getLogger().setLevel(logging.INFO) + +# Configurations +model_dir = 'PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer' +device = 'cpu' +use_trt = False + +# Prepare model +model_file = os.path.join(model_dir, "model.pdmodel") +params_file = os.path.join(model_dir, "model.pdiparams") +config_file = os.path.join(model_dir, "deploy.yaml") + +# Setup runtime option to select hardware, backend, etc. +option = fd.RuntimeOption() +if device.lower() == 'gpu': + option.use_gpu() +if use_trt: + option.use_trt_backend() + option.set_trt_cache_file('pp_lite_seg.trt') + +# Create model instance +model_instance = fd.vision.segmentation.PaddleSegModel( + model_file=model_file, + params_file=params_file, + config_file=config_file, + runtime_option=option) + +# Create server, setup REST API +app = SimpleServer() +app.register( + task_name="fd/ppliteseg", + model_handler=fd.serving.handler.VisionModelHandler, + predictor=model_instance) diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md index 85a4360fa..337507b49 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README.md @@ -18,7 +18,14 @@ Here we take [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.c ### Download PP-LiteSeg-B(STDC2)-cityscapes-without-argmax, and convert it to ONNX ```shell -https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +# Download Paddle2ONNX repository. +git clone https://github.com/PaddlePaddle/Paddle2ONNX + +# Download the Paddle static map model and fix the input shape. +## Go to the directory where the input shape is fixed for the Paddle static map model. +cd Paddle2ONNX/tools/paddle + +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz # Modify the input shape of PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer model from dynamic input to constant input. diff --git a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md index 5961d2e94..566691889 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md @@ -18,7 +18,14 @@ SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步 ### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型 ```shell -https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +# 下载Paddle2ONNX仓库 +git clone https://github.com/PaddlePaddle/Paddle2ONNX + +# 下载Paddle静态图模型并为Paddle静态图模型固定输入shape +## 进入为Paddle静态图模型固定输入shape的目录 +cd Paddle2ONNX/tools/paddle + +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz # 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入 From bc3a7ce8fe093482fc61f15acd616b4be2fa0b9d Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 8 Feb 2023 03:12:50 +0000 Subject: [PATCH 02/20] Update paddleseg doc --- .../segmentation/paddleseg/README_CN.md | 2 +- .../paddleseg/amlogic/a311d/README_CN.md | 4 +- .../paddleseg/android/README_CN.md | 4 +- .../paddleseg/ascend/README_CN.md | 48 +++++++ .../{quantize => ascend}/cpp/CMakeLists.txt | 2 +- .../paddleseg/ascend/cpp/README.md | 96 +++++++++++++ .../paddleseg/ascend/cpp/README_CN.md | 88 ++++++++++++ .../{quantize => ascend}/cpp/infer.cc | 52 +++---- .../paddleseg/ascend/python/README.md | 82 +++++++++++ .../paddleseg/ascend/python/README_CN.md | 79 ++++++++++ .../paddleseg/ascend/python/infer.py | 34 +++++ .../paddleseg/cpu-gpu/README_CN.md | 4 +- .../paddleseg/cpu-gpu/cpp/README_CN.md | 2 +- .../paddleseg/cpu-gpu/python/README.md | 2 +- .../paddleseg/cpu-gpu/python/README_CN.md | 2 +- .../paddleseg/kunlun/README_CN.md | 2 +- .../paddleseg/kunlun/cpp/README_CN.md | 57 +++----- .../paddleseg/kunlun/cpp/infer.cc | 136 +----------------- .../paddleseg/kunlun/python/README.md | 2 +- .../paddleseg/kunlun/python/README_CN.md | 39 +++-- .../paddleseg/kunlun/python/infer.py | 33 +---- .../paddleseg/kunlun/python/serving/README.md | 36 ----- .../kunlun/python/serving/README_CN.md | 36 ----- .../paddleseg/kunlun/python/serving/client.py | 23 --- .../paddleseg/kunlun/python/serving/server.py | 38 ----- .../paddleseg/quantize/cpp/README.md | 32 ----- .../paddleseg/quantize/cpp/README_CN.md | 32 ----- .../paddleseg/quantize/python/README.md | 29 ---- .../paddleseg/quantize/python/README_CN.md | 29 ---- .../paddleseg/quantize/python/infer.py | 76 ---------- .../paddleseg/rockchip/rknpu2/README_CN.md | 31 +++- .../rockchip/rknpu2/cpp/README_CN.md | 4 +- .../paddleseg/rockchip/rknpu2/pp_humanseg.md | 2 +- .../rockchip/rknpu2/python/README_CN.md | 8 +- .../paddleseg/rockchip/rv1126/README_CN.md | 16 ++- .../rockchip/rv1126/cpp/README_CN.md | 12 +- .../paddleseg/sophgo/README_CN.md | 13 +- .../paddleseg/sophgo/cpp/README_CN.md | 4 +- .../paddleseg/sophgo/python/README_CN.md | 2 +- .../segmentation/paddleseg/web/README_CN.md | 2 +- 40 files changed, 570 insertions(+), 625 deletions(-) create mode 100644 examples/vision/segmentation/paddleseg/ascend/README_CN.md rename examples/vision/segmentation/paddleseg/{quantize => ascend}/cpp/CMakeLists.txt (91%) create mode 100755 examples/vision/segmentation/paddleseg/ascend/cpp/README.md create mode 100644 examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md rename examples/vision/segmentation/paddleseg/{quantize => ascend}/cpp/infer.cc (55%) create mode 100755 examples/vision/segmentation/paddleseg/ascend/python/README.md create mode 100644 examples/vision/segmentation/paddleseg/ascend/python/README_CN.md create mode 100755 examples/vision/segmentation/paddleseg/ascend/python/infer.py delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py delete mode 100755 examples/vision/segmentation/paddleseg/quantize/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md delete mode 100755 examples/vision/segmentation/paddleseg/quantize/python/README.md delete mode 100644 examples/vision/segmentation/paddleseg/quantize/python/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/quantize/python/infer.py diff --git a/examples/vision/segmentation/paddleseg/README_CN.md b/examples/vision/segmentation/paddleseg/README_CN.md index 28bdce086..865c6c4aa 100644 --- a/examples/vision/segmentation/paddleseg/README_CN.md +++ b/examples/vision/segmentation/paddleseg/README_CN.md @@ -6,7 +6,7 @@ FastDeploy是一款全场景、易用灵活、极致高效的AI推理部署工 ## 详细文档 -- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU](cpu-gpu) +- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)](cpu-gpu) - [昆仑](kunlun) - [升腾](ascend) - [瑞芯微](rockchip) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md index ccb999450..3537dfef1 100644 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md @@ -6,7 +6,9 @@ 由于晶晨A311D的NPU仅支持INT8量化模型的部署,因此所支持的量化模型如下: - [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型,开发者可直接下载使用。 +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 + +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) | 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | |:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | diff --git a/examples/vision/segmentation/paddleseg/android/README_CN.md b/examples/vision/segmentation/paddleseg/android/README_CN.md index eb683bdfa..442947009 100644 --- a/examples/vision/segmentation/paddleseg/android/README_CN.md +++ b/examples/vision/segmentation/paddleseg/android/README_CN.md @@ -173,5 +173,5 @@ model.init(modelFile, paramFile, configFile, option); ## 更多参考文档 如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +- [在 Android 中使用 FastDeploy Java SDK](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) +- [在 Android 中使用 FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/README_CN.md new file mode 100644 index 000000000..fb29615fe --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/README_CN.md @@ -0,0 +1,48 @@ +# 使用FastDeploy部署PaddleSeg模型 + +FastDeploy支持在华为昇腾上部署PaddleSeg模型 + +## 模型版本说明 + +- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) + +目前FastDeploy支持如下模型的部署 + +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../matting/)下载对应模型,部署过程与此文档一致 + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | +|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/ascend/cpp/CMakeLists.txt similarity index 91% rename from examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/ascend/cpp/CMakeLists.txt index fea1a2888..93540a7e8 100644 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ PROJECT(infer_demo C CXX) -CMAKE_MINIMUM_REQUIRED (VERSION 3.12) +CMAKE_MINIMUM_REQUIRED (VERSION 3.10) # 指定下载解压后的fastdeploy库路径 option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") diff --git a/examples/vision/segmentation/paddleseg/ascend/cpp/README.md b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md new file mode 100755 index 000000000..bcccdd1cb --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md @@ -0,0 +1,96 @@ +English | [简体中文](README_CN.md) +# PaddleSeg C++ Deployment Example + +This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. + +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) + +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. + +```bash +mkdir build +cd build +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above +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 + +# Download Unet model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + + +# CPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# TensorRT inference on GPU +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 +# kunlunxin XPU inference +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +``` + +The visualized result after running is as follows +
+ +
+ +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PaddleSeg C++ Interface + +### PaddleSeg Class + +```c++ +fastdeploy::vision::segmentation::PaddleSegModel( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +#### Predict Function + +> ```c++ +> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **im**: Input images in HWC or BGR format +> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` + +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md new file mode 100644 index 000000000..38692dc26 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +在部署前,需自行编译基于华为昇腾NPU的预测库,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/huawei_ascend.md) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp + +mkdir build +cd build +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend +make -j + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PaddleSeg C++接口 + +### PaddleSeg类 + +```c++ +fastdeploy::vision::segmentation::PaddleSegModel( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +## 快速链接 +- [PaddleSeg模型介绍](../../) +- [Python部署](../python) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc b/examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc similarity index 55% rename from examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc index 158a30263..cf98dae4e 100644 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc @@ -13,25 +13,28 @@ // limitations under the License. #include "fastdeploy/vision.h" + #ifdef WIN32 const char sep = '\\'; #else const char sep = '/'; #endif -void InitAndInfer(const std::string& model_dir, const std::string& image_file, - const fastdeploy::RuntimeOption& option) { +void AscendInfer(const std::string& model_dir, const std::string& image_file) { auto model_file = model_dir + sep + "model.pdmodel"; auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; - + auto option = fastdeploy::RuntimeOption(); + option.UseAscend(); auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); - assert(model.Initialized()); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::SegmentationResult res; if (!model.Predict(im, &res)) { @@ -40,37 +43,20 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, } std::cout << res.Str() << std::endl; - + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } - int main(int argc, char* argv[]) { - if (argc < 4) { - std::cout << "Usage: infer_demo path/to/quant_model " - "path/to/image " - "run_option, " - "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg 0" - << std::endl; - std::cout << "The data type of run_option is int, 0: run on cpu with ORT " - "backend; 1: run " - "on gpu with TensorRT backend. " - << std::endl; + if (argc < 3) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppseg_model_dir ./test.jpeg" + << std::endl; return -1; } - fastdeploy::RuntimeOption option; - int flag = std::atoi(argv[3]); - - if (flag == 0) { - option.UseCpu(); - option.UseOrtBackend(); - } else if (flag == 1) { - option.UseCpu(); - option.UsePaddleInferBackend(); - } - - std::string model_dir = argv[1]; - std::string test_image = argv[2]; - InitAndInfer(model_dir, test_image, option); + AscendInfer(argv[1], argv[2]); return 0; -} \ No newline at end of file +} diff --git a/examples/vision/segmentation/paddleseg/ascend/python/README.md b/examples/vision/segmentation/paddleseg/ascend/python/README.md new file mode 100755 index 000000000..d37d92c9e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/python/README.md @@ -0,0 +1,82 @@ +English | [简体中文](README_CN.md) +# PaddleSeg Python Deployment Example + +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) + +This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +```bash +# Download the deployment example code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python + +# Download Unet model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# CPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True +# kunlunxin XPU inference +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +``` + +The visualized result after running is as follows +
+ +
+ +## PaddleSegModel Python Interface + +```python +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +### predict function + +> ```python +> PaddleSegModel.predict(input_image) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **input_image**(np.ndarray): Input data in HWC or BGR format + +> **Return** +> +> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax + +## Other Documents + +- [PaddleSeg Model Description](..) +- [PaddleSeg C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md new file mode 100644 index 000000000..909784fd3 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md @@ -0,0 +1,79 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 + +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +在部署前,需自行编译基于华为昇腾NPU的FastDeploy python wheel包,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/huawei_ascend.md),编译python wheel包并安装 + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 + + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PaddleSegModel Python接口 + +```python +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PaddleSegModel.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.SegmentationResult`结构体,SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +## 快速链接 + +- [PaddleSeg 模型介绍](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) diff --git a/examples/vision/segmentation/paddleseg/ascend/python/infer.py b/examples/vision/segmentation/paddleseg/ascend/python/infer.py new file mode 100755 index 000000000..180f30e80 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/python/infer.py @@ -0,0 +1,34 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of PaddleSeg model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + return parser.parse_args() + + +runtime_option = fd.RuntimeOption() +runtime_option.use_ascend() + +# 配置runtime,加载模型 +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +config_file = os.path.join(args.model, "deploy.yaml") +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片分割结果 +im = cv2.imread(args.image) +result = model.predict(im) +print(result) + +# 可视化结果 +vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) +cv2.imwrite("vis_img.png", vis_im) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md index a4ff4af5e..0109ac01a 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md @@ -1,5 +1,7 @@ # 使用FastDeploy部署PaddleSeg模型 +FastDeploy支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署PaddleSeg模型 + ## 模型版本说明 - [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) @@ -13,7 +15,7 @@ - [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) +>>**注意**】如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) ## 准备PaddleSeg部署模型 PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md index c5d39934b..7618e6f15 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md @@ -82,7 +82,7 @@ PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模 > **参数** > > > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) ### 类成员属性 #### 预处理参数 diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md index add5b053d..d37d92c9e 100755 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md @@ -40,7 +40,7 @@ The visualized result after running is as follows fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) for more information +PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information **Parameter** diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md index 1e31bd014..da23623b2 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md @@ -39,7 +39,7 @@ python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --ima fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) **参数** diff --git a/examples/vision/segmentation/paddleseg/kunlun/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/README_CN.md index a4ff4af5e..5fba79c12 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/README_CN.md +++ b/examples/vision/segmentation/paddleseg/kunlun/README_CN.md @@ -13,7 +13,7 @@ - [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../matting/)下载对应模型,部署过程与此文档一致 ## 准备PaddleSeg部署模型 PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md index df99e324e..55c6996fc 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md @@ -1,42 +1,30 @@ [English](README.md) | 简体中文 # PaddleSeg C++部署示例 -本目录下提供`infer.cc`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -在部署前,需确认以下两个步骤 +在部署前,需自行编译基于昆仑芯XPU的预测库,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/kunlunxin.md) -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) - -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 ```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp + mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 -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 +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend make -j -# 下载Unet模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# CPU推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# GPU上TensorRT推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# 昆仑芯XPU推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 # 华为昇腾推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png ``` 运行完成可视化结果如下图所示 @@ -44,12 +32,6 @@ wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) - ## PaddleSeg C++接口 ### PaddleSeg类 @@ -84,7 +66,7 @@ PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模 > **参数** > > > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) ### 类成员属性 #### 预处理参数 @@ -95,7 +77,12 @@ PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模 #### 后处理参数 > > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 -- [模型介绍](../../) +## 快速链接 +- [PaddleSeg模型介绍](../../) - [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc index e4d6e39d9..c695cd732 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc @@ -20,34 +20,6 @@ const char sep = '\\'; const char sep = '/'; #endif -void CpuInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseCpu(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); - - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - void KunlunXinInfer(const std::string& model_dir, const std::string& image_file) { auto model_file = model_dir + sep + "model.pdmodel"; @@ -77,116 +49,14 @@ void KunlunXinInfer(const std::string& model_dir, std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void GpuInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - - auto option = fastdeploy::RuntimeOption(); - option.UseGpu(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); - - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - -void TrtInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - - auto option = fastdeploy::RuntimeOption(); - option.UseGpu(); - option.UseTrtBackend(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); - - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - -void AscendInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseAscend(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); - - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - int main(int argc, char* argv[]) { - if (argc < 4) { + if (argc < 3) { std::cout << "Usage: infer_demo path/to/model_dir path/to/image run_option, " - "e.g ./infer_model ./ppseg_model_dir ./test.jpeg 0" + "e.g ./infer_model ./ppseg_model_dir ./test.jpeg" << std::endl; - std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " - "with gpu; 2: run with gpu and use tensorrt backend; 3: run " - "with kunlunxin." - << std::endl; return -1; } - - if (std::atoi(argv[3]) == 0) { - CpuInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 1) { - GpuInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 2) { - TrtInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 3) { - KunlunXinInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 4) { - AscendInfer(argv[1], argv[2]); - } + KunlunXinInfer(argv[1], argv[2]); return 0; } diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/README.md index add5b053d..d37d92c9e 100755 --- a/examples/vision/segmentation/paddleseg/kunlun/python/README.md +++ b/examples/vision/segmentation/paddleseg/kunlun/python/README.md @@ -40,7 +40,7 @@ The visualized result after running is as follows fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) for more information +PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information **Parameter** diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md index 61edc5b2b..7ce98b44e 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md +++ b/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md @@ -1,35 +1,25 @@ [English](README.md) | 简体中文 # PaddleSeg Python部署示例 -在部署前,需确认以下两个步骤 +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +在部署前,需自行编译基于昆仑芯XPU的FastDeploy wheel 包,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/kunlunxin.md),编译python wheel包并安装 -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 -本目录下提供`infer.py`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 ```bash #下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python +cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp -# 下载Unet模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU推理 -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU推理 -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -# 昆仑芯XPU推理 -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin # 华为昇腾推理 -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device ascend +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png ``` 运行完成可视化结果如下图所示 @@ -43,7 +33,7 @@ python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_ fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) **参数** @@ -67,7 +57,7 @@ PaddleSeg模型加载和初始化,其中model_file, params_file以及config_fi > **返回** > -> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > 返回`fastdeploy.vision.SegmentationResult`结构体,SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) ### 类成员属性 #### 预处理参数 @@ -78,9 +68,12 @@ PaddleSeg模型加载和初始化,其中model_file, params_file以及config_fi #### 后处理参数 > > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 -## 其它文档 +## 快速链接 - [PaddleSeg 模型介绍](..) - [PaddleSeg C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/infer.py b/examples/vision/segmentation/paddleseg/kunlun/python/infer.py index 6862330ed..bfbde415f 100755 --- a/examples/vision/segmentation/paddleseg/kunlun/python/infer.py +++ b/examples/vision/segmentation/paddleseg/kunlun/python/infer.py @@ -11,42 +11,13 @@ def parse_arguments(): "--model", required=True, help="Path of PaddleSeg model.") parser.add_argument( "--image", type=str, required=True, help="Path of test image file.") - parser.add_argument( - "--device", - type=str, - default='cpu', - help="Type of inference device, support 'kunlunxin', 'cpu' or 'gpu'.") - parser.add_argument( - "--use_trt", - type=ast.literal_eval, - default=False, - help="Wether to use tensorrt.") return parser.parse_args() -def build_option(args): - option = fd.RuntimeOption() - - if args.device.lower() == "gpu": - option.use_gpu() - - if args.device.lower() == "kunlunxin": - option.use_kunlunxin() - - if args.device.lower() == "ascend": - option.use_ascend() - - if args.use_trt: - option.use_trt_backend() - option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], - [1, 3, 2048, 2048]) - return option - - -args = parse_arguments() +runtime_option = fd.RuntimeOption() +runtime_option.use_kunlunxin() # 配置runtime,加载模型 -runtime_option = build_option(args) model_file = os.path.join(args.model, "model.pdmodel") params_file = os.path.join(args.model, "model.pdiparams") config_file = os.path.join(args.model, "deploy.yaml") diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md deleted file mode 100644 index da41a3a00..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/python/serving/README.md +++ /dev/null @@ -1,36 +0,0 @@ -English | [简体中文](README_CN.md) - -# PaddleSegmentation Python Simple Serving Demo - - -## Environment - -- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -Server: -```bash -# Download demo code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving - -# Download PP_LiteSeg model -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz - -# Launch server, change the configurations in server.py to select hardware, backend, etc. -# and use --host, --port to specify IP and port -fastdeploy simple_serving --app server:app -``` - -Client: -```bash -# Download demo code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving - -# Download test image -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# Send request and get inference result (Please adapt the IP and port if necessary) -python client.py -``` diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md deleted file mode 100644 index 3f382c904..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/python/serving/README_CN.md +++ /dev/null @@ -1,36 +0,0 @@ -简体中文 | [English](README.md) - -# PaddleSegmentation Python轻量服务化部署示例 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -服务端: -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving - -# 下载PP_LiteSeg模型文件 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz - -# 启动服务,可修改server.py中的配置项来指定硬件、后端等 -# 可通过--host、--port指定IP和端口号 -fastdeploy simple_serving --app server:app -``` - -客户端: -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/detection/paddledetection/python/serving - -# 下载测试图片 -wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg - -# 请求服务,获取推理结果(如有必要,请修改脚本中的IP和端口号) -python client.py -``` diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py b/examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py deleted file mode 100644 index e652c4462..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/python/serving/client.py +++ /dev/null @@ -1,23 +0,0 @@ -import requests -import json -import cv2 -import fastdeploy as fd -from fastdeploy.serving.utils import cv2_to_base64 - -if __name__ == '__main__': - url = "http://127.0.0.1:8000/fd/ppliteseg" - headers = {"Content-Type": "application/json"} - - im = cv2.imread("cityscapes_demo.png") - data = {"data": {"image": cv2_to_base64(im)}, "parameters": {}} - - resp = requests.post(url=url, headers=headers, data=json.dumps(data)) - if resp.status_code == 200: - r_json = json.loads(resp.json()["result"]) - result = fd.vision.utils.json_to_segmentation(r_json) - vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) - cv2.imwrite("visualized_result.jpg", vis_im) - print("Visualized result save in ./visualized_result.jpg") - else: - print("Error code:", resp.status_code) - print(resp.text) diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py b/examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py deleted file mode 100644 index 2ae2df09c..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/python/serving/server.py +++ /dev/null @@ -1,38 +0,0 @@ -import fastdeploy as fd -from fastdeploy.serving.server import SimpleServer -import os -import logging - -logging.getLogger().setLevel(logging.INFO) - -# Configurations -model_dir = 'PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer' -device = 'cpu' -use_trt = False - -# Prepare model -model_file = os.path.join(model_dir, "model.pdmodel") -params_file = os.path.join(model_dir, "model.pdiparams") -config_file = os.path.join(model_dir, "deploy.yaml") - -# Setup runtime option to select hardware, backend, etc. -option = fd.RuntimeOption() -if device.lower() == 'gpu': - option.use_gpu() -if use_trt: - option.use_trt_backend() - option.set_trt_cache_file('pp_lite_seg.trt') - -# Create model instance -model_instance = fd.vision.segmentation.PaddleSegModel( - model_file=model_file, - params_file=params_file, - config_file=config_file, - runtime_option=option) - -# Create server, setup REST API -app = SimpleServer() -app.register( - task_name="fd/ppliteseg", - model_handler=fd.serving.handler.VisionModelHandler, - predictor=model_instance) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/README.md b/examples/vision/segmentation/paddleseg/quantize/cpp/README.md deleted file mode 100755 index 9eb7c9146..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/README.md +++ /dev/null @@ -1,32 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantitative Model C++ Deployment Example - `infer.cc` in this directory can help you quickly complete the inference acceleration of PaddleSeg quantization model deployment on CPU. - -## Deployment Preparations -### FastDeploy Environment Preparations -- 1. For the software and hardware requirements, please refer to [FastDeploy Environment Requirements](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). -- 2. For the installation of FastDeploy Python whl package, please refer to [FastDeploy Python Installation](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). - -### Quantized Model Preparations -- 1. You can directly use the quantized model provided by FastDeploy for deployment. -- 2. You can use [one-click automatical compression tool](../../../../../../tools/common_tools/auto_compression/) provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) - -## Take the Quantized PP_LiteSeg_T_STDC1_cityscapes Model as an example for Deployment -Run the following commands in this directory to compile and deploy the quantized model. FastDeploy version 0.7.0 or higher is required (x.x.x>=0.7.0). -```bash -mkdir build -cd build -# Download pre-compiled FastDeploy libraries. You can choose the appropriate version from `pre-compiled FastDeploy libraries` mentioned above. -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 - -# Download the PP_LiteSeg_T_STDC1_cityscapes quantized model and test images provided by FastDeloy. -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# Use Paddle-Inference inference quantization model on CPU. -./infer_demo PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ cityscapes_demo.png 1 -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md deleted file mode 100644 index c4cde0b1f..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md +++ /dev/null @@ -1,32 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型 C++部署示例 -本目录下提供的`infer.cc`,可以帮助用户快速完成PaddleSeg量化模型在CPU上的部署推理加速. - -## 部署准备 -### FastDeploy环境准备 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -### 量化模型准备 -- 1. 用户可以直接使用由FastDeploy提供的量化模型进行部署. -- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) - -## 以量化后的PP_LiteSeg_T_STDC1_cityscapes模型为例, 进行部署 -在本目录执行如下命令即可完成编译,以及量化模型部署.支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) -```bash -mkdir build -cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 -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 - -# 下载FastDeloy提供的PP_LiteSeg_T_STDC1_cityscapes量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 在CPU上使用Paddle-Inference推理量化模型 -./infer_demo PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ cityscapes_demo.png 1 -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/README.md b/examples/vision/segmentation/paddleseg/quantize/python/README.md deleted file mode 100755 index 5607e1a80..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/README.md +++ /dev/null @@ -1,29 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantitative Model Python Deployment Example - `infer.py` in this directory can help you quickly complete the inference acceleration of PaddleSeg quantization model deployment on CPU/GPU. - -## Deployment Preparations -### FastDeploy Environment Preparations -- 1. For the software and hardware requirements, please refer to [FastDeploy Environment Requirements](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. For the installation of FastDeploy Python whl package, please refer to [FastDeploy Python Installation](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -### Quantized Model Preparations -- 1. You can directly use the quantized model provided by FastDeploy for deployment. -- 2. You can use [one-click automatical compression tool](../../../../../../tools/common_tools/auto_compression/) provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) - - -## Take the Quantized PP_LiteSeg_T_STDC1_cityscapes Model as an example for Deployment -```bash -# Download sample deployment code. -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/segmentation/paddleseg/quantize/python - -# Download the PP_LiteSeg_T_STDC1_cityscapes quantized model and test images provided by FastDeloy. -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# Use Paddle-Inference inference quantization model on CPU. -python infer.py --model PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT --image cityscapes_demo.png --device cpu --backend paddle - -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md deleted file mode 100644 index 1975a84fe..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md +++ /dev/null @@ -1,29 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型 Python部署示例 -本目录下提供的`infer.py`,可以帮助用户快速完成PaddleSeg量化模型在CPU/GPU上的部署推理加速. - -## 部署准备 -### FastDeploy环境准备 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -### 量化模型准备 -- 1. 用户可以直接使用由FastDeploy提供的量化模型进行部署. -- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) - - -## 以量化后的PP_LiteSeg_T_STDC1_cityscapes模型为例, 进行部署 -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/segmentation/paddleseg/quantize/python - -# 下载FastDeloy提供的PP_LiteSeg_T_STDC1_cityscapes量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 在CPU上使用Paddle-Inference推理量化模型 -python infer.py --model PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT --image cityscapes_demo.png --device cpu --backend paddle - -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/infer.py b/examples/vision/segmentation/paddleseg/quantize/python/infer.py deleted file mode 100644 index 85a875c1e..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/infer.py +++ /dev/null @@ -1,76 +0,0 @@ -import fastdeploy as fd -import cv2 -import os - - -def parse_arguments(): - import argparse - import ast - parser = argparse.ArgumentParser() - parser.add_argument( - "--model", required=True, help="Path of PaddleSeg model.") - parser.add_argument( - "--image", required=True, help="Path of test image file.") - parser.add_argument( - "--device", - type=str, - default='cpu', - help="Type of inference device, support 'cpu' or 'gpu'.") - parser.add_argument( - "--backend", - type=str, - default="default", - help="Type of inference backend, support ort/trt/paddle/openvino, default 'openvino' for cpu, 'tensorrt' for gpu" - ) - parser.add_argument( - "--device_id", - type=int, - default=0, - help="Define which GPU card used to run model.") - parser.add_argument( - "--cpu_thread_num", - type=int, - default=9, - help="Number of threads while inference on CPU.") - return parser.parse_args() - - -def build_option(args): - option = fd.RuntimeOption() - if args.device.lower() == "gpu": - option.use_gpu(0) - - option.set_cpu_thread_num(args.cpu_thread_num) - - if args.backend.lower() == "trt": - assert args.device.lower( - ) == "gpu", "TensorRT backend require inferences on device GPU." - option.use_trt_backend() - option.set_trt_cache_file(os.path.join(args.model, "model.trt")) - option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], - [1, 3, 2048, 2048]) - elif args.backend.lower() == "ort": - option.use_ort_backend() - elif args.backend.lower() == "paddle": - option.use_paddle_infer_backend() - elif args.backend.lower() == "openvino": - assert args.device.lower( - ) == "cpu", "OpenVINO backend require inference on device CPU." - option.use_openvino_backend() - return option - - -args = parse_arguments() - -# 配置runtime,加载模型 -runtime_option = build_option(args) -model_file = os.path.join(args.model, "model.pdmodel") -params_file = os.path.join(args.model, "model.pdiparams") -config_file = os.path.join(args.model, "deploy.yaml") -model = fd.vision.segmentation.PaddleSegModel( - model_file, params_file, config_file, runtime_option=runtime_option) - -# 预测图片检测结果 -im = cv2.imread(args.image) -result = model.predict(im) -print(result) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md index 7d10f82f2..b7a1be32a 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md @@ -6,9 +6,28 @@ - [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) 目前FastDeploy使用RKNPU2推理PPSeg支持如下模型的部署: +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) -| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------------------------------------------------------------------------------------|:-------|:---------|:-------|:------------|:---------------| +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:----------------|:-------|:---------|:-------|:------------|:---------------| | [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | | [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | | [PP-HumanSegV1-Lite(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | @@ -21,14 +40,16 @@ ## 准备PaddleSeg部署模型以及转换模型 RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: -* Paddle动态图模型转换为ONNX模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/contrib/PP-HumanSeg) -* ONNX模型转换RKNN模型的过程,请参考[转换文档](../../../../../docs/cn/faq/rknpu2/export.md)进行转换。 +* PaddleSeg训练模型导出为推理模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md),也可以使用上表中的FastDeploy的预导出模型 +* Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) +* ONNX模型转换RKNN模型的过程,请参考[转换文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/export.md)进行转换。 +上述步骤可以可参考以下具体示例 ## 模型转换example * [PPHumanSeg](./pp_humanseg.md) ## 详细部署文档 -- [RKNN总体部署教程](../../../../../docs/cn/faq/rknpu2/rknpu2.md) +- [RKNN总体部署教程](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) - [C++部署](cpp) - [Python部署](python) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md index 309d5f26c..45bb923a0 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md @@ -8,7 +8,7 @@ 1. 软硬件环境满足要求 2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库 -以上步骤请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)实现 +以上步骤请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)实现 ## 生成基本目录文件 @@ -37,7 +37,7 @@ mkdir thirdpartys ### 编译并拷贝SDK到thirdpartys文件夹 -请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录,请移动它至thirdpartys目录下. +请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-x-x-x目录,请移动它至thirdpartys目录下. ### 拷贝模型文件,以及配置文件至model文件夹 在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。 diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md index e0f458eb0..e212d4e2d 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md @@ -2,7 +2,7 @@ # PPHumanSeg模型部署 ## 转换模型 -下面以Portait-PP-HumanSegV2_Lite(肖像分割模型)为例子,教大家如何转换PPSeg模型到RKNN模型。 +下面以Portait-PP-HumanSegV2_Lite(肖像分割模型)为例子,教大家如何转换PaddleSeg模型到RKNN模型。 ```bash # 下载Paddle2ONNX仓库 diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md index b897dc369..0bf8b9396 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md @@ -3,9 +3,9 @@ 在部署前,需确认以下步骤 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/rknpu2.md) +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../matting/) +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../../matting/) 本目录下提供`infer.py`快速完成PPHumanseg在RKNPU上部署的示例。执行如下脚本即可完成 @@ -32,5 +32,5 @@ RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作 - [PaddleSeg 模型介绍](..) - [PaddleSeg C++部署](../cpp) -- [模型预测结果说明](../../../../../../docs/api/vision_results/) -- [转换PPSeg RKNN模型文档](../README.md) +- [模型预测结果说明](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) +- [转换PaddleSeg模型至RKNN模型文档](../README.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md index ce4cbb816..2b51362b8 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md @@ -1,12 +1,20 @@ [English](README.md) | 简体中文 -# PP-LiteSeg 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 RV1126 上。 +# 在瑞芯微 RV1126 上使用 FastDeploy 部署 PaddleSeg 模型 +瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。目前,FastDeploy 支持在 RV1126 上基于 Paddle-Lite 部署 PaddleSeg 相关模型 -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +## 瑞芯微 RV1126 支持的PaddleSeg模型 +由于瑞芯微 RV1126 的 NPU 仅支持 INT8 量化模型的部署,因此所支持的量化模型如下: +- [PP-LiteSeg 系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +为了方便开发者的测试,下面提供了 PaddleSeg 导出的部分模型,开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +>> **注意**: FastDeploy 模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) ## 详细部署文档 -在 RV1126 上只支持 C++ 的部署。 +目前,瑞芯微 RV1126 上只支持C++的部署。 - [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md index 15c1f273e..afd185ca0 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md @@ -5,22 +5,22 @@ ## 部署准备 ### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建) +1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/rv1126.md#交叉编译环境搭建) ### 模型准备 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 +3. 模型需要异构计算,异构计算文件可以参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) ## 在 RV1126 上部署量化后的 PP-LiteSeg 分割模型 请按照以下步骤完成在 RV1126 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/rv1126.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) 2. 将编译后的库拷贝到当前目录,可使用如下命令: ```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp +cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp ``` 3. 在当前路径下载部署所需的模型和示例图片: @@ -45,7 +45,7 @@ make install 5. 基于 adb 工具部署 PP-LiteSeg 分割模型到 Rockchip RV1126,可使用如下命令: ```bash # 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp/build/install/ +cd FastDeploy/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/build/install/ # 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID ``` @@ -54,4 +54,4 @@ bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -需要特别注意的是,在 RV1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) +需要特别注意的是,在 RV1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md index 566691889..563507c25 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md @@ -3,7 +3,15 @@ ## 支持模型列表 -- PP-LiteSeg部署模型实现来自[PaddleSeg PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 + +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | ## 准备PP-LiteSeg部署模型以及转换模型 @@ -93,5 +101,6 @@ model_deploy.py \ ``` 最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 -## 其他链接 +## 快速链接 - [Cpp部署](./cpp) +- [Python部署](./python) diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md index 6360a2907..fbb274b15 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md @@ -8,7 +8,7 @@ 1. 软硬件环境满足要求 2. 根据开发环境,从头编译FastDeploy仓库 -以上步骤请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)实现 +以上步骤请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)实现 ## 生成基本目录文件 @@ -26,7 +26,7 @@ ### 编译并拷贝SDK到thirdpartys文件夹 -请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录. +请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录. ### 拷贝模型文件,以及配置文件至model文件夹 将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md) diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md index 9cafb1dc9..a6eb37f8f 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md +++ b/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md @@ -3,7 +3,7 @@ 在部署前,需确认以下步骤 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md) +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md) 本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 diff --git a/examples/vision/segmentation/paddleseg/web/README_CN.md b/examples/vision/segmentation/paddleseg/web/README_CN.md index 81664eee3..2847da0be 100644 --- a/examples/vision/segmentation/paddleseg/web/README_CN.md +++ b/examples/vision/segmentation/paddleseg/web/README_CN.md @@ -8,7 +8,7 @@ ## 前端部署PP-Humanseg v1模型 -PP-Humanseg v1模型web demo部署及使用参考[文档](../../../../application/js/web_demo/README.md) +PP-Humanseg v1模型web demo部署及使用参考[文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/examples/application/js/README_CN.md) ## PP-Humanseg v1 js接口 From aef99f9b27bd0245470a21fffc713f575b32fac7 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Wed, 8 Feb 2023 14:33:10 +0800 Subject: [PATCH 03/20] Update README_CN.md --- examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md index 0109ac01a..e8fb39272 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md @@ -1,6 +1,6 @@ -# 使用FastDeploy部署PaddleSeg模型 +# PaddleSeg模型高性能全场景部署方案-FastDeploy -FastDeploy支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署PaddleSeg模型 +PaddleSeg通过FastDeploy支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署 ## 模型版本说明 From fa551282a29cd3d45c05b3f97aac856bff79ce69 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Wed, 8 Feb 2023 15:01:05 +0800 Subject: [PATCH 04/20] Update README_CN.md --- examples/vision/segmentation/paddleseg/serving/README_CN.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/README_CN.md index 0c2e5194b..7ea966f65 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/README_CN.md @@ -1,7 +1,9 @@ [English](README.md) | 简体中文 # 使用 FastDeploy 服务化部署 PaddleSeg 模型 ## FastDeploy 服务化部署介绍 -在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving。simple_serving 基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 +在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式: +- simple_serving和fastdeploy_serving。simple_serving 基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。 +- fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 ## 详细部署文档 From 844d80ecae0f36052cb7f2aa89a8fe0b4052c2a4 Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 8 Feb 2023 16:33:12 +0000 Subject: [PATCH 05/20] Update docs --- .../face_alignment_result_CN.md | 26 +- docs/api_docs/cpp/vision_results_cn.md | 306 ++++++++++++++++++ docs/api_docs/cpp/vision_results_en.md | 276 ++++++++++++++++ docs/cn/build_and_install/README.md | 1 + docs/cn/build_and_install/huawei_ascend.md | 14 +- .../faq/vision_result_related_problems.md} | 0 examples/vision/matting/ppmatting | 1 + examples/vision/matting/ppmatting/README.md | 42 --- .../vision/matting/ppmatting/README_CN.md | 43 --- .../matting/ppmatting/cpp/CMakeLists.txt | 14 - .../vision/matting/ppmatting/cpp/README.md | 93 ------ .../vision/matting/ppmatting/cpp/README_CN.md | 94 ------ .../vision/matting/ppmatting/cpp/infer.cc | 173 ---------- .../vision/matting/ppmatting/python/README.md | 81 ----- .../matting/ppmatting/python/README_CN.md | 81 ----- .../vision/matting/ppmatting/python/infer.py | 70 ---- .../vision/segmentation/paddleseg/README.md | 65 ++-- .../segmentation/paddleseg/README_CN.md | 23 -- .../paddleseg/amlogic/a311d/README.md | 32 +- .../paddleseg/amlogic/a311d/README_CN.md | 22 -- .../paddleseg/amlogic/a311d/cpp/README.md | 56 ++-- .../paddleseg/amlogic/a311d/cpp/README_CN.md | 59 ---- .../segmentation/paddleseg/android/README.md | 12 +- .../paddleseg/android/README_CN.md | 4 +- .../ascend/{README_CN.md => README.md} | 4 +- .../paddleseg/ascend/cpp/README.md | 100 ++---- .../paddleseg/ascend/cpp/README_CN.md | 88 ----- .../paddleseg/ascend/python/README.md | 88 ++--- .../paddleseg/ascend/python/README_CN.md | 79 ----- .../cpu-gpu/{README_CN.md => README.md} | 4 +- .../paddleseg/cpu-gpu/cpp/README.md | 105 ++---- .../paddleseg/cpu-gpu/cpp/README_CN.md | 106 ------ .../paddleseg/cpu-gpu/cpp/infer.cc | 9 +- .../paddleseg/cpu-gpu/python/README.md | 95 ++---- .../paddleseg/cpu-gpu/python/README_CN.md | 88 ----- .../paddleseg/cpu-gpu/python/infer.py | 4 + .../kunlun/{README_CN.md => README.md} | 4 +- .../paddleseg/kunlun/cpp/README.md | 101 ++---- .../paddleseg/kunlun/cpp/README_CN.md | 88 ----- .../paddleseg/kunlun/python/README.md | 89 ++--- .../paddleseg/kunlun/python/README_CN.md | 79 ----- .../segmentation/paddleseg/quantize/README.md | 51 ++- .../paddleseg/quantize/README_CN.md | 26 -- .../paddleseg/rockchip/rknpu2/README.md | 71 ++-- .../paddleseg/rockchip/rknpu2/README_CN.md | 55 ---- .../paddleseg/rockchip/rknpu2/cpp/README.md | 59 ++-- .../rockchip/rknpu2/cpp/README_CN.md | 73 ----- .../paddleseg/rockchip/rknpu2/pp_humanseg.md | 2 +- .../rockchip/rknpu2/python/README.md | 34 +- .../rockchip/rknpu2/python/README_CN.md | 36 --- .../paddleseg/rockchip/rv1126/README.md | 29 +- .../paddleseg/rockchip/rv1126/README_CN.md | 20 -- .../paddleseg/rockchip/rv1126/cpp/README.md | 54 ++-- .../rockchip/rv1126/cpp/README_CN.md | 57 ---- .../paddleseg/serving/README_CN.md | 4 +- .../segmentation/paddleseg/sophgo/README.md | 69 ++-- .../paddleseg/sophgo/README_CN.md | 106 ------ .../paddleseg/sophgo/cpp/README.md | 53 ++- .../paddleseg/sophgo/cpp/README_CN.md | 57 ---- .../paddleseg/sophgo/python/README.md | 34 +- .../paddleseg/sophgo/python/README_CN.md | 27 -- 61 files changed, 1117 insertions(+), 2519 deletions(-) create mode 100644 docs/api_docs/cpp/vision_results_cn.md create mode 100644 docs/api_docs/cpp/vision_results_en.md rename docs/{api/vision_results/faq_CN.md => cn/faq/vision_result_related_problems.md} (100%) create mode 120000 examples/vision/matting/ppmatting delete mode 100644 examples/vision/matting/ppmatting/README.md delete mode 100644 examples/vision/matting/ppmatting/README_CN.md delete mode 100644 examples/vision/matting/ppmatting/cpp/CMakeLists.txt delete mode 100755 examples/vision/matting/ppmatting/cpp/README.md delete mode 100644 examples/vision/matting/ppmatting/cpp/README_CN.md delete mode 100755 examples/vision/matting/ppmatting/cpp/infer.cc delete mode 100755 examples/vision/matting/ppmatting/python/README.md delete mode 100644 examples/vision/matting/ppmatting/python/README_CN.md delete mode 100755 examples/vision/matting/ppmatting/python/infer.py delete mode 100644 examples/vision/segmentation/paddleseg/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/amlogic/a311d/README.md delete mode 100644 examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md rename examples/vision/segmentation/paddleseg/ascend/{README_CN.md => README.md} (97%) mode change 100755 => 100644 examples/vision/segmentation/paddleseg/ascend/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/ascend/python/README.md delete mode 100644 examples/vision/segmentation/paddleseg/ascend/python/README_CN.md rename examples/vision/segmentation/paddleseg/cpu-gpu/{README_CN.md => README.md} (97%) mode change 100755 => 100644 examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md delete mode 100644 examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md rename examples/vision/segmentation/paddleseg/kunlun/{README_CN.md => README.md} (97%) mode change 100755 => 100644 examples/vision/segmentation/paddleseg/kunlun/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/kunlun/python/README.md delete mode 100644 examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/quantize/README.md delete mode 100644 examples/vision/segmentation/paddleseg/quantize/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md delete mode 100644 examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md mode change 100755 => 100644 examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md delete mode 100644 examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/sophgo/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md delete mode 100644 examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md diff --git a/docs/api/vision_results/face_alignment_result_CN.md b/docs/api/vision_results/face_alignment_result_CN.md index 1697fbfd5..ada0291fa 100644 --- a/docs/api/vision_results/face_alignment_result_CN.md +++ b/docs/api/vision_results/face_alignment_result_CN.md @@ -1,35 +1,27 @@ -简体中文 | [English](face_detection_result.md) -# FaceDetectionResult 人脸检测结果 +[English](face_alignment_result.md) | 简体中文 -FaceDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸检测出来的目标框、人脸landmarks,目标置信度和每张人脸的landmark数量。 +# FaceAlignmentResult 人脸对齐(人脸关键点检测)结果 + +FaceAlignmentResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸landmarks。 ## C++ 定义 -`fastdeploy::vision::FaceDetectionResult` +`fastdeploy::vision::FaceAlignmentResult` ```c++ -struct FaceDetectionResult { - std::vector> boxes; +struct FaceAlignmentResult { std::vector> landmarks; - std::vector scores; - int landmarks_per_face; void Clear(); std::string Str(); }; ``` -- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 -- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 -- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点,其元素个数与`boxes.size()`一致 -- **landmarks_per_face**: 成员变量,表示每个人脸框中的关键点的数量。 +- **landmarks**: 成员变量,表示单张人脸图片检测出来的所有关键点 - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) ## Python 定义 -`fastdeploy.vision.FaceDetectionResult` +`fastdeploy.vision.FaceAlignmentResult` -- **boxes**(list of list(float)): 成员变量,表示单张图片检测出来的所有目标框坐标。boxes是一个list,其每个元素为一个长度为4的list, 表示为一个框,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 -- **scores**(list of float): 成员变量,表示单张图片检测出来的所有目标置信度 -- **landmarks**(list of list(float)): 成员变量,表示单张图片检测出来的所有人脸的关键点 -- **landmarks_per_face**(int): 成员变量,表示每个人脸框中的关键点的数量。 +- **landmarks**(list of list(float)): 成员变量,表示单张人脸图片检测出来的所有关键点 diff --git a/docs/api_docs/cpp/vision_results_cn.md b/docs/api_docs/cpp/vision_results_cn.md new file mode 100644 index 000000000..73af7f9ed --- /dev/null +++ b/docs/api_docs/cpp/vision_results_cn.md @@ -0,0 +1,306 @@ +# 视觉模型预测结果说明 + +## ClassifyResult 图像分类结果 + +ClassifyResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像的分类结果和置信度。 + +### C++ 定义 + +`fastdeploy::vision::ClassifyResult` + +```c++ +struct ClassifyResult { + std::vector label_ids; + std::vector scores; + void Clear(); + std::string Str(); +}; +``` + +- **label_ids**: 成员变量,表示单张图片的分类结果,其个数根据在使用分类模型时传入的topk决定,例如可以返回top 5的分类结果 +- **scores**: 成员变量,表示单张图片在相应分类结果上的置信度,其个数根据在使用分类模型时传入的topk决定,例如可以返回top 5的分类置信度 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## SegmentationResult 图像分割结果 + +SegmentationResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像中每个像素预测出来的分割类别和分割类别的概率值。 + +### C++ 定义 + +`fastdeploy::vision::SegmentationResult` + +```c++ +struct SegmentationResult { + std::vector label_map; + std::vector score_map; + std::vector shape; + bool contain_score_map = false; + void Clear(); + void Free(); + std::string Str(); +}; +``` + +- **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`apply_softmax=True`) +- **shape**: 成员变量,表示输出图片的shape,为H\*W +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## DetectionResult 目标检测结果 + +DetectionResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::DetectionResult +``` + +```c++ +struct DetectionResult { + std::vector> boxes; + std::vector scores; + std::vector label_ids; + std::vector masks; + bool contain_masks = false; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **label_ids**: 成员变量,表示单张图片检测出来的所有目标类别,其元素个数与`boxes.size()`一致 +- **masks**: 成员变量,表示单张图片检测出来的所有实例mask,其元素个数及shape大小与`boxes`一致 +- **contain_masks**: 成员变量,表示检测结果中是否包含实例mask,实例分割模型的结果此项一般为true. +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +```c++ +fastdeploy::vision::Mask +``` +```c++ +struct Mask { + std::vector data; + std::vector shape; // (H,W) ... + + void Clear(); + std::string Str(); +}; +``` +- **data**: 成员变量,表示检测到的一个mask +- **shape**: 成员变量,表示mask的shape,如 (h,w) +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## FaceAlignmentResult 人脸对齐(人脸关键点检测)结果 + +FaceAlignmentResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸landmarks。 + +### C++ 定义 + +`fastdeploy::vision::FaceAlignmentResult` + +```c++ +struct FaceAlignmentResult { + std::vector> landmarks; + void Clear(); + std::string Str(); +}; +``` + +- **landmarks**: 成员变量,表示单张人脸图片检测出来的所有关键点 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## KeyPointDetectionResult 目标检测结果 + +KeyPointDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像中目标行为的各个关键点坐标和置信度。 + +### C++ 定义 + +`fastdeploy::vision::KeyPointDetectionResult` + +```c++ +struct KeyPointDetectionResult { + std::vector> keypoints; + std::vector scores; + int num_joints = -1; + void Clear(); + std::string Str(); +}; +``` + +- **keypoints**: 成员变量,表示识别到的目标行为的关键点坐标。 + `keypoints.size()= N * J` + - `N`:图片中的目标数量 + - `J`:num_joints(一个目标的关键点数量) +- **scores**: 成员变量,表示识别到的目标行为的关键点坐标的置信度。 + `scores.size()= N * J` + - `N`:图片中的目标数量 + - `J`:num_joints(一个目标的关键点数量) +- **num_joints**: 成员变量,一个目标的关键点数量 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +## FaceRecognitionResult 人脸识别结果 + +FaceRecognitionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸识别模型对图像特征的embedding。 +### C++ 定义 + +`fastdeploy::vision::FaceRecognitionResult` + +```c++ +struct FaceRecognitionResult { + std::vector embedding; + void Clear(); + std::string Str(); +}; +``` + +- **embedding**: 成员变量,表示人脸识别模型最终的提取的特征embedding,可以用来计算人脸之间的特征相似度。 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + + +## MattingResult 抠图结果 + +MattingResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明模型预测的alpha透明度的值,预测的前景等。 + +### C++ 定义 + +`fastdeploy::vision::MattingResult` + +```c++ +struct MattingResult { + std::vector alpha; + std::vector foreground; + std::vector shape; + bool contain_foreground = false; + void Clear(); + std::string Str(); +}; +``` + +- **alpha**: 是一维向量,为预测的alpha透明度的值,值域为[0.,1.],长度为hxw,h,w为输入图像的高和宽 +- **foreground**: 是一维向量,为预测的前景,值域为[0.,255.],长度为hxwxc,h,w为输入图像的高和宽,c一般为3,foreground不是一定有的,只有模型本身预测了前景,这个属性才会有效 +- **contain_foreground**: 表示预测的结果是否包含前景 +- **shape**: 表示输出结果的shape,当contain_foreground为false,shape只包含(h,w),当contain_foreground为true,shape包含(h,w,c), c一般为3 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## OCRResult OCR预测结果 + +OCRResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像检测和识别出来的文本框,文本框方向分类,以及文本框内的文本内容 + +### C++ 定义 + +```c++ +fastdeploy::vision::OCRResult +``` + +```c++ +struct OCRResult { + std::vector> boxes; + std::vector text; + std::vector rec_scores; + std::vector cls_scores; + std::vector cls_labels; + ResultType type = ResultType::OCR; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示单张图内检测出的框的个数,每个框以8个int数值依次表示框的4个坐标点,顺序为左下,右下,右上,左上 +- **text**: 成员变量,表示多个文本框内被识别出来的文本内容,其元素个数与`boxes.size()`一致 +- **rec_scores**: 成员变量,表示文本框内识别出来的文本的置信度,其元素个数与`boxes.size()`一致 +- **cls_scores**: 成员变量,表示文本框的分类结果的置信度,其元素个数与`boxes.size()`一致 +- **cls_labels**: 成员变量,表示文本框的方向分类类别,其元素个数与`boxes.size()`一致 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +## FaceDetectionResult 人脸检测结果 + +FaceDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸检测出来的目标框、人脸landmarks,目标置信度和每张人脸的landmark数量。 + +### C++ 定义 + +`fastdeploy::vision::FaceDetectionResult` + +```c++ +struct FaceDetectionResult { + std::vector> boxes; + std::vector> landmarks; + std::vector scores; + int landmarks_per_face; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点,其元素个数与`boxes.size()`一致 +- **landmarks_per_face**: 成员变量,表示每个人脸框中的关键点的数量。 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## HeadPoseResult 头部姿态结果 + +HeadPoseResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明头部姿态结果。 + +### C++ 定义 + +`fastdeploy::vision::HeadPoseResult` + +```c++ +struct HeadPoseResult { + std::vector euler_angles; + void Clear(); + std::string Str(); +}; +``` + +- **euler_angles**: 成员变量,表示单张人脸图片预测的欧拉角,存放的顺序是(yaw, pitch, roll), yaw 代表水平转角,pitch 代表垂直角,roll 代表翻滚角,值域都为 [-90,+90]度 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +API:`fastdeploy.vision.HeadPoseResult`, 该结果返回: +- **euler_angles**(list of float): 成员变量,表示单张人脸图片预测的欧拉角,存放的顺序是(yaw, pitch, roll), yaw 代表水平转角,pitch 代表垂直角,roll 代表翻滚角,值域都为 [-90, +90]度 + +## MOTResult 多目标跟踪结果 + +MOTResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明多目标跟踪中的检测出来的目标框、目标跟踪id、目标类别和目标置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::MOTResult +``` + +```c++ +struct MOTResult{ + // left top right bottom + std::vector> boxes; + std::vector ids; + std::vector scores; + std::vector class_ids; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单帧画面中检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **ids**: 成员变量,表示单帧画面中所有目标的id,其元素个数与`boxes.size()`一致 +- **scores**: 成员变量,表示单帧画面检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **class_ids**: 成员变量,表示单帧画面出来的所有目标类别,其元素个数与`boxes.size()`一致 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) diff --git a/docs/api_docs/cpp/vision_results_en.md b/docs/api_docs/cpp/vision_results_en.md new file mode 100644 index 000000000..122e90293 --- /dev/null +++ b/docs/api_docs/cpp/vision_results_en.md @@ -0,0 +1,276 @@ +# Description of Vision Results + +本文档的中文版本参考[视觉模型预测结果说明](./vision_results_cn.md) + +## Image Classification Result + +The ClassifyResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the classification result and confidence level of the image. + +### C++ Definition + +`fastdeploy::vision::ClassifyResult` + +```c++ +struct ClassifyResult { + std::vector label_ids; + std::vector scores; + void Clear(); + std::string Str(); +}; +``` + +- **label_ids**: Member variable which indicates the classification results of a single image. Its number is determined by the topk passed in when using the classification model, e.g. it can return the top 5 classification results. +- **scores**: Member variable which indicates the confidence level of a single image on the corresponding classification result. Its number is determined by the topk passed in when using the classification model, e.g. it can return the top 5 classification confidence level. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Segmentation Result + +The SegmentationResult code is defined in `fastdeploy/vision/common/result.h`, indicating the segmentation category and the segmentation category probability predicted in each pixel in the image. + +### C++ Definition + +``fastdeploy::vision::SegmentationResult`` + +```c++ +struct SegmentationResult { + std::vector label_map; + std::vector score_map; + std::vector shape; + bool contain_score_map = false; + void Clear(); + std::string Str(); +}; +``` + +- **label_map**: Member variable which indicates the segmentation category of each pixel in a single image. `label_map.size()` indicates the number of pixel points of a image. +- **score_map**: Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **shape**: Member variable which indicates the shape of the output image as H\*W. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +## Target Detection Result + +The DetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the target frame, target class and target confidence level detected in the image. + +### C++ Definition + +```c++ +fastdeploy::vision::DetectionResult +``` + +```c++ +struct DetectionResult { + std::vector> boxes; + std::vector scores; + std::vector label_ids; + std::vector masks; + bool contain_masks = false; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of boxes, each box is represented by 4 float values in order of xmin, ymin, xmax, ymax, i.e. the coordinates of the top left and bottom right corner. +- **scores**: Member variable which indicates the confidence level of all targets detected in a single image, where the number of elements is the same as `boxes.size()`. +- **label_ids**: Member variable which indicates all target categories detected in a single image, where the number of elements is the same as `boxes.size()`. +- **masks**: Member variable which indicates all detected instance masks of a single image, where the number of elements and the shape size are the same as `boxes`. +- **contain_masks**: Member variable which indicates whether the detected result contains instance masks, which is generally true for the instance segmentation model. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +```c++ +fastdeploy::vision::Mask +``` +```c++ +struct Mask { + std::vector data; + std::vector shape; // (H,W) ... + + void Clear(); + std::string Str(); +}; +``` +- **data**: Member variable which indicates a detected mask. +- **shape**: Member variable which indicates the shape of the mask, e.g. (h,w). +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Detection Result + +The FaceDetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the target frames, face landmarks, target confidence and the number of landmark per face. + +### C++ Definition + +``fastdeploy::vision::FaceDetectionResult`` + +```c++ +struct FaceDetectionResult { + std::vector> boxes; + std::vector> landmarks; + std::vector scores; + int landmarks_per_face; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of boxes, each box is represented by 4 float values in order of xmin, ymin, xmax, ymax, i.e. the coordinates of the top left and bottom right corner. +- **scores**: Member variable which indicates the confidence level of all targets detected in a single image, where the number of elements is the same as `boxes.size()`. +- **landmarks**: Member variable which indicates the keypoints of all faces detected in a single image, where the number of elements is the same as `boxes.size()`. +- **landmarks_per_face**: Member variable which indicates the number of keypoints in each face box. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Keypoint Detection Result + +The KeyPointDetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the coordinates and confidence level of each keypoint of the target's behavior in the image. + +### C++ Definition + +``fastdeploy::vision::KeyPointDetectionResult`` + +```c++ +struct KeyPointDetectionResult { + std::vector> keypoints; + std::vector scores; + int num_joints = -1; + void Clear(); + std::string Str(); +}; +``` + +- **keypoints**: Member variable which indicates the coordinates of the identified target behavior keypoint. + ` keypoints.size() = N * J`: + - `N`: the number of targets in the image + - `J`: num_joints (the number of keypoints of a target) +- **scores**: Member variable which indicates the confidence level of the keypoint coordinates of the identified target behavior. + `scores.size() = N * J`: + - `N`: the number of targets in the picture + - `J`:num_joints (the number of keypoints of a target) +- **num_joints**: Member variable which indicates the number of keypoints of a target. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Recognition Result + +The FaceRecognitionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the image features embedding in the face recognition model. +### C++ Definition + +`fastdeploy::vision::FaceRecognitionResult` + +```c++ +struct FaceRecognitionResult { + std::vector embedding; + void Clear(); + std::string Str(); +}; +``` + +- **embedding**: Member variable which indicates the final extracted feature embedding of the face recognition model, and can be used to calculate the facial feature similarity. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +## Matting Result + +The MattingResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the predicted value of alpha transparency predicted and the predicted foreground, etc. + +### C++ Definition + +``fastdeploy::vision::MattingResult`'' + +```c++ +struct MattingResult { + std::vector alpha; + std::vector foreground; + std::vector shape; + bool contain_foreground = false; + void Clear(); + std::string Str(); +}; +``` + +- **alpha**: It is a one-dimensional vector, indicating the predicted value of alpha transparency. The value range is [0.,1.], and the length is hxw, in which h,w represent the height and the width of the input image seperately. +- **foreground**: It is a one-dimensional vector, indicating the predicted foreground. The value range is [0.,255.], and the length is hxwxc, in which h,w represent the height and the width of the input image, and c is generally 3. This vector is valid only when the model itself predicts the foreground. +- **contain_foreground**: Used to indicate whether the result contains foreground. +- **shape**: Used to indicate the shape of the output. When contain_foreground is false, the shape only contains (h,w), while when contain_foreground is true, the shape contains (h,w,c), in which c is generally 3. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## OCR prediction result + +The OCRResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the text box detected in the image, text box orientation classification, and the text content. + +### C++ Definition + +```c++ +fastdeploy::vision::OCRResult +``` + +```c++ +struct OCRResult { + std::vector> boxes; + std::vector text; + std::vector rec_scores; + std::vector cls_scores; + std::vector cls_labels; + ResultType type = ResultType::OCR; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of detected boxes. Each box is represented by 8 int values to indicate the 4 coordinates of the box, in the order of lower left, lower right, upper right, upper left. +- **text**: Member variable which indicates the content of the recognized text in multiple text boxes, where the element number is the same as `boxes.size()`. +- **rec_scores**: Member variable which indicates the confidence level of the recognized text, where the element number is the same as `boxes.size()`. +- **cls_scores**: Member variable which indicates the confidence level of the classification result of the text box, where the element number is the same as `boxes.size()`. +- **cls_labels**: Member variable which indicates the directional category of the textbox, where the element number is the same as `boxes.size()`. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Alignment Result + +The FaceAlignmentResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate face landmarks. + +### C++ Definition + +`fastdeploy::vision::FaceAlignmentResult` + +```c++ +struct FaceAlignmentResult { + std::vector> landmarks; + void Clear(); + std::string Str(); +}; +``` + +- **landmarks**: Member variable which indicates all the key points detected in a single face image. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Head Pose Result + +The HeadPoseResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the head pose result. + +### C++ Definition + +``fastdeploy::vision::HeadPoseResult`'' + +```c++ +struct HeadPoseResult { + std::vector euler_angles; + void Clear(); + std::string Str(); +}; +``` + +- **euler_angles**: Member variable which indicates the Euler angles predicted for a single face image, stored in the order (yaw, pitch, roll), with yaw representing the horizontal turn angle, pitch representing the vertical angle, and roll representing the roll angle, all with a value range of [-90,+90]. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md index 92f575d8d..c6d5a23bc 100755 --- a/docs/cn/build_and_install/README.md +++ b/docs/cn/build_and_install/README.md @@ -4,6 +4,7 @@ ## FastDeploy预编译库安装 - [FastDeploy预编译库下载安装](download_prebuilt_libraries.md) +>> **注意**:FastDeploy目前只提供部分环境的预编译库,其他环境需要参考下方文档自行编译 ## 自行编译安装 - [NVIDIA GPU部署环境](gpu.md) diff --git a/docs/cn/build_and_install/huawei_ascend.md b/docs/cn/build_and_install/huawei_ascend.md index 3741027e2..980a4ba47 100644 --- a/docs/cn/build_and_install/huawei_ascend.md +++ b/docs/cn/build_and_install/huawei_ascend.md @@ -1,5 +1,17 @@ # 华为昇腾NPU 部署环境编译准备 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [华为昇腾环境准备](#一华为昇腾环境准备) +* [编译环境搭建](#二编译环境搭建) +* [基于 Paddle Lite 的 C++ FastDeploy 库编译](#三基于-paddle-lite-的-c-fastdeploy-库编译) +* [基于 Paddle Lite 的 Python FastDeploy 库编译](#四基于-paddle-lite-的-python-fastdeploy-库编译) +* [昇腾部署时开启FlyCV](#五昇腾部署时开启flycv) +* [昇腾部署Demo参考](#六昇腾部署demo参考) + +## 简介以及编译选项 + FastDeploy基于 Paddle-Lite 后端, 支持在华为昇腾NPU上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/demo_guides/huawei_ascend_npu.md)。 @@ -114,7 +126,7 @@ python setup.py bdist_wheel ## 五.昇腾部署时开启FlyCV [FlyCV](https://github.com/PaddlePaddle/FlyCV) 是一款高性能计算机图像处理库, 针对ARM架构做了很多优化, 相比其他图像处理库性能更为出色. FastDeploy现在已经集成FlyCV, 用户可以在支持的硬件平台上使用FlyCV, 实现模型端到端推理性能的加速. -模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FLyCV使用文档](./boost_cv_by_flycv.md). +模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FLyCV使用文档](../faq/boost_cv_by_flycv.md). ## 六.昇腾部署Demo参考 diff --git a/docs/api/vision_results/faq_CN.md b/docs/cn/faq/vision_result_related_problems.md similarity index 100% rename from docs/api/vision_results/faq_CN.md rename to docs/cn/faq/vision_result_related_problems.md diff --git a/examples/vision/matting/ppmatting b/examples/vision/matting/ppmatting new file mode 120000 index 000000000..c89893416 --- /dev/null +++ b/examples/vision/matting/ppmatting @@ -0,0 +1 @@ +/huangjianhui/doc/FastDeploy/examples/vision/segmentation/ppmatting/ \ No newline at end of file diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md deleted file mode 100644 index a2cbdc346..000000000 --- a/examples/vision/matting/ppmatting/README.md +++ /dev/null @@ -1,42 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting Model Deployment - -## Model Description - -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -## List of Supported Models - -Now FastDeploy supports the deployment of the following models - -- [PP-Matting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [PP-HumanMatting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [ModNet models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - - -## Export Deployment Model - -Before deployment, PP-Matting needs to be exported into the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information. (Tips: You need to set the `--input_shape` parameter of the export script when exporting PP-Matting and PP-HumanMatting models) - - -## Download Pre-trained Models - -For developers' testing, models exported by PP-Matting are provided below. Developers can download and use them directly. - -The accuracy metric is sourced from the model description in PP-Matting. (Accuracy data are not provided) Refer to the introduction in PP-Matting for more details. - -| Model | Parameter Size | Accuracy | Note | -|:---------------------------------------------------------------- |:----- |:----- | :------ | -| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | -| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | -| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | -| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | -| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | -| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | - - - -## Detailed Deployment Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) diff --git a/examples/vision/matting/ppmatting/README_CN.md b/examples/vision/matting/ppmatting/README_CN.md deleted file mode 100644 index a1c9801aa..000000000 --- a/examples/vision/matting/ppmatting/README_CN.md +++ /dev/null @@ -1,43 +0,0 @@ -[English](README.md) | 简体中文 -# PP-Matting模型部署 - -## 模型版本说明 - -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -## 支持模型列表 - -目前FastDeploy支持如下模型的部署 - -- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - - -## 导出部署模型 - -在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) - - -## 下载预训练模型 - -为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 - -其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 - - -| 模型 | 参数大小 | 精度 | 备注 | -|:---------------------------------------------------------------- |:----- |:----- | :------ | -| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | -| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | -| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | -| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | -| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | -| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | - - - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) diff --git a/examples/vision/matting/ppmatting/cpp/CMakeLists.txt b/examples/vision/matting/ppmatting/cpp/CMakeLists.txt deleted file mode 100644 index 93540a7e8..000000000 --- a/examples/vision/matting/ppmatting/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -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_demo ${PROJECT_SOURCE_DIR}/infer.cc) -# 添加FastDeploy库依赖 -target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/matting/ppmatting/cpp/README.md b/examples/vision/matting/ppmatting/cpp/README.md deleted file mode 100755 index fbe2c5fae..000000000 --- a/examples/vision/matting/ppmatting/cpp/README.md +++ /dev/null @@ -1,93 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting C++ Deployment Example - -This directory provides examples that `infer.cc` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -Taking the PP-Matting inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. - -```bash -mkdir build -cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above -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 - -# Download PP-Matting model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg - - -# CPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# TensorRT inference on GPU -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# kunlunxin XPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 -``` - -The visualized result after running is as follows -
- - - - -
- -The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/en/faq/use_sdk_on_windows.md) - -## PP-Matting C++ Interface - -### PPMatting Class - -```c++ -fastdeploy::vision::matting::PPMatting( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PP-Matting model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PPMatting::Predict(cv::Mat* im, MattingResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/cpp/README_CN.md b/examples/vision/matting/ppmatting/cpp/README_CN.md deleted file mode 100644 index 38e2e592a..000000000 --- a/examples/vision/matting/ppmatting/cpp/README_CN.md +++ /dev/null @@ -1,94 +0,0 @@ -[English](README.md) | 简体中文 -# PP-Matting C++部署示例 - -本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上 PP-Matting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) - -```bash -mkdir build -cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 -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 - -# 下载PP-Matting模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg - - -# CPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# GPU上TensorRT推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# 昆仑芯XPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 -``` - -运行完成可视化结果如下图所示 -
- - - - -
- -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -## PP-Matting C++接口 - -### PPMatting类 - -```c++ -fastdeploy::vision::matting::PPMatting( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PP-Matting模型加载和初始化,其中model_file为导出的Paddle模型格式。 - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -#### Predict函数 - -> ```c++ -> PPMatting::Predict(cv::Mat* im, MattingResult* result) -> ``` -> -> 模型预测接口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/cpp/infer.cc b/examples/vision/matting/ppmatting/cpp/infer.cc deleted file mode 100755 index 3b8309044..000000000 --- a/examples/vision/matting/ppmatting/cpp/infer.cc +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastdeploy/vision.h" - -#ifdef WIN32 -const char sep = '\\'; -#else -const char sep = '/'; -#endif - -void CpuInfer(const std::string& model_dir, const std::string& image_file, - const std::string& background_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseCpu(); - auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, - config_file, option); - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - cv::Mat bg = cv::imread(background_file); - fastdeploy::vision::MattingResult res; - if (!model.Predict(&im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); - cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); - std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " - "and ./visualized_result_fg.jpg" - << std::endl; -} - -void KunlunXinInfer(const std::string& model_dir, const std::string& image_file, - const std::string& background_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseKunlunXin(); - auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, - config_file, option); - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - cv::Mat bg = cv::imread(background_file); - fastdeploy::vision::MattingResult res; - if (!model.Predict(&im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); - cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); - std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " - "and ./visualized_result_fg.jpg" - << std::endl; -} - -void GpuInfer(const std::string& model_dir, const std::string& image_file, - const std::string& background_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - - auto option = fastdeploy::RuntimeOption(); - option.UseGpu(); - option.UsePaddleInferBackend(); - auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, - config_file, option); - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - cv::Mat bg = cv::imread(background_file); - fastdeploy::vision::MattingResult res; - if (!model.Predict(&im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); - cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); - std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " - "and ./visualized_result_fg.jpg" - << std::endl; -} - -void TrtInfer(const std::string& model_dir, const std::string& image_file, - const std::string& background_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - - auto option = fastdeploy::RuntimeOption(); - option.UseGpu(); - option.UseTrtBackend(); - option.SetTrtInputShape("img", {1, 3, 512, 512}); - auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, - config_file, option); - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - cv::Mat bg = cv::imread(background_file); - fastdeploy::vision::MattingResult res; - if (!model.Predict(&im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); - cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); - std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " - "and ./visualized_result_fg.jpg" - << std::endl; -} - -int main(int argc, char* argv[]) { - if (argc < 5) { - std::cout - << "Usage: infer_demo path/to/model_dir path/to/image run_option, " - "e.g ./infer_model ./PP-Matting-512 ./test.jpg ./test_bg.jpg 0" - << std::endl; - std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " - "with gpu; 2: run with gpu and use tensorrt backend, 3: run with kunlunxin." - << std::endl; - return -1; - } - if (std::atoi(argv[4]) == 0) { - CpuInfer(argv[1], argv[2], argv[3]); - } else if (std::atoi(argv[4]) == 1) { - GpuInfer(argv[1], argv[2], argv[3]); - } else if (std::atoi(argv[4]) == 2) { - TrtInfer(argv[1], argv[2], argv[3]); - } else if (std::atoi(argv[4]) == 3) { - KunlunXinInfer(argv[1], argv[2], argv[3]); - } - return 0; -} diff --git a/examples/vision/matting/ppmatting/python/README.md b/examples/vision/matting/ppmatting/python/README.md deleted file mode 100755 index 09fe0cdc2..000000000 --- a/examples/vision/matting/ppmatting/python/README.md +++ /dev/null @@ -1,81 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting Python Deployment Example - -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -This directory provides examples that `infer.py` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows -```bash -# Download the deployment example code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/matting/ppmatting/python - -# Download PP-Matting model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -# kunlunxin XPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin -``` - -The visualized result after running is as follows -
- - - - -
-## PP-Matting Python Interface - -```python -fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PP-Matting model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -### predict function - -> ```python -> PPMatting.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. - -### Class Member Variable - -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - - - -## Other Documents - -- [PP-Matting Model Description](..) -- [PP-Matting C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/python/README_CN.md b/examples/vision/matting/ppmatting/python/README_CN.md deleted file mode 100644 index cdfd7d378..000000000 --- a/examples/vision/matting/ppmatting/python/README_CN.md +++ /dev/null @@ -1,81 +0,0 @@ -[English](README.md) | 简体中文 -# PP-Matting Python部署示例 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/matting/ppmatting/python - -# 下载PP-Matting模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin -``` - -运行完成可视化结果如下图所示 -
- - - - -
-## PP-Matting Python接口 - -```python -fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PP-Matting模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -### predict函数 - -> ```python -> PPMatting.predict(input_image) -> ``` -> -> 模型预测结口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** -> -> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - - - -## 其它文档 - -- [PP-Matting 模型介绍](..) -- [PP-Matting C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/python/infer.py b/examples/vision/matting/ppmatting/python/infer.py deleted file mode 100755 index 512d0ca86..000000000 --- a/examples/vision/matting/ppmatting/python/infer.py +++ /dev/null @@ -1,70 +0,0 @@ -import fastdeploy as fd -import cv2 -import os - - -def parse_arguments(): - import argparse - import ast - parser = argparse.ArgumentParser() - parser.add_argument( - "--model", required=True, help="Path of PaddleSeg model.") - parser.add_argument( - "--image", type=str, required=True, help="Path of test image file.") - parser.add_argument( - "--bg", - type=str, - required=True, - default=None, - help="Path of test background image file.") - parser.add_argument( - "--device", - type=str, - default='cpu', - help="Type of inference device, support 'cpu', 'kunlunxin' or 'gpu'.") - parser.add_argument( - "--use_trt", - type=ast.literal_eval, - default=False, - help="Wether to use tensorrt.") - return parser.parse_args() - - -def build_option(args): - option = fd.RuntimeOption() - if args.device.lower() == "gpu": - option.use_gpu() - option.use_paddle_infer_backend() - - if args.use_trt: - option.use_trt_backend() - option.set_trt_input_shape("img", [1, 3, 512, 512]) - - if args.device.lower() == "kunlunxin": - option.use_kunlunxin() - return option - - -args = parse_arguments() - -# 配置runtime,加载模型 -runtime_option = build_option(args) -model_file = os.path.join(args.model, "model.pdmodel") -params_file = os.path.join(args.model, "model.pdiparams") -config_file = os.path.join(args.model, "deploy.yaml") -model = fd.vision.matting.PPMatting( - model_file, params_file, config_file, runtime_option=runtime_option) - -# 预测图片抠图结果 -im = cv2.imread(args.image) -bg = cv2.imread(args.bg) -result = model.predict(im) -print(result) -# 可视化结果 -vis_im = fd.vision.vis_matting(im, result) -vis_im_with_bg = fd.vision.swap_background(im, bg, result) -cv2.imwrite("visualized_result_fg.jpg", vis_im) -cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) -print( - "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" -) diff --git a/examples/vision/segmentation/paddleseg/README.md b/examples/vision/segmentation/paddleseg/README.md index de578cb22..a1947ae56 100644 --- a/examples/vision/segmentation/paddleseg/README.md +++ b/examples/vision/segmentation/paddleseg/README.md @@ -1,49 +1,32 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Model Deployment +# PaddleSeg高性能全场景模型部署方案——FastDeploy -## Model Description +## FastDeploy介绍 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg模型进行快速部署 -FastDeploy currently supports the deployment of the following models +## 支持如下的硬件部署 -- [U-Net models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/unet/README.md) -- [PP-LiteSeg models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) -- [PP-HumanSeg models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/contrib/PP-HumanSeg/README.md) -- [FCN models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/fcn/README.md) -- [DeepLabV3 models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/deeplabv3/README.md) - -【Attention】For **PP-Matting**、**PP-HumanMatting** and **ModNet** deployment, please refer to [Matting Model Deployment](../../matting) - -## Prepare PaddleSeg Deployment Model - -For the export of the PaddleSeg model, refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information - -**Attention** -- The exported PaddleSeg model contains three files, including `model.pdmodel`、`model.pdiparams` and `deploy.yaml`. FastDeploy will get the pre-processing information for inference from yaml files. - -## Download Pre-trained Model - -For developers' testing, part of the PaddleSeg exported models are provided below. -- without-argmax export mode: **Not specified**`--input_shape`,**specified**`--output_op none` -- with-argmax export mode:**Not specified**`--input_shape`,**specified**`--output_op argmax` - -Developers can download directly. +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](kunlun) | [昇腾](ascend) | [瑞芯微](rockchip) | +| [晶晨](amlogic) | [算能](sophgo) | -| Model | Parameter Size | Input Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | -| [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | -| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | -|[PP-HumanSegV1-Lite-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -|[PP-HumanSegV2-Lite-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -|[PP-HumanSegV1-Server-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2-Lite-with-argmax(Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | -| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(GPU inference for ONNXRuntime is not supported now) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | -| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | +## 更多部署方式 -## Detailed Deployment Tutorials +- [Android ARM CPU部署](android) +- [服务化Serving部署](serving) +- [web部署](web) +- [模型自动化压缩工具](quantize) -- [Python Deployment](python) -- [C++ Deployment](cpp) + +## 常见问题 + +遇到问题可查看常见问题集合文档或搜索FastDeploy issues,链接如下: + +[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) + +[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) + +若以上方式都无法解决问题,欢迎给FastDeploy提交新的[issue](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/paddleseg/README_CN.md b/examples/vision/segmentation/paddleseg/README_CN.md deleted file mode 100644 index 865c6c4aa..000000000 --- a/examples/vision/segmentation/paddleseg/README_CN.md +++ /dev/null @@ -1,23 +0,0 @@ -# 使用FastDeploy部署PaddleSeg模型 - -## FastDeploy介绍 - -FastDeploy是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg模型进行快速部署 - -## 详细文档 - -- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)](cpu-gpu) -- [昆仑](kunlun) -- [升腾](ascend) -- [瑞芯微](rockchip) -- [晶晨](amlogic) -- [算能](sophgo) -- [Android ARM CPU部署](android) -- [服务化Serving部署](serving) -- [模型自动化压缩工具](quantize) -- [web部署](web) - -## 常见问题 -遇到问题可查看常见问题集合文档或搜索 FastDeploy issues,链接如下。若都无法解决,欢迎给 FastDeploy 提交新的issue -[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) -[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md old mode 100755 new mode 100644 index db3e18110..9f856deb4 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md @@ -1,12 +1,30 @@ -English | [简体中文](README_CN.md) -# Deployment of PP-LiteSeg Quantification Model on A311D -Now FastDeploy allows deploying PP-LiteSeg quantization model to A311D based on Paddle Lite. +[English](README.md) | 简体中文 -For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) +# 在晶晨A311D上使用FastDeploy部署PaddleSeg模型 +晶晨A311D是一款先进的AI应用处理器。FastDeploy支持在A311D上基于Paddle-Lite部署PaddleSeg相关模型 +## 晶晨A311D支持的PaddleSeg模型 +目前所支持的PaddleSeg模型如下: +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -## Detailed Deployment Tutorials +## 预导出的推理模型 +为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 -Only C++ deployment is supported on A311D. +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +**注意** +- PaddleSeg量化模型包含`model.pdmodel`、`model.pdiparams`、`deploy.yaml`和`subgraph.txt`四个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,subgraph.txt是为了异构计算而存储的配置文件 +- 若以上列表中无满足要求的模型,可参考下方教程自行导出适配A311D的模型 -- [C++ deployment](cpp) +## PaddleSeg动态图模型导出为A311D支持的INT8模型 +模型导出分为以下两步 +1. PaddleSeg训练的动态图模型导出为推理静态图模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) +晶晨A311D仅支持INT8 +2. 将推理模型量化压缩为INT8模型,FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) + +## 详细部署文档 + +目前,A311D上只支持C++的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md deleted file mode 100644 index 3537dfef1..000000000 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/README_CN.md +++ /dev/null @@ -1,22 +0,0 @@ -[English](README.md) | 简体中文 -# 在晶晨A311D上使用FastDeploy部署PaddleSeg模型 -晶晨A311D是一款先进的AI应用处理器。目前,FastDeploy支持在A311D上基于Paddle-Lite部署PaddleSeg相关模型 - -## 晶晨A311D支持的PaddleSeg模型 -由于晶晨A311D的NPU仅支持INT8量化模型的部署,因此所支持的量化模型如下: -- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) - -为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 - -PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | -| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | ->> **注意**: FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) - -## 详细部署文档 - -目前,A311D上只支持C++的部署。 - -- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md old mode 100755 new mode 100644 index 0b8467ae4..57a71f86f --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md @@ -1,31 +1,28 @@ -English | [简体中文](README_CN.md) -# PP-LiteSeg Quantitative Model C++ Deployment Example +[English](README.md) | 简体中文 +# PP-LiteSeg 量化模型 C++ 部署示例 -`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-LiteSeg quantization model deployment on A311D. +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在晶晨 A311D 上的部署推理加速。 -## Deployment Preparations -### FastDeploy Cross-compile Environment Preparations -1. For the software and hardware environment, and the cross-compile environment, please refer to [FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/a311d.md#Cross-compilation-environment-construction). +## 部署准备 +### FastDeploy 交叉编译环境准备 +软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) -### Model Preparations -1. You can directly use the quantized model provided by FastDeploy for deployment. -2. You can use one-click automatical compression tool provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) -3. The model requires heterogeneous computation. Please refer to: [Heterogeneous Computation](./../../../../../../docs/en/faq/heterogeneous_computing_on_timvx_npu.md). Since the model is already provided, you can test the heterogeneous file we provide first to verify whether the accuracy meets the requirements. +### 模型准备 +1. 用户可以直接使用由[FastDeploy 提供的量化模型](../README_CN.md#晶晨a311d支持的paddleseg模型)进行部署。 +2. 若FastDeploy没有提供满足要求的量化模型,用户可以参考[PaddleSeg动态图模型导出为A311D支持的INT8模型](../README_CN.md#paddleseg动态图模型导出为a311d支持的int8模型)自行导出或训练量化模型 +3. 若上述导出或训练的模型出现精度下降或者报错,则需要使用异构计算,使得模型算子部分跑在A311D的ARM CPU上进行调试以及精度验证,其中异构计算所需的文件是subgraph.txt。具体关于异构计算可参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md)。 -For more information, please refer to [Model Quantization](../../quantize/README.md) +## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 +请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: -## Deploying the Quantized PP-LiteSeg Segmentation model on A311D -Please follow these steps to complete the deployment of the PP-LiteSeg quantization model on A311D. -1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/a311d.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite) - -2. Copy the compiled library to the current directory. You can run this line: +1. 将编译后的库拷贝到当前目录,可使用如下命令: ```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cp -r FastDeploy/build/fastdeploy-timvx/ path/to/paddleseg/amlogic/a311d/cpp ``` -3. Download the model and example images required for deployment in current path. +2. 在当前路径下载部署所需的模型和示例图片: ```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cd path/to/paddleseg/amlogic/a311d/cpp mkdir models && mkdir images wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz tar -xvf ppliteseg.tar.gz @@ -34,26 +31,29 @@ wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png cp -r cityscapes_demo.png images ``` -4. Compile the deployment example. You can run the following lines: +3. 编译部署示例,可使入如下命令: ```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +cd path/to/paddleseg/amlogic/a311d/cpp mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. make -j8 make install -# After success, an install folder will be created with a running demo and libraries required for deployment. +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 ``` -5. Deploy the PP-LiteSeg segmentation model to A311D based on adb. You can run the following lines: +4. 基于 adb 工具部署 PP-LiteSeg 分割模型到晶晨 A311D,可使用如下命令: ```bash -# Go to the install directory. -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp/build/install/ -# The following line represents: bash run_with_adb.sh, demo needed to run, model path, image path, DEVICE ID. +# 进入 install 目录 +cd path/to/paddleseg/amlogic/a311d/cpp/build/install/ +cp ../../run_with_adb.sh . +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID ``` -The output is: +部署成功后运行结果如下: -Please note that the model deployed on A311D needs to be quantized. You can refer to [Model Quantization](../../../../../../docs/en/quantize.md). +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md deleted file mode 100644 index 4780a9110..000000000 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README_CN.md +++ /dev/null @@ -1,59 +0,0 @@ -[English](README.md) | 简体中文 -# PP-LiteSeg 量化模型 C++ 部署示例 - -本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 晶晨A311D 上的部署推理加速。 - -## 部署准备 -### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#交叉编译环境搭建) - -### 模型准备 -1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 -2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 - -更多量化相关相关信息可查阅[模型量化](../../../quantize/README.md) - -## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 -请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) - -2. 将编译后的库拷贝到当前目录,可使用如下命令: -```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp -``` - -3. 在当前路径下载部署所需的模型和示例图片: -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp -mkdir models && mkdir images -wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz -tar -xvf ppliteseg.tar.gz -cp -r ppliteseg models -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp -r cityscapes_demo.png images -``` - -4. 编译部署示例,可使入如下命令: -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp -mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. -make -j8 -make install -# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 -``` - -5. 基于 adb 工具部署 PP-LiteSeg 分割模型到晶晨 A311D,可使用如下命令: -```bash -# 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/build/install/ -# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID -bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -``` - -部署成功后运行结果如下: - - - -需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/android/README.md b/examples/vision/segmentation/paddleseg/android/README.md index 0d845f2a0..ab06e1868 100644 --- a/examples/vision/segmentation/paddleseg/android/README.md +++ b/examples/vision/segmentation/paddleseg/android/README.md @@ -19,7 +19,7 @@ For real-time portrait segmentation on Android, this demo has good ease of use a

> **Notes:** ->> If you encounter an NDK configuration error during importing, compiling or running the program, please open ` File > Project Structure > SDK Location` and change `Andriod SDK location` to your locally configured SDK path. +>> If you encounter an NDK configuration error during importing, compiling or running the program, please open ` File > Project Structure > SDK Location` and change `Andriod SDK location` to your locally configured SDK path. 4. Click the Run button to automatically compile the APP and install it to your phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files, internet connection required.) The success interface is as follows. Figure 1: Install APP on phone; Figure 2: The opening interface, it will automatically recognize the person in the picture and draw the mask; Figure 3: APP setting options, click setting in the upper right corner, and you can set different options. @@ -159,11 +159,11 @@ model.init(modelFile, paramFile, configFile, option); For details, please refer to [SegmentationMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java). ## Replace FastDeploy SDK and model - Steps to replace the FastDeploy prediction libraries and model are very simple. The location of the prediction library is `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` indicates the version of the prediction library you are currently using. The location of the model is, `app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`. + Steps to replace the FastDeploy prediction libraries and model are very simple. The location of the prediction library is `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` indicates the version of the prediction library you are currently using. The location of the model is, `app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`. - Replace FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip it and put it in the `app/libs` directory. For details please refer to: - - [Use FastDeploy Java SDK on Android](../../../../../java/android/) + - [Use FastDeploy Java SDK on Android](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) -- Steps for replacing the PaddleSeg model. +- Steps for replacing the PaddleSeg model. - Put your PaddleSeg model in `app/src/main/assets/models`; - Modify the model path in `app/src/main/res/values/strings.xml`, such as: ```xml @@ -173,5 +173,5 @@ For details, please refer to [SegmentationMainActivity](./app/src/main/java/com/ ## Other Documenets If you are interested in more FastDeploy Java API documents and how to access the FastDeploy C++ API via JNI, you can refer to the following: -- [Use FastDeploy Java SDK on Android](../../../../../java/android/) -- [Use FastDeploy C++ SDK on Android](../../../../../docs/en/faq/use_cpp_sdk_on_android.md) +- [Use FastDeploy Java SDK on Android](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) +- [Use FastDeploy C++ SDK on Android](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/segmentation/paddleseg/android/README_CN.md b/examples/vision/segmentation/paddleseg/android/README_CN.md index 442947009..30938b697 100644 --- a/examples/vision/segmentation/paddleseg/android/README_CN.md +++ b/examples/vision/segmentation/paddleseg/android/README_CN.md @@ -10,7 +10,7 @@ ## 部署步骤 -1. 目标检测 PaddleSeg Demo 位于 `fastdeploy/examples/vision/segmentation/paddleseg/android` 目录 +1. 目标检测 PaddleSeg Demo 位于 `path/to/paddleseg/android` 目录 2. 用 Android Studio 打开 paddleseg/android 工程 3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) @@ -161,7 +161,7 @@ model.init(modelFile, paramFile, configFile, option); ## 替换 FastDeploy SDK和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`。 - 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + - [在 Android 中使用 FastDeploy Java SDK](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) - 替换PaddleSeg模型的步骤: - 将您的PaddleSeg模型放在 `app/src/main/assets/models` 目录下; diff --git a/examples/vision/segmentation/paddleseg/ascend/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/README.md similarity index 97% rename from examples/vision/segmentation/paddleseg/ascend/README_CN.md rename to examples/vision/segmentation/paddleseg/ascend/README.md index fb29615fe..475d8817b 100644 --- a/examples/vision/segmentation/paddleseg/ascend/README_CN.md +++ b/examples/vision/segmentation/paddleseg/ascend/README.md @@ -14,7 +14,7 @@ FastDeploy支持在华为昇腾上部署PaddleSeg模型 - [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) ->>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../matting/)下载对应模型,部署过程与此文档一致 +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../ppmatting/)下载对应模型,部署过程与此文档一致 ## 准备PaddleSeg部署模型 PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) @@ -22,7 +22,7 @@ PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.co **注意** - PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型模型 - without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` diff --git a/examples/vision/segmentation/paddleseg/ascend/cpp/README.md b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md old mode 100755 new mode 100644 index bcccdd1cb..cfa01c663 --- a/examples/vision/segmentation/paddleseg/ascend/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md @@ -1,96 +1,38 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -Before deployment, two steps require confirmation +## 华为昇腾NPU编译FastDeploy环境准备 +在部署前,需自行编译基于华为昇腾NPU的预测库,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) - -Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting/)下载 ```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + mkdir build cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above -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 +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend make -j -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# CPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# TensorRT inference on GPU -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# kunlunxin XPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +# 华为昇腾推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -## PaddleSeg C++ Interface - -### PaddleSeg Class - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` - -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) diff --git a/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md deleted file mode 100644 index 38692dc26..000000000 --- a/examples/vision/segmentation/paddleseg/ascend/cpp/README_CN.md +++ /dev/null @@ -1,88 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 - -在部署前,需自行编译基于华为昇腾NPU的预测库,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/huawei_ascend.md) - ->>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp - -mkdir build -cd build -# 使用编译完成的FastDeploy库编译infer_demo -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend -make -j - -# 下载PP-LiteSeg模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 华为昇腾推理 -./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png -``` - -运行完成可视化结果如下图所示 -
- -
- -## PaddleSeg C++接口 - -### PaddleSeg类 - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -#### Predict函数 - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> 模型预测接口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 快速链接 -- [PaddleSeg模型介绍](../../) -- [Python部署](../python) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) -) diff --git a/examples/vision/segmentation/paddleseg/ascend/python/README.md b/examples/vision/segmentation/paddleseg/ascend/python/README.md old mode 100755 new mode 100644 index d37d92c9e..ee11ea7b9 --- a/examples/vision/segmentation/paddleseg/ascend/python/README.md +++ b/examples/vision/segmentation/paddleseg/ascend/python/README.md @@ -1,82 +1,36 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 -Before deployment, two steps require confirmation +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +## 华为昇腾NPU编译FastDeploy wheel包环境准备 +在部署前,需自行编译基于华为昇腾NPU的FastDeploy python wheel包并安装,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting)下载 -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) -This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -# Download the deployment example code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -# kunlunxin XPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +# 华为昇腾推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-## PaddleSegModel Python Interface +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -### predict function - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax - -## Other Documents - -- [PaddleSeg Model Description](..) -- [PaddleSeg C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md b/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md deleted file mode 100644 index 909784fd3..000000000 --- a/examples/vision/segmentation/paddleseg/ascend/python/README_CN.md +++ /dev/null @@ -1,79 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 - -在部署前,需自行编译基于华为昇腾NPU的FastDeploy python wheel包,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/huawei_ascend.md),编译python wheel包并安装 - ->>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 - - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp - -# 下载PP-LiteSeg模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 华为昇腾推理 -python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png -``` - -运行完成可视化结果如下图所示 -
- -
- -## PaddleSegModel Python接口 - -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -### predict函数 - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> 模型预测结口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** -> -> > 返回`fastdeploy.vision.SegmentationResult`结构体,SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 快速链接 - -- [PaddleSeg 模型介绍](..) -- [PaddleSeg C++部署](../cpp) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md similarity index 97% rename from examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md rename to examples/vision/segmentation/paddleseg/cpu-gpu/README.md index 0109ac01a..7c9901a9c 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md @@ -15,7 +15,7 @@ FastDeploy支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立 - [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) ->>**注意**】如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting/) +>>**注意** 如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../ppmatting) ## 准备PaddleSeg部署模型 PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) @@ -23,7 +23,7 @@ PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.co **注意** - PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 - without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md old mode 100755 new mode 100644 index bcccdd1cb..2c1f54e9a --- a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md @@ -1,96 +1,59 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. +本目录下提供`infer.cc`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。 -Before deployment, two steps require confirmation +## 部署环境准备 -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +在部署前,需确认软硬件环境,同时下载预编译部署库,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) +>> **注意** 如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../ppmatting) -Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) ```bash +#下载部署示例代码 +cd path/to/paddleseg/cpp-gpu/cpp + mkdir build cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 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 -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# TensorRT inference on GPU -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# kunlunxin XPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +# CPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# GPU上Paddle-TensorRT推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 2 ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) +> **注意:** +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md) -## PaddleSeg C++ Interface +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) -### PaddleSeg Class - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` - -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 常见问题 +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md deleted file mode 100644 index 7618e6f15..000000000 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README_CN.md +++ /dev/null @@ -1,106 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下提供`infer.cc`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) - -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) - -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/cpp-gpu/cpp - -mkdir build -cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 -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 - -# 下载PP-LiteSeg模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - - -# CPU推理 -./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU推理 -./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# GPU上TensorRT推理 -./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 2 -``` - -运行完成可视化结果如下图所示 -
- -
- -> **注意:** -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md) - -## PaddleSeg C++接口 - -### PaddleSeg类 - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -#### Predict函数 - -> ```c++ -> PaddleSegModel::Predict(const cv::Mat &im, SegmentationResult *result) -> ``` -> -> 模型预测接口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 快速链接 -- [PaddleSeg模型介绍](../../) -- [Python部署](../python) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) -- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) -- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) -- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc index 5269a0c2e..af79d3204 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc @@ -85,7 +85,14 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file) { auto option = fastdeploy::RuntimeOption(); option.UseGpu(); option.UseTrtBackend(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( + // If use original Tensorrt, not Paddle-TensorRT, + // comment the following two lines + option.EnablePaddleToTrt(); + option.EnablePaddleTrtCollectShape(); + option.SetTrtInputShape("x", {1, 3, 256, 256}, {1, 3, 1024, 1024}, + {1, 3, 2048, 2048}) + + auto model = fastdeploy::vision::segmentation::PaddleSegModel( model_file, params_file, config_file, option); if (!model.Initialized()) { diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md old mode 100755 new mode 100644 index d37d92c9e..12d7c7eb1 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md @@ -1,82 +1,45 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 +本目录下提供`infer.py`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。执行如下脚本即可完成 -Before deployment, two steps require confirmation +## 部署环境准备 -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../ppmatting) -This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -# Download the deployment example code +#下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python +cd FastDeploy/examples/vision/segmentation/paddleseg/cpu-gpu/python -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载Unet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -# kunlunxin XPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +# CPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# GPU上使用Paddle-TensorRT推理 (注意:Paddle-TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-## PaddleSegModel Python Interface +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -### predict function - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax - -## Other Documents - -- [PaddleSeg Model Description](..) -- [PaddleSeg C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md deleted file mode 100644 index da23623b2..000000000 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README_CN.md +++ /dev/null @@ -1,88 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) - -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) - -本目录下提供`infer.py`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/cpu-gpu/python - -# 下载Unet模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# CPU推理 -python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU推理 -python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -``` - -运行完成可视化结果如下图所示 -
- -
- -## PaddleSegModel Python接口 - -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -### predict函数 - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> 模型预测结口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** -> -> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 其它文档 - -- [PaddleSeg 模型介绍](..) -- [PaddleSeg C++部署](../cpp) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) -- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) -- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) -- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py index ba961159f..d90f6eb4c 100755 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py @@ -32,6 +32,10 @@ def build_option(args): if args.use_trt: option.use_trt_backend() + # If use original Tensorrt, not Paddle-TensorRT, + # comment the following two lines + option.enable_paddle_to_trt() + option.enable_paddle_trt_collect_shape() option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], [1, 3, 2048, 2048]) return option diff --git a/examples/vision/segmentation/paddleseg/kunlun/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/README.md similarity index 97% rename from examples/vision/segmentation/paddleseg/kunlun/README_CN.md rename to examples/vision/segmentation/paddleseg/kunlun/README.md index 5fba79c12..08406d082 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/README_CN.md +++ b/examples/vision/segmentation/paddleseg/kunlun/README.md @@ -13,7 +13,7 @@ - [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) ->>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../matting/)下载对应模型,部署过程与此文档一致 +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../ppmating/)下载对应模型,部署过程与此文档一致 ## 准备PaddleSeg部署模型 PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) @@ -21,7 +21,7 @@ PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.co **注意** - PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 - without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md old mode 100755 new mode 100644 index bcccdd1cb..b85e3874e --- a/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md @@ -1,96 +1,39 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -Before deployment, two steps require confirmation +## 昆仑芯XPU编译FastDeploy环境准备 +在部署前,需自行编译基于昆仑芯XPU的预测库,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) - -Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 ```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + mkdir build cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above -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 +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend make -j -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# CPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# TensorRT inference on GPU -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# kunlunxin XPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +# 华为昇腾推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -## PaddleSeg C++ Interface - -### PaddleSeg Class - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` - -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 快速链接 +how_to_change_backend.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md deleted file mode 100644 index 55c6996fc..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/cpp/README_CN.md +++ /dev/null @@ -1,88 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 - -在部署前,需自行编译基于昆仑芯XPU的预测库,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/kunlunxin.md) - ->>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp - -mkdir build -cd build -# 使用编译完成的FastDeploy库编译infer_demo -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend -make -j - -# 下载PP-LiteSeg模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 华为昇腾推理 -./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png -``` - -运行完成可视化结果如下图所示 -
- -
- -## PaddleSeg C++接口 - -### PaddleSeg类 - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -#### Predict函数 - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> 模型预测接口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 快速链接 -- [PaddleSeg模型介绍](../../) -- [Python部署](../python) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) -) diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/README.md old mode 100755 new mode 100644 index d37d92c9e..aee36bffe --- a/examples/vision/segmentation/paddleseg/kunlun/python/README.md +++ b/examples/vision/segmentation/paddleseg/kunlun/python/README.md @@ -1,82 +1,37 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 -Before deployment, two steps require confirmation +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +## 昆仑XPU编译FastDeploy wheel包环境准备 + +在部署前,需自行编译基于昆仑XPU的FastDeploy python wheel包并安装,参考文档[昆仑芯XPU部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting)下载 -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) -This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -# Download the deployment example code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -# kunlunxin XPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +# 华为昇腾推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png ``` -The visualized result after running is as follows +运行完成可视化结果如下图所示
-## PaddleSegModel Python Interface +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -### predict function - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax - -## Other Documents - -- [PaddleSeg Model Description](..) -- [PaddleSeg C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md b/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md deleted file mode 100644 index 7ce98b44e..000000000 --- a/examples/vision/segmentation/paddleseg/kunlun/python/README_CN.md +++ /dev/null @@ -1,79 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 - -在部署前,需自行编译基于昆仑芯XPU的FastDeploy wheel 包,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/kunlunxin.md),编译python wheel包并安装 - ->>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 - - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/ascend/cpp - -# 下载PP-LiteSeg模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 华为昇腾推理 -python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png -``` - -运行完成可视化结果如下图所示 -
- -
- -## PaddleSegModel Python接口 - -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -### predict函数 - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> 模型预测结口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** -> -> > 返回`fastdeploy.vision.SegmentationResult`结构体,SegmentationResult结构体说明参考[SegmentationResult结构体介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 - -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - -## 快速链接 - -- [PaddleSeg 模型介绍](..) -- [PaddleSeg C++部署](../cpp) - -## 常见问题 -- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) -- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) diff --git a/examples/vision/segmentation/paddleseg/quantize/README.md b/examples/vision/segmentation/paddleseg/quantize/README.md old mode 100755 new mode 100644 index ab0fa77fc..708d21e93 --- a/examples/vision/segmentation/paddleseg/quantize/README.md +++ b/examples/vision/segmentation/paddleseg/quantize/README.md @@ -1,37 +1,26 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantized Model Deployment -FastDeploy already supports the deployment of quantitative models and provides a tool to automatically compress model with just one click. -You can use the one-click automatical model compression tool to quantify and deploy the models, or directly download the quantified models provided by FastDeploy for deployment. +[English](README.md) | 简体中文 +# PaddleSeg 量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. -## FastDeploy One-Click Automation Model Compression Tool -FastDeploy provides an one-click automatical model compression tool that can quantify a model simply by entering configuration file. -For details, please refer to [one-click automatical compression tool](../../../../../tools/common_tools/auto_compression/). -Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder. +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](https://github.com/PaddlePaddle/FastDeploy/tree/develop/tools/common_tools/auto_compression) +>> **注意**: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 -## Download the Quantized PaddleSeg Model -You can also directly download the quantized models in the following table for deployment (click model name to download). +## 量化完成的PaddleSeg模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) -Note: -- Runtime latency is the inference latency of the model on various Runtimes, including CPU->GPU data copy, GPU inference, and GPU->CPU data copy time. It does not include the respective pre and post processing time of the models. -- The end-to-end latency is the latency of the model in the actual inference scenario, including the pre and post processing of the model. -- The measured latencies are averaged over 1000 inferences, in milliseconds. -- INT8 + FP16 is to enable the FP16 inference option for Runtime while inferring the INT8 quantization model. -- INT8 + FP16 + PM is the option to use Pinned Memory while inferring INT8 quantization model and turning on FP16, which can speed up the GPU->CPU data copy speed. -- The maximum speedup ratio is obtained by dividing the FP32 latency by the fastest INT8 inference latency. -- The strategy is quantitative distillation training, using a small number of unlabeled data sets to train the quantitative model, and verify the accuracy on the full validation set, INT8 accuracy does not represent the highest INT8 accuracy. -- The CPU is Intel(R) Xeon(R) Gold 6271C with a fixed CPU thread count of 1 in all tests. The GPU is Tesla T4, TensorRT version 8.4.15. +| 模型 | 量化方式 | +| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) |量化蒸馏训练 | -#### Runtime Benchmark -| Model |Inference Backends | Hardware | FP32 Runtime Latency | INT8 Runtime Latency | INT8 + FP16 Runtime Latency | INT8+FP16+PM Runtime Latency | Max Speedup | FP32 mIoU | INT8 mIoU | Method | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 1138.04| 602.62 |None|None | 1.89 |77.37 | 71.62 |Quantaware Distillation Training | +量化后模型的Benchmark比较,请参考[量化模型 Benchmark](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quantize.md) -#### End to End Benchmark -| Model |Inference Backends | Hardware | FP32 End2End Latency | INT8 End2End Latency | INT8 + FP16 End2End Latency | INT8+FP16+PM End2End Latency | Max Speedup | FP32 mIoU | INT8 mIoU | Method | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 4726.65| 4134.91|None|None | 1.14 |77.37 | 71.62 |Quantaware Distillation Training| +## 支持部署量化模型的硬件 +FastDeploy 量化模型部署的过程大致都与FP32模型类似,只是模型量化与非量化的区别,如果硬件在量化模型部署过程有特殊处理,也会在文档中特别标明,因此量化模型部署可以参考如下硬件的链接 -## Detailed Deployment Documents - -- [Python Deployment](python) -- [C++ Deployment](cpp) +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](kunlun) | [昇腾](ascend) | [瑞芯微](rockchip) | +| [晶晨](amlogic) | [算能](sophgo) | diff --git a/examples/vision/segmentation/paddleseg/quantize/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/README_CN.md deleted file mode 100644 index a9b287754..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/README_CN.md +++ /dev/null @@ -1,26 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. - -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](https://github.com/PaddlePaddle/FastDeploy/tree/develop/tools/common_tools/auto_compression) ->> **注意**: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 - -## 量化完成的PaddleSeg模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) - -| 模型 | 量化方式 | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) |量化蒸馏训练 | - -量化后模型的Benchmark比较,请参考[量化模型 Benchmark](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quantize.md) - -## 支持部署量化模型的硬件 -FastDeploy 量化模型部署的过程大致都与FP32模型类似,只是模型量化与非量化的区别,如果硬件在量化模型部署过程有特殊处理,也会在文档中特别标明,因此量化模型部署可以参考如下硬件的链接 -- [NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU](../cpu-gpu) -- [昆仑](../kunlun) -- [升腾](../ascend) -- [瑞芯微](../rockchip) -- [晶晨](../amlogic) -- [算能](../sophgo) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md index 40606fee0..f6d1a0b12 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md @@ -1,34 +1,63 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Model Deployment +[English](README.md) | 简体中文 -## Model Version +# 基于RKNPU2使用FastDeploy部署PaddleSeg模型 +RKNPU2 提供了一个高性能接口来访问 Rockchip NPU,支持如下硬件的部署 +- RK3566/RK3568 +- RK3588/RK3588S +- RV1103/RV1106 + +本示例基于 RV3588 来介绍如何使用 FastDeploy 部署 PaddleSeg 模型 + +## 模型版本说明 - [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) -Currently FastDeploy using RKNPU2 to infer PPSeg supports the following model deployments: +目前FastDeploy使用RKNPU2推理PaddleSeg支持如下模型的部署: +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) -| Model | Parameter File Size | Input Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------------------------------------------------------------------------------------|:-------|:---------|:-------|:------------|:---------------| +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:----------------|:-------|:---------|:-------|:------------|:---------------| | [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | | [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | -| [PP-HumanSegV1-Lite(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -| [PP-HumanSegV2-Lite(Universal portrait segmentation model)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -| [PP-HumanSegV1-Server(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2_Lite(Portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [PP-HumanSegV1-Lite(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +| [PP-HumanSegV2-Lite(通用人像分割模型)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +| [PP-HumanSegV1-Server(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2_Lite(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | | [FCN-HRNet-W18-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | | [Deeplabv3-ResNet101-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | -## Prepare PaddleSeg Deployment Model and Conversion Model -RKNPU needs to convert the Paddle model to RKNN model before deploying, the steps are as follows: -* For the conversion of Paddle dynamic diagram model to ONNX model, please refer to [PaddleSeg Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/contrib/PP-HumanSeg). -* For the process of converting ONNX model to RKNN model, please refer to [Conversion document](../../../../../docs/en/faq/rknpu2/export.md). +## 准备PaddleSeg部署模型以及转换模型 +RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: +* PaddleSeg训练模型导出为推理模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md),也可以使用上表中的FastDeploy的预导出模型 +* Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) +* ONNX模型转换RKNN模型的过程,请参考[转换文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/export.md)进行转换。 -## An example of Model Conversion +上述步骤可参考以下具体示例 -* [PPHumanSeg](./pp_humanseg_EN.md) +## 模型转换example -## Detailed Deployment Document -- [Overall RKNN Deployment Guidance](../../../../../docs/en/faq/rknpu2/rknpu2.md) -- [Deploy with C++](cpp) -- [Deploy with Python](python) +* [PP-HumanSeg](./pp_humanseg.md) + +## 详细部署文档 +- [RKNN总体部署教程](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) +- [C++部署](cpp) +- [Python部署](python) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md deleted file mode 100644 index b7a1be32a..000000000 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README_CN.md +++ /dev/null @@ -1,55 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 模型部署 - -## 模型版本说明 - -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) - -目前FastDeploy使用RKNPU2推理PPSeg支持如下模型的部署: -- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) -- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) -- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) -- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) - -## 准备PaddleSeg部署模型 -PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -**注意** -- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 - -## 下载预训练模型 - -为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 -- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` -- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` - -开发者可直接下载使用。 - -| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:----------------|:-------|:---------|:-------|:------------|:---------------| -| [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | -| [PP-HumanSegV1-Lite(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -| [PP-HumanSegV2-Lite(通用人像分割模型)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -| [PP-HumanSegV1-Server(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2_Lite(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | -| [FCN-HRNet-W18-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | -| [Deeplabv3-ResNet101-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | - -## 准备PaddleSeg部署模型以及转换模型 -RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: -* PaddleSeg训练模型导出为推理模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md),也可以使用上表中的FastDeploy的预导出模型 -* Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) -* ONNX模型转换RKNN模型的过程,请参考[转换文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/export.md)进行转换。 -上述步骤可以可参考以下具体示例 - -## 模型转换example - -* [PPHumanSeg](./pp_humanseg.md) - -## 详细部署文档 -- [RKNN总体部署教程](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) -- [C++部署](cpp) -- [Python部署](python) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md index 1fe268f81..b6d4c18bf 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md @@ -1,31 +1,31 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Deployment Examples for C++ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -This directory demonstrates the deployment of PaddleSeg series models on RKNPU2. The following deployment process takes PHumanSeg as an example. +本目录下用于展示PaddleSeg系列模型在RKNPU2上的部署,以下的部署过程以PPHumanSeg为例子。 -Before deployment, the following two steps need to be confirmed: +在部署前,需确认以下两个步骤: -1. Hardware and software environment meets the requirements. -2. Download the pre-compiled deployment repository or compile the FastDeploy repository from scratch according to the development environment. +1. 软硬件环境满足要求 +2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库 -For the above steps, please refer to [How to Build RKNPU2 Deployment Environment](../../../../../../docs/en/build_and_install/rknpu2.md). +以上步骤请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)实现 -## Generate Basic Directory Files +## 生成基本目录文件 -The routine consists of the following parts: +该例程由以下几个部分组成 ```text . ├── CMakeLists.txt -├── build # Compile Folder -├── image # Folder for images +├── build # 编译文件夹 +├── image # 存放图片的文件夹 ├── infer_cpu_npu.cc ├── infer_cpu_npu.h ├── main.cc -├── model # Folder for models -└── thirdpartys # Folder for sdk +├── model # 存放模型文件的文件夹 +└── thirdpartys # 存放sdk的文件夹 ``` -First, please build a directory structure +首先需要先生成目录结构 ```bash mkdir build mkdir images @@ -33,23 +33,23 @@ mkdir model mkdir thirdpartys ``` -## Compile +## 编译 -### Compile and Copy SDK to folder thirdpartys +### 编译并拷贝SDK到thirdpartys文件夹 -Please refer to [How to Build RKNPU2 Deployment Environment](../../../../../../docs/en/build_and_install/rknpu2.md) to compile SDK.After compiling, the fastdeploy-0.0.3 directory will be created in the build directory, please move it to the thirdpartys directory. +请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-x-x-x目录,请移动它至thirdpartys目录下. -### Copy model and configuration files to folder Model -In the process of Paddle dynamic map model -> Paddle static map model -> ONNX mdoel, ONNX file and the corresponding yaml configuration file will be generated. Please move the configuration file to the folder model. -After converting to RKNN, the model file also needs to be copied to folder model. Run the following command to download and use (the model file is RK3588. RK3568 needs to be [reconverted to PPSeg RKNN model](../README.md)). +### 拷贝模型文件,以及配置文件至model文件夹 +在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。 +转换为RKNN后的模型文件也需要拷贝至model,输入以下命令下载使用(模型文件为RK3588,RK3568需要重新[转换PPSeg RKNN模型](../README.md))。 -### Prepare Test Images to folder image +### 准备测试图片至image文件夹 ```bash wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip unzip -qo images.zip ``` -### Compile example +### 编译example ```bash cd build @@ -58,16 +58,19 @@ make -j8 make install ``` -## Running Routines +## 运行例程 ```bash cd ./build/install ./rknpu_test model/Portrait_PP_HumanSegV2_Lite_256x144_infer/ images/portrait_heng.jpg ``` -## Notes -The input requirement for the model on RKNPU is to use NHWC format, and image normalization will be embedded into the model when converting the RKNN model, so we need to call DisableNormalizeAndPermute(C++) or disable_normalize_and_permute(Python) first when deploying with FastDeploy to disable normalization and data format conversion in the preprocessing stage. +## 注意事项 +RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换 -- [Model Description](../../) -- [Python Deployment](../python) -- [Convert PPSeg and RKNN model](../README.md) +## 快速链接 +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) +- [转换PPSeg RKNN模型文档](../README.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md deleted file mode 100644 index 45bb923a0..000000000 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README_CN.md +++ /dev/null @@ -1,73 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下用于展示PaddleSeg系列模型在RKNPU2上的部署,以下的部署过程以PPHumanSeg为例子。 - -在部署前,需确认以下两个步骤: - -1. 软硬件环境满足要求 -2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库 - -以上步骤请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)实现 - -## 生成基本目录文件 - -该例程由以下几个部分组成 -```text -. -├── CMakeLists.txt -├── build # 编译文件夹 -├── image # 存放图片的文件夹 -├── infer_cpu_npu.cc -├── infer_cpu_npu.h -├── main.cc -├── model # 存放模型文件的文件夹 -└── thirdpartys # 存放sdk的文件夹 -``` - -首先需要先生成目录结构 -```bash -mkdir build -mkdir images -mkdir model -mkdir thirdpartys -``` - -## 编译 - -### 编译并拷贝SDK到thirdpartys文件夹 - -请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-x-x-x目录,请移动它至thirdpartys目录下. - -### 拷贝模型文件,以及配置文件至model文件夹 -在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。 -转换为RKNN后的模型文件也需要拷贝至model,输入以下命令下载使用(模型文件为RK3588,RK3568需要重新[转换PPSeg RKNN模型](../README.md))。 - -### 准备测试图片至image文件夹 -```bash -wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip -unzip -qo images.zip -``` - -### 编译example - -```bash -cd build -cmake .. -make -j8 -make install -``` - -## 运行例程 - -```bash -cd ./build/install -./rknpu_test model/Portrait_PP_HumanSegV2_Lite_256x144_infer/ images/portrait_heng.jpg -``` - -## 注意事项 -RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换。 - -- [模型介绍](../../) -- [Python部署](../python) -- [转换PPSeg RKNN模型文档](../README.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md index e212d4e2d..ede1656df 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md @@ -1,5 +1,5 @@ [English](pp_humanseg_EN.md) | 简体中文 -# PPHumanSeg模型部署 +# PP-HumanSeg模型转换示例 ## 转换模型 下面以Portait-PP-HumanSegV2_Lite(肖像分割模型)为例子,教大家如何转换PaddleSeg模型到RKNN模型。 diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md index f5b99400f..5b7c3df35 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md @@ -1,36 +1,38 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Deployment Examples for Python +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 -Before deployment, the following step need to be confirmed: +在部署前,需确认以下步骤 -- 1. Hardware and software environment meets the requirements, please refer to [Environment Requirements for FastDeploy](../../../../../../docs/en/build_and_install/rknpu2.md). +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) -【Note】If you are deploying **PP-Matting**, **PP-HumanMatting** or **ModNet**, please refer to [Matting Model Deployment](../../../../matting/). +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../../matting/) -This directory provides `infer.py` for a quick example of PPHumanseg deployment on RKNPU. This can be done by running the following script. +本目录下提供`infer.py`快速完成PPHumanseg在RKNPU上部署的示例。执行如下脚本即可完成 ```bash -# Download the deploying demo code. +# 下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/segmentation/paddleseg/python -# Download images. +# 下载图片 wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip unzip images.zip -# Inference. +# 推理 python3 infer.py --model_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn \ --config_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/deploy.yaml \ --image images/portrait_heng.jpg ``` -## Notes -The input requirement for the model on RKNPU is to use NHWC format, and image normalization will be embedded into the model when converting the RKNN model, so we need to call DisableNormalizeAndPermute(C++) or disable_normalize_and_permute(Python) first when deploying with FastDeploy to disable normalization and data format conversion in the preprocessing stage. +## 注意事项 +RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换。 -## Other Documents +## 快速链接 -- [PaddleSeg Model Description](..) -- [PaddleSeg C++ Deployment](../cpp) -- [Description of the prediction](../../../../../../docs/api/vision_results/) -- [Convert PPSeg and RKNN model](../README.md) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) +- [转换PaddleSeg模型至RKNN模型文档](../README_CN.md#准备paddleseg部署模型以及转换模型) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md deleted file mode 100644 index 0bf8b9396..000000000 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README_CN.md +++ /dev/null @@ -1,36 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -在部署前,需确认以下步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) - -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../../matting/) - -本目录下提供`infer.py`快速完成PPHumanseg在RKNPU上部署的示例。执行如下脚本即可完成 - -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python - -# 下载图片 -wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip -unzip images.zip - -# 推理 -python3 infer.py --model_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn \ - --config_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/deploy.yaml \ - --image images/portrait_heng.jpg -``` - - -## 注意事项 -RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换。 - -## 其它文档 - -- [PaddleSeg 模型介绍](..) -- [PaddleSeg C++部署](../cpp) -- [模型预测结果说明](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/segmentation_result_CN.md) -- [转换PaddleSeg模型至RKNN模型文档](../README.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md old mode 100755 new mode 100644 index 7e4620b18..5f92e7f6f --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md @@ -1,12 +1,27 @@ -English | [简体中文](README_CN.md) -# Deployment of PP-LiteSeg Quantification Model on RV1126 -Now FastDeploy allows deploying PP-LiteSeg quantization model to RV1126 based on Paddle Lite. +[English](README.md) | 简体中文 +# 在瑞芯微 RV1126 上使用 FastDeploy 部署 PaddleSeg 模型 +瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。目前,FastDeploy 支持在 RV1126 上基于 Paddle-Lite 部署 PaddleSeg 相关模型 -For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) +## 瑞芯微 RV1126 支持的PaddleSeg模型 +目前瑞芯微 RV1126 的 NPU 支持的量化模型如下: +## 预导出的推理模型 +为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +**注意** +- PaddleSeg量化模型包含`model.pdmodel`、`model.pdiparams`、`deploy.yaml`和`subgraph.txt`四个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,subgraph.txt是为了异构计算而存储的配置文件 +- 若以上列表中无满足要求的模型,可参考下方教程自行导出适配A311D的模型 -## Detailed Deployment Tutorials +## PaddleSeg动态图模型导出为RV1126支持的INT8模型 +模型导出分为以下两步 +1. PaddleSeg训练的动态图模型导出为推理静态图模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) +瑞芯微RV1126仅支持INT8 +2. 将推理模型量化压缩为INT8模型,FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) -Only C++ deployment is supported on RV1126. +## 详细部署文档 -- [C++ Deployment](cpp) +目前,瑞芯微 RV1126 上只支持C++的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md deleted file mode 100644 index 2b51362b8..000000000 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README_CN.md +++ /dev/null @@ -1,20 +0,0 @@ -[English](README.md) | 简体中文 -# 在瑞芯微 RV1126 上使用 FastDeploy 部署 PaddleSeg 模型 -瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。目前,FastDeploy 支持在 RV1126 上基于 Paddle-Lite 部署 PaddleSeg 相关模型 - -## 瑞芯微 RV1126 支持的PaddleSeg模型 -由于瑞芯微 RV1126 的 NPU 仅支持 INT8 量化模型的部署,因此所支持的量化模型如下: -- [PP-LiteSeg 系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) - -为了方便开发者的测试,下面提供了 PaddleSeg 导出的部分模型,开发者可直接下载使用。 - -| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | -| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | ->> **注意**: FastDeploy 模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) - -## 详细部署文档 - -目前,瑞芯微 RV1126 上只支持C++的部署。 - -- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md old mode 100755 new mode 100644 index 0022e6840..aacad9ab1 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md @@ -1,29 +1,27 @@ -English | [简体中文](README_CN.md) -# PP-LiteSeg Quantitative Model C++ Deployment Example +[English](README.md) | 简体中文 +# PP-LiteSeg 量化模型 C++ 部署示例 -`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-LiteSeg quantization model deployment on RV1126. +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 RV1126 上的部署推理加速。 -## Deployment Preparations -### FastDeploy Cross-compile Environment Preparations -1. For the software and hardware environment, and the cross-compile environment, please refer to [Preparations for FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/rv1126.md#Cross-compilation-environment-construction). +## 部署准备 +### FastDeploy 交叉编译环境准备 +软硬件环境满足要求,以及交叉编译环境的准备,请参考:[瑞芯微RV1126部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) -### Model Preparations -1. You can directly use the quantized model provided by FastDeploy for deployment. -2. You can use one-click automatical compression tool provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) -3. The model requires heterogeneous computation. Please refer to: [Heterogeneous Computation](./../../../../../../docs/en/faq/heterogeneous_computing_on_timvx_npu.md). Since the model is already provided, you can test the heterogeneous file we provide first to verify whether the accuracy meets the requirements. +### 模型准备 +1. 用户可以直接使用由[FastDeploy 提供的量化模型](../README_CN.md#瑞芯微-rv1126-支持的paddleseg模型)进行部署。 +2. 若FastDeploy没有提供满足要求的量化模型,用户可以参考[PaddleSeg动态图模型导出为RV1126支持的INT8模型](../README_CN.md#paddleseg动态图模型导出为rv1126支持的int8模型)自行导出或训练量化模型 +3. 若上述导出或训练的模型出现精度下降或者报错,则需要使用异构计算,使得模型算子部分跑在RV1126的ARM CPU上进行调试以及精度验证,其中异构计算所需的文件是subgraph.txt。具体关于异构计算可参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md)。 -For more information, please refer to [Model Quantization](../../quantize/README.md). +## 在 RV1126 上部署量化后的 PP-LiteSeg 分割模型 +请按照以下步骤完成在 RV1126 上部署 PP-LiteSeg 量化模型: +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) -## Deploying the Quantized PP-LiteSeg Segmentation model on RV1126 -Please follow these steps to complete the deployment of the PP-LiteSeg quantization model on RV1126. -1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/rv1126.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite). - -2. Copy the compiled library to the current directory. You can run this line: +2. 将编译后的库拷贝到当前目录,可使用如下命令: ```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp +cp -r FastDeploy/build/fastdeploy-timvx/ path/to/paddleseg/rockchip/rv1126/cpp ``` -3. Download the model and example images required for deployment in current path. +3. 在当前路径下载部署所需的模型和示例图片: ```bash mkdir models && mkdir images wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz @@ -33,25 +31,29 @@ wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png cp -r cityscapes_demo.png images ``` -4. Compile the deployment example. You can run the following lines: +4. 编译部署示例,可使入如下命令: ```bash mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=armhf .. make -j8 make install -# After success, an install folder will be created with a running demo and libraries required for deployment. +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 ``` -5. Deploy the PP-LiteSeg segmentation model to Rockchip RV1126 based on adb. You can run the following lines: +5. 基于 adb 工具部署 PP-LiteSeg 分割模型到 Rockchip RV1126,可使用如下命令: ```bash -# Go to the install directory. -cd FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp/build/install/ -# The following line represents: bash run_with_adb.sh, demo needed to run, model path, image path, DEVICE ID. +# 进入 install 目录 +cd path/to/paddleseg/rockchip/rv1126/cpp/build/install/ +cp ../../run_with_adb.sh . +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID ``` -The output is: +部署成功后运行结果如下: -Please note that the model deployed on RV1126 needs to be quantized. You can refer to [Model Quantization](../../../../../../docs/en/quantize.md). + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md deleted file mode 100644 index afd185ca0..000000000 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README_CN.md +++ /dev/null @@ -1,57 +0,0 @@ -[English](README.md) | 简体中文 -# PP-LiteSeg 量化模型 C++ 部署示例 - -本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 RV1126 上的部署推理加速。 - -## 部署准备 -### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/rv1126.md#交叉编译环境搭建) - -### 模型准备 -1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 -2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 - -更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) - -## 在 RV1126 上部署量化后的 PP-LiteSeg 分割模型 -请按照以下步骤完成在 RV1126 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) - -2. 将编译后的库拷贝到当前目录,可使用如下命令: -```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp -``` - -3. 在当前路径下载部署所需的模型和示例图片: -```bash -mkdir models && mkdir images -wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz -tar -xvf ppliteseg.tar.gz -cp -r ppliteseg models -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp -r cityscapes_demo.png images -``` - -4. 编译部署示例,可使入如下命令: -```bash -mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=armhf .. -make -j8 -make install -# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 -``` - -5. 基于 adb 工具部署 PP-LiteSeg 分割模型到 Rockchip RV1126,可使用如下命令: -```bash -# 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/build/install/ -# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID -bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -``` - -部署成功后运行结果如下: - - - -需要特别注意的是,在 RV1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../quantize/README.md) diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/README_CN.md index 0c2e5194b..ea1599432 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/README_CN.md @@ -1,7 +1,9 @@ [English](README.md) | 简体中文 # 使用 FastDeploy 服务化部署 PaddleSeg 模型 ## FastDeploy 服务化部署介绍 -在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving。simple_serving 基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 +在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving +- simple_serving基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。 +- fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 ## 详细部署文档 diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md index 337507b49..1c08a5b7a 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README.md @@ -1,41 +1,51 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -## Supporting Model List +## 支持模型列表 -- PP-LiteSeg deployment models are from [PaddleSeg PP-LiteSeg series model](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md). +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -## PP-LiteSeg Model Deployment and Conversion Preparations +## 预导出的推理模型 -Befor SOPHGO-TPU model deployment, you should first convert Paddle model to bmodel model. Specific steps are as follows: -- Download Paddle model: [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz). -- Convert Paddle model to ONNX model. Please refer to [Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX). -- For the process of converting ONNX model to bmodel, please refer to [TPU-MLIR](https://github.com/sophgo/tpu-mlir). +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 -## Model Converting Example +PaddleSeg训练模型导出为推理模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) -Here we take [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) as an example to show you how to convert Paddle model to SOPHGO-TPU model. +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | -### Download PP-LiteSeg-B(STDC2)-cityscapes-without-argmax, and convert it to ONNX +## 将PaddleSeg推理模型转换为bmodel模型步骤 + +SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下: +- 下载Paddle模型[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) +- Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) +- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir) + +## bmode模型转换example + +下面以[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)为例,教大家如何转换Paddle模型到SOPHGO-TPU支持的bmodel模型 + +### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型 ```shell -# Download Paddle2ONNX repository. +# 下载Paddle2ONNX仓库 git clone https://github.com/PaddlePaddle/Paddle2ONNX -# Download the Paddle static map model and fix the input shape. -## Go to the directory where the input shape is fixed for the Paddle static map model. +# 下载Paddle静态图模型并为Paddle静态图模型固定输入shape +## 进入为Paddle静态图模型固定输入shape的目录 cd Paddle2ONNX/tools/paddle wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -# Modify the input shape of PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer model from dynamic input to constant input. +# 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入 python paddle_infer_shape.py --model_dir PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer \ --model_filename model.pdmodel \ --params_filename model.pdiparams \ --save_dir pp_liteseg_fix \ --input_shape_dict="{'x':[1,3,512,512]}" -# Convert constant input Paddle model to ONNX model. +#将固定输入的Paddle模型转换成ONNX模型 paddle2onnx --model_dir pp_liteseg_fix \ --model_filename model.pdmodel \ --params_filename model.pdiparams \ @@ -43,32 +53,32 @@ paddle2onnx --model_dir pp_liteseg_fix \ --enable_dev_version True ``` -### Export bmodel +### 导出bmodel模型 -Take converting BM1684x model to bmodel as an example. You need to download [TPU-MLIR](https://github.com/sophgo/tpu-mlir) project. For the process of installation, please refer to [TPU-MLIR Document](https://github.com/sophgo/tpu-mlir/blob/master/README.md). -### 1. Installation +以转换BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 +#### 1. 安装 ``` shell docker pull sophgo/tpuc_dev:latest -# myname1234 is just an example, you can customize your own name. +# myname1234是一个示例,也可以设置其他名字 docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest source ./envsetup.sh ./build.sh ``` -### 2. Convert ONNX model to bmodel +#### 2. ONNX模型转换为bmodel模型 ``` shell mkdir pp_liteseg && cd pp_liteseg -# Put the test image in this file, and put the converted pp_liteseg.onnx into this folder. +#在该文件中放入测试图片,同时将上一步转换的pp_liteseg.onnx放入该文件夹中 cp -rf ${REGRESSION_PATH}/dataset/COCO2017 . cp -rf ${REGRESSION_PATH}/image . -# Put in the onnx model file pp_liteseg.onnx. +#放入onnx模型文件pp_liteseg.onnx mkdir workspace && cd workspace -# Convert ONNX model to mlir model, the parameter --output_names can be viewed via NETRON. +#将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看 model_transform.py \ --model_name pp_liteseg \ --model_def ../pp_liteseg.onnx \ @@ -82,7 +92,7 @@ model_transform.py \ --test_result pp_liteseg_top_outputs.npz \ --mlir pp_liteseg.mlir -# Convert mlir model to BM1684x F32 bmodel. +#将mlir模型转换为BM1684x的F32 bmodel模型 model_deploy.py \ --mlir pp_liteseg.mlir \ --quantize F32 \ @@ -91,7 +101,8 @@ model_deploy.py \ --test_reference pp_liteseg_top_outputs.npz \ --model pp_liteseg_1684x_f32.bmodel ``` -The final bmodel, pp_liteseg_1684x_f32.bmodel, can run on BM1684x. If you want to further accelerate the model, you can convert ONNX model to INT8 bmodel. For details, please refer to [TPU-MLIR Document](https://github.com/sophgo/tpu-mlir/blob/master/README.md). +最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 -## Other Documents -- [Cpp Deployment](./cpp) +## 快速链接 +- [Cpp部署](./cpp) +- [Python部署](./python) diff --git a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md deleted file mode 100644 index 563507c25..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md +++ /dev/null @@ -1,106 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -## 支持模型列表 - -- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) - -为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 - -PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) - -| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | -| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | - -## 准备PP-LiteSeg部署模型以及转换模型 - -SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下: -- 下载Paddle模型[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) -- Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) -- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir) - -## 模型转换example - -下面以[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型 - -### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型 -```shell -# 下载Paddle2ONNX仓库 -git clone https://github.com/PaddlePaddle/Paddle2ONNX - -# 下载Paddle静态图模型并为Paddle静态图模型固定输入shape -## 进入为Paddle静态图模型固定输入shape的目录 -cd Paddle2ONNX/tools/paddle - -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz - -# 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入 -python paddle_infer_shape.py --model_dir PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer \ - --model_filename model.pdmodel \ - --params_filename model.pdiparams \ - --save_dir pp_liteseg_fix \ - --input_shape_dict="{'x':[1,3,512,512]}" - -#将固定输入的Paddle模型转换成ONNX模型 -paddle2onnx --model_dir pp_liteseg_fix \ - --model_filename model.pdmodel \ - --params_filename model.pdiparams \ - --save_file pp_liteseg.onnx \ - --enable_dev_version True -``` - -### 导出bmodel模型 - -以转换BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 -### 1. 安装 -``` shell -docker pull sophgo/tpuc_dev:latest - -# myname1234是一个示例,也可以设置其他名字 -docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest - -source ./envsetup.sh -./build.sh -``` - -### 2. ONNX模型转换为bmodel模型 -``` shell -mkdir pp_liteseg && cd pp_liteseg - -#在该文件中放入测试图片,同时将上一步转换的pp_liteseg.onnx放入该文件夹中 -cp -rf ${REGRESSION_PATH}/dataset/COCO2017 . -cp -rf ${REGRESSION_PATH}/image . -#放入onnx模型文件pp_liteseg.onnx - -mkdir workspace && cd workspace - -#将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看 -model_transform.py \ - --model_name pp_liteseg \ - --model_def ../pp_liteseg.onnx \ - --input_shapes [[1,3,512,512]] \ - --mean 0.0,0.0,0.0 \ - --scale 0.0039216,0.0039216,0.0039216 \ - --keep_aspect_ratio \ - --pixel_format rgb \ - --output_names bilinear_interp_v2_6.tmp_0 \ - --test_input ../image/dog.jpg \ - --test_result pp_liteseg_top_outputs.npz \ - --mlir pp_liteseg.mlir - -#将mlir模型转换为BM1684x的F32 bmodel模型 -model_deploy.py \ - --mlir pp_liteseg.mlir \ - --quantize F32 \ - --chip bm1684x \ - --test_input pp_liteseg_in_f32.npz \ - --test_reference pp_liteseg_top_outputs.npz \ - --model pp_liteseg_1684x_f32.bmodel -``` -最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 - -## 快速链接 -- [Cpp部署](./cpp) -- [Python部署](./python) diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md index eae65d559..3f33c398c 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md @@ -1,57 +1,56 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -`infer.cc` in this directory provides a quick example of accelerated deployment of the pp_liteseg model on SOPHGO BM1684x. +本目录下提供`infer.cc`快速完成PP-LiteSeg在SOPHGO BM1684x板子上加速部署的示例。 -Before deployment, the following two steps need to be confirmed: +## 算能硬件编译FastDeploy环境准备 +在部署前,需自行编译基于算能硬件的预测库,参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境) -1. Hardware and software environment meets the requirements. -2. Compile the FastDeploy repository from scratch according to the development environment. +## 生成基本目录文件 -For the above steps, please refer to [How to Build SOPHGO Deployment Environment](../../../../../../docs/en/build_and_install/sophgo.md). - -## Generate Basic Directory Files - -The routine consists of the following parts: +该例程由以下几个部分组成 ```text . ├── CMakeLists.txt -├── build # Compile Folder -├── image # Folder for images +├── fastdeploy-sophgo # 编译文件夹 +├── image # 存放图片的文件夹 ├── infer.cc -└── model # Folder for models +└── model # 存放模型文件的文件夹 ``` -## Compile +## 编译 -### Compile and Copy SDK to folder thirdpartys +### 编译FastDeploy -Please refer to [How to Build SOPHGO Deployment Environment](../../../../../../docs/en/build_and_install/sophgo.md) to compile SDK.After compiling, the fastdeploy-0.0.3 directory will be created in the build directory. +请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)编译SDK,编译完成后,将在build目录下生成fastdeploy-sophgo目录。拷贝fastdeploy-sophgo至当前目录 -### Copy model and configuration files to folder Model -Convert Paddle model to SOPHGO bmodel model. For the conversion steps, please refer to [Document](../README.md). -Please copy the converted SOPHGO bmodel to folder model. +### 拷贝模型文件,以及配置文件至model文件夹 +将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) -### Prepare Test Images to folder image +将转换后的SOPHGO bmodel模型文件拷贝至model中 + +### 准备测试图片至image文件夹 ```bash wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png cp cityscapes_demo.png ./images ``` -### Compile example +### 编译example ```bash cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-sophgo make ``` -## Running Routines +## 运行例程 ```bash ./infer_demo model images/cityscapes_demo.png ``` - -- [Model Description](../../) -- [Model Conversion](../) +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) +- [模型转换](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md deleted file mode 100644 index fbb274b15..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md +++ /dev/null @@ -1,57 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下提供`infer.cc`快速完成pp_liteseg模型在SOPHGO BM1684x板子上加速部署的示例。 - -在部署前,需确认以下两个步骤: - -1. 软硬件环境满足要求 -2. 根据开发环境,从头编译FastDeploy仓库 - -以上步骤请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)实现 - -## 生成基本目录文件 - -该例程由以下几个部分组成 -```text -. -├── CMakeLists.txt -├── build # 编译文件夹 -├── image # 存放图片的文件夹 -├── infer.cc -└── model # 存放模型文件的文件夹 -``` - -## 编译 - -### 编译并拷贝SDK到thirdpartys文件夹 - -请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录. - -### 拷贝模型文件,以及配置文件至model文件夹 -将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md) -将转换后的SOPHGO bmodel模型文件拷贝至model中 - -### 准备测试图片至image文件夹 -```bash -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp cityscapes_demo.png ./images -``` - -### 编译example - -```bash -cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3 -make -``` - -## 运行例程 - -```bash -./infer_demo model images/cityscapes_demo.png -``` - - -- [模型介绍](../../) -- [模型转换](../) diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README.md b/examples/vision/segmentation/paddleseg/sophgo/python/README.md index 5aba6590f..e646d6a90 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/python/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/python/README.md @@ -1,27 +1,33 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 -Before deployment, the following step need to be confirmed: +## 算能硬件编译FastDeploy wheel包环境准备 -- 1. Hardware and software environment meets the requirements. Please refer to [FastDeploy Environment Requirement](../../../../../../docs/en/build_and_install/sophgo.md). +在部署前,需自行编译基于算能硬件的FastDeploy python wheel包并安装,参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境) -`infer.py` in this directory provides a quick example of deployment of the pp_liteseg model on SOPHGO TPU. Please run the following script: +本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 ```bash -# Download the sample deployment code. +# 下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/sophgo/python +cd path/to/paddleseg/sophgo/python -# Download images. +# 下载图片 wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# Inference. +# PaddleSeg模型转换为bmodel模型 +将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) + +# 推理 python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png -# The returned result. -The result is saved as sophgo_img.png. +# 运行完成后返回结果如下所示 +运行结果保存在sophgo_img.png中 ``` -## Other Documents -- [pp_liteseg C++ Deployment](../cpp) -- [Converting pp_liteseg SOPHGO model](../README.md) +## 快速链接 +- [pp_liteseg C++部署](../cpp) +- [转换 pp_liteseg SOPHGO模型文档](../README_CN.md#导出bmodel模型) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md deleted file mode 100644 index a6eb37f8f..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md +++ /dev/null @@ -1,27 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -在部署前,需确认以下步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md) - -本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 - -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/sophgo/python - -# 下载图片 -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 推理 -python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png - -# 运行完成后返回结果如下所示 -运行结果保存在sophgo_img.png中 -``` - -## 其它文档 -- [pp_liteseg C++部署](../cpp) -- [转换 pp_liteseg SOPHGO模型文档](../README.md) From eb1992d1a6e24966eb2b159ad6724791baf24ee7 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Thu, 9 Feb 2023 00:36:05 +0800 Subject: [PATCH 06/20] Update ppmatting --- examples/vision/matting/ppmatting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vision/matting/ppmatting b/examples/vision/matting/ppmatting index c89893416..c64ba0454 120000 --- a/examples/vision/matting/ppmatting +++ b/examples/vision/matting/ppmatting @@ -1 +1 @@ -/huangjianhui/doc/FastDeploy/examples/vision/segmentation/ppmatting/ \ No newline at end of file +../segmentation/ppmatting/ From b6b8835739136d6ca1be06d61e5b761f7b573f12 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Thu, 9 Feb 2023 00:36:54 +0800 Subject: [PATCH 07/20] Update README.md --- examples/vision/segmentation/paddleseg/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vision/segmentation/paddleseg/README.md b/examples/vision/segmentation/paddleseg/README.md index a1947ae56..c240e41b7 100644 --- a/examples/vision/segmentation/paddleseg/README.md +++ b/examples/vision/segmentation/paddleseg/README.md @@ -1,4 +1,4 @@ -# PaddleSeg高性能全场景模型部署方案——FastDeploy +# PaddleSeg高性能全场景模型部署方案—FastDeploy ## FastDeploy介绍 From 14352eacdf88eeba2fee170567ca9420e6d214c9 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Thu, 9 Feb 2023 00:38:38 +0800 Subject: [PATCH 08/20] Update README.md --- .../vision/segmentation/paddleseg/rockchip/rknpu2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md index f6d1a0b12..21a9b92ba 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md @@ -53,7 +53,7 @@ RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如 上述步骤可参考以下具体示例 -## 模型转换example +## 模型转换示例 * [PP-HumanSeg](./pp_humanseg.md) From c47a1c81aa14b8ad560155ac1a94b8474b6fbccf Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 8 Feb 2023 16:50:08 +0000 Subject: [PATCH 09/20] Update soft link --- examples/vision/matting/ppmatting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vision/matting/ppmatting b/examples/vision/matting/ppmatting index c64ba0454..352f37bf2 120000 --- a/examples/vision/matting/ppmatting +++ b/examples/vision/matting/ppmatting @@ -1 +1 @@ -../segmentation/ppmatting/ +../segmentation/ppmatting/ \ No newline at end of file From 09929d9d28777b0a0c23627164ece23d49a50cde Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 8 Feb 2023 17:08:33 +0000 Subject: [PATCH 10/20] Update docs --- .../vision/segmentation/ppmatting/README.md | 42 +++++ .../segmentation/ppmatting/README_CN.md | 43 +++++ .../segmentation/ppmatting/cpp/CMakeLists.txt | 14 ++ .../segmentation/ppmatting/cpp/README.md | 93 ++++++++++ .../segmentation/ppmatting/cpp/README_CN.md | 94 ++++++++++ .../segmentation/ppmatting/cpp/infer.cc | 170 ++++++++++++++++++ .../segmentation/ppmatting/python/README.md | 81 +++++++++ .../ppmatting/python/README_CN.md | 80 +++++++++ .../segmentation/ppmatting/python/infer.py | 70 ++++++++ 9 files changed, 687 insertions(+) create mode 100644 examples/vision/segmentation/ppmatting/README.md create mode 100644 examples/vision/segmentation/ppmatting/README_CN.md create mode 100644 examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt create mode 100755 examples/vision/segmentation/ppmatting/cpp/README.md create mode 100644 examples/vision/segmentation/ppmatting/cpp/README_CN.md create mode 100644 examples/vision/segmentation/ppmatting/cpp/infer.cc create mode 100755 examples/vision/segmentation/ppmatting/python/README.md create mode 100644 examples/vision/segmentation/ppmatting/python/README_CN.md create mode 100755 examples/vision/segmentation/ppmatting/python/infer.py diff --git a/examples/vision/segmentation/ppmatting/README.md b/examples/vision/segmentation/ppmatting/README.md new file mode 100644 index 000000000..a2cbdc346 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/README.md @@ -0,0 +1,42 @@ +English | [简体中文](README_CN.md) +# PP-Matting Model Deployment + +## Model Description + +- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + +## List of Supported Models + +Now FastDeploy supports the deployment of the following models + +- [PP-Matting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-HumanMatting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [ModNet models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + + +## Export Deployment Model + +Before deployment, PP-Matting needs to be exported into the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information. (Tips: You need to set the `--input_shape` parameter of the export script when exporting PP-Matting and PP-HumanMatting models) + + +## Download Pre-trained Models + +For developers' testing, models exported by PP-Matting are provided below. Developers can download and use them directly. + +The accuracy metric is sourced from the model description in PP-Matting. (Accuracy data are not provided) Refer to the introduction in PP-Matting for more details. + +| Model | Parameter Size | Accuracy | Note | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | +| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | +| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | +| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | +| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | +| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | + + + +## Detailed Deployment Tutorials + +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/segmentation/ppmatting/README_CN.md b/examples/vision/segmentation/ppmatting/README_CN.md new file mode 100644 index 000000000..a1c9801aa --- /dev/null +++ b/examples/vision/segmentation/ppmatting/README_CN.md @@ -0,0 +1,43 @@ +[English](README.md) | 简体中文 +# PP-Matting模型部署 + +## 模型版本说明 + +- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + + +## 导出部署模型 + +在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) + + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 + +其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | +| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | +| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | +| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | +| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | +| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt b/examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt new file mode 100644 index 000000000..93540a7e8 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +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_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/segmentation/ppmatting/cpp/README.md b/examples/vision/segmentation/ppmatting/cpp/README.md new file mode 100755 index 000000000..f678fabd4 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpp/README.md @@ -0,0 +1,93 @@ +English | [简体中文](README_CN.md) +# PP-Matting C++ Deployment Example + +This directory provides examples that `infer.cc` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) + +Taking the PP-Matting inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. + +```bash +mkdir build +cd build +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above +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 + +# Download PP-Matting model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + + +# CPU inference +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 +# GPU inference +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 +# TensorRT inference on GPU +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 +# kunlunxin XPU inference +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 +``` + +The visualized result after running is as follows +
+ + + + +
+ +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/en/faq/use_sdk_on_windows.md) + +## PP-Matting C++ Interface + +### PPMatting Class + +```c++ +fastdeploy::vision::matting::PPMatting( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PP-Matting model loading and initialization, among which model_file is the exported Paddle model format. + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +#### Predict Function + +> ```c++ +> PPMatting::Predict(cv::Mat* im, MattingResult* result) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **im**: Input images in HWC or BGR format +> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/cpp/README_CN.md b/examples/vision/segmentation/ppmatting/cpp/README_CN.md new file mode 100644 index 000000000..38e2e592a --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpp/README_CN.md @@ -0,0 +1,94 @@ +[English](README.md) | 简体中文 +# PP-Matting C++部署示例 + +本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 PP-Matting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +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 + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + + +# CPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 +# GPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 +# GPU上TensorRT推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 +# 昆仑芯XPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 +``` + +运行完成可视化结果如下图所示 +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-Matting C++接口 + +### PPMatting类 + +```c++ +fastdeploy::vision::matting::PPMatting( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PP-Matting模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PPMatting::Predict(cv::Mat* im, MattingResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/cpp/infer.cc b/examples/vision/segmentation/ppmatting/cpp/infer.cc new file mode 100644 index 000000000..e7f1ffbcb --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpp/infer.cc @@ -0,0 +1,170 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "fastdeploy/vision.h" + +#ifdef WIN32 +const char sep = '\\'; +#else +const char sep = '/'; +#endif + +void CpuInfer(const std::string& model_dir, const std::string& image_file, + const std::string& background_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + cv::Mat bg = cv::imread(background_file); + fastdeploy::vision::MattingResult res; + if (!model.Predict(&im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisMatting(im, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); + cv::imwrite("visualized_result.jpg", vis_im_with_bg); + cv::imwrite("visualized_result_fg.jpg", vis_im); + std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " + "and ./visualized_result_fg.jpg" + << std::endl; +} + +void KunlunXinInfer(const std::string& model_dir, const std::string& image_file, + const std::string& background_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseKunlunXin(); + auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + cv::Mat bg = cv::imread(background_file); + fastdeploy::vision::MattingResult res; + if (!model.Predict(&im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisMatting(im, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); + cv::imwrite("visualized_result.jpg", vis_im_with_bg); + cv::imwrite("visualized_result_fg.jpg", vis_im); + std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " + "and ./visualized_result_fg.jpg" + << std::endl; +} + +void GpuInfer(const std::string& model_dir, const std::string& image_file, + const std::string& background_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UsePaddleInferBackend(); + auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + cv::Mat bg = cv::imread(background_file); + fastdeploy::vision::MattingResult res; + if (!model.Predict(&im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisMatting(im, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); + cv::imwrite("visualized_result.jpg", vis_im_with_bg); + cv::imwrite("visualized_result_fg.jpg", vis_im); + std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " + "and ./visualized_result_fg.jpg" + << std::endl; +} + +void TrtInfer(const std::string& model_dir, const std::string& image_file, + const std::string& background_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + option.SetTrtInputShape("img", {1, 3, 512, 512}); + auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + cv::Mat bg = cv::imread(background_file); + fastdeploy::vision::MattingResult res; + if (!model.Predict(&im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisMatting(im, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); + cv::imwrite("visualized_result.jpg", vis_im_with_bg); + cv::imwrite("visualized_result_fg.jpg", vis_im); + std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " + "and ./visualized_result_fg.jpg" + << std::endl; +} + +int main(int argc, char* argv[]) { + if (argc < 5) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./PP-Matting-512 ./test.jpg ./test_bg.jpg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu; 2: run with gpu and use tensorrt backend, 3: run " + "with kunlunxin." + << std::endl; + return -1; + } + if (std::atoi(argv[4]) == 0) { + CpuInfer(argv[1], argv[2], argv[3]); + } else if (std::atoi(argv[4]) == 1) { + GpuInfer(argv[1], argv[2], argv[3]); + } else if (std::atoi(argv[4]) == 2) { + TrtInfer(argv[1], argv[2], argv[3]); + } else if (std::atoi(argv[4]) == 3) { + KunlunXinInfer(argv[1], argv[2], argv[3]); + } + return 0; +} diff --git a/examples/vision/segmentation/ppmatting/python/README.md b/examples/vision/segmentation/ppmatting/python/README.md new file mode 100755 index 000000000..fb7d42617 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/python/README.md @@ -0,0 +1,81 @@ +English | [简体中文](README_CN.md) +# PP-Matting Python Deployment Example + +Before deployment, two steps require confirmation + +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) + +This directory provides examples that `infer.py` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +```bash +# Download the deployment example code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/matting/ppmatting/python + +# Download PP-Matting model files and test images +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +# CPU inference +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu +# GPU inference +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +# kunlunxin XPU inference +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin +``` + +The visualized result after running is as follows +
+ + + + +
+## PP-Matting Python Interface + +```python +fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-Matting model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information + +**Parameter** + +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default + +### predict function + +> ```python +> PPMatting.predict(input_image) +> ``` +> +> Model prediction interface. Input images and output detection results. +> +> **Parameter** +> +> > * **input_image**(np.ndarray): Input data in HWC or BGR format + +> **Return** +> +> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. + +### Class Member Variable + +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + + + +## Other Documents + +- [PP-Matting Model Description](..) +- [PP-Matting C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/python/README_CN.md b/examples/vision/segmentation/ppmatting/python/README_CN.md new file mode 100644 index 000000000..5e676a1cf --- /dev/null +++ b/examples/vision/segmentation/ppmatting/python/README_CN.md @@ -0,0 +1,80 @@ +[English](README.md) | 简体中文 +# PP-Matting Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/matting/ppmatting/python + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +# CPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu +# GPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin +``` + +运行完成可视化结果如下图所示 +
+ + + + +
+## PP-Matting Python接口 + +```python +fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-Matting模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PPMatting.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +## 其它文档 + +- [PP-Matting 模型介绍](..) +- [PP-Matting C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/python/infer.py b/examples/vision/segmentation/ppmatting/python/infer.py new file mode 100755 index 000000000..512d0ca86 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/python/infer.py @@ -0,0 +1,70 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of PaddleSeg model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + parser.add_argument( + "--bg", + type=str, + required=True, + default=None, + help="Path of test background image file.") + parser.add_argument( + "--device", + type=str, + default='cpu', + help="Type of inference device, support 'cpu', 'kunlunxin' or 'gpu'.") + parser.add_argument( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + if args.device.lower() == "gpu": + option.use_gpu() + option.use_paddle_infer_backend() + + if args.use_trt: + option.use_trt_backend() + option.set_trt_input_shape("img", [1, 3, 512, 512]) + + if args.device.lower() == "kunlunxin": + option.use_kunlunxin() + return option + + +args = parse_arguments() + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +config_file = os.path.join(args.model, "deploy.yaml") +model = fd.vision.matting.PPMatting( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片抠图结果 +im = cv2.imread(args.image) +bg = cv2.imread(args.bg) +result = model.predict(im) +print(result) +# 可视化结果 +vis_im = fd.vision.vis_matting(im, result) +vis_im_with_bg = fd.vision.swap_background(im, bg, result) +cv2.imwrite("visualized_result_fg.jpg", vis_im) +cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) +print( + "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" +) From ad63c2707ae9255b8fe8a897ef2fbfce8ec7e852 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng <58363586+Zheng-Bicheng@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:45:24 +0800 Subject: [PATCH 11/20] [Doc]Update RKNPU2 docs (#1266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新docs --- docs/cn/build_and_install/rknpu2.md | 2 +- docs/cn/faq/rknpu2/rknpu2.md | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/cn/build_and_install/rknpu2.md b/docs/cn/build_and_install/rknpu2.md index 33ee596fe..f432c94ce 100644 --- a/docs/cn/build_and_install/rknpu2.md +++ b/docs/cn/build_and_install/rknpu2.md @@ -11,5 +11,5 @@ RKNPU2指的是Rockchip推出的RK356X以及RK3588系列芯片的NPU。 * [RKNPU2开发环境搭建](../faq/rknpu2/environment.md) * [编译FastDeploy](../faq/rknpu2/build.md) * [RKNN模型导出建议](../faq/rknpu2/export.md) -* [RKNPU2模型部署demo](../faq/rknpu2/rknpu2.md) +* [RKNPU2模型速度一览表](../faq/rknpu2/rknpu2.md) * [RKNPU2 常见问题合集](../faq/rknpu2/issues.md) diff --git a/docs/cn/faq/rknpu2/rknpu2.md b/docs/cn/faq/rknpu2/rknpu2.md index 81f35bd43..99554e5ba 100644 --- a/docs/cn/faq/rknpu2/rknpu2.md +++ b/docs/cn/faq/rknpu2/rknpu2.md @@ -13,18 +13,20 @@ 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 | -| 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 | +| 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) | +|----------------------|--------------------------------------------------------------------------------------------------|--------------------------|--------------------| +| Detection | [Picodet](../../../../examples/vision/detection/paddledetection/rknpu2/README.md) | Picodet-s | 162/112 | +| Detection | [PaddleDetection Yolov8](../../../../examples/vision/detection/paddledetection/rknpu2/README.md) | yolov8-n | -/100 | +| Detection | [PPYOLOE](../../../../examples/vision/detection/paddledetection/rknpu2/README.md) | ppyoloe-s(int8) | -/77 | +| 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 | ## 预编译库下载 From 0414f0fd734abba5a91b62dda081d54b124b4172 Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Thu, 9 Feb 2023 02:43:38 +0000 Subject: [PATCH 12/20] Update doc --- docs/api/vision_results/README_CN.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/api/vision_results/README_CN.md b/docs/api/vision_results/README_CN.md index a6ad2a808..94efce21e 100755 --- a/docs/api/vision_results/README_CN.md +++ b/docs/api/vision_results/README_CN.md @@ -16,6 +16,3 @@ FastDeploy根据视觉模型的任务类型,定义了不同的结构体(`fastd | OCRResult | [C++/Python文档](./ocr_result.md) | 文本框检测,分类和文本识别返回结果 | OCR系列模型等 | | MOTResult | [C++/Python文档](./mot_result.md) | 多目标跟踪返回结果 | pptracking系列模型等 | | HeadPoseResult | [C++/Python文档](./headpose_result.md) | 头部姿态估计返回结果 | FSANet系列模型等 | - -## 常见问题 -- [如何将视觉模型预测结果转换为numpy格式](./faq_CN.md) From 9574d301c8509d26b697147b415bd0e31779d1fb Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Thu, 9 Feb 2023 03:27:48 +0000 Subject: [PATCH 13/20] Add ppmatting soft link --- examples/vision/matting/ppmatting | 1 - examples/vision/matting/ppmatting/README.md | 1 + examples/vision/matting/ppmatting/README_CN.md | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) delete mode 120000 examples/vision/matting/ppmatting create mode 120000 examples/vision/matting/ppmatting/README.md create mode 120000 examples/vision/matting/ppmatting/README_CN.md diff --git a/examples/vision/matting/ppmatting b/examples/vision/matting/ppmatting deleted file mode 120000 index 352f37bf2..000000000 --- a/examples/vision/matting/ppmatting +++ /dev/null @@ -1 +0,0 @@ -../segmentation/ppmatting/ \ No newline at end of file diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md new file mode 120000 index 000000000..a6452162a --- /dev/null +++ b/examples/vision/matting/ppmatting/README.md @@ -0,0 +1 @@ +../../segmentation/ppmatting/README.md \ No newline at end of file diff --git a/examples/vision/matting/ppmatting/README_CN.md b/examples/vision/matting/ppmatting/README_CN.md new file mode 120000 index 000000000..00a0e19ce --- /dev/null +++ b/examples/vision/matting/ppmatting/README_CN.md @@ -0,0 +1 @@ +../../segmentation/ppmatting/README_CN.md \ No newline at end of file From b1dc8c09899e3f3672dff089dbb9a9460056dcac Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Thu, 9 Feb 2023 03:56:36 +0000 Subject: [PATCH 14/20] Create README.md in ppmatting directory --- examples/vision/matting/ppmatting/README.md | 4 +++- examples/vision/matting/ppmatting/README_CN.md | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) mode change 120000 => 100644 examples/vision/matting/ppmatting/README.md delete mode 120000 examples/vision/matting/ppmatting/README_CN.md diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md deleted file mode 120000 index a6452162a..000000000 --- a/examples/vision/matting/ppmatting/README.md +++ /dev/null @@ -1 +0,0 @@ -../../segmentation/ppmatting/README.md \ No newline at end of file diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md new file mode 100644 index 000000000..2e8389bc1 --- /dev/null +++ b/examples/vision/matting/ppmatting/README.md @@ -0,0 +1,3 @@ +PP-Matting deployment examples, please refer to [document](../../segmentation/ppmatting/README_CN.md). + +PP-Matting的部署示例,请参考[文档](../../segmentation/ppmatting/README_CN.md). diff --git a/examples/vision/matting/ppmatting/README_CN.md b/examples/vision/matting/ppmatting/README_CN.md deleted file mode 120000 index 00a0e19ce..000000000 --- a/examples/vision/matting/ppmatting/README_CN.md +++ /dev/null @@ -1 +0,0 @@ -../../segmentation/ppmatting/README_CN.md \ No newline at end of file From b405cc3a2c5b54d07771894ede57ef29678627e5 Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Thu, 9 Feb 2023 07:38:11 +0000 Subject: [PATCH 15/20] Update ppmatting directory --- examples/vision/matting/ppmatting/README.md | 4 +- .../paddleseg/amlogic/a311d/README.md | 12 ++- .../segmentation/paddleseg/ascend/README.md | 11 ++- .../segmentation/paddleseg/cpu-gpu/README.md | 7 +- .../segmentation/paddleseg/kunlun/README.md | 9 +- .../paddleseg/rockchip/rknpu2/README.md | 6 +- .../rockchip/rknpu2/python/README.md | 2 +- .../paddleseg/rockchip/rv1126/README.md | 14 ++- .../paddleseg/serving/README_CN.md | 45 ++++++++- .../serving/fastdeploy_serving/README.md | 2 + .../serving/fastdeploy_serving/README_CN.md | 4 +- .../serving/simple_serving/README.md | 2 +- .../serving/simple_serving/README_CN.md | 5 +- .../segmentation/paddleseg/sophgo/README.md | 9 +- .../vision/segmentation/ppmatting/README.md | 46 +++------ .../segmentation/ppmatting/ascend/README.md | 1 + .../segmentation/ppmatting/cpp/README.md | 93 ------------------ .../segmentation/ppmatting/cpp/README_CN.md | 94 ------------------- .../{README_CN.md => cpu-gpu/README.md} | 28 +++--- .../{ => cpu-gpu}/cpp/CMakeLists.txt | 0 .../ppmatting/cpu-gpu/cpp/README.md | 60 ++++++++++++ .../ppmatting/{ => cpu-gpu}/cpp/infer.cc | 4 + .../ppmatting/cpu-gpu/python/README.md | 52 ++++++++++ .../ppmatting/{ => cpu-gpu}/python/infer.py | 4 + .../segmentation/ppmatting/kunlun/README.md | 1 + .../segmentation/ppmatting/python/README.md | 81 ---------------- .../ppmatting/python/README_CN.md | 80 ---------------- 27 files changed, 250 insertions(+), 426 deletions(-) create mode 120000 examples/vision/segmentation/ppmatting/ascend/README.md delete mode 100755 examples/vision/segmentation/ppmatting/cpp/README.md delete mode 100644 examples/vision/segmentation/ppmatting/cpp/README_CN.md rename examples/vision/segmentation/ppmatting/{README_CN.md => cpu-gpu/README.md} (56%) rename examples/vision/segmentation/ppmatting/{ => cpu-gpu}/cpp/CMakeLists.txt (100%) create mode 100644 examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md rename examples/vision/segmentation/ppmatting/{ => cpu-gpu}/cpp/infer.cc (97%) create mode 100644 examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md rename examples/vision/segmentation/ppmatting/{ => cpu-gpu}/python/infer.py (91%) create mode 120000 examples/vision/segmentation/ppmatting/kunlun/README.md delete mode 100755 examples/vision/segmentation/ppmatting/python/README.md delete mode 100644 examples/vision/segmentation/ppmatting/python/README_CN.md diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md index 2e8389bc1..2a54d53c7 100644 --- a/examples/vision/matting/ppmatting/README.md +++ b/examples/vision/matting/ppmatting/README.md @@ -1,3 +1,3 @@ -PP-Matting deployment examples, please refer to [document](../../segmentation/ppmatting/README_CN.md). +PaddleSeg Matting deployment examples, please refer to [document](../../segmentation/ppmatting/README_CN.md). -PP-Matting的部署示例,请参考[文档](../../segmentation/ppmatting/README_CN.md). +PaddleSeg Matting的部署示例,请参考[文档](../../segmentation/ppmatting/README_CN.md). diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md index 9f856deb4..c9a04fd41 100644 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md @@ -1,13 +1,17 @@ [English](README.md) | 简体中文 -# 在晶晨A311D上使用FastDeploy部署PaddleSeg模型 -晶晨A311D是一款先进的AI应用处理器。FastDeploy支持在A311D上基于Paddle-Lite部署PaddleSeg相关模型 +# PaddleSeg在晶晨A311D上通过FastDeploy部署模型 +晶晨A311D是一款先进的AI应用处理器。PaddleSeg支持通过FastDeploy在A311D上基于Paddle-Lite部署相关Segmentation模型 ## 晶晨A311D支持的PaddleSeg模型 -目前所支持的PaddleSeg模型如下: + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前晶晨A311D所支持的PaddleSeg模型如下: - [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -## 预导出的推理模型 +## 预导出的量化推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 | 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | diff --git a/examples/vision/segmentation/paddleseg/ascend/README.md b/examples/vision/segmentation/paddleseg/ascend/README.md index 475d8817b..05f4d8348 100644 --- a/examples/vision/segmentation/paddleseg/ascend/README.md +++ b/examples/vision/segmentation/paddleseg/ascend/README.md @@ -1,10 +1,13 @@ -# 使用FastDeploy部署PaddleSeg模型 +[English](README.md) | 简体中文 -FastDeploy支持在华为昇腾上部署PaddleSeg模型 +# PaddleSeg利用FastDeploy在华为昇腾上部署模型 -## 模型版本说明 +PaddleSeg支持通过FastDeploy在华为昇腾上部署Segmentation相关模型 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +## 支持的PaddleSeg模型 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 目前FastDeploy支持如下模型的部署 diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md index a5e02e6c9..b126e9ddb 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/README.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md @@ -1,10 +1,13 @@ +[English](README.md) | 简体中文 + # PaddleSeg模型高性能全场景部署方案-FastDeploy -PaddleSeg通过FastDeploy支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署 +PaddleSeg支持利用FastDeploy在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署Segmentation模型 ## 模型版本说明 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 目前FastDeploy支持如下模型的部署 diff --git a/examples/vision/segmentation/paddleseg/kunlun/README.md b/examples/vision/segmentation/paddleseg/kunlun/README.md index 08406d082..cdb727988 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/README.md +++ b/examples/vision/segmentation/paddleseg/kunlun/README.md @@ -1,8 +1,13 @@ -# 使用FastDeploy部署PaddleSeg模型 +[English](README.md) | 简体中文 + +# PaddleSeg模型高性能全场景部署方案-FastDeploy + +PaddleSeg支持利用FastDeploy在昆仑芯片上部署Segmentation模型 ## 模型版本说明 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 目前FastDeploy支持如下模型的部署 diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md index 21a9b92ba..a536630e3 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md @@ -1,6 +1,7 @@ [English](README.md) | 简体中文 -# 基于RKNPU2使用FastDeploy部署PaddleSeg模型 +# PaddleSeg利用FastDeploy基于RKNPU2部署Segmentation模型 + RKNPU2 提供了一个高性能接口来访问 Rockchip NPU,支持如下硬件的部署 - RK3566/RK3568 - RK3588/RK3588S @@ -10,7 +11,8 @@ RKNPU2 提供了一个高性能接口来访问 Rockchip NPU,支持如下硬件 ## 模型版本说明 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 目前FastDeploy使用RKNPU2推理PaddleSeg支持如下模型的部署: - [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md index 5b7c3df35..7524b6c60 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md @@ -3,7 +3,7 @@ 在部署前,需确认以下步骤 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) +- 1. 软硬件环境满足要求,RKNPU2环境部署等参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) 【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../../matting/) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md index 5f92e7f6f..12b9a0d05 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md @@ -1,10 +1,16 @@ [English](README.md) | 简体中文 -# 在瑞芯微 RV1126 上使用 FastDeploy 部署 PaddleSeg 模型 -瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。目前,FastDeploy 支持在 RV1126 上基于 Paddle-Lite 部署 PaddleSeg 相关模型 +# PaddleSeg在瑞芯微 RV1126上通过FastDeploy部署模型 +瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。PaddleSeg支持通过FastDeploy在RV1126上基于Paddle-Lite部署相关Segmentation模型 + +## 瑞芯微 RV1126支持的PaddleSeg模型 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 -## 瑞芯微 RV1126 支持的PaddleSeg模型 目前瑞芯微 RV1126 的 NPU 支持的量化模型如下: -## 预导出的推理模型 +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) + +## 预导出的量化推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 | 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/README_CN.md index ea1599432..803465941 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/README_CN.md @@ -1,10 +1,53 @@ [English](README.md) | 简体中文 -# 使用 FastDeploy 服务化部署 PaddleSeg 模型 +# PaddleSeg 使用 FastDeploy 服务化部署 Segmentation 模型 ## FastDeploy 服务化部署介绍 在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving - simple_serving基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。 - fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 +## 模型版本说明 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前FastDeploy支持如下模型的部署 + +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +>>**注意** 如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../ppmatting) + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 预导出的推理模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | +| [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | +|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +| [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + ## 详细部署文档 - [fastdeploy serving](fastdeploy_serving) diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md index a451e8730..c5b6dd41f 100644 --- a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md @@ -1,6 +1,8 @@ English | [简体中文](README_CN.md) # PaddleSegmentation Serving Deployment Demo +Before serving deployment, it is necessary to confirm the hardware and software environment requirements of the service image and the image pull command, please refer to [FastDeploy service deployment](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README.md) + ## Launch Serving ```bash diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md index ac8965d75..ae346cb5b 100644 --- a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md @@ -1,9 +1,7 @@ [English](README.md) | 简体中文 # PaddleSeg 服务化部署示例 -在服务化部署前,需确认 - -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README_CN.md) +在服务化部署前,需确认服务化镜像的软硬件环境要求和镜像拉取命令,请参考[FastDeploy服务化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README_CN.md) ## 启动服务 diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md index da41a3a00..686164ad7 100644 --- a/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md @@ -5,7 +5,7 @@ English | [简体中文](README_CN.md) ## Environment -- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) +- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/en/build_and_install#install-prebuilt-fastdeploy) Server: ```bash diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md index d12bb9f2e..db06103ed 100644 --- a/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md @@ -2,10 +2,9 @@ # PaddleSeg Python轻量服务化部署示例 -在部署前,需确认以下两个步骤 +## 部署环境准备 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/download_prebuilt_libraries.md) +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) 服务端: ```bash diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md index 1c08a5b7a..366656a75 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README.md @@ -1,8 +1,13 @@ [English](README.md) | 简体中文 -# PaddleSeg C++部署示例 +# PaddleSeg在算能(Sophgo)硬件上通过FastDeploy部署模型 +PaddleSeg支持通过FastDeploy在算能TPU上部署相关Segmentation模型 -## 支持模型列表 +## 算能硬件支持的PaddleSeg模型 +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前算能TPU支持的模型如下: - [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) ## 预导出的推理模型 diff --git a/examples/vision/segmentation/ppmatting/README.md b/examples/vision/segmentation/ppmatting/README.md index a2cbdc346..b3dd9cc80 100644 --- a/examples/vision/segmentation/ppmatting/README.md +++ b/examples/vision/segmentation/ppmatting/README.md @@ -1,42 +1,22 @@ -English | [简体中文](README_CN.md) -# PP-Matting Model Deployment +# PaddleSeg高性能全场景模型部署方案—FastDeploy -## Model Description +## FastDeploy介绍 -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg Matting模型进行快速部署 -## List of Supported Models +## 支持如下的硬件部署 -Now FastDeploy supports the deployment of the following models +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](cpu-gpu) | [昇腾](cpu-gpu) | -- [PP-Matting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [PP-HumanMatting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [ModNet models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +## 常见问题 +遇到问题可查看常见问题集合文档或搜索FastDeploy issues,链接如下: -## Export Deployment Model +[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) -Before deployment, PP-Matting needs to be exported into the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information. (Tips: You need to set the `--input_shape` parameter of the export script when exporting PP-Matting and PP-HumanMatting models) +[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) - -## Download Pre-trained Models - -For developers' testing, models exported by PP-Matting are provided below. Developers can download and use them directly. - -The accuracy metric is sourced from the model description in PP-Matting. (Accuracy data are not provided) Refer to the introduction in PP-Matting for more details. - -| Model | Parameter Size | Accuracy | Note | -|:---------------------------------------------------------------- |:----- |:----- | :------ | -| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | -| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | -| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | -| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | -| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | -| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | - - - -## Detailed Deployment Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) +若以上方式都无法解决问题,欢迎给FastDeploy提交新的[issue](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/ppmatting/ascend/README.md b/examples/vision/segmentation/ppmatting/ascend/README.md new file mode 120000 index 000000000..3ed44e130 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/ascend/README.md @@ -0,0 +1 @@ +../cpu-gpu/README.md \ No newline at end of file diff --git a/examples/vision/segmentation/ppmatting/cpp/README.md b/examples/vision/segmentation/ppmatting/cpp/README.md deleted file mode 100755 index f678fabd4..000000000 --- a/examples/vision/segmentation/ppmatting/cpp/README.md +++ /dev/null @@ -1,93 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting C++ Deployment Example - -This directory provides examples that `infer.cc` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -Taking the PP-Matting inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. - -```bash -mkdir build -cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above -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 - -# Download PP-Matting model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg - - -# CPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# TensorRT inference on GPU -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# kunlunxin XPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 -``` - -The visualized result after running is as follows -
- - - - -
- -The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/en/faq/use_sdk_on_windows.md) - -## PP-Matting C++ Interface - -### PPMatting Class - -```c++ -fastdeploy::vision::matting::PPMatting( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PP-Matting model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PPMatting::Predict(cv::Mat* im, MattingResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/cpp/README_CN.md b/examples/vision/segmentation/ppmatting/cpp/README_CN.md deleted file mode 100644 index 38e2e592a..000000000 --- a/examples/vision/segmentation/ppmatting/cpp/README_CN.md +++ /dev/null @@ -1,94 +0,0 @@ -[English](README.md) | 简体中文 -# PP-Matting C++部署示例 - -本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上 PP-Matting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) - -```bash -mkdir build -cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 -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 - -# 下载PP-Matting模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg - - -# CPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# GPU上TensorRT推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# 昆仑芯XPU推理 -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 -``` - -运行完成可视化结果如下图所示 -
- - - - -
- -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -## PP-Matting C++接口 - -### PPMatting类 - -```c++ -fastdeploy::vision::matting::PPMatting( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PP-Matting模型加载和初始化,其中model_file为导出的Paddle模型格式。 - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -#### Predict函数 - -> ```c++ -> PPMatting::Predict(cv::Mat* im, MattingResult* result) -> ``` -> -> 模型预测接口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/README_CN.md b/examples/vision/segmentation/ppmatting/cpu-gpu/README.md similarity index 56% rename from examples/vision/segmentation/ppmatting/README_CN.md rename to examples/vision/segmentation/ppmatting/cpu-gpu/README.md index a1c9801aa..e590ac42c 100644 --- a/examples/vision/segmentation/ppmatting/README_CN.md +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/README.md @@ -1,30 +1,32 @@ -[English](README.md) | 简体中文 -# PP-Matting模型部署 +# PaddleSeg Matting模型高性能全场景部署方案-FastDeploy + +PaddleSeg通过[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)、昆仑芯、华为昇腾硬件上部署Matting模型 ## 模型版本说明 -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -## 支持模型列表 +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +>> **注意**:支持PaddleSeg高于2.6版本的Matting模型 目前FastDeploy支持如下模型的部署 -- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) +- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) +- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) -## 导出部署模型 +## 准备PaddleSeg部署模型 +在部署前,需要先将Matting模型导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) -在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 - -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 +>> **注意**`deploy.yaml`文件记录导出模型的`input_shape`以及预处理信息,若不满足要求,用户可重新导出相关模型 | 模型 | 参数大小 | 精度 | 备注 | |:---------------------------------------------------------------- |:----- |:----- | :------ | @@ -35,8 +37,6 @@ | [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | | [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | - - ## 详细部署文档 - [Python部署](python) diff --git a/examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/ppmatting/cpp/CMakeLists.txt rename to examples/vision/segmentation/ppmatting/cpu-gpu/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md new file mode 100644 index 000000000..b88b79942 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md @@ -0,0 +1,60 @@ +[English](README.md) | 简体中文 +# PP-Matting C++部署示例 + +本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU、昆仑芯、华为昇腾以及GPU上通过Paddle-TensorRT加速部署的示例。 + +在部署前,需确认软硬件环境,同时下载预编译部署库,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install) + +>> **注意** 只有CPU、GPU提供预编译库,华为昇腾以及昆仑芯需要参考以上文档自行编译部署环境 + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +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 + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + + +# CPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 +# GPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 +# GPU上TensorRT推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 +# 昆仑芯XPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 +``` +>> ***注意** 以上示例未提供华为昇腾的示例,在编译好昇腾部署环境后,只需改造一行代码,将示例文件中KunlunXinInfer方法的`option.UseKunlunXin()`为`option.UseAscend()`就可以完成在华为昇腾上的推理部署 + +运行完成可视化结果如下图所示 +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) + +## 常见问题 +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/ppmatting/cpp/infer.cc b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc similarity index 97% rename from examples/vision/segmentation/ppmatting/cpp/infer.cc rename to examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc index e7f1ffbcb..3af778f88 100644 --- a/examples/vision/segmentation/ppmatting/cpp/infer.cc +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc @@ -121,6 +121,10 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, auto option = fastdeploy::RuntimeOption(); option.UseGpu(); option.UseTrtBackend(); + // If use original Tensorrt, not Paddle-TensorRT, + // comment the following two lines + option.EnablePaddleToTrt(); + option.EnablePaddleTrtCollectShape(); option.SetTrtInputShape("img", {1, 3, 512, 512}); auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, config_file, option); diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md b/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md new file mode 100644 index 000000000..2adb2458a --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md @@ -0,0 +1,52 @@ +[English](README.md) | 简体中文 +# PP-Matting Python部署示例 + +本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU、昆仑芯、华为昇腾,以及GPU上通过Paddle-TensorRT加速部署的示例。执行如下脚本即可完成 + +## 部署环境准备 + +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install) +>> **注意** 只有CPU、GPU提供预编译库,华为昇腾以及昆仑芯需要参考以上文档自行编译部署环境 + + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/matting/ppmatting/python + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +# CPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu +# GPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin +``` +>> ***注意** 以上示例未提供华为昇腾的示例,在编译好昇腾部署环境后,只需改造一行代码,将示例文件中的`option.use_kunlunxin()`为`option.use_ascend()`就可以完成在华为昇腾上的推理部署 + +运行完成可视化结果如下图所示 +
+ + + + +
+ +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/ppmatting/python/infer.py b/examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py similarity index 91% rename from examples/vision/segmentation/ppmatting/python/infer.py rename to examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py index 512d0ca86..4d7ebb978 100755 --- a/examples/vision/segmentation/ppmatting/python/infer.py +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py @@ -38,6 +38,10 @@ def build_option(args): if args.use_trt: option.use_trt_backend() + # If use original Tensorrt, not Paddle-TensorRT, + # comment the following two lines + option.enable_paddle_to_trt() + option.enable_paddle_trt_collect_shape() option.set_trt_input_shape("img", [1, 3, 512, 512]) if args.device.lower() == "kunlunxin": diff --git a/examples/vision/segmentation/ppmatting/kunlun/README.md b/examples/vision/segmentation/ppmatting/kunlun/README.md new file mode 120000 index 000000000..3ed44e130 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/kunlun/README.md @@ -0,0 +1 @@ +../cpu-gpu/README.md \ No newline at end of file diff --git a/examples/vision/segmentation/ppmatting/python/README.md b/examples/vision/segmentation/ppmatting/python/README.md deleted file mode 100755 index fb7d42617..000000000 --- a/examples/vision/segmentation/ppmatting/python/README.md +++ /dev/null @@ -1,81 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting Python Deployment Example - -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -This directory provides examples that `infer.py` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows -```bash -# Download the deployment example code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/matting/ppmatting/python - -# Download PP-Matting model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -# kunlunxin XPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin -``` - -The visualized result after running is as follows -
- - - - -
-## PP-Matting Python Interface - -```python -fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PP-Matting model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -### predict function - -> ```python -> PPMatting.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. - -### Class Member Variable - -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - - - -## Other Documents - -- [PP-Matting Model Description](..) -- [PP-Matting C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/ppmatting/python/README_CN.md b/examples/vision/segmentation/ppmatting/python/README_CN.md deleted file mode 100644 index 5e676a1cf..000000000 --- a/examples/vision/segmentation/ppmatting/python/README_CN.md +++ /dev/null @@ -1,80 +0,0 @@ -[English](README.md) | 简体中文 -# PP-Matting Python部署示例 - -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 - -```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/matting/ppmatting/python - -# 下载PP-Matting模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz -tar -xvf PP-Matting-512.tgz -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg -wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin -``` - -运行完成可视化结果如下图所示 -
- - - - -
-## PP-Matting Python接口 - -```python -fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -PP-Matting模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -**参数** - -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 - -### predict函数 - -> ```python -> PPMatting.predict(input_image) -> ``` -> -> 模型预测结口,输入图像直接输出检测结果。 -> -> **参数** -> -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** -> -> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - - -## 其它文档 - -- [PP-Matting 模型介绍](..) -- [PP-Matting C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) From ba5a1b79e1162e473e44dbc12a221cda13a0881a Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Mon, 13 Feb 2023 07:20:07 +0000 Subject: [PATCH 16/20] Update by comments --- docs/api_docs/cpp/vision_results_cn.md | 34 +++++++++++++---- docs/api_docs/cpp/vision_results_en.md | 38 +++++++++++++------ docs/cn/build_and_install/huawei_ascend.md | 2 +- docs/cn/faq/vision_result_related_problems.md | 2 +- .../segmentation/paddleseg/android/README.md | 4 +- .../paddleseg/android/README_CN.md | 4 +- 6 files changed, 58 insertions(+), 26 deletions(-) diff --git a/docs/api_docs/cpp/vision_results_cn.md b/docs/api_docs/cpp/vision_results_cn.md index 73af7f9ed..669343eb4 100644 --- a/docs/api_docs/cpp/vision_results_cn.md +++ b/docs/api_docs/cpp/vision_results_cn.md @@ -1,3 +1,5 @@ +[English](./vision_results_en.md) | 简体中文 + # 视觉模型预测结果说明 ## ClassifyResult 图像分类结果 @@ -6,7 +8,9 @@ ClassifyResult代码定义在`fastdeploy/vision/common/result.h`中,用于表 ### C++ 定义 -`fastdeploy::vision::ClassifyResult` +```c++ +fastdeploy::vision::ClassifyResult +``` ```c++ struct ClassifyResult { @@ -28,7 +32,9 @@ SegmentationResult代码定义在`fastdeploy/vision/common/result.h`中,用于 ### C++ 定义 -`fastdeploy::vision::SegmentationResult` +```c++ +fastdeploy::vision::SegmentationResult +``` ```c++ struct SegmentationResult { @@ -102,7 +108,9 @@ FaceAlignmentResult 代码定义在`fastdeploy/vision/common/result.h`中,用 ### C++ 定义 -`fastdeploy::vision::FaceAlignmentResult` +```c++ +fastdeploy::vision::FaceAlignmentResult +``` ```c++ struct FaceAlignmentResult { @@ -122,7 +130,9 @@ KeyPointDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中, ### C++ 定义 -`fastdeploy::vision::KeyPointDetectionResult` +```c++ +fastdeploy::vision::KeyPointDetectionResult +``` ```c++ struct KeyPointDetectionResult { @@ -152,7 +162,9 @@ struct KeyPointDetectionResult { FaceRecognitionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸识别模型对图像特征的embedding。 ### C++ 定义 -`fastdeploy::vision::FaceRecognitionResult` +```c++ +fastdeploy::vision::FaceRecognitionResult +``` ```c++ struct FaceRecognitionResult { @@ -174,7 +186,9 @@ MattingResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表 ### C++ 定义 -`fastdeploy::vision::MattingResult` +```c++ +fastdeploy::vision::MattingResult +``` ```c++ struct MattingResult { @@ -232,7 +246,9 @@ FaceDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用 ### C++ 定义 -`fastdeploy::vision::FaceDetectionResult` +```c++ +fastdeploy::vision::FaceDetectionResult +``` ```c++ struct FaceDetectionResult { @@ -258,7 +274,9 @@ HeadPoseResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表 ### C++ 定义 -`fastdeploy::vision::HeadPoseResult` +```c++ +fastdeploy::vision::HeadPoseResult +``` ```c++ struct HeadPoseResult { diff --git a/docs/api_docs/cpp/vision_results_en.md b/docs/api_docs/cpp/vision_results_en.md index 122e90293..356f66b8e 100644 --- a/docs/api_docs/cpp/vision_results_en.md +++ b/docs/api_docs/cpp/vision_results_en.md @@ -1,6 +1,6 @@ -# Description of Vision Results +English | [简体中文](./vision_results_cn.md) -本文档的中文版本参考[视觉模型预测结果说明](./vision_results_cn.md) +# Description of Vision Results ## Image Classification Result @@ -8,7 +8,9 @@ The ClassifyResult code is defined in `fastdeploy/vision/common/result.h`, and i ### C++ Definition -`fastdeploy::vision::ClassifyResult` +```c++ +fastdeploy::vision::ClassifyResult +``` ```c++ struct ClassifyResult { @@ -31,7 +33,9 @@ The SegmentationResult code is defined in `fastdeploy/vision/common/result.h`, i ### C++ Definition -``fastdeploy::vision::SegmentationResult`` +```c++ +fastdeploy::vision::SegmentationResult +``` ```c++ struct SegmentationResult { @@ -104,7 +108,9 @@ The FaceDetectionResult code is defined in `fastdeploy/vision/common/result.h`, ### C++ Definition -``fastdeploy::vision::FaceDetectionResult`` +```c++ +fastdeploy::vision::FaceDetectionResult +``` ```c++ struct FaceDetectionResult { @@ -131,7 +137,9 @@ The KeyPointDetectionResult code is defined in `fastdeploy/vision/common/result. ### C++ Definition -``fastdeploy::vision::KeyPointDetectionResult`` +```c++ +fastdeploy::vision::KeyPointDetectionResult +``` ```c++ struct KeyPointDetectionResult { @@ -161,7 +169,9 @@ struct KeyPointDetectionResult { The FaceRecognitionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the image features embedding in the face recognition model. ### C++ Definition -`fastdeploy::vision::FaceRecognitionResult` +```c++ +fastdeploy::vision::FaceRecognitionResult +``` ```c++ struct FaceRecognitionResult { @@ -180,8 +190,9 @@ struct FaceRecognitionResult { The MattingResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the predicted value of alpha transparency predicted and the predicted foreground, etc. ### C++ Definition - -``fastdeploy::vision::MattingResult`'' +```c++ +fastdeploy::vision::MattingResult +``` ```c++ struct MattingResult { @@ -239,8 +250,9 @@ struct OCRResult { The FaceAlignmentResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate face landmarks. ### C++ Definition - -`fastdeploy::vision::FaceAlignmentResult` +```c++ +fastdeploy::vision::FaceAlignmentResult +``` ```c++ struct FaceAlignmentResult { @@ -261,7 +273,9 @@ The HeadPoseResult code is defined in `fastdeploy/vision/common/result.h`, and i ### C++ Definition -``fastdeploy::vision::HeadPoseResult`'' +```c++ +fastdeploy::vision::HeadPoseResult +``` ```c++ struct HeadPoseResult { diff --git a/docs/cn/build_and_install/huawei_ascend.md b/docs/cn/build_and_install/huawei_ascend.md index b95311a28..4e621e305 100644 --- a/docs/cn/build_and_install/huawei_ascend.md +++ b/docs/cn/build_and_install/huawei_ascend.md @@ -126,7 +126,7 @@ python setup.py bdist_wheel ## 五.昇腾部署时开启FlyCV [FlyCV](https://github.com/PaddlePaddle/FlyCV) 是一款高性能计算机图像处理库, 针对ARM架构做了很多优化, 相比其他图像处理库性能更为出色. FastDeploy现在已经集成FlyCV, 用户可以在支持的硬件平台上使用FlyCV, 实现模型端到端推理性能的加速. -模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FLyCV使用文档](../faq/boost_cv_by_flycv.md). +模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FlyCV使用文档](../faq/boost_cv_by_flycv.md). ## 六.昇腾部署Demo参考 diff --git a/docs/cn/faq/vision_result_related_problems.md b/docs/cn/faq/vision_result_related_problems.md index 59ce781d8..0426a2d18 100644 --- a/docs/cn/faq/vision_result_related_problems.md +++ b/docs/cn/faq/vision_result_related_problems.md @@ -4,7 +4,7 @@ ## 将视觉模型预测结果转换为numpy格式 这里以[SegmentationResult](./segmentation_result_CN.md)为例,展示如何抽取SegmentationResult中的label_map或者score_map来转为numpy格式,同时也可以利用已有数据new SegmentationResult结构体 -``` +``` python import fastdeploy as fd import cv2 import numpy as np diff --git a/examples/vision/segmentation/paddleseg/android/README.md b/examples/vision/segmentation/paddleseg/android/README.md index ab06e1868..ad363015b 100644 --- a/examples/vision/segmentation/paddleseg/android/README.md +++ b/examples/vision/segmentation/paddleseg/android/README.md @@ -1,5 +1,5 @@ English | [简体中文](README_CN.md) -# PaddleSeg Android Demo for Target Detection +# PaddleSeg Android Demo for Image Segmentation For real-time portrait segmentation on Android, this demo has good ease of use and openness. You can run your own training model in the demo. @@ -10,7 +10,7 @@ For real-time portrait segmentation on Android, this demo has good ease of use a ## Deployment Steps -1. Target detection PaddleSeg Demo is located in `fastdeploy/examples/vision/segmentation/paddleseg/android` directory. +1. Image Segmentation PaddleSeg Demo is located in `fastdeploy/examples/vision/segmentation/paddleseg/android` directory. 2. Please use Android Studio to open paddleseg/android project. 3. Connect your phone to your computer, turn on USB debugging and file transfer mode, and connect your own mobile device on Android Studio (your phone needs to be enabled to allow software installation from USB). diff --git a/examples/vision/segmentation/paddleseg/android/README_CN.md b/examples/vision/segmentation/paddleseg/android/README_CN.md index 30938b697..1414e8ae9 100644 --- a/examples/vision/segmentation/paddleseg/android/README_CN.md +++ b/examples/vision/segmentation/paddleseg/android/README_CN.md @@ -1,5 +1,5 @@ [English](README.md) | 简体中文 -# 目标检测 PaddleSeg Android Demo 使用文档 +# 图像分割 PaddleSeg Android Demo 使用文档 在 Android 上实现实时的人像分割功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 @@ -10,7 +10,7 @@ ## 部署步骤 -1. 目标检测 PaddleSeg Demo 位于 `path/to/paddleseg/android` 目录 +1. 图像分割 PaddleSeg Demo 位于 `path/to/paddleseg/android` 目录 2. 用 Android Studio 打开 paddleseg/android 工程 3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) From 1d26cc59203772def073f5cbeccbb78d224b1d0a Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Mon, 13 Feb 2023 11:30:38 +0000 Subject: [PATCH 17/20] Delete redundant directory --- .../segmentation/paddleseg/cpp/README.md | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100755 examples/vision/segmentation/paddleseg/cpp/README.md diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpp/README.md deleted file mode 100755 index 572e38078..000000000 --- a/examples/vision/segmentation/paddleseg/cpp/README.md +++ /dev/null @@ -1,98 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example - -This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. - -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) - -Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. - -```bash -mkdir build -cd build -# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above -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 - -# Download Unet model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz -tar -xvf Unet_cityscapes_without_argmax_infer.tgz -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - - -# CPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# TensorRT inference on GPU -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# kunlunxin XPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 -# Huawei Ascend Inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4 -``` - -The visualized result after running is as follows -
- -
- -The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: -- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -## PaddleSeg C++ Interface - -### PaddleSeg Class - -```c++ -fastdeploy::vision::segmentation::PaddleSegModel( - const string& model_file, - const string& params_file = "", - const string& config_file, - const RuntimeOption& runtime_option = RuntimeOption(), - const ModelFormat& model_format = ModelFormat::PADDLE) -``` - -PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path -> * **config_file**(str): Inference deployment configuration file -> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(ModelFormat): Model format. Paddle format by default - -#### Predict Function - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **im**: Input images in HWC or BGR format -> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult - -### Class Member Variable -#### Pre-processing Parameter -Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results - -> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` - -#### Post-processing Parameter -> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) From e8ac9be57b0eefa80751c4d58d071b0b017092e2 Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Mon, 13 Feb 2023 20:02:44 +0800 Subject: [PATCH 18/20] Update README.md --- examples/vision/segmentation/paddleseg/quantize/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/vision/segmentation/paddleseg/quantize/README.md b/examples/vision/segmentation/paddleseg/quantize/README.md index 708d21e93..632772247 100644 --- a/examples/vision/segmentation/paddleseg/quantize/README.md +++ b/examples/vision/segmentation/paddleseg/quantize/README.md @@ -12,6 +12,7 @@ FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输 用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) | 模型 | 量化方式 | +|:----- | :-- | | [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) |量化蒸馏训练 | 量化后模型的Benchmark比较,请参考[量化模型 Benchmark](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quantize.md) From fb1d95c7c91f4131e87666fe5c129a9f4233b95d Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 15 Feb 2023 07:11:41 +0000 Subject: [PATCH 19/20] Update docs --- docs/api/vision_results/segmentation_result.md | 4 ++-- .../api/vision_results/segmentation_result_CN.md | 4 ++-- docs/api_docs/cpp/vision_results_cn.md | 2 +- docs/api_docs/cpp/vision_results_en.md | 2 +- .../paddleseg/amlogic/a311d/README.md | 13 ++++++++++++- .../segmentation/paddleseg/kunlun/README.md | 12 +++++++++++- .../paddleseg/rockchip/rv1126/README.md | 16 ++++++++++++++-- .../serving/{README_CN.md => README.md} | 4 ++-- .../serving/fastdeploy_serving/README.md | 6 +++++- .../serving/fastdeploy_serving/README_CN.md | 3 +++ .../paddleseg/serving/simple_serving/README.md | 3 ++- .../serving/simple_serving/README_CN.md | 2 ++ .../segmentation/paddleseg/sophgo/README.md | 5 +++++ 13 files changed, 62 insertions(+), 14 deletions(-) rename examples/vision/segmentation/paddleseg/serving/{README_CN.md => README.md} (93%) diff --git a/docs/api/vision_results/segmentation_result.md b/docs/api/vision_results/segmentation_result.md index 426d38d1e..0852254ea 100644 --- a/docs/api/vision_results/segmentation_result.md +++ b/docs/api/vision_results/segmentation_result.md @@ -19,7 +19,7 @@ struct SegmentationResult { ``` - **label_map**: Member variable which indicates the segmentation category of each pixel in a single image. `label_map.size()` indicates the number of pixel points of a image. -- **score_map**: Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **score_map**: Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. - **shape**: Member variable which indicates the shape of the output image as H\*W. - **Clear()**: Member function used to clear the results stored in the structure. - **Str()**: Member function used to output the information in the structure as string (for Debug). @@ -29,5 +29,5 @@ struct SegmentationResult { `fastdeploy.vision.SegmentationResult` - **label_map**(list of int): Member variable which indicates the segmentation category of each pixel in a single image. -- **score_map**(list of float): Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **score_map**(list of float): Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. - **shape**(list of int): Member variable which indicates the shape of the output image as H\*W. diff --git a/docs/api/vision_results/segmentation_result_CN.md b/docs/api/vision_results/segmentation_result_CN.md index 0b3e22ee1..42b6eaf73 100644 --- a/docs/api/vision_results/segmentation_result_CN.md +++ b/docs/api/vision_results/segmentation_result_CN.md @@ -20,7 +20,7 @@ struct SegmentationResult { ``` - **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 -- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`apply_softmax=True`) +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 - **shape**: 成员变量,表示输出图片的shape,为H\*W - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 @@ -31,5 +31,5 @@ struct SegmentationResult { `fastdeploy.vision.SegmentationResult` - **label_map**(list of int): 成员变量,表示单张图片每个像素点的分割类别 -- **score_map**(list of float): 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/python/)`apply_softmax=true`) +- **score_map**(list of float): 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 - **shape**(list of int): 成员变量,表示输出图片的shape,为H\*W diff --git a/docs/api_docs/cpp/vision_results_cn.md b/docs/api_docs/cpp/vision_results_cn.md index 669343eb4..73b3b4e6d 100644 --- a/docs/api_docs/cpp/vision_results_cn.md +++ b/docs/api_docs/cpp/vision_results_cn.md @@ -49,7 +49,7 @@ struct SegmentationResult { ``` - **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 -- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`apply_softmax=True`) +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 - **shape**: 成员变量,表示输出图片的shape,为H\*W - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 diff --git a/docs/api_docs/cpp/vision_results_en.md b/docs/api_docs/cpp/vision_results_en.md index 356f66b8e..7feb3793c 100644 --- a/docs/api_docs/cpp/vision_results_en.md +++ b/docs/api_docs/cpp/vision_results_en.md @@ -49,7 +49,7 @@ struct SegmentationResult { ``` - **label_map**: Member variable which indicates the segmentation category of each pixel in a single image. `label_map.size()` indicates the number of pixel points of a image. -- **score_map**: Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **score_map**: Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. - **shape**: Member variable which indicates the shape of the output image as H\*W. - **Clear()**: Member function used to clear the results stored in the structure. - **Str()**: Member function used to output the information in the structure as string (for Debug). diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md index c9a04fd41..80a85d8da 100644 --- a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md @@ -1,8 +1,19 @@ [English](README.md) | 简体中文 -# PaddleSeg在晶晨A311D上通过FastDeploy部署模型 +# PaddleSeg在晶晨NPU上通过FastDeploy部署模型 + +## PaddleSeg支持部署的晶晨芯片型号 +支持如下芯片的部署 +- Amlogic A311D +- Amlogic C308X +- Amlogic S905D3 + +本示例基于晶晨A311D来介绍如何使用FastDeploy部署PaddleSeg模型 + 晶晨A311D是一款先进的AI应用处理器。PaddleSeg支持通过FastDeploy在A311D上基于Paddle-Lite部署相关Segmentation模型 +>> **注意**:需要注意的是,芯原(verisilicon)作为 IP 设计厂商,本身并不提供实体SoC产品,而是授权其 IP 给芯片厂商,如:晶晨(Amlogic),瑞芯微(Rockchip)等。因此本文是适用于被芯原授权了 NPU IP 的芯片产品。只要芯片产品没有大副修改芯原的底层库,则该芯片就可以使用本文档作为 Paddle Lite 推理部署的参考和教程。在本文中,晶晨 SoC 中的 NPU 和 瑞芯微 SoC 中的 NPU 统称为芯原 NPU。 + ## 晶晨A311D支持的PaddleSeg模型 - [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) diff --git a/examples/vision/segmentation/paddleseg/kunlun/README.md b/examples/vision/segmentation/paddleseg/kunlun/README.md index cdb727988..305ce688c 100644 --- a/examples/vision/segmentation/paddleseg/kunlun/README.md +++ b/examples/vision/segmentation/paddleseg/kunlun/README.md @@ -1,6 +1,16 @@ [English](README.md) | 简体中文 -# PaddleSeg模型高性能全场景部署方案-FastDeploy +# PaddleSeg利用FastDeploy在昆仑芯上部署模型 + +## PaddleSeg支持部署的昆仑芯的芯片型号 +支持如下芯片的部署 +- 昆仑 818-100(推理芯片) +- 昆仑 818-300(训练芯片) + +支持如下芯片的设备 +- K100/K200 昆仑 AI 加速卡 +- R200 昆仑芯 AI 加速卡 + PaddleSeg支持利用FastDeploy在昆仑芯片上部署Segmentation模型 diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md index 12b9a0d05..e03960f09 100644 --- a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md @@ -1,6 +1,18 @@ [English](README.md) | 简体中文 -# PaddleSeg在瑞芯微 RV1126上通过FastDeploy部署模型 -瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。PaddleSeg支持通过FastDeploy在RV1126上基于Paddle-Lite部署相关Segmentation模型 +# PaddleSeg在瑞芯微NPU上通过FastDeploy部署模型 + +## PaddleSeg支持部署的瑞芯微的芯片型号 +支持如下芯片的部署 +- Rockchip RV1109 +- Rockchip RV1126 +- Rockchip RK1808 + +>> **注意**:需要注意的是,芯原(verisilicon)作为 IP 设计厂商,本身并不提供实体SoC产品,而是授权其 IP 给芯片厂商,如:晶晨(Amlogic),瑞芯微(Rockchip)等。因此本文是适用于被芯原授权了 NPU IP 的芯片产品。只要芯片产品没有大副修改芯原的底层库,则该芯片就可以使用本文档作为 Paddle Lite 推理部署的参考和教程。在本文中,晶晨 SoC 中的 NPU 和 瑞芯微 SoC 中的 NPU 统称为芯原 NPU。 +瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。 + +本示例基于RV1126来介绍如何使用FastDeploy部署PaddleSeg模型 + +PaddleSeg支持通过FastDeploy在RV1126上基于Paddle-Lite部署相关Segmentation模型 ## 瑞芯微 RV1126支持的PaddleSeg模型 diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/README.md similarity index 93% rename from examples/vision/segmentation/paddleseg/serving/README_CN.md rename to examples/vision/segmentation/paddleseg/serving/README.md index 803465941..00074183d 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/README.md @@ -2,8 +2,8 @@ # PaddleSeg 使用 FastDeploy 服务化部署 Segmentation 模型 ## FastDeploy 服务化部署介绍 在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving -- simple_serving基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性。 -- fastdeploy_serving基于Triton Inference Server框架,是一套完备且性能卓越的服务化部署框架,可用于实际生产。 +- simple_serving:适用于只需要通过http等调用AI推理任务,没有高并发需求的场景。simple_serving基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性 +- fastdeploy_serving:适用于高并发、高吞吐量请求的场景。基于Triton Inference Server框架,是一套可用于实际生产的完备且性能卓越的服务化部署框架 ## 模型版本说明 diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md index c5b6dd41f..120b3994a 100644 --- a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md @@ -1,5 +1,9 @@ English | [简体中文](README_CN.md) -# PaddleSegmentation Serving Deployment Demo +# PaddleSeg Serving Deployment Demo + +The PaddleSeg serving deployment Demo is built with FastDeploy Serving. FastDeploy Serving is a service-oriented deployment framework suitable for high-concurrency and high-throughput requests encapsulated based on the Triton Inference Server framework. It is a complete and high-performance service-oriented deployment framework that can be used in actual production. If you don’t need high-concurrency and high-throughput scenarios, and just want to quickly test the feasibility of online deployment of the model, please refer to [fastdeploy_serving](../simple_serving/) + +## Environment Before serving deployment, it is necessary to confirm the hardware and software environment requirements of the service image and the image pull command, please refer to [FastDeploy service deployment](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README.md) diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md index ae346cb5b..a07a773e5 100644 --- a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md @@ -1,6 +1,9 @@ [English](README.md) | 简体中文 # PaddleSeg 服务化部署示例 +PaddleSeg 服务化部署示例是利用FastDeploy Serving搭建的服务化部署示例。FastDeploy Serving是基于Triton Inference Server框架封装的适用于高并发、高吞吐量请求的服务化部署框架,是一套可用于实际生产的完备且性能卓越的服务化部署框架。如没有高并发,高吞吐场景的需求,只想快速检验模型线上部署的可行性,请参考[fastdeploy_serving](../simple_serving/) + +## 部署环境准备 在服务化部署前,需确认服务化镜像的软硬件环境要求和镜像拉取命令,请参考[FastDeploy服务化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README_CN.md) diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md index 686164ad7..ea8223ecc 100644 --- a/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md @@ -1,7 +1,8 @@ English | [简体中文](README_CN.md) -# PaddleSegmentation Python Simple Serving Demo +# PaddleSeg Python Simple Serving Demo +PaddleSeg Python Simple serving is an example of serving deployment built by FastDeploy based on the Flask framework that can quickly verify the feasibility of online model deployment. It completes AI inference tasks based on http requests, and is suitable for simple scenarios without concurrent inference task. For high concurrency and high throughput scenarios, please refer to [fastdeploy_serving](../fastdeploy_serving/) ## Environment diff --git a/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md index db06103ed..afc1325dc 100644 --- a/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md @@ -2,6 +2,8 @@ # PaddleSeg Python轻量服务化部署示例 +PaddleSeg Python轻量服务化部署是FastDeploy基于Flask框架搭建的可快速验证线上模型部署可行性的服务化部署示例,基于http请求完成AI推理任务,适用于无并发推理的简单场景,如有高并发,高吞吐场景的需求请参考[fastdeploy_serving](../fastdeploy_serving/) + ## 部署环境准备 在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md index 366656a75..67f636486 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README.md @@ -1,5 +1,10 @@ [English](README.md) | 简体中文 # PaddleSeg在算能(Sophgo)硬件上通过FastDeploy部署模型 + +## PaddleSeg支持部署的Sophgo的芯片型号 +支持如下芯片的部署 +- Sophgo 1684X + PaddleSeg支持通过FastDeploy在算能TPU上部署相关Segmentation模型 ## 算能硬件支持的PaddleSeg模型 From 3835d066540a1a40886681285035d8ebeec589ab Mon Sep 17 00:00:00 2001 From: felixhjh <852142024@qq.com> Date: Wed, 15 Feb 2023 07:33:45 +0000 Subject: [PATCH 20/20] Save png format image in matting example to support transparent background --- examples/vision/matting/modnet/cpp/infer.cc | 6 +++--- examples/vision/matting/modnet/python/infer.py | 2 +- examples/vision/matting/rvm/cpp/infer.cc | 6 +++--- examples/vision/matting/rvm/python/infer.py | 2 +- examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/vision/matting/modnet/cpp/infer.cc b/examples/vision/matting/modnet/cpp/infer.cc index aa280eddd..1fef35218 100644 --- a/examples/vision/matting/modnet/cpp/infer.cc +++ b/examples/vision/matting/modnet/cpp/infer.cc @@ -35,7 +35,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -65,7 +65,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -96,7 +96,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; diff --git a/examples/vision/matting/modnet/python/infer.py b/examples/vision/matting/modnet/python/infer.py index 37c749010..0be874271 100644 --- a/examples/vision/matting/modnet/python/infer.py +++ b/examples/vision/matting/modnet/python/infer.py @@ -57,7 +57,7 @@ print(result) # 可视化结果 vis_im = fd.vision.vis_matting_alpha(im, result) vis_im_with_bg = fd.vision.swap_background(im, bg, result) -cv2.imwrite("visualized_result_fg.jpg", vis_im) +cv2.imwrite("visualized_result_fg.png", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" diff --git a/examples/vision/matting/rvm/cpp/infer.cc b/examples/vision/matting/rvm/cpp/infer.cc index 9e2a2aa5d..4ca975216 100755 --- a/examples/vision/matting/rvm/cpp/infer.cc +++ b/examples/vision/matting/rvm/cpp/infer.cc @@ -41,7 +41,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -69,7 +69,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -103,7 +103,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result.jpg " "and ./visualized_result_fg.jpg" << std::endl; diff --git a/examples/vision/matting/rvm/python/infer.py b/examples/vision/matting/rvm/python/infer.py index 0e9eb6b21..b2ade3c0b 100755 --- a/examples/vision/matting/rvm/python/infer.py +++ b/examples/vision/matting/rvm/python/infer.py @@ -105,7 +105,7 @@ if args.image is not None: # 可视化结果 vis_im = fd.vision.vis_matting(im, result) vis_im_with_bg = fd.vision.swap_background(im, bg, result) - cv2.imwrite("visualized_result_fg.jpg", vis_im) + cv2.imwrite("visualized_result_fg.png", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc index 975f0e76b..9f1e69d5e 100644 --- a/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc @@ -44,7 +44,7 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file, auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -74,7 +74,7 @@ void KunlunXinInfer(const std::string& model_dir, const std::string& image_file, auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -143,7 +143,7 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl;