Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
9939ad5c
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9939ad5c
编写于
5月 13, 2021
作者:
L
Le Hou
提交者:
A. Unique TensorFlower
5月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 373623867
上级
4b820994
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
9 deletion
+37
-9
official/core/train_lib.py
official/core/train_lib.py
+4
-2
official/core/train_utils.py
official/core/train_utils.py
+21
-0
official/modeling/multitask/train_lib.py
official/modeling/multitask/train_lib.py
+12
-7
未找到文件。
official/core/train_lib.py
浏览文件 @
9939ad5c
...
@@ -124,9 +124,11 @@ def run_experiment(
...
@@ -124,9 +124,11 @@ def run_experiment(
else
:
else
:
raise
NotImplementedError
(
'The mode is not implemented: %s'
%
mode
)
raise
NotImplementedError
(
'The mode is not implemented: %s'
%
mode
)
if
hasattr
(
trainer
.
model
,
'count_params'
):
num_params
=
train_utils
.
try_count_params
(
trainer
.
model
)
if
num_params
is
not
None
:
logging
.
info
(
'Number of trainable params in model: %f Millions.'
,
logging
.
info
(
'Number of trainable params in model: %f Millions.'
,
trainer
.
model
.
count_params
()
/
10.
**
6
)
num_params
/
10.
**
6
)
if
run_post_eval
:
if
run_post_eval
:
with
distribution_strategy
.
scope
():
with
distribution_strategy
.
scope
():
return
trainer
.
model
,
trainer
.
evaluate
(
return
trainer
.
model
,
trainer
.
evaluate
(
...
...
official/core/train_utils.py
浏览文件 @
9939ad5c
...
@@ -367,3 +367,24 @@ def remove_ckpts(model_dir):
...
@@ -367,3 +367,24 @@ def remove_ckpts(model_dir):
file_to_remove
=
os
.
path
.
join
(
model_dir
,
'checkpoint'
)
file_to_remove
=
os
.
path
.
join
(
model_dir
,
'checkpoint'
)
if
tf
.
io
.
gfile
.
exists
(
file_to_remove
):
if
tf
.
io
.
gfile
.
exists
(
file_to_remove
):
tf
.
io
.
gfile
.
remove
(
file_to_remove
)
tf
.
io
.
gfile
.
remove
(
file_to_remove
)
def
try_count_params
(
model
:
tf
.
keras
.
Model
):
"""Count the number of parameters if model is possible.
Args:
model: Try to count the number of params in this model.
Returns:
The number of parameters or None.
"""
if
hasattr
(
model
,
'count_params'
):
try
:
return
model
.
count_params
()
except
ValueError
:
logging
.
info
(
'Number of trainable params unknown, because the build() '
'methods in keras layers were not called. This is probably '
'because the model was not feed any input, e.g., the max '
'train step already reached before this run.'
)
return
None
return
None
official/modeling/multitask/train_lib.py
浏览文件 @
9939ad5c
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"""Multitask training driver library."""
"""Multitask training driver library."""
# pytype: disable=attribute-error
# pytype: disable=attribute-error
import
os
import
os
from
typing
import
Optional
from
absl
import
logging
from
absl
import
logging
import
orbit
import
orbit
import
tensorflow
as
tf
import
tensorflow
as
tf
...
@@ -139,7 +140,8 @@ def run_experiment_with_multitask_eval(
...
@@ -139,7 +140,8 @@ def run_experiment_with_multitask_eval(
params
:
configs
.
MultiEvalExperimentConfig
,
params
:
configs
.
MultiEvalExperimentConfig
,
model_dir
:
str
,
model_dir
:
str
,
run_post_eval
:
bool
=
False
,
run_post_eval
:
bool
=
False
,
save_summary
:
bool
=
True
)
->
tf
.
keras
.
Model
:
save_summary
:
bool
=
True
,
trainer
:
Optional
[
core_lib
.
Trainer
]
=
None
)
->
tf
.
keras
.
Model
:
"""Runs train/eval configured by the experiment params.
"""Runs train/eval configured by the experiment params.
Args:
Args:
...
@@ -153,6 +155,9 @@ def run_experiment_with_multitask_eval(
...
@@ -153,6 +155,9 @@ def run_experiment_with_multitask_eval(
run_post_eval: Whether to run post eval once after training, metrics logs
run_post_eval: Whether to run post eval once after training, metrics logs
are returned.
are returned.
save_summary: Whether to save train and validation summary.
save_summary: Whether to save train and validation summary.
trainer: the core_lib.Trainer instance. It should be created within the
strategy.scope(). If not provided, an instance will be created by default
if `mode` contains 'train'.
Returns:
Returns:
model: `tf.keras.Model` instance.
model: `tf.keras.Model` instance.
...
@@ -161,19 +166,19 @@ def run_experiment_with_multitask_eval(
...
@@ -161,19 +166,19 @@ def run_experiment_with_multitask_eval(
is_training
=
'train'
in
mode
is_training
=
'train'
in
mode
is_eval
=
'eval'
in
mode
is_eval
=
'eval'
in
mode
with
distribution_strategy
.
scope
():
with
distribution_strategy
.
scope
():
optimizer
=
train_task
.
create_optimizer
(
params
.
trainer
.
optimizer_config
,
params
.
runtime
)
model
=
train_task
.
build_model
()
if
is_training
:
if
is_training
:
trainer
=
core_lib
.
Trainer
(
trainer
=
trainer
or
core_lib
.
Trainer
(
config
=
params
,
config
=
params
,
task
=
train_task
,
task
=
train_task
,
model
=
model
,
model
=
train_task
.
build_model
(),
optimizer
=
optimizer
,
optimizer
=
train_task
.
create_optimizer
(
params
.
trainer
.
optimizer_config
,
params
.
runtime
),
train
=
True
,
train
=
True
,
evaluate
=
False
)
evaluate
=
False
)
else
:
else
:
trainer
=
None
trainer
=
None
model
=
trainer
.
model
if
trainer
else
train_task
.
build_model
()
if
is_eval
:
if
is_eval
:
evaluator
=
evaluator_lib
.
MultiTaskEvaluator
(
evaluator
=
evaluator_lib
.
MultiTaskEvaluator
(
task
=
eval_tasks
,
task
=
eval_tasks
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录