Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
dc95e6fe
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看板
提交
dc95e6fe
编写于
6月 28, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add asyn impl
上级
5ba1b5fd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
10 deletion
+30
-10
python/pipeline/pipeline_client.py
python/pipeline/pipeline_client.py
+30
-10
未找到文件。
python/pipeline/pipeline_client.py
浏览文件 @
dc95e6fe
...
@@ -16,6 +16,7 @@ import grpc
...
@@ -16,6 +16,7 @@ import grpc
import
numpy
as
np
import
numpy
as
np
from
numpy
import
*
from
numpy
import
*
import
logging
import
logging
import
functools
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2_grpc
from
.proto
import
pipeline_service_pb2_grpc
...
@@ -31,7 +32,7 @@ class PipelineClient(object):
...
@@ -31,7 +32,7 @@ class PipelineClient(object):
self
.
_stub
=
pipeline_service_pb2_grpc
.
PipelineServiceStub
(
self
.
_stub
=
pipeline_service_pb2_grpc
.
PipelineServiceStub
(
self
.
_channel
)
self
.
_channel
)
def
_pack_
data_for_infer
(
self
,
feed_dict
):
def
_pack_
request_package
(
self
,
feed_dict
):
req
=
pipeline_service_pb2
.
Request
()
req
=
pipeline_service_pb2
.
Request
()
for
key
,
value
in
feed_dict
.
items
():
for
key
,
value
in
feed_dict
.
items
():
if
not
isinstance
(
value
,
str
):
if
not
isinstance
(
value
,
str
):
...
@@ -40,15 +41,7 @@ class PipelineClient(object):
...
@@ -40,15 +41,7 @@ class PipelineClient(object):
req
.
value
.
append
(
value
)
req
.
value
.
append
(
value
)
return
req
return
req
def
predict
(
self
,
feed_dict
,
fetch
):
def
_unpack_response_package
(
self
,
resp
,
fetch
):
if
not
isinstance
(
feed_dict
,
dict
):
raise
TypeError
(
"feed must be dict type with format: {name: value}."
)
if
not
isinstance
(
fetch
,
list
):
raise
TypeError
(
"fetch_with_type must be list type with format: [name]."
)
req
=
self
.
_pack_data_for_infer
(
feed_dict
)
resp
=
self
.
_stub
.
inference
(
req
)
if
resp
.
ecode
!=
0
:
if
resp
.
ecode
!=
0
:
return
{
"ecode"
:
resp
.
ecode
,
"error_info"
:
resp
.
error_info
}
return
{
"ecode"
:
resp
.
ecode
,
"error_info"
:
resp
.
error_info
}
fetch_map
=
{
"ecode"
:
resp
.
ecode
}
fetch_map
=
{
"ecode"
:
resp
.
ecode
}
...
@@ -62,3 +55,30 @@ class PipelineClient(object):
...
@@ -62,3 +55,30 @@ class PipelineClient(object):
pass
pass
fetch_map
[
key
]
=
data
fetch_map
[
key
]
=
data
return
fetch_map
return
fetch_map
def
predict
(
self
,
feed_dict
,
fetch
,
asyn
=
False
):
if
not
isinstance
(
feed_dict
,
dict
):
raise
TypeError
(
"feed must be dict type with format: {name: value}."
)
if
not
isinstance
(
fetch
,
list
):
raise
TypeError
(
"fetch must be list type with format: [name]."
)
req
=
self
.
_pack_request_package
(
feed_dict
)
if
not
asyn
:
resp
=
self
.
_stub
.
inference
(
req
)
return
self
.
_unpack_response_package
(
resp
)
else
:
call_future
=
self
.
_stub
.
inference
.
future
(
req
)
return
PipelinePredictFuture
(
call_future
,
functools
.
partial
(
self
.
_unpack_response_package
,
fetch
=
fetch
))
class
PipelinePredictFuture
(
object
):
def
__init__
(
self
,
call_future
,
callback_func
):
self
.
call_future_
=
call_future
self
.
callback_func_
=
callback_func
def
result
(
self
):
resp
=
self
.
call_future_
.
result
()
return
self
.
callback_func_
(
resp
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录