Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
08f5877f
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看板
提交
08f5877f
编写于
8月 06, 2020
作者:
W
wangjiawei04
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt grpc to blazeface
上级
f88fc43f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
92 addition
and
49 deletion
+92
-49
core/general-client/include/general_model.h
core/general-client/include/general_model.h
+1
-0
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+1
-0
core/general-client/src/pybind_general_model.cpp
core/general-client/src/pybind_general_model.cpp
+2
-0
core/general-server/op/general_reader_op.cpp
core/general-server/op/general_reader_op.cpp
+30
-26
core/general-server/proto/general_model_service.proto
core/general-server/proto/general_model_service.proto
+1
-1
python/paddle_serving_app/local_predict.py
python/paddle_serving_app/local_predict.py
+1
-2
python/paddle_serving_app/reader/__init__.py
python/paddle_serving_app/reader/__init__.py
+1
-1
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+32
-8
python/paddle_serving_server/__init__.py
python/paddle_serving_server/__init__.py
+23
-11
未找到文件。
core/general-client/include/general_model.h
浏览文件 @
08f5877f
...
...
@@ -234,6 +234,7 @@ class PredictorClient {
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
int
>>&
float_shape
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>&
int_feed_batch
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>&
lod_slot_batch
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
vector
<
int
>>&
int_shape
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
...
...
core/general-client/src/general_model.cpp
浏览文件 @
08f5877f
...
...
@@ -352,6 +352,7 @@ int PredictorClient::numpy_predict(
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
int
>>
&
float_shape
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>
&
lod_slot_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
vector
<
int
>>
&
int_shape
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
...
...
core/general-client/src/pybind_general_model.cpp
浏览文件 @
08f5877f
...
...
@@ -127,6 +127,7 @@ PYBIND11_MODULE(serving_client, m) {
const
std
::
vector
<
std
::
vector
<
int
>>
&
float_shape
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
int64_t
>>>&
lod_slot_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
vector
<
int
>>
&
int_shape
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
...
...
@@ -136,6 +137,7 @@ PYBIND11_MODULE(serving_client, m) {
float_feed_name
,
float_shape
,
int_feed_batch
,
lod_slot_batch
,
int_feed_name
,
int_shape
,
fetch_name
,
...
...
core/general-server/op/general_reader_op.cpp
浏览文件 @
08f5877f
...
...
@@ -69,6 +69,17 @@ int conf_check(const Request *req,
return
0
;
}
void
print_lods
(
const
std
::
vector
<
std
::
vector
<
size_t
>>&
lod
)
{
std
::
cout
<<
"print lod info here"
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
lod
.
size
();
++
i
)
{
std
::
cout
<<
"the "
<<
i
<<
" th level of lod: "
<<
std
::
endl
;
for
(
size_t
j
=
0
;
j
<
lod
[
i
].
size
();
++
j
)
{
std
::
cout
<<
lod
[
i
][
j
]
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
}
int
GeneralReaderOp
::
inference
()
{
// reade request from client
const
Request
*
req
=
dynamic_cast
<
const
Request
*>
(
get_request_message
());
...
...
@@ -133,13 +144,20 @@ int GeneralReaderOp::inference() {
elem_size
[
i
]
=
sizeof
(
int32_t
);
lod_tensor
.
dtype
=
paddle
::
PaddleDType
::
INT32
;
}
if
(
model_config
->
_is_lod_feed
[
i
])
{
lod_tensor
.
lod
.
resize
(
1
);
lod_tensor
.
lod
[
0
].
push_back
(
0
);
VLOG
(
2
)
<<
"var["
<<
i
<<
"] is lod_tensor"
;
}
else
{
lod_tensor
.
shape
.
push_back
(
batch_size
);
//implement lod tensor here
std
::
cout
<<
"lod size: "
<<
req
->
insts
(
0
).
tensor_array
(
i
).
lod_size
()
<<
std
::
endl
;
if
(
req
->
insts
(
0
).
tensor_array
(
i
).
lod_size
()
>
0
)
{
lod_tensor
.
lod
.
resize
(
1
);
for
(
int
k
=
0
;
k
<
req
->
insts
(
0
).
tensor_array
(
i
).
lod_size
();
++
k
)
{
lod_tensor
.
lod
[
0
].
push_back
(
req
->
insts
(
0
).
tensor_array
(
i
).
lod
(
k
));
}
}
//if (model_config->_is_lod_feed[i]) {
// lod_tensor.lod.resize(1);
// lod_tensor.lod[0].push_back(0);
// VLOG(2) << "var[" << i << "] is lod_tensor";
//}
else
{
capacity
[
i
]
=
1
;
for
(
int
k
=
0
;
k
<
req
->
insts
(
0
).
tensor_array
(
i
).
shape_size
();
++
k
)
{
int
dim
=
req
->
insts
(
0
).
tensor_array
(
i
).
shape
(
k
);
...
...
@@ -150,6 +168,7 @@ int GeneralReaderOp::inference() {
VLOG
(
2
)
<<
"var["
<<
i
<<
"] is tensor, capacity: "
<<
capacity
[
i
];
}
lod_tensor
.
name
=
model_config
->
_feed_name
[
i
];
print_lods
(
lod_tensor
.
lod
);
out
->
push_back
(
lod_tensor
);
}
...
...
@@ -183,13 +202,13 @@ int GeneralReaderOp::inference() {
VLOG
(
2
)
<<
"new len: "
<<
cur_len
+
sample_len
;
}
out
->
at
(
i
).
data
.
Resize
(
tensor_size
*
elem_size
[
i
]);
out
->
at
(
i
).
shape
=
{
out
->
at
(
i
).
lod
[
0
].
back
()
};
out
->
at
(
i
).
shape
=
{};
for
(
int
j
=
1
;
j
<
req
->
insts
(
0
).
tensor_array
(
i
).
shape_size
();
++
j
)
{
out
->
at
(
i
).
shape
.
push_back
(
req
->
insts
(
0
).
tensor_array
(
i
).
shape
(
j
));
}
if
(
out
->
at
(
i
).
shape
.
size
()
==
1
)
{
out
->
at
(
i
).
shape
.
push_back
(
1
);
}
//
if (out->at(i).shape.size() == 1) {
//
out->at(i).shape.push_back(1);
//
}
VLOG
(
2
)
<<
"var["
<<
i
<<
"] is lod_tensor and len="
<<
out
->
at
(
i
).
lod
[
0
].
back
();
}
else
{
...
...
@@ -211,11 +230,6 @@ int GeneralReaderOp::inference() {
for
(
int
k
=
0
;
k
<
elem_num
;
++
k
)
{
dst_ptr
[
offset
+
k
]
=
req
->
insts
(
j
).
tensor_array
(
i
).
int64_data
(
k
);
}
if
(
out
->
at
(
i
).
lod
.
size
()
==
1
)
{
offset
=
out
->
at
(
i
).
lod
[
0
][
j
+
1
];
}
else
{
offset
+=
capacity
[
i
];
}
}
}
else
if
(
elem_type
[
i
]
==
1
)
{
float
*
dst_ptr
=
static_cast
<
float
*>
(
out
->
at
(
i
).
data
.
data
());
...
...
@@ -227,11 +241,6 @@ int GeneralReaderOp::inference() {
for
(
int
k
=
0
;
k
<
elem_num
;
++
k
)
{
dst_ptr
[
offset
+
k
]
=
req
->
insts
(
j
).
tensor_array
(
i
).
float_data
(
k
);
}
if
(
out
->
at
(
i
).
lod
.
size
()
==
1
)
{
offset
=
out
->
at
(
i
).
lod
[
0
][
j
+
1
];
}
else
{
offset
+=
capacity
[
i
];
}
}
}
else
if
(
elem_type
[
i
]
==
2
)
{
int32_t
*
dst_ptr
=
static_cast
<
int32_t
*>
(
out
->
at
(
i
).
data
.
data
());
...
...
@@ -243,11 +252,6 @@ int GeneralReaderOp::inference() {
for
(
int
k
=
0
;
k
<
elem_num
;
++
k
)
{
dst_ptr
[
offset
+
k
]
=
req
->
insts
(
j
).
tensor_array
(
i
).
int_data
(
k
);
}
if
(
out
->
at
(
i
).
lod
.
size
()
==
1
)
{
offset
=
out
->
at
(
i
).
lod
[
0
][
j
+
1
];
}
else
{
offset
+=
capacity
[
i
];
}
}
}
}
...
...
core/general-server/proto/general_model_service.proto
浏览文件 @
08f5877f
...
...
@@ -26,7 +26,7 @@ message Tensor {
repeated
float
float_data
=
4
;
optional
int32
elem_type
=
5
;
repeated
int32
shape
=
6
;
repeated
int32
lod
=
7
;
// only for fetch tensor currently
repeated
int32
lod
=
7
;
};
message
FeedInst
{
repeated
Tensor
tensor_array
=
1
;
};
...
...
python/paddle_serving_app/local_predict.py
浏览文件 @
08f5877f
...
...
@@ -116,7 +116,6 @@ class Debugger(object):
input_names
=
self
.
predictor
.
get_input_names
()
for
name
in
input_names
:
print
(
feed
)
if
isinstance
(
feed
[
name
],
list
):
feed
[
name
]
=
np
.
array
(
feed
[
name
]).
reshape
(
self
.
feed_shapes_
[
name
])
...
...
@@ -131,7 +130,7 @@ class Debugger(object):
input_tensor
=
self
.
predictor
.
get_input_tensor
(
name
)
#TODO:set lods
if
"{}.lod"
.
format
(
name
)
in
feed
:
input_tensor
.
set_lod
(
feed
[
"{}.lod"
.
format
(
name
)
])
input_tensor
.
set_lod
(
[
feed
[
"{}.lod"
.
format
(
name
)]
])
if
batch
==
True
:
input_tensor
.
copy_from_cpu
(
feed
[
name
][
np
.
newaxis
,:])
else
:
...
...
python/paddle_serving_app/reader/__init__.py
浏览文件 @
08f5877f
...
...
@@ -14,7 +14,7 @@
from
.chinese_bert_reader
import
ChineseBertReader
from
.image_reader
import
ImageReader
,
File2Image
,
URL2Image
,
Sequential
,
Normalize
from
.image_reader
import
CenterCrop
,
Resize
,
Transpose
,
Div
,
RGB2BGR
,
BGR2RGB
,
ResizeByFactor
from
.image_reader
import
RCNNPostprocess
,
SegPostprocess
,
PadStride
from
.image_reader
import
RCNNPostprocess
,
SegPostprocess
,
PadStride
,
BlazeFacePostprocess
from
.image_reader
import
DBPostProcess
,
FilterBoxes
,
GetRotateCropImage
,
SortedBoxes
from
.lac_reader
import
LACReader
from
.senta_reader
import
SentaReader
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
08f5877f
...
...
@@ -234,6 +234,11 @@ class Client(object):
pass
def
predict
(
self
,
feed
=
None
,
fetch
=
None
,
need_variant_tag
=
False
):
"""
predict inferface
@feed: feed name and its lod
"""
self
.
profile_
.
record
(
'py_prepro_0'
)
if
feed
is
None
or
fetch
is
None
:
...
...
@@ -257,6 +262,7 @@ class Client(object):
int_slot_batch
=
[]
float_slot_batch
=
[]
lod_slot_batch
=
[]
int_feed_names
=
[]
float_feed_names
=
[]
int_shape
=
[]
...
...
@@ -277,9 +283,14 @@ class Client(object):
for
i
,
feed_i
in
enumerate
(
feed_batch
):
int_slot
=
[]
float_slot
=
[]
lod_slot
=
[]
#print("feed_i", feed_i)
for
key
in
feed_i
:
if
key
not
in
self
.
feed_names_
:
#print("key", key)
if
".lod"
not
in
key
and
key
not
in
self
.
feed_names_
:
raise
ValueError
(
"Wrong feed name: {}."
.
format
(
key
))
if
".lod"
in
key
:
continue
#if not isinstance(feed_i[key], np.ndarray):
self
.
shape_check
(
feed_i
,
key
)
if
self
.
feed_types_
[
key
]
in
int_type
:
...
...
@@ -308,8 +319,14 @@ class Client(object):
else
:
float_slot
.
append
(
feed_i
[
key
])
self
.
all_numpy_input
=
False
if
".lod"
in
key
:
lod_slot
.
append
(
var
.
lod
)
int_slot_batch
.
append
(
int_slot
)
float_slot_batch
.
append
(
float_slot
)
lod_slot_batch
.
append
(
lod_slot
)
#print("int slot", int_slot_batch)
#print("float slot", float_slot_batch)
self
.
profile_
.
record
(
'py_prepro_1'
)
self
.
profile_
.
record
(
'py_client_infer_0'
)
...
...
@@ -318,7 +335,7 @@ class Client(object):
if
self
.
all_numpy_input
:
res
=
self
.
client_handle_
.
numpy_predict
(
float_slot_batch
,
float_feed_names
,
float_shape
,
int_slot_batch
,
int_feed_names
,
int_shape
,
fetch_names
,
result_batch_handle
,
int_feed_names
,
lod_slot_batch
,
int_shape
,
fetch_names
,
result_batch_handle
,
self
.
pid
)
elif
self
.
has_numpy_input
==
False
:
res
=
self
.
client_handle_
.
batch_predict
(
...
...
@@ -466,7 +483,7 @@ class MultiLangClient(object):
if
var
.
is_lod_tensor
:
self
.
lod_tensor_set_
.
add
(
var
.
alias_name
)
def
_pack_inference_request
(
self
,
feed
,
fetch
,
is_python
):
def
_pack_inference_request
(
self
,
feed
,
fetch
,
is_python
,
batch
=
False
):
req
=
multi_lang_general_model_service_pb2
.
InferenceRequest
()
req
.
fetch_var_names
.
extend
(
fetch
)
req
.
is_python
=
is_python
...
...
@@ -477,12 +494,17 @@ class MultiLangClient(object):
feed_batch
=
feed
else
:
raise
Exception
(
"{} not support"
.
format
(
type
(
feed
)))
req
.
feed_var_names
.
extend
(
feed_batch
[
0
].
keys
())
for
x
in
feed_batch
[
0
].
keys
():
if
".lod"
not
in
x
:
req
.
feed_var_names
.
append
(
x
)
init_feed_names
=
False
for
feed_data
in
feed_batch
:
inst
=
multi_lang_general_model_service_pb2
.
FeedInst
()
for
name
in
req
.
feed_var_names
:
tensor
=
multi_lang_general_model_service_pb2
.
Tensor
()
if
"{}.lod"
.
format
(
name
)
in
feed_data
:
var_lod
=
feed_data
[
"{}.lod"
.
format
(
name
)]
tensor
.
lod
.
extend
(
var_lod
)
var
=
feed_data
[
name
]
v_type
=
self
.
feed_types_
[
name
]
if
is_python
:
...
...
@@ -536,6 +558,8 @@ class MultiLangClient(object):
raise
Exception
(
"error tensor value type."
)
else
:
raise
Exception
(
"var must be list or ndarray."
)
if
batch
==
False
:
tensor
.
shape
.
append
(
1
)
if
isinstance
(
var
,
np
.
ndarray
):
tensor
.
shape
.
extend
(
list
(
var
.
shape
))
else
:
...
...
@@ -602,12 +626,12 @@ class MultiLangClient(object):
fetch
,
need_variant_tag
=
False
,
asyn
=
False
,
is_python
=
True
):
is_python
=
True
,
batch
=
False
):
if
not
asyn
:
try
:
self
.
profile_
.
record
(
'py_prepro_0'
)
req
=
self
.
_pack_inference_request
(
feed
,
fetch
,
is_python
=
is_python
)
req
=
self
.
_pack_inference_request
(
feed
,
fetch
,
is_python
=
is_python
,
batch
=
batch
)
self
.
profile_
.
record
(
'py_prepro_1'
)
self
.
profile_
.
record
(
'py_client_infer_0'
)
...
...
@@ -626,7 +650,7 @@ class MultiLangClient(object):
except
grpc
.
RpcError
as
e
:
return
{
"serving_status_code"
:
e
.
code
()}
else
:
req
=
self
.
_pack_inference_request
(
feed
,
fetch
,
is_python
=
is_python
)
req
=
self
.
_pack_inference_request
(
feed
,
fetch
,
is_python
=
is_python
,
batch
=
batch
)
call_future
=
self
.
stub_
.
Inference
.
future
(
req
,
timeout
=
self
.
rpc_timeout_s_
)
return
MultiLangPredictFuture
(
...
...
python/paddle_serving_server/__init__.py
浏览文件 @
08f5877f
...
...
@@ -533,6 +533,8 @@ class MultiLangServerServiceServicer(multi_lang_general_model_service_pb2_grpc.
raise
Exception
(
"error type."
)
data
.
shape
=
list
(
feed_inst
.
tensor_array
[
idx
].
shape
)
feed_dict
[
name
]
=
data
if
len
(
var
.
lod
)
>
0
:
feed_dict
[
"{}.lod"
.
format
(
name
)]
=
var
.
lod
feed_batch
.
append
(
feed_dict
)
return
feed_batch
,
fetch_names
,
is_python
...
...
@@ -569,12 +571,16 @@ class MultiLangServerServiceServicer(multi_lang_general_model_service_pb2_grpc.
raise
Exception
(
"error type."
)
tensor
.
shape
.
extend
(
list
(
model_result
[
name
].
shape
))
if
name
in
self
.
lod_tensor_set_
:
tensor
.
lod
.
extend
(
model_result
[
"{}.lod"
.
format
(
name
)]
.
tolist
())
tmp_lod
=
model_result
[
"{}.lod"
.
format
(
name
)]
if
isinstance
(
tmp_lod
,
list
):
tensor
.
lod
.
extend
(
tmp_lod
)
else
:
tensor
.
lod
.
extend
(
tmp_lod
.
tolist
())
inst
.
tensor_array
.
append
(
tensor
)
model_output
.
insts
.
append
(
inst
)
model_output
.
engine_name
=
model_name
resp
.
outputs
.
append
(
model_output
)
#print("resp", resp)
return
resp
def
SetTimeout
(
self
,
request
,
context
):
...
...
@@ -587,15 +593,21 @@ class MultiLangServerServiceServicer(multi_lang_general_model_service_pb2_grpc.
return
resp
def
Inference
(
self
,
request
,
context
):
feed_dict
,
fetch_names
,
is_python
=
self
.
_unpack_inference_request
(
request
)
if
self
.
local_predictor
==
None
:
ret
=
self
.
bclient_
.
predict
(
feed
=
feed_dict
,
fetch
=
fetch_names
,
need_variant_tag
=
True
)
else
:
ret
=
[
self
.
local_predictor
.
predict
(
feed
=
feed_dict
[
0
],
fetch
=
fetch_names
),
"VariantTagNeeded"
]
return
self
.
_pack_inference_response
(
ret
,
fetch_names
,
is_python
)
try
:
feed_dict
,
fetch_names
,
is_python
=
self
.
_unpack_inference_request
(
request
)
if
self
.
local_predictor
==
None
:
ret
=
self
.
bclient_
.
predict
(
feed
=
feed_dict
,
fetch
=
fetch_names
,
need_variant_tag
=
True
)
else
:
ret
=
[
self
.
local_predictor
.
predict
(
feed
=
feed_dict
[
0
],
fetch
=
fetch_names
),
"VariantTagNeeded"
]
#print("ret", ret)
res
=
self
.
_pack_inference_response
(
ret
,
fetch_names
,
is_python
)
return
res
except
Exception
as
e
:
import
traceback
print
(
traceback
.
format_exc
())
def
GetClientConfig
(
self
,
request
,
context
):
resp
=
multi_lang_general_model_service_pb2
.
GetClientConfigResponse
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录