Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
c7eb18eb
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
185
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7eb18eb
编写于
6月 11, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update demo for imdb model ensemble && bug fix
上级
67ca0f84
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
60 deletion
+59
-60
python/examples/imdb/test_py_client.py
python/examples/imdb/test_py_client.py
+8
-11
python/examples/imdb/test_py_server.py
python/examples/imdb/test_py_server.py
+28
-32
python/paddle_serving_client/pyclient.py
python/paddle_serving_client/pyclient.py
+4
-3
python/paddle_serving_server/pyserver.py
python/paddle_serving_server/pyserver.py
+19
-14
未找到文件。
python/examples/
fit_a_line
/test_py_client.py
→
python/examples/
imdb
/test_py_client.py
浏览文件 @
c7eb18eb
...
@@ -13,26 +13,23 @@
...
@@ -13,26 +13,23 @@
# limitations under the License.
# limitations under the License.
from
paddle_serving_client.pyclient
import
PyClient
from
paddle_serving_client.pyclient
import
PyClient
import
numpy
as
np
import
numpy
as
np
from
paddle_serving_app.reader
import
IMDBDataset
from
line_profiler
import
LineProfiler
from
line_profiler
import
LineProfiler
client
=
PyClient
()
client
=
PyClient
()
client
.
connect
(
'localhost:8080'
)
client
.
connect
(
'localhost:8080'
)
x
=
np
.
array
(
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
],
dtype
=
'float'
)
lp
=
LineProfiler
()
lp
=
LineProfiler
()
lp_wrapper
=
lp
(
client
.
predict
)
lp_wrapper
=
lp
(
client
.
predict
)
words
=
'i am very sad | 0'
imdb_dataset
=
IMDBDataset
()
imdb_dataset
.
load_resource
(
'imdb.vocab'
)
for
i
in
range
(
1
):
for
i
in
range
(
1
):
fetch_map
=
lp_wrapper
(
feed
=
{
"x"
:
x
},
fetch
=
[
"combine_op_output"
]
)
word_ids
,
label
=
imdb_dataset
.
get_words_and_label
(
words
)
# fetch_map = client.predict
(
fetch_map
=
lp_wrapper
(
# feed={"x": x}, fetch_with_type={"combine_op_output": "float"}
)
feed
=
{
"words"
:
word_ids
},
fetch
=
[
"combined_prediction"
]
)
print
(
fetch_map
)
print
(
fetch_map
)
#lp.print_stats()
#lp.print_stats()
python/examples/
fit_a_line
/test_py_server.py
→
python/examples/
imdb
/test_py_server.py
浏览文件 @
c7eb18eb
...
@@ -28,46 +28,42 @@ logging.basicConfig(
...
@@ -28,46 +28,42 @@ logging.basicConfig(
class
CombineOp
(
Op
):
class
CombineOp
(
Op
):
def
preprocess
(
self
,
input_data
):
def
preprocess
(
self
,
input_data
):
c
nt
=
0
c
ombined_prediction
=
0
for
op_name
,
channeldata
in
input_data
.
items
():
for
op_name
,
channeldata
in
input_data
.
items
():
logging
.
debug
(
"CombineOp preprocess: {}"
.
format
(
op_name
))
data
=
channeldata
.
parse
()
data
=
channeldata
.
parse
()
cnt
+=
data
[
"price"
]
logging
.
info
(
"{}: {}"
.
format
(
op_name
,
data
[
"prediction"
]))
data
=
{
"combine_op_output"
:
cnt
}
combined_prediction
+=
data
[
"prediction"
]
data
=
{
"combined_prediction"
:
combined_prediction
/
2
}
return
data
return
data
read_op
=
Op
(
name
=
"read"
,
inputs
=
None
)
read_op
=
Op
(
name
=
"read"
,
inputs
=
None
)
uci1_op
=
Op
(
name
=
"uci1
"
,
bow_op
=
Op
(
name
=
"bow
"
,
inputs
=
[
read_op
],
inputs
=
[
read_op
],
server_model
=
"./uci_housing
_model"
,
server_model
=
"imdb_bow
_model"
,
server_port
=
"9393"
,
server_port
=
"9393"
,
device
=
"cpu"
,
device
=
"cpu"
,
client_config
=
"uci_housing_client
/serving_client_conf.prototxt"
,
client_config
=
"imdb_bow_client_conf
/serving_client_conf.prototxt"
,
server_name
=
"127.0.0.1:9393"
,
server_name
=
"127.0.0.1:9393"
,
fetch_names
=
[
"price
"
],
fetch_names
=
[
"prediction
"
],
concurrency
=
1
,
concurrency
=
1
,
timeout
=
0.
1
,
timeout
=
0.0
1
,
retry
=
2
)
retry
=
2
)
uci2_op
=
Op
(
name
=
"uci2
"
,
cnn_op
=
Op
(
name
=
"cnn
"
,
inputs
=
[
read_op
],
inputs
=
[
read_op
],
server_model
=
"./uci_housing
_model"
,
server_model
=
"imdb_cnn
_model"
,
server_port
=
"9292"
,
server_port
=
"9292"
,
device
=
"cpu"
,
device
=
"cpu"
,
client_config
=
"uci_housing_client
/serving_client_conf.prototxt"
,
client_config
=
"imdb_cnn_client_conf
/serving_client_conf.prototxt"
,
server_name
=
"127.0.0.1:9292"
,
server_name
=
"127.0.0.1:9292"
,
fetch_names
=
[
"price
"
],
fetch_names
=
[
"prediction
"
],
concurrency
=
1
,
concurrency
=
1
,
timeout
=-
1
,
timeout
=-
1
,
retry
=
1
)
retry
=
1
)
combine_op
=
CombineOp
(
combine_op
=
CombineOp
(
name
=
"combine"
,
name
=
"combine"
,
inputs
=
[
bow_op
,
cnn_op
],
concurrency
=
1
,
timeout
=-
1
,
retry
=
1
)
inputs
=
[
uci1_op
,
uci2_op
],
concurrency
=
1
,
timeout
=-
1
,
retry
=
1
)
pyserver
=
PyServer
(
profile
=
False
,
retry
=
1
)
pyserver
=
PyServer
(
profile
=
False
,
retry
=
1
)
pyserver
.
add_ops
([
read_op
,
uci1_op
,
uci2
_op
,
combine_op
])
pyserver
.
add_ops
([
read_op
,
bow_op
,
cnn
_op
,
combine_op
])
pyserver
.
prepare_server
(
port
=
8080
,
worker_num
=
2
)
pyserver
.
prepare_server
(
port
=
8080
,
worker_num
=
2
)
pyserver
.
run_server
()
pyserver
.
run_server
()
python/paddle_serving_client/pyclient.py
浏览文件 @
c7eb18eb
...
@@ -30,9 +30,10 @@ class PyClient(object):
...
@@ -30,9 +30,10 @@ class PyClient(object):
def
_pack_data_for_infer
(
self
,
feed_data
):
def
_pack_data_for_infer
(
self
,
feed_data
):
req
=
general_python_service_pb2
.
Request
()
req
=
general_python_service_pb2
.
Request
()
for
name
,
data
in
feed_data
.
items
():
for
name
,
data
in
feed_data
.
items
():
if
not
isinstance
(
data
,
np
.
ndarray
):
if
isinstance
(
data
,
list
):
raise
TypeError
(
data
=
np
.
array
(
data
)
"only numpy array type is supported temporarily."
)
elif
not
isinstance
(
data
,
np
.
ndarray
):
raise
TypeError
(
"only list and numpy array type is supported."
)
req
.
feed_var_names
.
append
(
name
)
req
.
feed_var_names
.
append
(
name
)
req
.
feed_insts
.
append
(
data
.
tobytes
())
req
.
feed_insts
.
append
(
data
.
tobytes
())
req
.
shape
.
append
(
np
.
array
(
data
.
shape
,
dtype
=
"int32"
).
tobytes
())
req
.
shape
.
append
(
np
.
array
(
data
.
shape
,
dtype
=
"int32"
).
tobytes
())
...
...
python/paddle_serving_server/pyserver.py
浏览文件 @
c7eb18eb
...
@@ -462,10 +462,10 @@ class Op(object):
...
@@ -462,10 +462,10 @@ class Op(object):
call_future
=
None
call_future
=
None
error_info
=
None
error_info
=
None
if
self
.
with_serving
():
if
self
.
with_serving
():
for
i
in
range
(
self
.
_retry
):
_profiler
.
record
(
"{}{}-midp_0"
.
format
(
self
.
name
,
_profiler
.
record
(
"{}{}-midp_0"
.
format
(
self
.
name
,
concurrency_idx
))
concurrency_idx
))
if
self
.
_timeout
>
0
:
if
self
.
_timeout
>
0
:
for
i
in
range
(
self
.
_retry
)
:
try
:
try
:
call_future
=
func_timeout
.
func_timeout
(
call_future
=
func_timeout
.
func_timeout
(
self
.
_timeout
,
self
.
_timeout
,
...
@@ -475,19 +475,25 @@ class Op(object):
...
@@ -475,19 +475,25 @@ class Op(object):
logging
.
error
(
"error: timeout"
)
logging
.
error
(
"error: timeout"
)
error_info
=
"{}({}): timeout"
.
format
(
error_info
=
"{}({}): timeout"
.
format
(
self
.
name
,
concurrency_idx
)
self
.
name
,
concurrency_idx
)
if
i
+
1
<
self
.
_retry
:
error_info
=
None
logging
.
warn
(
self
.
_log
(
"warn: timeout, retry({})"
.
format
(
i
+
1
)))
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
error
(
"error: {}"
.
format
(
e
))
logging
.
error
(
"error: {}"
.
format
(
e
))
error_info
=
"{}({}): {}"
.
format
(
error_info
=
"{}({}): {}"
.
format
(
self
.
name
,
concurrency_idx
,
e
)
self
.
name
,
concurrency_idx
,
e
)
else
:
logging
.
warn
(
self
.
_log
(
e
))
call_future
=
self
.
midprocess
(
data
)
# TODO
_profiler
.
record
(
"{}{}-midp_1"
.
format
(
self
.
name
,
break
concurrency_idx
))
else
:
if
i
+
1
<
self
.
_retry
:
break
error_info
=
None
else
:
logging
.
warn
(
call_future
=
self
.
midprocess
(
data
)
self
.
_log
(
"warn: timeout, retry({})"
.
format
(
i
+
1
)))
_profiler
.
record
(
"{}{}-midp_1"
.
format
(
self
.
name
,
concurrency_idx
))
_profiler
.
record
(
"{}{}-postp_0"
.
format
(
self
.
name
,
_profiler
.
record
(
"{}{}-postp_0"
.
format
(
self
.
name
,
concurrency_idx
))
concurrency_idx
))
if
error_info
is
not
None
:
if
error_info
is
not
None
:
...
@@ -843,7 +849,6 @@ class PyServer(object):
...
@@ -843,7 +849,6 @@ class PyServer(object):
return
op
.
start
(
concurrency_idx
)
return
op
.
start
(
concurrency_idx
)
def
_run_ops
(
self
):
def
_run_ops
(
self
):
#TODO
for
op
in
self
.
_ops
:
for
op
in
self
.
_ops
:
op_concurrency
=
op
.
get_concurrency
()
op_concurrency
=
op
.
get_concurrency
()
logging
.
debug
(
"run op: {}, op_concurrency: {}"
.
format
(
logging
.
debug
(
"run op: {}, op_concurrency: {}"
.
format
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录