Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
e3801c55
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看板
未验证
提交
e3801c55
编写于
12月 10, 2020
作者:
T
Tingquan Gao
提交者:
GitHub
12月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the bug about calling create_predictor repeatedly in hubserving (#462)
上级
022a4114
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
51 addition
and
49 deletion
+51
-49
deploy/hubserving/clas/module.py
deploy/hubserving/clas/module.py
+3
-2
deploy/hubserving/readme.md
deploy/hubserving/readme.md
+1
-1
deploy/hubserving/readme_en.md
deploy/hubserving/readme_en.md
+1
-1
tools/infer/predict.py
tools/infer/predict.py
+16
-45
tools/infer/utils.py
tools/infer/utils.py
+30
-0
未找到文件。
deploy/hubserving/clas/module.py
浏览文件 @
e3801c55
...
...
@@ -25,7 +25,7 @@ import numpy as np
import
paddlehub
as
hub
import
tools.infer.predict
as
paddle_predict
from
tools.infer.utils
import
Base64ToCV2
from
tools.infer.utils
import
Base64ToCV2
,
create_paddle_predictor
from
deploy.hubserving.clas.params
import
read_params
...
...
@@ -96,6 +96,7 @@ class ClasSystem(hub.Module):
assert
predicted_data
!=
[],
"There is not any image to be predicted. Please check the input data."
predictor
=
create_paddle_predictor
(
self
.
args
)
all_results
=
[]
for
img
in
predicted_data
:
if
img
is
None
:
...
...
@@ -106,7 +107,7 @@ class ClasSystem(hub.Module):
self
.
args
.
image_file
=
img
self
.
args
.
top_k
=
top_k
classes
,
scores
=
paddle_predict
.
main
(
self
.
args
)
classes
,
scores
=
paddle_predict
.
predict
(
self
.
args
,
predictor
)
elapse
=
time
.
time
()
-
starttime
logger
.
info
(
"Predict time: {}"
.
format
(
elapse
))
...
...
deploy/hubserving/readme.md
浏览文件 @
e3801c55
...
...
@@ -138,7 +138,7 @@ hub serving start -c deploy/hubserving/clas/config.json
```
hub uninstall clas_system
```
- 4、 安装修改后的新服务包
```
hub install deploy/hubserving/clas
_system
/
```
```
hub install deploy/hubserving/clas/
```
- 5、重新启动服务
```
hub serving start -m clas_system
```
deploy/hubserving/readme_en.md
浏览文件 @
e3801c55
...
...
@@ -144,7 +144,7 @@ hub uninstall clas_system
```
-
4. Install modified service module
```
shell
hub
install
deploy/hubserving/clas
_system
/
hub
install
deploy/hubserving/clas/
```
-
5. Restart service
```
shell
...
...
tools/infer/predict.py
浏览文件 @
e3801c55
...
...
@@ -19,51 +19,8 @@ import numpy as np
import
cv2
import
time
from
paddle.inference
import
Config
from
paddle.inference
import
create_predictor
def
create_paddle_predictor
(
args
):
config
=
Config
(
args
.
model_file
,
args
.
params_file
)
if
args
.
use_gpu
:
config
.
enable_use_gpu
(
args
.
gpu_mem
,
0
)
else
:
config
.
disable_gpu
()
if
args
.
enable_mkldnn
:
# cache 10 different shapes for mkldnn to avoid memory leak
config
.
set_mkldnn_cache_capacity
(
10
)
config
.
enable_mkldnn
()
config
.
disable_glog_info
()
config
.
switch_ir_optim
(
args
.
ir_optim
)
# default true
if
args
.
use_tensorrt
:
config
.
enable_tensorrt_engine
(
precision_mode
=
Config
.
Precision
.
Half
if
args
.
use_fp16
else
Config
.
Precision
.
Float32
,
max_batch_size
=
args
.
batch_size
)
config
.
enable_memory_optim
()
# use zero copy
config
.
switch_use_feed_fetch_ops
(
False
)
predictor
=
create_predictor
(
config
)
return
predictor
def
main
(
args
):
if
not
args
.
enable_benchmark
:
assert
args
.
batch_size
==
1
assert
args
.
use_fp16
is
False
else
:
assert
args
.
use_gpu
is
True
assert
args
.
model
is
not
None
# HALF precission predict only work when using tensorrt
if
args
.
use_fp16
is
True
:
assert
args
.
use_tensorrt
is
True
predictor
=
create_paddle_predictor
(
args
)
def
predict
(
args
,
predictor
):
input_names
=
predictor
.
get_input_names
()
input_tensor
=
predictor
.
get_input_handle
(
input_names
[
0
])
...
...
@@ -91,10 +48,11 @@ def main(args):
output
=
output_tensor
.
copy_to_cpu
()
classes
,
scores
=
utils
.
postprocess
(
output
,
args
)
if
args
.
hubserving
:
return
classes
,
scores
print
(
"Current image file: {}"
.
format
(
args
.
image_file
))
print
(
"
\t
top-1 class: {0}"
.
format
(
classes
[
0
]))
print
(
"
\t
top-1 score: {0}"
.
format
(
scores
[
0
]))
else
:
for
i
in
range
(
0
,
test_num
+
10
):
inputs
=
np
.
random
.
rand
(
args
.
batch_size
,
3
,
224
,
...
...
@@ -117,6 +75,19 @@ def main(args):
/
test_num
))
def
main
(
args
):
if
not
args
.
enable_benchmark
:
assert
args
.
batch_size
==
1
else
:
assert
args
.
model
is
not
None
# HALF precission predict only work when using tensorrt
if
args
.
use_fp16
is
True
:
assert
args
.
use_tensorrt
is
True
predictor
=
utils
.
create_paddle_predictor
(
args
)
predict
(
args
,
predictor
)
if
__name__
==
"__main__"
:
args
=
utils
.
parse_args
()
main
(
args
)
tools/infer/utils.py
浏览文件 @
e3801c55
...
...
@@ -15,6 +15,8 @@
import
argparse
import
cv2
import
numpy
as
np
from
paddle.inference
import
Config
from
paddle.inference
import
create_predictor
def
parse_args
():
...
...
@@ -65,6 +67,34 @@ def parse_args():
return
parser
.
parse_args
()
def
create_paddle_predictor
(
args
):
config
=
Config
(
args
.
model_file
,
args
.
params_file
)
if
args
.
use_gpu
:
config
.
enable_use_gpu
(
args
.
gpu_mem
,
0
)
else
:
config
.
disable_gpu
()
if
args
.
enable_mkldnn
:
# cache 10 different shapes for mkldnn to avoid memory leak
config
.
set_mkldnn_cache_capacity
(
10
)
config
.
enable_mkldnn
()
config
.
disable_glog_info
()
config
.
switch_ir_optim
(
args
.
ir_optim
)
# default true
if
args
.
use_tensorrt
:
config
.
enable_tensorrt_engine
(
precision_mode
=
Config
.
Precision
.
Half
if
args
.
use_fp16
else
Config
.
Precision
.
Float32
,
max_batch_size
=
args
.
batch_size
)
config
.
enable_memory_optim
()
# use zero copy
config
.
switch_use_feed_fetch_ops
(
False
)
predictor
=
create_predictor
(
config
)
return
predictor
def
preprocess
(
img
,
args
):
resize_op
=
ResizeImage
(
resize_short
=
args
.
resize_short
)
img
=
resize_op
(
img
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录