Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
43c55732
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,发现更多精彩内容 >>
提交
43c55732
编写于
1月 19, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix general model op batch predict bug
上级
9c3c3eb9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
26 deletion
+21
-26
examples/demo-serving/op/general_model_op.cpp
examples/demo-serving/op/general_model_op.cpp
+21
-26
未找到文件。
examples/demo-serving/op/general_model_op.cpp
浏览文件 @
43c55732
...
...
@@ -14,8 +14,8 @@
#include "examples/demo-serving/op/general_model_op.h"
#include <algorithm>
#include <sstream>
#include <iostream>
#include <sstream>
#include "core/predictor/framework/infer.h"
#include "core/predictor/framework/memory.h"
...
...
@@ -69,9 +69,7 @@ int GeneralModelOp::inference() {
}
else
{
lod_tensor
.
shape
.
push_back
(
batch_size
);
capacity
[
i
]
=
1
;
for
(
int
k
=
0
;
k
<
req
->
insts
(
0
).
tensor_array
(
i
).
shape_size
();
++
k
)
{
for
(
int
k
=
0
;
k
<
req
->
insts
(
0
).
tensor_array
(
i
).
shape_size
();
++
k
)
{
int
dim
=
req
->
insts
(
0
).
tensor_array
(
i
).
shape
(
k
);
VLOG
(
3
)
<<
"shape for var["
<<
i
<<
"]: "
<<
dim
;
capacity
[
i
]
*=
dim
;
...
...
@@ -90,10 +88,9 @@ int GeneralModelOp::inference() {
for
(
int
i
=
0
;
i
<
var_num
;
++
i
)
{
if
(
in
->
at
(
i
).
lod
.
size
()
==
1
)
{
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
const
Tensor
&
tensor
=
req
->
insts
(
j
).
tensor_array
(
i
);
const
Tensor
&
tensor
=
req
->
insts
(
j
).
tensor_array
(
i
);
int
data_len
=
tensor
.
data_size
();
VLOG
(
3
)
<<
"tensor size for var["
<<
i
<<
"]: "
<<
tensor
.
data_size
();
VLOG
(
3
)
<<
"tensor size for var["
<<
i
<<
"]: "
<<
tensor
.
data_size
();
int
cur_len
=
in
->
at
(
i
).
lod
[
0
].
back
();
VLOG
(
3
)
<<
"current len: "
<<
cur_len
;
in
->
at
(
i
).
lod
[
0
].
push_back
(
cur_len
+
data_len
);
...
...
@@ -101,18 +98,18 @@ int GeneralModelOp::inference() {
}
in
->
at
(
i
).
data
.
Resize
(
in
->
at
(
i
).
lod
[
0
].
back
()
*
elem_size
[
i
]);
in
->
at
(
i
).
shape
=
{
in
->
at
(
i
).
lod
[
0
].
back
(),
1
};
VLOG
(
3
)
<<
"var["
<<
i
<<
"] is lod_tensor and len="
<<
in
->
at
(
i
).
lod
[
0
].
back
();
VLOG
(
3
)
<<
"var["
<<
i
<<
"] is lod_tensor and len="
<<
in
->
at
(
i
).
lod
[
0
].
back
();
}
else
{
in
->
at
(
i
).
data
.
Resize
(
batch_size
*
capacity
[
i
]
*
elem_size
[
i
]);
VLOG
(
3
)
<<
"var["
<<
i
<<
"] is tensor and capacity="
<<
batch_size
*
capacity
[
i
];
VLOG
(
3
)
<<
"var["
<<
i
<<
"] is tensor and capacity="
<<
batch_size
*
capacity
[
i
];
}
}
for
(
int
i
=
0
;
i
<
var_num
;
++
i
)
{
if
(
elem_type
[
i
]
==
0
)
{
int64_t
*
dst_ptr
=
static_cast
<
int64_t
*>
(
in
->
at
(
i
).
data
.
data
());
int64_t
*
dst_ptr
=
static_cast
<
int64_t
*>
(
in
->
at
(
i
).
data
.
data
());
int
offset
=
0
;
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
for
(
int
k
=
0
;
k
<
req
->
insts
(
j
).
tensor_array
(
i
).
data_size
();
++
k
)
{
...
...
@@ -126,7 +123,7 @@ int GeneralModelOp::inference() {
}
}
}
else
{
float
*
dst_ptr
=
static_cast
<
float
*>
(
in
->
at
(
i
).
data
.
data
());
float
*
dst_ptr
=
static_cast
<
float
*>
(
in
->
at
(
i
).
data
.
data
());
int
offset
=
0
;
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
for
(
int
k
=
0
;
k
<
req
->
insts
(
j
).
tensor_array
(
i
).
data_size
();
++
k
)
{
...
...
@@ -151,17 +148,16 @@ int GeneralModelOp::inference() {
if
(
predictor
::
InferManager
::
instance
().
infer
(
GENERAL_MODEL_NAME
,
in
,
out
,
batch_size
))
{
LOG
(
ERROR
)
<<
"Failed do infer in fluid model: "
<<
GENERAL_MODEL_NAME
;
LOG
(
ERROR
)
<<
"Failed do infer in fluid model: "
<<
GENERAL_MODEL_NAME
;
return
-
1
;
}
Response
*
res
=
mutable_data
<
Response
>
();
Response
*
res
=
mutable_data
<
Response
>
();
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
FetchInst
*
fetch_inst
=
res
->
add_insts
();
FetchInst
*
fetch_inst
=
res
->
add_insts
();
for
(
int
j
=
0
;
j
<
out
->
size
();
++
j
)
{
Tensor
*
tensor
=
fetch_inst
->
add_tensor_array
();
Tensor
*
tensor
=
fetch_inst
->
add_tensor_array
();
tensor
->
set_elem_type
(
1
);
if
(
out
->
at
(
j
).
lod
.
size
()
==
1
)
{
tensor
->
add_shape
(
-
1
);
...
...
@@ -174,30 +170,29 @@ int GeneralModelOp::inference() {
}
for
(
int
i
=
0
;
i
<
out
->
size
();
++
i
)
{
float
*
data_ptr
=
static_cast
<
float
*>
(
out
->
at
(
i
).
data
.
data
());
float
*
data_ptr
=
static_cast
<
float
*>
(
out
->
at
(
i
).
data
.
data
());
int
cap
=
1
;
for
(
int
j
=
0
;
j
<
out
->
at
(
i
).
shape
.
size
();
++
j
)
{
for
(
int
j
=
1
;
j
<
out
->
at
(
i
).
shape
.
size
();
++
j
)
{
cap
*=
out
->
at
(
i
).
shape
[
j
];
}
if
(
out
->
at
(
i
).
lod
.
size
()
==
1
)
{
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
for
(
int
k
=
out
->
at
(
i
).
lod
[
0
][
j
];
k
<
out
->
at
(
i
).
lod
[
0
][
j
+
1
];
for
(
int
k
=
out
->
at
(
i
).
lod
[
0
][
j
];
k
<
out
->
at
(
i
).
lod
[
0
][
j
+
1
];
k
++
)
{
res
->
mutable_insts
(
j
)
->
mutable_tensor_array
(
i
)
->
add_data
(
(
char
*
)
(
&
(
data_ptr
[
k
])),
sizeof
(
float
));
reinterpret_cast
<
char
*>
(
&
(
data_ptr
[
k
])),
sizeof
(
float
));
}
}
}
else
{
for
(
int
j
=
0
;
j
<
batch_size
;
++
j
)
{
for
(
int
k
=
j
*
cap
;
k
<
(
j
+
1
)
*
cap
;
++
k
)
{
res
->
mutable_insts
(
j
)
->
mutable_tensor_array
(
i
)
->
add_data
(
(
char
*
)
(
&
(
data_ptr
[
k
])),
sizeof
(
float
));
reinterpret_cast
<
char
*>
(
&
(
data_ptr
[
k
])),
sizeof
(
float
));
}
}
}
}
for
(
size_t
i
=
0
;
i
<
in
->
size
();
++
i
)
{
(
*
in
)[
i
].
shape
.
clear
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录