[Docs] Pick seg fastdeploy docs from PaddleSeg (#1482)

* [Docs] Pick seg fastdeploy docs from PaddleSeg

* [Docs] update seg docs

* [Docs] Add c&csharp examples for seg

* [Docs] Add c&csharp examples for seg

* [Doc] Update paddleseg README.md

* Update README.md
This commit is contained in:
DefTruth
2023-03-17 11:22:46 +08:00
committed by GitHub
parent 3b1343c726
commit 5b143219ce
177 changed files with 1019 additions and 815 deletions

View File

@@ -0,0 +1,42 @@
[English](README.md) | 简体中文
# PaddleSeg 算能 Python部署示例
## 1. 部署环境准备
在部署前需自行编译基于算能硬件的FastDeploy python wheel包并安装参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境)
本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成
## 2. 部署模型准备
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../README.md)或者[自行导出PaddleSeg部署模型](../README.md)。
## 3. 运行部署示例
```bash
# 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/segmentation/semantic_segmentation/sophgo/python
# # 如果您希望从PaddleSeg下载示例代码请运行
# git clone https://github.com/PaddlePaddle/PaddleSeg.git
# # 注意如果当前分支找不到下面的fastdeploy测试代码请切换到develop分支
# # git checkout develop
# cd PaddleSeg/deploy/fastdeploy/semantic_segmentation/sophgo/python
# 下载图片
wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
# PaddleSeg模型转换为bmodel模型
将Paddle模型转换为SOPHGO bmodel模型转换步骤参考[文档](../README_CN.md)
# 推理
python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png
# 运行完成后返回结果如下所示
运行结果保存在sophgo_img.png中
```
## 4. 更多指南
- [PP-LiteSeg SOPHGO C++部署](../cpp)
- [转换 PP-LiteSeg SOPHGO模型文档](../README.md)
## 5. 常见问题
- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md)

View File

@@ -0,0 +1,45 @@
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 model.")
parser.add_argument(
"--config_file", required=True, help="Path of config file.")
parser.add_argument(
"--image", type=str, required=True, help="Path of test image file.")
return parser.parse_args()
args = parse_arguments()
# 配置runtime加载模型
runtime_option = fd.RuntimeOption()
runtime_option.use_sophgo()
model_file = args.model
params_file = ""
config_file = args.config_file
model = fd.vision.segmentation.PaddleSegModel(
model_file,
params_file,
config_file,
runtime_option=runtime_option,
model_format=fd.ModelFormat.SOPHGO)
# 预测图片分类结果
im_org = cv2.imread(args.image)
#bmodel 是静态模型,模型输入固定,这里设置为[512, 512]
im = cv2.resize(im_org, [512, 512], interpolation=cv2.INTER_LINEAR)
result = model.predict(im)
print(result)
# 预测结果可视化
vis_im = fd.vision.vis_segmentation(im, result, weight=0.5)
cv2.imwrite("sophgo_img.png", vis_im)