Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
7631f3b4
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7631f3b4
编写于
10月 23, 2017
作者:
C
Cao Ying
提交者:
GitHub
10月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #392 from pengli09/fix-model-saving-bug
Fix model saving bugs.
上级
13ff59e9
1a4bfa3e
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
41 addition
and
44 deletion
+41
-44
ctr/train.py
ctr/train.py
+1
-1
deep_speech_2/model_utils/model.py
deep_speech_2/model_utils/model.py
+2
-2
dssm/train.py
dssm/train.py
+1
-1
generate_chinese_poetry/train.py
generate_chinese_poetry/train.py
+4
-4
generate_sequence_by_rnn_lm/train.py
generate_sequence_by_rnn_lm/train.py
+2
-2
globally_normalized_reader/train.py
globally_normalized_reader/train.py
+4
-4
hsigmoid/train.py
hsigmoid/train.py
+6
-3
image_classification/train.py
image_classification/train.py
+9
-9
ltr/lambda_rank.py
ltr/lambda_rank.py
+1
-1
ltr/ranknet.py
ltr/ranknet.py
+1
-1
mt_with_external_memory/train.py
mt_with_external_memory/train.py
+2
-2
nce_cost/train.py
nce_cost/train.py
+2
-8
nested_sequence/text_classification/train.py
nested_sequence/text_classification/train.py
+1
-1
nmt_without_attention/train.py
nmt_without_attention/train.py
+1
-1
scheduled_sampling/scheduled_sampling.py
scheduled_sampling/scheduled_sampling.py
+1
-1
sequence_tagging_for_ner/train.py
sequence_tagging_for_ner/train.py
+1
-1
ssd/train.py
ssd/train.py
+1
-1
text_classification/train.py
text_classification/train.py
+1
-1
未找到文件。
ctr/train.py
浏览文件 @
7631f3b4
...
...
@@ -95,7 +95,7 @@ def train():
args
.
model_output_prefix
,
event
.
pass_id
,
event
.
batch_id
,
result
.
cost
)
with
gzip
.
open
(
path
,
'w'
)
as
f
:
params
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
trainer
.
train
(
reader
=
paddle
.
batch
(
...
...
deep_speech_2/model_utils/model.py
浏览文件 @
7631f3b4
...
...
@@ -111,7 +111,7 @@ class DeepSpeech2Model(object):
output_model_path
=
os
.
path
.
join
(
output_model_dir
,
"params.latest.tar.gz"
)
with
gzip
.
open
(
output_model_path
,
'w'
)
as
f
:
self
.
_parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
print
(
"
\n
Pass: %d, Batch: %d, TrainCost: %f"
%
(
event
.
pass_id
,
event
.
batch_id
+
1
,
cost_sum
/
cost_counter
))
...
...
@@ -136,7 +136,7 @@ class DeepSpeech2Model(object):
output_model_path
=
os
.
path
.
join
(
output_model_dir
,
"params.pass-%d.tar.gz"
%
event
.
pass_id
)
with
gzip
.
open
(
output_model_path
,
'w'
)
as
f
:
self
.
_parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
# run train
trainer
.
train
(
...
...
dssm/train.py
浏览文件 @
7631f3b4
...
...
@@ -237,7 +237,7 @@ def train(train_data_path=None,
with
open
(
"%sdssm_%s_pass_%05d.tar"
%
(
args
.
model_output_prefix
,
model_desc
,
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
trainer
.
train
(
reader
=
train_reader
,
...
...
generate_chinese_poetry/train.py
浏览文件 @
7631f3b4
...
...
@@ -12,9 +12,9 @@ logger = logging.getLogger("paddle")
logger
.
setLevel
(
logging
.
INFO
)
def
save_model
(
save_path
,
parameters
):
def
save_model
(
trainer
,
save_path
,
parameters
):
with
gzip
.
open
(
save_path
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
def
load_initial_model
(
model_path
,
parameters
):
...
...
@@ -111,7 +111,7 @@ def train(num_passes,
save_path
=
os
.
path
.
join
(
save_dir_path
,
"pass_%05d_batch_%05d.tar.gz"
%
(
event
.
pass_id
,
event
.
batch_id
))
save_model
(
save_path
,
parameters
)
save_model
(
trainer
,
save_path
,
parameters
)
if
not
event
.
batch_id
%
5
:
logger
.
info
(
"Pass %d, Batch %d, Cost %f, %s"
%
(
...
...
@@ -120,7 +120,7 @@ def train(num_passes,
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
save_path
=
os
.
path
.
join
(
save_dir_path
,
"pass_%05d.tar.gz"
%
event
.
pass_id
)
save_model
(
save_path
,
parameters
)
save_model
(
trainer
,
save_path
,
parameters
)
# start training
trainer
.
train
(
...
...
generate_sequence_by_rnn_lm/train.py
浏览文件 @
7631f3b4
...
...
@@ -60,7 +60,7 @@ def train(topology,
"rnn_lm_pass_%05d_batch_%03d.tar.gz"
%
(
event
.
pass_id
,
event
.
batch_id
))
with
gzip
.
open
(
save_name
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
if
test_reader
is
not
None
:
...
...
@@ -70,7 +70,7 @@ def train(topology,
save_name
=
os
.
path
.
join
(
model_save_dir
,
"rnn_lm_pass_%05d.tar.gz"
%
(
event
.
pass_id
))
with
gzip
.
open
(
save_name
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
logger
.
info
(
"start training..."
)
trainer
.
train
(
...
...
globally_normalized_reader/train.py
浏览文件 @
7631f3b4
...
...
@@ -43,7 +43,7 @@ def load_pretrained_parameters(path):
return
np
.
load
(
path
)
def
save_model
(
save_path
,
parameters
):
def
save_model
(
trainer
,
save_path
,
parameters
):
""" Save the trained parameters.
Arguments:
...
...
@@ -51,7 +51,7 @@ def save_model(save_path, parameters):
- parameters: The trained model parameters.
"""
with
gzip
.
open
(
save_path
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
def
show_parameter_init_info
(
parameters
):
...
...
@@ -161,7 +161,7 @@ def build_event_handler(config, parameters, trainer):
if
event
.
batch_id
and
not
event
.
batch_id
%
config
.
checkpoint_period
:
save_path
=
os
.
path
.
join
(
config
.
save_dir
,
"checkpoint_param.latest.tar.gz"
)
save_model
(
save_path
,
parameters
)
save_model
(
trainer
,
save_path
,
parameters
)
if
not
event
.
batch_id
%
config
.
log_period
:
logger
.
info
(
"Pass %d, Batch %d, Cost %f"
%
...
...
@@ -170,7 +170,7 @@ def build_event_handler(config, parameters, trainer):
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
save_path
=
os
.
path
.
join
(
config
.
save_dir
,
"pass_%05d.tar.gz"
%
event
.
pass_id
)
save_model
(
save_path
,
parameters
)
save_model
(
trainer
,
save_path
,
parameters
)
return
event_handler
...
...
hsigmoid/train.py
浏览文件 @
7631f3b4
...
...
@@ -22,7 +22,12 @@ def main(save_dir="models"):
regularization
=
paddle
.
optimizer
.
L2Regularization
(
8e-4
))
cost
=
ngram_lm
(
hidden_size
=
256
,
embed_size
=
32
,
dict_size
=
dict_size
)
parameters
=
paddle
.
parameters
.
create
(
cost
)
adam_optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
3e-3
,
regularization
=
paddle
.
optimizer
.
L2Regularization
(
8e-4
))
trainer
=
paddle
.
trainer
.
SGD
(
cost
,
parameters
,
adam_optimizer
)
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
...
...
@@ -30,7 +35,7 @@ def main(save_dir="models"):
event
.
pass_id
)
logger
.
info
(
"Save model into %s ..."
%
model_name
)
with
gzip
.
open
(
model_name
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
event
.
batch_id
and
event
.
batch_id
%
10
==
0
:
...
...
@@ -41,8 +46,6 @@ def main(save_dir="models"):
"Pass %d, Batch %d, Cost %f, Test Cost %f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
result
.
cost
))
trainer
=
paddle
.
trainer
.
SGD
(
cost
,
parameters
,
adam_optimizer
)
trainer
.
train
(
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
...
...
image_classification/train.py
浏览文件 @
7631f3b4
...
...
@@ -81,6 +81,13 @@ def main():
# reader.test_reader('val.list'),
batch_size
=
BATCH_SIZE
)
# Create trainer
trainer
=
paddle
.
trainer
.
SGD
(
cost
=
cost
,
parameters
=
parameters
,
update_equation
=
optimizer
,
extra_layers
=
extra_layers
)
# End batch and end pass event handler
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
...
...
@@ -89,21 +96,14 @@ def main():
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
)
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
with
gzip
.
open
(
'params_pass_%d.tar.gz'
%
event
.
pass_id
,
'w'
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
result
=
trainer
.
test
(
reader
=
test_reader
)
print
"
\n
Test with Pass %d, %s"
%
(
event
.
pass_id
,
result
.
metrics
)
# Create trainer
trainer
=
paddle
.
trainer
.
SGD
(
cost
=
cost
,
parameters
=
parameters
,
update_equation
=
optimizer
,
extra_layers
=
extra_layers
)
trainer
.
train
(
reader
=
train_reader
,
num_passes
=
200
,
event_handler
=
event_handler
)
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
main
()
ltr/lambda_rank.py
浏览文件 @
7631f3b4
...
...
@@ -82,7 +82,7 @@ def train_lambda_rank(num_passes):
print
"
\n
Test with Pass %d, %s"
%
(
event
.
pass_id
,
result
.
metrics
)
with
gzip
.
open
(
"lambda_rank_params_%d.tar.gz"
%
(
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
feeding
=
{
"label"
:
0
,
"data"
:
1
}
trainer
.
train
(
...
...
ltr/ranknet.py
浏览文件 @
7631f3b4
...
...
@@ -86,7 +86,7 @@ def train_ranknet(num_passes):
print
"
\n
Test with Pass %d, %s"
%
(
event
.
pass_id
,
result
.
metrics
)
with
gzip
.
open
(
"ranknet_params_%d.tar.gz"
%
(
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
trainer
.
train
(
reader
=
train_reader
,
...
...
mt_with_external_memory/train.py
浏览文件 @
7631f3b4
...
...
@@ -129,7 +129,7 @@ def train():
print
"Pass: %d, Batch: %d, TrainCost: %f, %s"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
)
with
gzip
.
open
(
"checkpoints/params.latest.tar.gz"
,
'w'
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
else
:
sys
.
stdout
.
write
(
'.'
)
sys
.
stdout
.
flush
()
...
...
@@ -139,7 +139,7 @@ def train():
result
.
metrics
)
with
gzip
.
open
(
"checkpoints/params.pass-%d.tar.gz"
%
event
.
pass_id
,
'w'
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
# run train
if
not
os
.
path
.
exists
(
'checkpoints'
):
...
...
nce_cost/train.py
浏览文件 @
7631f3b4
...
...
@@ -28,13 +28,7 @@ def train(model_save_dir):
if
event
.
batch_id
and
not
event
.
batch_id
%
10
:
logger
.
info
(
"Pass %d, Batch %d, Cost %f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
))
save_path
=
os
.
path
.
join
(
model_save_dir
,
"model_pass_%05d.tar.gz"
%
event
.
pass_id
)
logger
.
info
(
"Save model into %s ..."
%
save_path
)
with
gzip
.
open
(
save_path
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
elif
isinstance
(
event
,
paddle
.
event
.
EndPass
):
result
=
trainer
.
test
(
paddle
.
batch
(
paddle
.
dataset
.
imikolov
.
test
(
word_dict
,
5
),
64
))
logger
.
info
(
"Test Pass %d, Cost %f"
%
(
event
.
pass_id
,
result
.
cost
))
...
...
@@ -43,7 +37,7 @@ def train(model_save_dir):
"model_pass_%05d.tar.gz"
%
event
.
pass_id
)
logger
.
info
(
"Save model into %s ..."
%
save_path
)
with
gzip
.
open
(
save_path
,
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
trainer
.
train
(
paddle
.
batch
(
...
...
nested_sequence/text_classification/train.py
浏览文件 @
7631f3b4
...
...
@@ -179,7 +179,7 @@ def train(train_data_dir, test_data_dir, word_dict_path, label_dict_path,
with
gzip
.
open
(
os
.
path
.
join
(
model_save_dir
,
"params_pass_%05d.tar.gz"
%
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
# begin training network
trainer
.
train
(
...
...
nmt_without_attention/train.py
浏览文件 @
7631f3b4
...
...
@@ -50,7 +50,7 @@ def train(save_dir_path, source_dict_dim, target_dict_dim):
os
.
path
.
join
(
save_path
,
"nmt_without_att_%05d_batch_%05d.tar.gz"
%
event
.
pass_id
,
event
.
batch_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
if
event
.
batch_id
and
not
event
.
batch_id
%
10
:
logger
.
info
(
"Pass %d, Batch %d, Cost %f, %s"
%
(
...
...
scheduled_sampling/scheduled_sampling.py
浏览文件 @
7631f3b4
...
...
@@ -264,7 +264,7 @@ def main():
# save parameters
with
gzip
.
open
(
'params_pass_%d.tar.gz'
%
event
.
pass_id
,
'w'
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
# start to train
trainer
.
train
(
...
...
sequence_tagging_for_ner/train.py
浏览文件 @
7631f3b4
...
...
@@ -87,7 +87,7 @@ def main(train_data_file,
with
gzip
.
open
(
os
.
path
.
join
(
model_save_dir
,
"params_pass_%d.tar.gz"
%
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
result
=
trainer
.
test
(
reader
=
test_reader
,
feeding
=
feeding
)
logger
.
info
(
"
\n
Test with Pass %d, %s"
%
(
event
.
pass_id
,
...
...
ssd/train.py
浏览文件 @
7631f3b4
...
...
@@ -55,7 +55,7 @@ def train(train_file_list, dev_file_list, data_args, init_model_path):
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
with
gzip
.
open
(
'checkpoints/params_pass_%05d.tar.gz'
%
\
event
.
pass_id
,
'w'
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
result
=
trainer
.
test
(
reader
=
dev_reader
,
feeding
=
feeding
)
print
"
\n
Test with Pass %d, TestCost: %f, Detection mAP=%g"
%
\
(
event
.
pass_id
,
...
...
text_classification/train.py
浏览文件 @
7631f3b4
...
...
@@ -141,7 +141,7 @@ def train(topology,
with
gzip
.
open
(
os
.
path
.
join
(
model_save_dir
,
"dnn_params_pass_%05d.tar.gz"
%
event
.
pass_id
),
"w"
)
as
f
:
parameters
.
to_tar
(
f
)
trainer
.
save_parameter_
to_tar
(
f
)
trainer
.
train
(
reader
=
train_reader
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录