Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PALM
提交
ebe2d6ad
P
PALM
项目概览
PaddlePaddle
/
PALM
通知
4
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PALM
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ebe2d6ad
编写于
1月 10, 2020
作者:
X
Xiaoyao Xi
提交者:
GitHub
1月 10, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #47 from wangxiao1021/updatesaver
update saver
上级
2efeb39b
7b96751c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
10 deletion
+15
-10
paddlepalm/trainer.py
paddlepalm/trainer.py
+2
-1
paddlepalm/utils/saver.py
paddlepalm/utils/saver.py
+13
-9
未找到文件。
paddlepalm/trainer.py
浏览文件 @
ebe2d6ad
...
...
@@ -282,13 +282,14 @@ class Trainer(object):
print
(
'random init params...'
)
self
.
_exe
.
run
(
self
.
_train_init_prog
)
def
load_pretrain
(
self
,
model_path
):
def
load_pretrain
(
self
,
model_path
,
convert
=
False
):
# load pretrain model (or ckpt)
assert
self
.
_exe
is
not
None
,
"You need to random_init_params before load pretrain models."
saver
.
init_pretraining_params
(
self
.
_exe
,
model_path
,
convert
=
convert
,
main_program
=
self
.
_train_init_prog
)
def
set_predict_head
(
self
):
...
...
paddlepalm/utils/saver.py
浏览文件 @
ebe2d6ad
...
...
@@ -46,20 +46,24 @@ def init_checkpoint(exe, init_checkpoint_path, main_program, skip_list = []):
def
init_pretraining_params
(
exe
,
pretraining_params_path
,
convert
,
main_program
):
assert
os
.
path
.
exists
(
pretraining_params_path
),
"[%s] cann't be found."
%
pretraining_params_path
if
convert
:
assert
os
.
path
.
exists
(
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
)),
"__palmmodel__ not found."
assert
os
.
path
.
exists
(
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
)),
"__palmmodel__ not found."
print
(
"Loading pretraining parameters from {}..."
.
format
(
pretraining_params_path
))
with
tarfile
.
open
(
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
),
'r'
)
as
f
:
f
.
extractall
(
os
.
path
.
join
(
pretraining_params_path
,
'.temp'
))
log_path
=
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
)
pretraining_params_path
=
os
.
path
.
join
(
pretraining_params_path
,
'.temp'
)
with
tarfile
.
open
(
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
),
'r'
)
as
f
:
f
.
extractall
(
os
.
path
.
join
(
pretraining_params_path
,
'.temp'
))
else
:
log_path
=
pretraining_params_path
log_path
=
os
.
path
.
join
(
pretraining_params_path
,
'__palmmodel__'
)
pretraining_params_path
=
os
.
path
.
join
(
pretraining_params_path
,
'.temp'
)
print
(
"Loading pretraining parameters from {}..."
.
format
(
pretraining_params_path
))
def
existed_params
(
var
):
if
not
isinstance
(
var
,
fluid
.
framework
.
Parameter
):
...
...
@@ -73,8 +77,8 @@ def init_pretraining_params(exe,
pretraining_params_path
,
main_program
=
main_program
,
predicate
=
existed_params
)
shutil
.
rmtree
(
pretraining_params_path
)
if
convert
:
shutil
.
rmtree
(
pretraining_params_path
)
print
(
''
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录