Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
93af8d73
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看板
提交
93af8d73
编写于
1月 17, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change batch predict inferface
上级
21e1cc08
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
25 addition
and
23 deletion
+25
-23
core/general-client/include/general_model.h
core/general-client/include/general_model.h
+3
-3
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+9
-4
core/general-client/src/pybind_general_model.cpp
core/general-client/src/pybind_general_model.cpp
+7
-9
python/examples/imdb/test_client_batch.py
python/examples/imdb/test_client_batch.py
+3
-3
python/paddle_serving/serving_client/__init__.py
python/paddle_serving/serving_client/__init__.py
+3
-4
未找到文件。
core/general-client/include/general_model.h
浏览文件 @
93af8d73
...
...
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>
#include <fstream>
#include <map>
#include <string>
...
...
@@ -58,13 +59,12 @@ class PredictorClient {
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
);
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
predict_for_batch
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
batch_predict
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>&
float_feed_batch
,
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
const
int64_t
&
batch_size
);
const
std
::
vector
<
std
::
string
>&
fetch_name
);
std
::
vector
<
std
::
vector
<
float
>>
predict_with_profile
(
const
std
::
vector
<
std
::
vector
<
float
>>&
float_feed
,
...
...
core/general-client/src/general_model.cpp
浏览文件 @
93af8d73
...
...
@@ -171,13 +171,13 @@ std::vector<std::vector<float>> PredictorClient::predict(
return
fetch_result
;
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
PredictorClient
::
predict_for_batch
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
PredictorClient
::
batch_predict
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
&
float_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
const
int64_t
&
batch_size
)
{
const
std
::
vector
<
std
::
string
>
&
fetch_name
)
{
int
batch_size
=
std
::
max
(
float_feed_batch
.
size
(),
int_feed_batch
.
size
());
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
fetch_result_batch
;
if
(
fetch_name
.
size
()
==
0
)
{
return
fetch_result_batch
;
...
...
@@ -229,6 +229,8 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::predict_for_batch(
tensor
->
add_shape
(
_shape
[
idx
][
j
]);
}
tensor
->
set_elem_type
(
0
);
VLOG
(
3
)
<<
"feed var name "
<<
name
<<
" index "
<<
vec_idx
<<
"first data "
<<
int_feed
[
vec_idx
][
0
];
for
(
int
j
=
0
;
j
<
int_feed
[
vec_idx
].
size
();
++
j
)
{
tensor
->
add_data
(
const_cast
<
char
*>
(
reinterpret_cast
<
const
char
*>
(
&
(
int_feed
[
vec_idx
][
j
]))),
...
...
@@ -248,10 +250,13 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::predict_for_batch(
for
(
int
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
for
(
auto
&
name
:
fetch_name
)
{
int
idx
=
_fetch_name_to_idx
[
name
];
int
len
=
res
.
insts
(
0
).
tensor_array
(
idx
).
data_size
();
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
data_size
();
VLOG
(
3
)
<<
"fetch name: "
<<
name
;
VLOG
(
3
)
<<
"tensor data size: "
<<
len
;
fetch_result_batch
[
bi
][
idx
].
resize
(
len
);
VLOG
(
3
)
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
<<
*
(
const
float
*
)
res
.
insts
(
bi
).
tensor_array
(
idx
).
data
(
0
).
c_str
();
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
fetch_result_batch
[
bi
][
idx
][
i
]
=
*
(
const
float
*
)
res
.
insts
(
bi
).
tensor_array
(
idx
).
data
(
i
).
c_str
();
...
...
core/general-client/src/pybind_general_model.cpp
浏览文件 @
93af8d73
...
...
@@ -57,7 +57,7 @@ PYBIND11_MODULE(serving_client, m) {
fetch_name
);
})
.
def
(
"
predict_for_batch
"
,
.
def
(
"
batch_predict
"
,
[](
PredictorClient
&
self
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
&
float_feed_batch
,
...
...
@@ -65,14 +65,12 @@ PYBIND11_MODULE(serving_client, m) {
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
const
int64_t
&
batch_size
)
{
return
self
.
predict_for_batch
(
float_feed_batch
,
float_feed_name
,
int_feed_batch
,
int_feed_name
,
fetch_name
,
batch_size
);
const
std
::
vector
<
std
::
string
>
&
fetch_name
)
{
return
self
.
batch_predict
(
float_feed_batch
,
float_feed_name
,
int_feed_batch
,
int_feed_name
,
fetch_name
);
});
}
...
...
python/examples/imdb/test_client_batch.py
浏览文件 @
93af8d73
...
...
@@ -19,7 +19,7 @@ from multiprocessing import Pool
import
time
def
predict_for_batch
(
batch_size
=
4
):
def
batch_predict
(
batch_size
=
4
):
client
=
Client
()
client
.
load_client_config
(
conf_file
)
client
.
connect
([
"127.0.0.1:8010"
])
...
...
@@ -33,7 +33,7 @@ def predict_for_batch(batch_size=4):
fetch
=
[
"acc"
,
"cost"
,
"prediction"
]
feed_batch
.
append
(
feed
)
if
len
(
feed_batch
)
==
batch_size
:
fetch_batch
=
client
.
predict_for_batch
(
fetch_batch
=
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
for
i
in
range
(
batch_size
):
print
(
"{} {}"
.
format
(
fetch_batch
[
i
][
"prediction"
][
1
],
...
...
@@ -47,4 +47,4 @@ def predict_for_batch(batch_size=4):
if
__name__
==
'__main__'
:
conf_file
=
sys
.
argv
[
1
]
batch_size
=
int
(
sys
.
argv
[
2
])
predict_for_batch
(
batch_size
)
batch_predict
(
batch_size
)
python/paddle_serving/serving_client/__init__.py
浏览文件 @
93af8d73
...
...
@@ -154,8 +154,7 @@ class Client(object):
return
result_map
def
predict_for_batch
(
self
,
feed_batch
=
[],
fetch
=
[]):
batch_size
=
len
(
feed_batch
)
def
batch_predict
(
self
,
feed_batch
=
[],
fetch
=
[]):
int_slot_batch
=
[]
float_slot_batch
=
[]
int_feed_names
=
[]
...
...
@@ -184,9 +183,9 @@ class Client(object):
if
key
in
self
.
fetch_names_
:
fetch_names
.
append
(
key
)
result_batch
=
self
.
client_handle_
.
predict_for_batch
(
result_batch
=
self
.
client_handle_
.
batch_predict
(
float_slot_batch
,
float_feed_names
,
int_slot_batch
,
int_feed_names
,
fetch_names
,
batch_size
)
fetch_names
)
result_map_batch
=
[]
for
result
in
result_batch
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录