Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
5acbb589
S
Serving
项目概览
PaddlePaddle
/
Serving
1 年多 前同步成功
通知
186
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看板
提交
5acbb589
编写于
5月 09, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add default preprocess in pyserving
上级
f21134b0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
19 deletion
+28
-19
python/examples/imdb/test_py_server.py
python/examples/imdb/test_py_server.py
+8
-17
python/paddle_serving_server/pyserver.py
python/paddle_serving_server/pyserver.py
+20
-2
未找到文件。
python/examples/imdb/test_py_server.py
浏览文件 @
5acbb589
...
...
@@ -22,14 +22,6 @@ import python_service_channel_pb2
# channel data: {name(str): data(bytes)}
class
ImdbOp
(
Op
):
def
preprocess
(
self
,
input_data
):
data
=
input_data
[
0
]
# batchsize=1
feed
=
{}
for
inst
in
data
.
insts
:
feed
[
inst
.
name
]
=
np
.
frombuffer
(
inst
.
data
,
dtype
=
'int64'
)
# feed[inst.name] = np.frombuffer(inst.data)
return
feed
def
postprocess
(
self
,
output_data
):
data
=
python_service_channel_pb2
.
ChannelData
()
inst
=
python_service_channel_pb2
.
Inst
()
...
...
@@ -58,14 +50,6 @@ class CombineOp(Op):
class
UciOp
(
Op
):
def
preprocess
(
self
,
input_data
):
data
=
input_data
[
0
]
# batchsize=1
feed
=
{}
for
inst
in
data
.
insts
:
feed
[
inst
.
name
]
=
np
.
frombuffer
(
inst
.
data
,
dtype
=
'float'
)
# feed[inst.name] = np.frombuffer(inst.data)
return
feed
def
postprocess
(
self
,
output_data
):
data
=
python_service_channel_pb2
.
ChannelData
()
inst
=
python_service_channel_pb2
.
Inst
()
...
...
@@ -83,7 +67,9 @@ bow_out_channel = Channel()
combine_out_channel
=
Channel
()
cnn_op
=
UciOp
(
inputs
=
[
read_channel
],
in_dtype
=
'float'
,
outputs
=
[
cnn_out_channel
],
out_dtype
=
'float'
,
server_model
=
"./uci_housing_model"
,
server_port
=
"9393"
,
device
=
"cpu"
,
...
...
@@ -92,7 +78,9 @@ cnn_op = UciOp(
fetch_names
=
[
"price"
])
bow_op
=
UciOp
(
inputs
=
[
read_channel
],
in_dtype
=
'float'
,
outputs
=
[
bow_out_channel
],
out_dtype
=
'float'
,
server_model
=
"./uci_housing_model"
,
server_port
=
"9292"
,
device
=
"cpu"
,
...
...
@@ -120,7 +108,10 @@ bow_op = ImdbOp(
fetch_names=["acc", "cost", "prediction"])
'''
combine_op
=
CombineOp
(
inputs
=
[
cnn_out_channel
,
bow_out_channel
],
outputs
=
[
combine_out_channel
])
inputs
=
[
cnn_out_channel
,
bow_out_channel
],
in_dtype
=
'float'
,
outputs
=
[
combine_out_channel
],
out_dtype
=
'float'
)
pyserver
=
PyServer
()
pyserver
.
add_channel
(
read_channel
)
...
...
python/paddle_serving_server/pyserver.py
浏览文件 @
5acbb589
...
...
@@ -19,7 +19,7 @@ import os
import
paddle_serving_server
from
paddle_serving_client
import
Client
from
concurrent
import
futures
import
numpy
import
numpy
as
np
import
grpc
import
general_python_service_pb2
import
general_python_service_pb2_grpc
...
...
@@ -63,7 +63,10 @@ class Channel(Queue.Queue):
class
Op
(
object
):
def
__init__
(
self
,
inputs
,
in_dtype
,
outputs
,
out_dtype
,
batchsize
=
1
,
server_model
=
None
,
server_port
=
None
,
device
=
None
,
...
...
@@ -72,7 +75,10 @@ class Op(object):
fetch_names
=
None
):
self
.
_run
=
False
self
.
set_inputs
(
inputs
)
self
.
_in_dtype
=
in_dtype
self
.
set_outputs
(
outputs
)
self
.
_out_dtype
=
out_dtype
self
.
_batch_size
=
batchsize
self
.
_client
=
None
if
client_config
is
not
None
and
\
server_name
is
not
None
and
\
...
...
@@ -108,7 +114,19 @@ class Op(object):
self
.
_outputs
=
channels
def
preprocess
(
self
,
input_data
):
return
input_data
if
len
(
input_data
)
!=
1
:
raise
Exception
(
'this Op has multiple previous channels. Please override this method'
)
feed_batch
=
[]
for
data
in
input_data
:
if
len
(
data
.
insts
)
!=
self
.
_batch_size
:
raise
Exception
(
'len(data_insts) != self._batch_size'
)
feed
=
{}
for
inst
in
data
.
insts
:
feed
[
inst
.
name
]
=
np
.
frombuffer
(
inst
.
data
,
dtype
=
self
.
_in_dtype
)
feed_batch
.
append
(
feed
)
return
feed_batch
def
midprocess
(
self
,
data
):
# data = preprocess(input), which must be a dict
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录