Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f5990b46
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f5990b46
编写于
1月 30, 2018
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into core_add_inference_unittest
上级
f5d93368
db8da025
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
23 addition
and
21 deletion
+23
-21
paddle/framework/program_desc.h
paddle/framework/program_desc.h
+1
-0
paddle/framework/prune.cc
paddle/framework/prune.cc
+2
-1
paddle/inference/io.cc
paddle/inference/io.cc
+12
-12
paddle/inference/io.h
paddle/inference/io.h
+5
-4
paddle/inference/tests/book/test_inference_recognize_digits.cc
...e/inference/tests/book/test_inference_recognize_digits.cc
+3
-4
未找到文件。
paddle/framework/program_desc.h
浏览文件 @
f5990b46
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#include <memory>
#include <vector>
#include "paddle/framework/block_desc.h"
#include "paddle/framework/framework.pb.h"
#include "paddle/framework/proto_desc.h"
#include "paddle/platform/macros.h"
...
...
paddle/framework/prune.cc
浏览文件 @
f5990b46
...
...
@@ -21,11 +21,12 @@ limitations under the License. */
#include <vector>
#include <glog/logging.h>
#include "paddle/framework/feed_fetch_type.h"
namespace
paddle
{
namespace
framework
{
const
std
::
string
kFeedOpType
=
"feed"
;
const
std
::
string
kFetchOpType
=
"fetch"
;
const
std
::
string
kDropOutOpType
=
"dropout"
;
const
std
::
string
kBatchNormOpType
=
"batch_norm"
;
...
...
paddle/inference/io.cc
浏览文件 @
f5990b46
...
...
@@ -22,11 +22,11 @@ namespace paddle {
namespace
inference
{
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
()
==
framework
::
kFeedOpType
)
{
continue
;
...
...
@@ -45,12 +45,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
))
{
VLOG
(
3
)
<<
"parameter's name: "
<<
var
->
Name
();
...
...
@@ -73,7 +73,7 @@ void LoadPersistables(framework::Executor& executor,
delete
load_program
;
}
framework
::
ProgramDesc
*
Load
(
framework
::
Executor
&
executor
,
std
::
unique_ptr
<
framework
::
ProgramDesc
>
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
)
{
std
::
string
model_filename
=
dirname
+
"/__model__"
;
...
...
@@ -87,10 +87,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
浏览文件 @
f5990b46
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "paddle/framework/executor.h"
...
...
@@ -26,9 +27,9 @@ namespace inference {
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
,
std
::
unique_ptr
<
framework
::
ProgramDesc
>
Load
(
framework
::
Executor
&
executor
,
framework
::
Scope
&
scope
,
const
std
::
string
&
dirname
);
...
...
paddle/inference/tests/book/test_inference_recognize_digits.cc
浏览文件 @
f5990b46
...
...
@@ -31,7 +31,7 @@ void TestInference(const std::string& dirname,
auto
*
scope
=
new
paddle
::
framework
::
Scope
();
// 2. Initialize the inference_program and load all parameters from file
auto
*
inference_program
=
paddle
::
inference
::
Load
(
executor
,
*
scope
,
dirname
);
auto
inference_program
=
paddle
::
inference
::
Load
(
executor
,
*
scope
,
dirname
);
// 3. Get the feed_target_names and fetch_target_names
const
std
::
vector
<
std
::
string
>&
feed_target_names
=
...
...
@@ -39,14 +39,14 @@ void TestInference(const std::string& dirname,
const
std
::
vector
<
std
::
string
>&
fetch_target_names
=
inference_program
->
GetFetchTargetNames
();
// 4. Prepare inputs
// 4. Prepare inputs
: set up maps for feed targets
std
::
map
<
std
::
string
,
const
paddle
::
framework
::
LoDTensor
*>
feed_targets
;
for
(
size_t
i
=
0
;
i
<
feed_target_names
.
size
();
++
i
)
{
// Please make sure that cpu_feeds[i] is right for feed_target_names[i]
feed_targets
[
feed_target_names
[
i
]]
=
cpu_feeds
[
i
];
}
// 5. Define Tensor to get the outputs
// 5. Define Tensor to get the outputs
: set up maps for fetch targets
std
::
map
<
std
::
string
,
paddle
::
framework
::
LoDTensor
*>
fetch_targets
;
for
(
size_t
i
=
0
;
i
<
fetch_target_names
.
size
();
++
i
)
{
fetch_targets
[
fetch_target_names
[
i
]]
=
cpu_fetchs
[
i
];
...
...
@@ -55,7 +55,6 @@ void TestInference(const std::string& dirname,
// 6. Run the inference program
executor
.
Run
(
*
inference_program
,
scope
,
feed_targets
,
fetch_targets
);
delete
inference_program
;
delete
scope
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录