Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
c1a96315
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看板
提交
c1a96315
编写于
3月 09, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use PredictorRes
上级
9c3bd01d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
55 deletion
+18
-55
core/general-client/include/general_model.h
core/general-client/include/general_model.h
+1
-28
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+11
-14
core/general-client/src/pybind_general_model.cpp
core/general-client/src/pybind_general_model.cpp
+1
-7
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+5
-6
未找到文件。
core/general-client/include/general_model.h
浏览文件 @
c1a96315
...
...
@@ -59,18 +59,6 @@ class PredictorRes {
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
vector
<
float
>>>
_float_map
;
};
class
PredictorResBatch
{
public:
PredictorResBatch
()
{}
~
PredictorResBatch
()
{}
public:
const
PredictorRes
&
at
(
const
int
index
)
{
return
_predictres_vector
[
index
];
}
public:
std
::
vector
<
PredictorRes
>
_predictres_vector
;
};
class
PredictorClient
{
public:
PredictorClient
()
{}
...
...
@@ -96,28 +84,13 @@ class PredictorClient {
PredictorRes
&
predict_res
,
// NOLINT
const
int
&
pid
);
std
::
vector
<
std
::
vector
<
float
>>
predict
(
const
std
::
vector
<
std
::
vector
<
float
>>&
float_feed
,
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>&
int_feed
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
);
int
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
,
PredictorResBatch
&
predict_res
,
// NOLINT
const
int
&
pid
);
std
::
vector
<
PredictorRes
>
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
,
PredictorRes
&
predict_res_batch
,
// NOLINT
const
int
&
pid
);
private:
...
...
core/general-client/src/general_model.cpp
浏览文件 @
c1a96315
...
...
@@ -270,14 +270,15 @@ int PredictorClient::batch_predict(
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
,
PredictorRes
Batch
&
predict_res_batch
,
PredictorRes
&
predict_res_batch
,
const
int
&
pid
)
{
int
batch_size
=
std
::
max
(
float_feed_batch
.
size
(),
int_feed_batch
.
size
());
predict_res_batch
.
_int64_map
.
clear
();
predict_res_batch
.
_float_map
.
clear
();
Timer
timeline
;
int64_t
preprocess_start
=
timeline
.
TimeStampUS
();
predict_res_batch
.
_predictres_vector
.
resize
(
batch_size
);
int
fetch_name_num
=
fetch_name
.
size
();
_api
.
thrd_clear
();
...
...
@@ -366,37 +367,33 @@ int PredictorClient::batch_predict(
}
else
{
client_infer_end
=
timeline
.
TimeStampUS
();
postprocess_start
=
client_infer_end
;
for
(
auto
&
name
:
fetch_name
)
{
predict_res_batch
.
_int64_map
[
name
].
resize
(
batch_size
);
predict_res_batch
.
_float_map
[
name
].
resize
(
batch_size
);
}
for
(
int
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
predict_res_batch
.
_predictres_vector
[
bi
].
_int64_map
.
clear
();
predict_res_batch
.
_predictres_vector
[
bi
].
_float_map
.
clear
();
for
(
auto
&
name
:
fetch_name
)
{
int
idx
=
_fetch_name_to_idx
[
name
];
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
data_size
();
if
(
_fetch_name_to_type
[
name
]
==
0
)
{
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data_size
();
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: int64 len : "
<<
len
;
predict_res_batch
.
_predictres_vector
[
bi
].
_int64_map
[
name
].
resize
(
1
);
predict_res_batch
.
_predictres_vector
[
bi
].
_int64_map
[
name
]
[
0
].
resize
(
len
);
predict_res_batch
.
_int64_map
[
name
][
bi
].
resize
(
len
);
VLOG
(
2
)
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
<<
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data
(
0
);
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
predict_res_batch
.
_
predictres_vector
[
bi
].
_int64_map
[
name
][
0
][
i
]
=
predict_res_batch
.
_
int64_map
[
name
][
bi
][
i
]
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data
(
i
);
}
}
else
if
(
_fetch_name_to_type
[
name
]
==
1
)
{
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data_size
();
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: float32 len : "
<<
len
;
predict_res_batch
.
_predictres_vector
[
bi
].
_float_map
[
name
].
resize
(
1
);
predict_res_batch
.
_predictres_vector
[
bi
].
_float_map
[
name
]
[
0
].
resize
(
len
);
predict_res_batch
.
_float_map
[
name
][
bi
].
resize
(
len
);
VLOG
(
2
)
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
<<
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data
(
0
);
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
predict_res_batch
.
_
predictres_vector
[
bi
].
_float_map
[
name
][
0
][
i
]
=
predict_res_batch
.
_
float_map
[
name
][
bi
][
i
]
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data
(
i
);
}
}
...
...
core/general-client/src/pybind_general_model.cpp
浏览文件 @
c1a96315
...
...
@@ -41,12 +41,6 @@ PYBIND11_MODULE(serving_client, m) {
},
py
::
return_value_policy
::
reference
);
py
::
class_
<
PredictorResBatch
>
(
m
,
"PredictorResBatch"
,
py
::
buffer_protocol
())
.
def
(
py
::
init
())
.
def
(
"at"
,
[](
PredictorResBatch
&
self
,
int
index
)
{
return
self
.
at
(
index
);
},
py
::
return_value_policy
::
reference
);
py
::
class_
<
PredictorClient
>
(
m
,
"PredictorClient"
,
py
::
buffer_protocol
())
.
def
(
py
::
init
())
.
def
(
"init_gflags"
,
...
...
@@ -97,7 +91,7 @@ PYBIND11_MODULE(serving_client, m) {
&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
PredictorRes
Batch
&
predict_res_batch
,
PredictorRes
&
predict_res_batch
,
const
int
&
pid
)
{
return
self
.
batch_predict
(
float_feed_batch
,
float_feed_name
,
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
c1a96315
...
...
@@ -89,7 +89,6 @@ class Client(object):
def
load_client_config
(
self
,
path
):
from
.serving_client
import
PredictorClient
from
.serving_client
import
PredictorRes
from
.serving_client
import
PredictorResBatch
model_conf
=
m_config
.
GeneralModelConfig
()
f
=
open
(
path
,
'r'
)
model_conf
=
google
.
protobuf
.
text_format
.
Merge
(
...
...
@@ -100,7 +99,6 @@ class Client(object):
# get feed shapes, feed types
# map feed names to index
self
.
result_handle_
=
PredictorRes
()
self
.
result_batch_handle_
=
PredictorResBatch
()
self
.
client_handle_
=
PredictorClient
()
self
.
client_handle_
.
init
(
path
)
read_env_flags
=
[
"profile_client"
,
"profile_server"
]
...
...
@@ -205,20 +203,21 @@ class Client(object):
if
key
in
self
.
fetch_names_
:
fetch_names
.
append
(
key
)
result_batch
=
self
.
result_
batch_
handle_
result_batch
=
self
.
result_handle_
res
=
self
.
client_handle_
.
batch_predict
(
float_slot_batch
,
float_feed_names
,
int_slot_batch
,
int_feed_names
,
fetch_names
,
result_batch
,
self
.
pid
)
result_map_batch
=
[]
for
index
in
range
(
batch_size
):
result
=
result_batch
.
at
(
index
)
result_map
=
{}
for
i
,
name
in
enumerate
(
fetch_names
):
if
self
.
fetch_names_to_type_
[
name
]
==
int_type
:
result_map
[
name
]
=
result
.
get_int64_by_name
(
name
)[
0
]
result_map
[
name
]
=
result_batch
.
get_int64_by_name
(
name
)[
index
]
elif
self
.
fetch_names_to_type_
[
name
]
==
float_type
:
result_map
[
name
]
=
result
.
get_float_by_name
(
name
)[
0
]
result_map
[
name
]
=
result_batch
.
get_float_by_name
(
name
)[
index
]
result_map_batch
.
append
(
result_map
)
return
result_map_batch
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录