Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
2ba9f25f
S
Serving
项目概览
PaddlePaddle
/
Serving
12 个月 前同步成功
通知
183
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2ba9f25f
编写于
5月 23, 2020
作者:
D
Dong Daxiang
提交者:
GitHub
5月 23, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #581 from MRXLT/lod-numpy
lod tensor feed support numpy array input
上级
1e11450e
adfd94c7
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
64 addition
and
39 deletion
+64
-39
core/general-server/op/general_reader_op.cpp
core/general-server/op/general_reader_op.cpp
+19
-5
core/general-server/op/general_response_op.cpp
core/general-server/op/general_response_op.cpp
+37
-17
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+8
-17
未找到文件。
core/general-server/op/general_reader_op.cpp
浏览文件 @
2ba9f25f
...
...
@@ -131,7 +131,7 @@ int GeneralReaderOp::inference() {
lod_tensor
.
dtype
=
paddle
::
PaddleDType
::
FLOAT32
;
}
if
(
req
->
insts
(
0
).
tensor_array
(
i
).
shape
(
0
)
==
-
1
)
{
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"
;
...
...
@@ -153,6 +153,7 @@ int GeneralReaderOp::inference() {
// specify the memory needed for output tensor_vector
for
(
int
i
=
0
;
i
<
var_num
;
++
i
)
{
if
(
out
->
at
(
i
).
lod
.
size
()
==
1
)
{
int
tensor_size
=
0
;
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
const
Tensor
&
tensor
=
req
->
insts
(
j
).
tensor_array
(
i
);
int
data_len
=
0
;
...
...
@@ -162,15 +163,28 @@ int GeneralReaderOp::inference() {
data_len
=
tensor
.
float_data_size
();
}
VLOG
(
2
)
<<
"tensor size for var["
<<
i
<<
"]: "
<<
data_len
;
tensor_size
+=
data_len
;
int
cur_len
=
out
->
at
(
i
).
lod
[
0
].
back
();
VLOG
(
2
)
<<
"current len: "
<<
cur_len
;
out
->
at
(
i
).
lod
[
0
].
push_back
(
cur_len
+
data_len
);
VLOG
(
2
)
<<
"new len: "
<<
cur_len
+
data_len
;
int
sample_len
=
0
;
if
(
tensor
.
shape_size
()
==
1
)
{
sample_len
=
data_len
;
}
else
{
sample_len
=
tensor
.
shape
(
0
);
}
out
->
at
(
i
).
lod
[
0
].
push_back
(
cur_len
+
sample_len
);
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
()};
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
);
}
out
->
at
(
i
).
data
.
Resize
(
out
->
at
(
i
).
lod
[
0
].
back
()
*
elem_size
[
i
]);
out
->
at
(
i
).
shape
=
{
out
->
at
(
i
).
lod
[
0
].
back
(),
1
};
VLOG
(
2
)
<<
"var["
<<
i
<<
"] is lod_tensor and len="
<<
out
->
at
(
i
).
lod
[
0
].
back
();
}
else
{
...
...
core/general-server/op/general_response_op.cpp
浏览文件 @
2ba9f25f
...
...
@@ -15,8 +15,10 @@
#include "core/general-server/op/general_response_op.h"
#include <algorithm>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <utility>
#include "core/general-server/op/general_infer_helper.h"
#include "core/predictor/framework/infer.h"
#include "core/predictor/framework/memory.h"
...
...
@@ -86,37 +88,51 @@ int GeneralResponseOp::inference() {
// To get the order of model return values
output
->
set_engine_name
(
pre_name
);
FetchInst
*
fetch_inst
=
output
->
add_insts
();
std
::
map
<
std
::
string
,
int
>
fetch_index_map
;
for
(
int
i
=
0
;
i
<
in
->
size
();
++
i
)
{
VLOG
(
2
)
<<
"index "
<<
i
<<
" var "
<<
in
->
at
(
i
).
name
;
fetch_index_map
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
in
->
at
(
i
).
name
,
i
));
}
for
(
auto
&
idx
:
fetch_index
)
{
Tensor
*
tensor
=
fetch_inst
->
add_tensor_array
();
tensor
->
set_elem_type
(
1
);
int
true_idx
=
fetch_index_map
[
model_config
->
_fetch_name
[
idx
]];
if
(
model_config
->
_is_lod_fetch
[
idx
])
{
VLOG
(
2
)
<<
"out["
<<
idx
<<
"] is lod_tensor"
;
for
(
int
k
=
0
;
k
<
in
->
at
(
idx
).
shape
.
size
();
++
k
)
{
VLOG
(
2
)
<<
"out["
<<
idx
<<
"] "
<<
model_config
->
_fetch_name
[
idx
]
<<
" is lod_tensor"
;
for
(
int
k
=
0
;
k
<
in
->
at
(
true_idx
).
shape
.
size
();
++
k
)
{
VLOG
(
2
)
<<
"shape["
<<
k
<<
"]: "
<<
in
->
at
(
idx
).
shape
[
k
];
tensor
->
add_shape
(
in
->
at
(
idx
).
shape
[
k
]);
tensor
->
add_shape
(
in
->
at
(
true_
idx
).
shape
[
k
]);
}
}
else
{
VLOG
(
2
)
<<
"out["
<<
idx
<<
"] is tensor"
;
for
(
int
k
=
0
;
k
<
in
->
at
(
idx
).
shape
.
size
();
++
k
)
{
VLOG
(
2
)
<<
"shape["
<<
k
<<
"]: "
<<
in
->
at
(
idx
).
shape
[
k
];
tensor
->
add_shape
(
in
->
at
(
idx
).
shape
[
k
]);
VLOG
(
2
)
<<
"out["
<<
idx
<<
"] "
<<
model_config
->
_fetch_name
[
idx
]
<<
" is tensor"
;
for
(
int
k
=
0
;
k
<
in
->
at
(
true_idx
).
shape
.
size
();
++
k
)
{
VLOG
(
2
)
<<
"shape["
<<
k
<<
"]: "
<<
in
->
at
(
true_idx
).
shape
[
k
];
tensor
->
add_shape
(
in
->
at
(
true_idx
).
shape
[
k
]);
}
}
}
int
var_idx
=
0
;
for
(
auto
&
idx
:
fetch_index
)
{
int
true_idx
=
fetch_index_map
[
model_config
->
_fetch_name
[
idx
]];
int
cap
=
1
;
for
(
int
j
=
0
;
j
<
in
->
at
(
idx
).
shape
.
size
();
++
j
)
{
cap
*=
in
->
at
(
idx
).
shape
[
j
];
}
if
(
in
->
at
(
idx
).
dtype
==
paddle
::
PaddleDType
::
INT64
)
{
int64_t
*
data_ptr
=
static_cast
<
int64_t
*>
(
in
->
at
(
idx
).
data
.
data
());
for
(
int
j
=
0
;
j
<
in
->
at
(
true_idx
).
shape
.
size
();
++
j
)
{
cap
*=
in
->
at
(
true_idx
).
shape
[
j
];
}
if
(
in
->
at
(
true_idx
).
dtype
==
paddle
::
PaddleDType
::
INT64
)
{
VLOG
(
2
)
<<
"Prepare float var ["
<<
model_config
->
_fetch_name
[
idx
]
<<
"]."
;
int64_t
*
data_ptr
=
static_cast
<
int64_t
*>
(
in
->
at
(
true_idx
).
data
.
data
());
if
(
model_config
->
_is_lod_fetch
[
idx
])
{
FetchInst
*
fetch_p
=
output
->
mutable_insts
(
0
);
for
(
int
j
=
0
;
j
<
in
->
at
(
idx
).
lod
[
0
].
size
();
++
j
)
{
for
(
int
j
=
0
;
j
<
in
->
at
(
true_
idx
).
lod
[
0
].
size
();
++
j
)
{
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_lod
(
in
->
at
(
idx
).
lod
[
0
][
j
]);
in
->
at
(
true_
idx
).
lod
[
0
][
j
]);
}
for
(
int
j
=
0
;
j
<
cap
;
++
j
)
{
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_int64_data
(
data_ptr
[
j
]);
...
...
@@ -127,14 +143,17 @@ int GeneralResponseOp::inference() {
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_int64_data
(
data_ptr
[
j
]);
}
}
VLOG
(
2
)
<<
"fetch var ["
<<
model_config
->
_fetch_name
[
idx
]
<<
"] ready"
;
var_idx
++
;
}
else
if
(
in
->
at
(
idx
).
dtype
==
paddle
::
PaddleDType
::
FLOAT32
)
{
float
*
data_ptr
=
static_cast
<
float
*>
(
in
->
at
(
idx
).
data
.
data
());
}
else
if
(
in
->
at
(
true_idx
).
dtype
==
paddle
::
PaddleDType
::
FLOAT32
)
{
VLOG
(
2
)
<<
"Prepare float var ["
<<
model_config
->
_fetch_name
[
idx
]
<<
"]."
;
float
*
data_ptr
=
static_cast
<
float
*>
(
in
->
at
(
true_idx
).
data
.
data
());
if
(
model_config
->
_is_lod_fetch
[
idx
])
{
FetchInst
*
fetch_p
=
output
->
mutable_insts
(
0
);
for
(
int
j
=
0
;
j
<
in
->
at
(
idx
).
lod
[
0
].
size
();
++
j
)
{
for
(
int
j
=
0
;
j
<
in
->
at
(
true_
idx
).
lod
[
0
].
size
();
++
j
)
{
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_lod
(
in
->
at
(
idx
).
lod
[
0
][
j
]);
in
->
at
(
true_
idx
).
lod
[
0
][
j
]);
}
for
(
int
j
=
0
;
j
<
cap
;
++
j
)
{
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_float_data
(
data_ptr
[
j
]);
...
...
@@ -145,6 +164,7 @@ int GeneralResponseOp::inference() {
fetch_p
->
mutable_tensor_array
(
var_idx
)
->
add_float_data
(
data_ptr
[
j
]);
}
}
VLOG
(
2
)
<<
"fetch var ["
<<
model_config
->
_fetch_name
[
idx
]
<<
"] ready"
;
var_idx
++
;
}
}
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
2ba9f25f
...
...
@@ -203,7 +203,12 @@ class Client(object):
def
shape_check
(
self
,
feed
,
key
):
if
key
in
self
.
lod_tensor_set
:
return
if
len
(
feed
[
key
])
!=
self
.
feed_tensor_len
[
key
]:
if
isinstance
(
feed
[
key
],
list
)
and
len
(
feed
[
key
])
!=
self
.
feed_tensor_len
[
key
]:
raise
SystemExit
(
"The shape of feed tensor {} not match."
.
format
(
key
))
if
type
(
feed
[
key
]).
__module__
==
np
.
__name__
and
np
.
size
(
feed
[
key
])
!=
self
.
feed_tensor_len
[
key
]:
raise
SystemExit
(
"The shape of feed tensor {} not match."
.
format
(
key
))
...
...
@@ -254,23 +259,16 @@ class Client(object):
for
key
in
feed_i
:
if
key
not
in
self
.
feed_names_
:
raise
ValueError
(
"Wrong feed name: {}."
.
format
(
key
))
if
not
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
#
if not isinstance(feed_i[key], np.ndarray):
self
.
shape_check
(
feed_i
,
key
)
if
self
.
feed_types_
[
key
]
==
int_type
:
if
i
==
0
:
int_feed_names
.
append
(
key
)
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
if
key
in
self
.
lod_tensor_set
:
raise
ValueError
(
"LodTensor var can not be ndarray type."
)
int_shape
.
append
(
list
(
feed_i
[
key
].
shape
))
else
:
int_shape
.
append
(
self
.
feed_shapes_
[
key
])
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
if
key
in
self
.
lod_tensor_set
:
raise
ValueError
(
"LodTensor var can not be ndarray type."
)
#int_slot.append(np.reshape(feed_i[key], (-1)).tolist())
int_slot
.
append
(
feed_i
[
key
])
self
.
has_numpy_input
=
True
else
:
...
...
@@ -280,17 +278,10 @@ class Client(object):
if
i
==
0
:
float_feed_names
.
append
(
key
)
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
if
key
in
self
.
lod_tensor_set
:
raise
ValueError
(
"LodTensor var can not be ndarray type."
)
float_shape
.
append
(
list
(
feed_i
[
key
].
shape
))
else
:
float_shape
.
append
(
self
.
feed_shapes_
[
key
])
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
if
key
in
self
.
lod_tensor_set
:
raise
ValueError
(
"LodTensor var can not be ndarray type."
)
#float_slot.append(np.reshape(feed_i[key], (-1)).tolist())
float_slot
.
append
(
feed_i
[
key
])
self
.
has_numpy_input
=
True
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录