[Docs] Pick paddleclas fastdeploy docs from PaddleClas (#1654)

* Adjust folders structures in paddleclas

* remove useless files

* Update sophgo

* improve readme
This commit is contained in:
yunyaoXYY
2023-03-23 13:06:09 +08:00
committed by GitHub
parent ab65557121
commit c91e99b5f5
90 changed files with 2005 additions and 2584 deletions

View File

@@ -1,33 +1,39 @@
English | [简体中文](README_CN.md)
# PaddleClas Python Deployment Example
# PaddleClas Python部署示例
本目录下提供`infer.py`快速完成 ResNet50_vd 在SOPHGO TPU上部署的示例.
Before deployment, the following step need to be confirmed:
- 1. Hardware and software environment meets the requirements. Please refer to [FastDeploy Environment Requirement](../../../../../../docs/en/build_and_install/sophgo.md).
## 1. 部署环境准备
`infer.py` in this directory provides a quick example of deployment of the ResNet50_vd model on SOPHGO TPU. Please run the following script:
在部署前需自行编译基于算能硬件的FastDeploy python wheel包并安装参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境)
## 2.运行部署示例
```bash
# Download the sample deployment code.
# 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/classification/paddleclas/sophgo/python
cd FastDeploy/examples/vision/classification/paddleclas/sophgo/python
# Download images.
# 如果您希望从PaddleClas下载示例代码请运行
git clone https://github.com/PaddlePaddle/PaddleClas.git
# 注意如果当前分支找不到下面的fastdeploy测试代码请切换到develop分支
git checkout develop
cd PaddleClas/deploy/fastdeploy/sophgo/python
# 下载图片
wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
# Inference. Need to manually set the model, configuration file and image path used for inference.
# 推理转换好的模型
# 手动设置推理使用的模型、配置文件和图片路径
python3 infer.py --auto False --model_file ./bmodel/resnet50_1684x_f32.bmodel --config_file ResNet50_vd_infer/inference_cls.yaml --image ILSVRC2012_val_00000010.jpeg
# Automatic completion of downloading data - model compilation - inference, no need to set up model, configuration file and image paths.
# 自动完成下载数据-模型编译-推理,不需要设置模型、配置文件和图片路径
python3 infer.py --auto True --model '' --config_file '' --image ''
# The returned result.
# 运行完成后返回结果如下所示
ClassifyResult(
label_ids: 153,
scores: 0.684570,
)
```
## Other Documents
- [ResNet50_vd C++ Deployment](../cpp)
- [Converting ResNet50_vd SOPHGO model](../README.md)
## 4. 其它文档
- [ResNet50_vd C++部署](../python)
- [转换ResNet50_vd SOPHGO模型文档](../README.md)

View File

@@ -1,34 +0,0 @@
[English](README.md) | 简体中文
# PaddleClas Python部署示例
在部署前,需确认以下步骤
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md)
本目录下提供`infer.py`快速完成 ResNet50_vd 在SOPHGO TPU上部署的示例。执行如下脚本即可完成
```bash
# 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/classification/paddleclas/sophgo/python
# 下载图片
wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
# 手动设置推理使用的模型、配置文件和图片路径
python3 infer.py --auto False --model_file ./bmodel/resnet50_1684x_f32.bmodel --config_file ResNet50_vd_infer/inference_cls.yaml --image ILSVRC2012_val_00000010.jpeg
# 自动完成下载数据-模型编译-推理,不需要设置模型、配置文件和图片路径
python3 infer.py --auto True --model '' --config_file '' --image ''
# 运行完成后返回结果如下所示
ClassifyResult(
label_ids: 153,
scores: 0.684570,
)
```
## 其它文档
- [ResNet50_vd C++部署](../cpp)
- [转换ResNet50_vd SOPHGO模型文档](../README.md)

View File

@@ -3,13 +3,18 @@ import cv2
import os
from subprocess import run
def parse_arguments():
import argparse
import ast
parser = argparse.ArgumentParser()
parser.add_argument("--auto", required=True, help="Auto download, convert, compile and infer if True")
parser.add_argument(
"--auto",
required=True,
help="Auto download, convert, compile and infer if True")
parser.add_argument("--model", required=True, help="Path of bmodel")
parser.add_argument("--config_file", required=True, help="Path of config file")
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.")
parser.add_argument(
@@ -17,6 +22,7 @@ def parse_arguments():
return parser.parse_args()
def download():
cmd_str = 'wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz'
jpg_str = 'wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg'
@@ -27,27 +33,33 @@ def download():
run(jpg_str, shell=True)
run(tar_str, shell=True)
def paddle2onnx():
cmd_str = 'paddle2onnx --model_dir ResNet50_vd_infer \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--save_file ResNet50_vd_infer.onnx \
--enable_dev_version True'
print(cmd_str)
run(cmd_str, shell=True)
def mlir_prepare():
mlir_path = os.getenv("MODEL_ZOO_PATH")
mlir_path = mlir_path[:-13]
cmd_list = ['mkdir ResNet50',
'cp -rf ' + os.path.join(mlir_path, 'regression/dataset/COCO2017/') + ' ./ResNet50',
'cp -rf ' + os.path.join(mlir_path, 'regression/image/') + ' ./ResNet50',
'cp ResNet50_vd_infer.onnx ./ResNet50/',
'mkdir ./ResNet50/workspace']
cmd_list = [
'mkdir ResNet50', 'cp -rf ' + os.path.join(
mlir_path, 'regression/dataset/COCO2017/') + ' ./ResNet50',
'cp -rf ' + os.path.join(mlir_path,
'regression/image/') + ' ./ResNet50',
'cp ResNet50_vd_infer.onnx ./ResNet50/', 'mkdir ./ResNet50/workspace'
]
for str in cmd_list:
print(str)
run(str, shell=True)
def onnx2mlir():
cmd_str = 'model_transform.py \
--model_name ResNet50_vd_infer \
@@ -61,11 +73,13 @@ def onnx2mlir():
--test_input ../image/dog.jpg \
--test_result ./ResNet50_vd_infer_top_outputs.npz \
--mlir ./ResNet50_vd_infer.mlir'
print(cmd_str)
os.chdir('./ResNet50/workspace/')
run(cmd_str, shell=True)
os.chdir('../../')
def mlir2bmodel():
cmd_str = 'model_deploy.py \
--mlir ./ResNet50_vd_infer.mlir \
@@ -74,6 +88,7 @@ def mlir2bmodel():
--test_input ./ResNet50_vd_infer_in_f32.npz \
--test_reference ./ResNet50_vd_infer_top_outputs.npz \
--model ./ResNet50_vd_infer_1684x_f32.bmodel'
print(cmd_str)
os.chdir('./ResNet50/workspace')
run(cmd_str, shell=True)
@@ -82,7 +97,7 @@ def mlir2bmodel():
args = parse_arguments()
if(args.auto):
if (args.auto):
download()
paddle2onnx()
mlir_prepare()