Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
7aad48b9
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看板
提交
7aad48b9
编写于
5月 18, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try to get numpy array from ModelRes
上级
082fedde
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
35 addition
and
9 deletion
+35
-9
core/general-client/include/general_model.h
core/general-client/include/general_model.h
+14
-0
core/general-client/src/pybind_general_model.cpp
core/general-client/src/pybind_general_model.cpp
+18
-6
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+3
-3
未找到文件。
core/general-client/include/general_model.h
浏览文件 @
7aad48b9
...
@@ -69,9 +69,15 @@ class ModelRes {
...
@@ -69,9 +69,15 @@ class ModelRes {
const
std
::
vector
<
int64_t
>&
get_int64_by_name
(
const
std
::
string
&
name
)
{
const
std
::
vector
<
int64_t
>&
get_int64_by_name
(
const
std
::
string
&
name
)
{
return
_int64_value_map
[
name
];
return
_int64_value_map
[
name
];
}
}
std
::
vector
<
int64_t
>&&
get_int64_by_name_with_rv
(
const
std
::
string
&
name
)
{
return
std
::
move
(
_int64_value_map
[
name
]);
}
const
std
::
vector
<
float
>&
get_float_by_name
(
const
std
::
string
&
name
)
{
const
std
::
vector
<
float
>&
get_float_by_name
(
const
std
::
string
&
name
)
{
return
_float_value_map
[
name
];
return
_float_value_map
[
name
];
}
}
std
::
vector
<
float
>&&
get_float_by_name_with_rv
(
const
std
::
string
&
name
)
{
return
std
::
move
(
_float_value_map
[
name
]);
}
const
std
::
vector
<
int
>&
get_shape
(
const
std
::
string
&
name
)
{
const
std
::
vector
<
int
>&
get_shape
(
const
std
::
string
&
name
)
{
return
_shape_map
[
name
];
return
_shape_map
[
name
];
}
}
...
@@ -121,10 +127,18 @@ class PredictorRes {
...
@@ -121,10 +127,18 @@ class PredictorRes {
const
std
::
string
&
name
)
{
const
std
::
string
&
name
)
{
return
_models
[
model_idx
].
get_int64_by_name
(
name
);
return
_models
[
model_idx
].
get_int64_by_name
(
name
);
}
}
std
::
vector
<
int64_t
>&&
get_int64_by_name_with_rv
(
const
int
model_idx
,
const
std
::
string
&
name
)
{
return
std
::
move
(
_models
[
model_idx
].
get_int64_by_name_with_rv
(
name
));
}
const
std
::
vector
<
float
>&
get_float_by_name
(
const
int
model_idx
,
const
std
::
vector
<
float
>&
get_float_by_name
(
const
int
model_idx
,
const
std
::
string
&
name
)
{
const
std
::
string
&
name
)
{
return
_models
[
model_idx
].
get_float_by_name
(
name
);
return
_models
[
model_idx
].
get_float_by_name
(
name
);
}
}
std
::
vector
<
float
>&&
get_float_by_name_with_rv
(
const
int
model_idx
,
const
std
::
string
&
name
)
{
return
std
::
move
(
_models
[
model_idx
].
get_float_by_name_with_rv
(
name
));
}
const
std
::
vector
<
int
>&
get_shape
(
const
int
model_idx
,
const
std
::
vector
<
int
>&
get_shape
(
const
int
model_idx
,
const
std
::
string
&
name
)
{
const
std
::
string
&
name
)
{
return
_models
[
model_idx
].
get_shape
(
name
);
return
_models
[
model_idx
].
get_shape
(
name
);
...
...
core/general-client/src/pybind_general_model.cpp
浏览文件 @
7aad48b9
...
@@ -32,14 +32,26 @@ PYBIND11_MODULE(serving_client, m) {
...
@@ -32,14 +32,26 @@ PYBIND11_MODULE(serving_client, m) {
.
def
(
py
::
init
())
.
def
(
py
::
init
())
.
def
(
"get_int64_by_name"
,
.
def
(
"get_int64_by_name"
,
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
return
self
.
get_int64_by_name
(
model_idx
,
name
);
// https://github.com/pybind/pybind11/issues/1042
},
std
::
vector
<
int64_t
>
*
ptr
=
new
std
::
vector
<
int64_t
>
(
py
::
return_value_policy
::
reference
)
std
::
move
(
self
.
get_int64_by_name_with_rv
(
model_idx
,
name
)));
auto
capsule
=
py
::
capsule
(
ptr
,
[](
void
*
p
)
{
delete
reinterpret_cast
<
std
::
vector
<
int64_t
>
*>
(
p
);
});
return
py
::
array
(
ptr
->
size
(),
ptr
->
data
(),
capsule
);
})
.
def
(
"get_float_by_name"
,
.
def
(
"get_float_by_name"
,
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
return
self
.
get_float_by_name
(
model_idx
,
name
);
std
::
vector
<
float
>
*
ptr
=
new
std
::
vector
<
float
>
(
},
std
::
move
(
self
.
get_float_by_name_with_rv
(
model_idx
,
name
)));
py
::
return_value_policy
::
reference
)
auto
capsule
=
py
::
capsule
(
ptr
,
[](
void
*
p
)
{
delete
reinterpret_cast
<
std
::
vector
<
float
>
*>
(
p
);
});
return
py
::
array
(
ptr
->
size
(),
ptr
->
data
(),
capsule
);
// return self.get_float_by_name(model_idx, name);
})
//,
// py::return_value_policy::reference)
.
def
(
"get_shape"
,
.
def
(
"get_shape"
,
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
[](
PredictorRes
&
self
,
int
model_idx
,
std
::
string
&
name
)
{
return
self
.
get_shape
(
model_idx
,
name
);
return
self
.
get_shape
(
model_idx
,
name
);
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
7aad48b9
...
@@ -319,7 +319,7 @@ class Client(object):
...
@@ -319,7 +319,7 @@ class Client(object):
if
self
.
fetch_names_to_type_
[
name
]
==
int_type
:
if
self
.
fetch_names_to_type_
[
name
]
==
int_type
:
result_map
[
name
]
=
result_batch
.
get_int64_by_name
(
mi
,
name
)
result_map
[
name
]
=
result_batch
.
get_int64_by_name
(
mi
,
name
)
shape
=
result_batch
.
get_shape
(
mi
,
name
)
shape
=
result_batch
.
get_shape
(
mi
,
name
)
result_map
[
name
]
=
np
.
array
(
result_map
[
name
],
dtype
=
'int64'
)
#
result_map[name] = np.array(result_map[name], dtype='int64')
result_map
[
name
].
shape
=
shape
result_map
[
name
].
shape
=
shape
if
name
in
self
.
lod_tensor_set
:
if
name
in
self
.
lod_tensor_set
:
result_map
[
"{}.lod"
.
format
(
name
)]
=
np
.
array
(
result_map
[
"{}.lod"
.
format
(
name
)]
=
np
.
array
(
...
@@ -327,8 +327,8 @@ class Client(object):
...
@@ -327,8 +327,8 @@ class Client(object):
elif
self
.
fetch_names_to_type_
[
name
]
==
float_type
:
elif
self
.
fetch_names_to_type_
[
name
]
==
float_type
:
result_map
[
name
]
=
result_batch
.
get_float_by_name
(
mi
,
name
)
result_map
[
name
]
=
result_batch
.
get_float_by_name
(
mi
,
name
)
shape
=
result_batch
.
get_shape
(
mi
,
name
)
shape
=
result_batch
.
get_shape
(
mi
,
name
)
result_map
[
name
]
=
np
.
array
(
#
result_map[name] = np.array(
result_map
[
name
],
dtype
=
'float32'
)
#
result_map[name], dtype='float32')
result_map
[
name
].
shape
=
shape
result_map
[
name
].
shape
=
shape
if
name
in
self
.
lod_tensor_set
:
if
name
in
self
.
lod_tensor_set
:
result_map
[
"{}.lod"
.
format
(
name
)]
=
np
.
array
(
result_map
[
"{}.lod"
.
format
(
name
)]
=
np
.
array
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录