Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
e8f31562
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看板
提交
e8f31562
编写于
8月 31, 2021
作者:
S
ShiningZhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add datatype param for PredictorData
上级
1344d989
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
13 deletion
+43
-13
core/general-client/include/client.h
core/general-client/include/client.h
+11
-4
core/general-client/src/brpc_client.cpp
core/general-client/src/brpc_client.cpp
+0
-1
core/general-client/src/client.cpp
core/general-client/src/client.cpp
+32
-8
未找到文件。
core/general-client/include/client.h
浏览文件 @
e8f31562
...
@@ -69,22 +69,26 @@ class PredictorData {
...
@@ -69,22 +69,26 @@ class PredictorData {
void
add_float_data
(
const
std
::
vector
<
float
>&
data
,
void
add_float_data
(
const
std
::
vector
<
float
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
=
1
);
void
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
void
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
=
0
);
void
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
void
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
=
2
);
void
add_string_data
(
const
std
::
string
&
data
,
void
add_string_data
(
const
std
::
string
&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
=
3
);
const
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>&
float_data_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>&
float_data_map
()
const
{
return
_float_data_map
;
return
_float_data_map
;
...
@@ -134,6 +138,8 @@ class PredictorData {
...
@@ -134,6 +138,8 @@ class PredictorData {
return
&
_lod_map
;
return
&
_lod_map
;
};
};
int
get_datatype
(
std
::
string
name
)
const
;
std
::
string
print
();
std
::
string
print
();
private:
private:
...
@@ -189,6 +195,7 @@ class PredictorData {
...
@@ -189,6 +195,7 @@ class PredictorData {
std
::
map
<
std
::
string
,
std
::
string
>
_string_data_map
;
std
::
map
<
std
::
string
,
std
::
string
>
_string_data_map
;
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
_shape_map
;
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
_shape_map
;
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
_lod_map
;
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
_lod_map
;
std
::
map
<
std
::
string
,
int
>
_datatype_map
;
};
};
class
PredictorInputs
:
public
PredictorData
{
class
PredictorInputs
:
public
PredictorData
{
...
...
core/general-client/src/brpc_client.cpp
浏览文件 @
e8f31562
...
@@ -29,7 +29,6 @@ using baidu::paddle_serving::Timer;
...
@@ -29,7 +29,6 @@ using baidu::paddle_serving::Timer;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Request
;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Request
;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Tensor
;
using
baidu
::
paddle_serving
::
predictor
::
general_model
::
Tensor
;
enum
ProtoDataType
{
P_INT64
,
P_FLOAT32
,
P_INT32
,
P_STRING
};
using
configure
::
SDKConf
;
using
configure
::
SDKConf
;
using
configure
::
VariantConf
;
using
configure
::
VariantConf
;
...
...
core/general-client/src/client.cpp
浏览文件 @
e8f31562
...
@@ -107,37 +107,53 @@ int ServingClient::load_client_config(const std::vector<std::string> &conf_file)
...
@@ -107,37 +107,53 @@ int ServingClient::load_client_config(const std::vector<std::string> &conf_file)
void
PredictorData
::
add_float_data
(
const
std
::
vector
<
float
>&
data
,
void
PredictorData
::
add_float_data
(
const
std
::
vector
<
float
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
)
{
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
)
{
_float_data_map
[
name
]
=
data
;
_float_data_map
[
name
]
=
data
;
_shape_map
[
name
]
=
shape
;
_shape_map
[
name
]
=
shape
;
_lod_map
[
name
]
=
lod
;
_lod_map
[
name
]
=
lod
;
_datatype_map
[
name
]
=
datatype
;
}
}
void
PredictorData
::
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
void
PredictorData
::
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
)
{
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
)
{
_int64_data_map
[
name
]
=
data
;
_int64_data_map
[
name
]
=
data
;
_shape_map
[
name
]
=
shape
;
_shape_map
[
name
]
=
shape
;
_lod_map
[
name
]
=
lod
;
_lod_map
[
name
]
=
lod
;
_datatype_map
[
name
]
=
datatype
;
}
}
void
PredictorData
::
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
void
PredictorData
::
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
)
{
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
)
{
_int32_data_map
[
name
]
=
data
;
_int32_data_map
[
name
]
=
data
;
_shape_map
[
name
]
=
shape
;
_shape_map
[
name
]
=
shape
;
_lod_map
[
name
]
=
lod
;
_lod_map
[
name
]
=
lod
;
_datatype_map
[
name
]
=
datatype
;
}
}
void
PredictorData
::
add_string_data
(
const
std
::
string
&
data
,
void
PredictorData
::
add_string_data
(
const
std
::
string
&
data
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
)
{
const
std
::
vector
<
int
>&
lod
,
const
int
datatype
)
{
_string_data_map
[
name
]
=
data
;
_string_data_map
[
name
]
=
data
;
_shape_map
[
name
]
=
shape
;
_shape_map
[
name
]
=
shape
;
_lod_map
[
name
]
=
lod
;
_lod_map
[
name
]
=
lod
;
_datatype_map
[
name
]
=
datatype
;
}
int
PredictorData
::
get_datatype
(
std
::
string
name
)
const
{
std
::
map
<
std
::
string
,
int
>::
const_iterator
it
=
_datatype_map
.
find
(
name
);
if
(
it
!=
_datatype_map
.
end
())
{
return
it
->
second
;
}
return
0
;
}
}
std
::
string
PredictorData
::
print
()
{
std
::
string
PredictorData
::
print
()
{
...
@@ -173,6 +189,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -173,6 +189,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
const
std
::
vector
<
float
>&
float_data
=
iter
->
second
;
const
std
::
vector
<
float
>&
float_data
=
iter
->
second
;
const
std
::
vector
<
int
>&
float_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
float_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
float_lod
=
lod_map
.
at
(
name
);
const
std
::
vector
<
int
>&
float_lod
=
lod_map
.
at
(
name
);
// default datatype = P_FLOAT32
int
datatype
=
inputs
.
get_datatype
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
...
@@ -191,7 +209,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -191,7 +209,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
for
(
uint32_t
j
=
0
;
j
<
float_lod
.
size
();
++
j
)
{
for
(
uint32_t
j
=
0
;
j
<
float_lod
.
size
();
++
j
)
{
tensor
->
add_lod
(
float_lod
[
j
]);
tensor
->
add_lod
(
float_lod
[
j
]);
}
}
tensor
->
set_elem_type
(
P_FLOAT32
);
tensor
->
set_elem_type
(
datatype
);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_alias_name
(
name
);
tensor
->
set_alias_name
(
name
);
...
@@ -207,6 +225,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -207,6 +225,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
const
std
::
vector
<
int64_t
>&
int64_data
=
iter
->
second
;
const
std
::
vector
<
int64_t
>&
int64_data
=
iter
->
second
;
const
std
::
vector
<
int
>&
int64_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int64_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int64_lod
=
lod_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int64_lod
=
lod_map
.
at
(
name
);
// default datatype = P_INT64
int
datatype
=
inputs
.
get_datatype
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
...
@@ -222,7 +242,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -222,7 +242,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
for
(
uint32_t
j
=
0
;
j
<
int64_lod
.
size
();
++
j
)
{
for
(
uint32_t
j
=
0
;
j
<
int64_lod
.
size
();
++
j
)
{
tensor
->
add_lod
(
int64_lod
[
j
]);
tensor
->
add_lod
(
int64_lod
[
j
]);
}
}
tensor
->
set_elem_type
(
P_INT64
);
tensor
->
set_elem_type
(
datatype
);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_alias_name
(
name
);
tensor
->
set_alias_name
(
name
);
...
@@ -237,6 +257,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -237,6 +257,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
const
std
::
vector
<
int32_t
>&
int32_data
=
iter
->
second
;
const
std
::
vector
<
int32_t
>&
int32_data
=
iter
->
second
;
const
std
::
vector
<
int
>&
int32_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int32_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int32_lod
=
lod_map
.
at
(
name
);
const
std
::
vector
<
int
>&
int32_lod
=
lod_map
.
at
(
name
);
// default datatype = P_INT32
int
datatype
=
inputs
.
get_datatype
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
...
@@ -252,7 +274,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -252,7 +274,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
for
(
uint32_t
j
=
0
;
j
<
int32_lod
.
size
();
++
j
)
{
for
(
uint32_t
j
=
0
;
j
<
int32_lod
.
size
();
++
j
)
{
tensor
->
add_lod
(
int32_lod
[
j
]);
tensor
->
add_lod
(
int32_lod
[
j
]);
}
}
tensor
->
set_elem_type
(
P_INT32
);
tensor
->
set_elem_type
(
datatype
);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_alias_name
(
name
);
tensor
->
set_alias_name
(
name
);
...
@@ -267,6 +289,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -267,6 +289,8 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
const
std
::
string
&
string_data
=
iter
->
second
;
const
std
::
string
&
string_data
=
iter
->
second
;
const
std
::
vector
<
int
>&
string_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
string_shape
=
shape_map
.
at
(
name
);
const
std
::
vector
<
int
>&
string_lod
=
lod_map
.
at
(
name
);
const
std
::
vector
<
int
>&
string_lod
=
lod_map
.
at
(
name
);
// default datatype = P_STRING
int
datatype
=
inputs
.
get_datatype
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
std
::
map
<
std
::
string
,
int
>::
const_iterator
feed_name_it
=
feed_name_to_idx
.
find
(
name
);
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
if
(
feed_name_it
==
feed_name_to_idx
.
end
())
{
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
LOG
(
ERROR
)
<<
"Do not find ["
<<
name
<<
"] in feed_map!"
;
...
@@ -281,7 +305,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
...
@@ -281,7 +305,7 @@ int PredictorInputs::GenProto(const PredictorInputs& inputs,
for
(
uint32_t
j
=
0
;
j
<
string_lod
.
size
();
++
j
)
{
for
(
uint32_t
j
=
0
;
j
<
string_lod
.
size
();
++
j
)
{
tensor
->
add_lod
(
string_lod
[
j
]);
tensor
->
add_lod
(
string_lod
[
j
]);
}
}
tensor
->
set_elem_type
(
P_STRING
);
tensor
->
set_elem_type
(
datatype
);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_name
(
feed_name
[
idx
]);
tensor
->
set_alias_name
(
name
);
tensor
->
set_alias_name
(
name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录