Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
db8da025
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
db8da025
编写于
1月 30, 2018
作者:
K
kexinzhao
提交者:
Yiqun Liu
1月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix comments (#7978)
上级
311334e0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
42 deletion
+41
-42
paddle/framework/program_desc.cc
paddle/framework/program_desc.cc
+10
-10
paddle/framework/program_desc.h
paddle/framework/program_desc.h
+2
-3
paddle/inference/example.cc
paddle/inference/example.cc
+11
-12
paddle/inference/io.cc
paddle/inference/io.cc
+12
-12
paddle/inference/io.h
paddle/inference/io.h
+6
-5
未找到文件。
paddle/framework/program_desc.cc
浏览文件 @
db8da025
...
...
@@ -67,26 +67,26 @@ ProgramDesc::ProgramDesc(const std::string &binary_str) {
}
}
const
std
::
vector
<
std
::
string
>
ProgramDesc
::
GetFeed
Var
Names
()
{
const
std
::
vector
<
std
::
string
>
ProgramDesc
::
GetFeed
Target
Names
()
{
BlockDesc
*
global_block
=
blocks_
[
0
].
get
();
std
::
vector
<
std
::
string
>
feed_
var
_names
;
std
::
vector
<
std
::
string
>
feed_
target
_names
;
for
(
auto
*
op
:
global_block
->
AllOps
())
{
if
(
op
->
Type
()
==
"feed"
)
{
feed_
var_names
.
insert
(
feed_var
_names
.
begin
(),
op
->
Output
(
"Out"
)[
0
]);
if
(
op
->
Type
()
==
kFeedOpType
)
{
feed_
target_names
.
insert
(
feed_target
_names
.
begin
(),
op
->
Output
(
"Out"
)[
0
]);
}
}
return
feed_
var
_names
;
return
feed_
target
_names
;
}
const
std
::
vector
<
std
::
string
>
ProgramDesc
::
GetFetch
Var
Names
()
{
const
std
::
vector
<
std
::
string
>
ProgramDesc
::
GetFetch
Target
Names
()
{
BlockDesc
*
global_block
=
blocks_
[
0
].
get
();
std
::
vector
<
std
::
string
>
fetch_
var
_names
;
std
::
vector
<
std
::
string
>
fetch_
target
_names
;
for
(
auto
*
op
:
global_block
->
AllOps
())
{
if
(
op
->
Type
()
==
"fetch"
)
{
fetch_
var
_names
.
push_back
(
op
->
Input
(
"X"
)[
0
]);
if
(
op
->
Type
()
==
kFetchOpType
)
{
fetch_
target
_names
.
push_back
(
op
->
Input
(
"X"
)[
0
]);
}
}
return
fetch_
var
_names
;
return
fetch_
target
_names
;
}
}
// namespace framework
...
...
paddle/framework/program_desc.h
浏览文件 @
db8da025
...
...
@@ -45,9 +45,8 @@ class ProgramDesc {
proto
::
ProgramDesc
*
Proto
();
const
std
::
vector
<
std
::
string
>
GetFeedVarNames
();
const
std
::
vector
<
std
::
string
>
GetFetchVarNames
();
const
std
::
vector
<
std
::
string
>
GetFeedTargetNames
();
const
std
::
vector
<
std
::
string
>
GetFetchTargetNames
();
private:
proto
::
ProgramDesc
desc_
;
...
...
paddle/inference/example.cc
浏览文件 @
db8da025
...
...
@@ -40,15 +40,15 @@ int main(int argc, char** argv) {
std
::
string
dirname
=
FLAGS_dirname
;
// 2. Initialize the inference program
auto
*
inference_program
=
paddle
::
inference
::
Load
(
*
executor
,
*
scope
,
dirname
);
auto
inference_program
=
paddle
::
inference
::
Load
(
*
executor
,
*
scope
,
dirname
);
// 3. Optional: perform optimization on the inference_program
// 4. Get the feed_
var_names and fetch_var
_names
const
std
::
vector
<
std
::
string
>&
feed_
var
_names
=
inference_program
->
GetFeed
Var
Names
();
const
std
::
vector
<
std
::
string
>&
fetch_
var
_names
=
inference_program
->
GetFetch
Var
Names
();
// 4. Get the feed_
target_names and fetch_target
_names
const
std
::
vector
<
std
::
string
>&
feed_
target
_names
=
inference_program
->
GetFeed
Target
Names
();
const
std
::
vector
<
std
::
string
>&
fetch_
target
_names
=
inference_program
->
GetFetch
Target
Names
();
// 5. Generate input
paddle
::
framework
::
LoDTensor
input
;
...
...
@@ -68,14 +68,14 @@ int main(int argc, char** argv) {
std
::
map
<
std
::
string
,
paddle
::
framework
::
LoDTensor
*>
fetch_targets
;
// set_feed_variable
for
(
size_t
i
=
0
;
i
<
feed_
var
_names
.
size
();
++
i
)
{
feed_targets
[
feed_
var
_names
[
i
]]
=
&
feeds
[
i
];
for
(
size_t
i
=
0
;
i
<
feed_
target
_names
.
size
();
++
i
)
{
feed_targets
[
feed_
target
_names
[
i
]]
=
&
feeds
[
i
];
}
// get_fetch_variable
fetchs
.
resize
(
fetch_
var
_names
.
size
());
for
(
size_t
i
=
0
;
i
<
fetch_
var
_names
.
size
();
++
i
)
{
fetch_targets
[
fetch_
var
_names
[
i
]]
=
&
fetchs
[
i
];
fetchs
.
resize
(
fetch_
target
_names
.
size
());
for
(
size_t
i
=
0
;
i
<
fetch_
target
_names
.
size
();
++
i
)
{
fetch_targets
[
fetch_
target
_names
[
i
]]
=
&
fetchs
[
i
];
}
// Run the inference program
...
...
@@ -97,7 +97,6 @@ int main(int argc, char** argv) {
std
::
cout
<<
std
::
endl
;
}
delete
inference_program
;
delete
scope
;
delete
executor
;
...
...
paddle/inference/io.cc
浏览文件 @
db8da025
...
...
@@ -21,11 +21,11 @@ namespace inference {
const
std
::
string
kFeedOpType
=
"feed"
;
bool
IsParameter
(
const
framework
::
VarDesc
*
var
,
const
framework
::
ProgramDesc
*
main_program
)
{
const
framework
::
ProgramDesc
&
main_program
)
{
if
(
var
->
Persistable
())
{
// There are many unreachable variables in the program
for
(
size_t
i
=
0
;
i
<
main_program
->
Size
();
++
i
)
{
const
framework
::
BlockDesc
&
block
=
main_program
->
Block
(
i
);
for
(
size_t
i
=
0
;
i
<
main_program
.
Size
();
++
i
)
{
const
framework
::
BlockDesc
&
block
=
main_program
.
Block
(
i
);
for
(
auto
*
op
:
block
.
AllOps
())
{
if
(
op
->
Type
()
==
kFeedOpType
)
{
continue
;
...
...
@@ -44,12 +44,12 @@ bool IsParameter(const framework::VarDesc* var,
void
LoadPersistables
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
,
framework
::
ProgramDesc
*
main_program
)
{
framework
::
BlockDesc
*
global_block
=
main_program
->
Mutable
Block
(
0
);
const
framework
::
ProgramDesc
&
main_program
)
{
const
framework
::
BlockDesc
&
global_block
=
main_program
.
Block
(
0
);
framework
::
ProgramDesc
*
load_program
=
new
framework
::
ProgramDesc
();
framework
::
BlockDesc
*
load_block
=
load_program
->
MutableBlock
(
0
);
for
(
auto
*
var
:
global_block
->
AllVars
())
{
for
(
auto
*
var
:
global_block
.
AllVars
())
{
if
(
IsParameter
(
var
,
main_program
))
{
LOG
(
INFO
)
<<
"parameter's name: "
<<
var
->
Name
();
...
...
@@ -72,9 +72,9 @@ void LoadPersistables(framework::Executor& executor,
delete
load_program
;
}
framework
::
ProgramDesc
*
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
)
{
std
::
unique_ptr
<
framework
::
ProgramDesc
>
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
)
{
std
::
string
model_filename
=
dirname
+
"/__model__"
;
LOG
(
INFO
)
<<
"loading model from "
<<
model_filename
;
std
::
ifstream
inputfs
(
model_filename
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
...
...
@@ -86,10 +86,10 @@ framework::ProgramDesc* Load(framework::Executor& executor,
inputfs
.
read
(
&
program_desc_str
[
0
],
program_desc_str
.
size
());
inputfs
.
close
();
framework
::
ProgramDesc
*
main_program
=
new
framework
::
ProgramDesc
(
program_desc_str
);
std
::
unique_ptr
<
framework
::
ProgramDesc
>
main_program
(
new
framework
::
ProgramDesc
(
program_desc_str
)
)
;
LoadPersistables
(
executor
,
scope
,
dirname
,
main_program
);
LoadPersistables
(
executor
,
scope
,
dirname
,
*
main_program
);
return
main_program
;
}
...
...
paddle/inference/io.h
浏览文件 @
db8da025
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "paddle/framework/block_desc.h"
...
...
@@ -26,16 +27,16 @@ namespace paddle {
namespace
inference
{
bool
IsParameter
(
const
framework
::
VarDesc
*
var
,
const
framework
::
ProgramDesc
*
main_program
);
const
framework
::
ProgramDesc
&
main_program
);
void
LoadPersistables
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
,
framework
::
ProgramDesc
*
main_program
);
const
framework
::
ProgramDesc
&
main_program
);
framework
::
ProgramDesc
*
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
);
std
::
unique_ptr
<
framework
::
ProgramDesc
>
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
);
}
// namespace inference
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录