Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
27b71751
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看板
提交
27b71751
编写于
5月 22, 2018
作者:
T
tangwei12
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update python annotation
上级
e901de66
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
14 deletion
+21
-14
python/paddle/fluid/io.py
python/paddle/fluid/io.py
+21
-14
未找到文件。
python/paddle/fluid/io.py
浏览文件 @
27b71751
...
@@ -463,7 +463,10 @@ def save_checkpoint(executor,
...
@@ -463,7 +463,10 @@ def save_checkpoint(executor,
save_interval_secs
=
600
,
save_interval_secs
=
600
,
main_program
=
None
):
main_program
=
None
):
"""
"""
Save Variables to Checkpoint Directory
Save Checkpoint will save persistable LodTensor variables from main_program in checkpoint directory,
directory named by serial number from 0 to (n -1), save_checkpoint use LRU strategy
to keep numbers of checkpoint directory, the numbers of checkpoint directory are max_num_checkpoints at most,
The interval time between two save_checkpoint must great than or equal to save_interval_secs.
:param dirname
:param dirname
:param max_num_checkpoints
:param max_num_checkpoints
...
@@ -489,7 +492,7 @@ def save_checkpoint(executor,
...
@@ -489,7 +492,7 @@ def save_checkpoint(executor,
dirname
=
cur_dir
,
dirname
=
cur_dir
,
main_program
=
main_program
,
main_program
=
main_program
,
vars
=
None
,
vars
=
None
,
predicate
=
is_checkpoint_var
,
predicate
=
_
is_checkpoint_var
,
filename
=
None
)
filename
=
None
)
_write_success
(
cur_dir
)
_write_success
(
cur_dir
)
_lru_delete
(
dirname
,
max_num_checkpoints
)
_lru_delete
(
dirname
,
max_num_checkpoints
)
...
@@ -497,10 +500,11 @@ def save_checkpoint(executor,
...
@@ -497,10 +500,11 @@ def save_checkpoint(executor,
def
load_checkpoint
(
executor
,
dirname
=
None
,
main_program
=
None
):
def
load_checkpoint
(
executor
,
dirname
=
None
,
main_program
=
None
):
"""
"""
Load Variables from Checkpint Dir
Load checkpoint from directory by executor,
it will find lastest checkpoint file and load it auto.
:param dirname
:param executor
:param executor
:param dirname
:param main_program
:param main_program
"""
"""
...
@@ -517,14 +521,16 @@ def load_checkpoint(executor, dirname=None, main_program=None):
...
@@ -517,14 +521,16 @@ def load_checkpoint(executor, dirname=None, main_program=None):
executor
,
executor
,
dirname
=
cur_dir
,
dirname
=
cur_dir
,
main_program
=
main_program
,
main_program
=
main_program
,
predicate
=
is_checkpoint_var
,
predicate
=
_
is_checkpoint_var
,
filename
=
None
)
filename
=
None
)
def
is_checkpoint_var
(
var
):
def
_
is_checkpoint_var
(
var
):
"""
"""
VarType will fliter out FEED_MINIBATCH FETCH_LIST RAW
checkpoint will not save or load all the variables.
VarName will fliter out Gradient
var type is FEED_MINIBATCH/FETCH_LIST/RAW and var name is end with @GRAD are discarded.
:param var
"""
"""
if
var
.
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
FEED_MINIBATCH
or
\
if
var
.
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
FEED_MINIBATCH
or
\
var
.
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
FETCH_LIST
or
\
var
.
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
FETCH_LIST
or
\
...
@@ -545,9 +551,6 @@ def _interval_secs_exceed(dirname, save_interval_secs):
...
@@ -545,9 +551,6 @@ def _interval_secs_exceed(dirname, save_interval_secs):
def
_lru_delete
(
dirname
,
max_num_checkpoints
=
3
):
def
_lru_delete
(
dirname
,
max_num_checkpoints
=
3
):
"""
retain checkpoint nums with max_num_checkpoints
"""
dirs
=
os
.
listdir
(
dirname
)
dirs
=
os
.
listdir
(
dirname
)
serials
=
[]
serials
=
[]
for
serial
in
dirs
:
for
serial
in
dirs
:
...
@@ -568,7 +571,9 @@ def _lru_delete(dirname, max_num_checkpoints=3):
...
@@ -568,7 +571,9 @@ def _lru_delete(dirname, max_num_checkpoints=3):
def
_write_success
(
dirname
):
def
_write_success
(
dirname
):
"""
"""
write _SUCCESS to checkpoint dir
write an empty _SUCCESS file to checkpoint dir, indicate this checkpoint is correct.
:param dirname
"""
"""
success_file
=
os
.
path
.
join
(
dirname
,
SUCCESS_MARK_FILENAME
)
success_file
=
os
.
path
.
join
(
dirname
,
SUCCESS_MARK_FILENAME
)
with
open
(
success_file
,
'a'
):
with
open
(
success_file
,
'a'
):
...
@@ -577,7 +582,9 @@ def _write_success(dirname):
...
@@ -577,7 +582,9 @@ def _write_success(dirname):
def
_get_lastest_checkpoint_dir
(
checkpoint_dir
):
def
_get_lastest_checkpoint_dir
(
checkpoint_dir
):
"""
"""
get the biggest number in checkpoint_dir, which has _SUCCESS
get the latest file in checkpoint directory, the _SUCCESS file must exist in the directory
:param checkpoint_dir
"""
"""
if
not
checkpoint_dir
.
strip
():
if
not
checkpoint_dir
.
strip
():
return
-
1
return
-
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录