Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
354c36d4
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
354c36d4
编写于
3月 21, 2023
作者:
Y
yunyaoXYY
提交者:
Wei Shengyu
3月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update sophgo
上级
60ec4bab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
10 deletion
+96
-10
deploy/fastdeploy/sophgo/python/infer.py
deploy/fastdeploy/sophgo/python/infer.py
+92
-8
docs/zh_CN/fastdeploy/sophgo/python/README.md
docs/zh_CN/fastdeploy/sophgo/python/README.md
+4
-2
未找到文件。
deploy/fastdeploy/sophgo/python/infer.py
浏览文件 @
354c36d4
import
fastdeploy
as
fd
import
cv2
import
os
from
subprocess
import
run
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."
)
"--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
(
"--image"
,
type
=
str
,
required
=
True
,
help
=
"Path of test image file."
)
parser
.
add_argument
(
...
...
@@ -18,16 +23,95 @@ 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'
tar_str
=
'tar xvf ResNet50_vd_infer.tgz'
if
not
os
.
path
.
exists
(
'ResNet50_vd_infer.tgz'
):
run
(
cmd_str
,
shell
=
True
)
if
not
os
.
path
.
exists
(
'ILSVRC2012_val_00000010.jpeg'
):
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'
]
for
str
in
cmd_list
:
print
(
str
)
run
(
str
,
shell
=
True
)
def
onnx2mlir
():
cmd_str
=
'model_transform.py \
--model_name ResNet50_vd_infer \
--model_def ../ResNet50_vd_infer.onnx \
--input_shapes [[1,3,224,224]] \
--mean 0.0,0.0,0.0 \
--scale 0.0039216,0.0039216,0.0039216 \
--keep_aspect_ratio \
--pixel_format rgb \
--output_names save_infer_model/scale_0.tmp_1 \
--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 \
--quantize F32 \
--chip bm1684x \
--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
)
os
.
chdir
(
'../../'
)
args
=
parse_arguments
()
# 配置runtime,加载模型
if
(
args
.
auto
):
download
()
paddle2onnx
()
mlir_prepare
()
onnx2mlir
()
mlir2bmodel
()
# config runtime and load the model
runtime_option
=
fd
.
RuntimeOption
()
runtime_option
.
use_sophgo
()
model_file
=
args
.
model
model_file
=
'./ResNet50/workspace/ResNet50_vd_infer_1684x_f32.bmodel'
if
args
.
auto
else
args
.
model
params_file
=
""
config_file
=
args
.
config_file
config_file
=
'./ResNet50_vd_infer/inference_cls.yaml'
if
args
.
auto
else
args
.
config_file
image_file
=
'./ILSVRC2012_val_00000010.jpeg'
if
args
.
auto
else
args
.
image
model
=
fd
.
vision
.
classification
.
PaddleClasModel
(
model_file
,
params_file
,
...
...
@@ -35,7 +119,7 @@ model = fd.vision.classification.PaddleClasModel(
runtime_option
=
runtime_option
,
model_format
=
fd
.
ModelFormat
.
SOPHGO
)
#
预测图片分类结果
im
=
cv2
.
imread
(
args
.
imag
e
)
#
predict the results of image classification
im
=
cv2
.
imread
(
image_fil
e
)
result
=
model
.
predict
(
im
,
args
.
topk
)
print
(
result
)
docs/zh_CN/fastdeploy/sophgo/python/README.md
浏览文件 @
354c36d4
...
...
@@ -9,7 +9,6 @@
## 2.运行部署示例
```
bash
# 下载部署示例代码
# 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd
FastDeploy/examples/vision/classification/paddleclas/sophgo/python
...
...
@@ -23,7 +22,10 @@ cd PaddleClas/deploy/fastdeploy/sophgo/python
wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
# 推理转换好的模型
python3 infer.py
--model_file
./bmodel/resnet50_1684x_f32.bmodel
--config_file
ResNet50_vd_infer/inference_cls.yaml
--image
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
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录