Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
兽拳
Paddle
提交
9db107da
P
Paddle
项目概览
兽拳
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9db107da
编写于
2月 27, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renamed and add comments
上级
2af9aac2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
7 deletion
+19
-7
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+14
-5
python/paddle/fluid/learning_rate_decay.py
python/paddle/fluid/learning_rate_decay.py
+2
-1
python/paddle/fluid/tests/unittests/test_learning_rate_decay.py
.../paddle/fluid/tests/unittests/test_learning_rate_decay.py
+3
-1
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
9db107da
...
@@ -69,7 +69,7 @@ __all__ = [
...
@@ -69,7 +69,7 @@ __all__ = [
'softmax_with_cross_entropy'
,
'softmax_with_cross_entropy'
,
'smooth_l1'
,
'smooth_l1'
,
'one_hot'
,
'one_hot'
,
'
global
_step_counter'
,
'
autoincreased
_step_counter'
,
]
]
...
@@ -3253,23 +3253,32 @@ def one_hot(input, depth):
...
@@ -3253,23 +3253,32 @@ def one_hot(input, depth):
return
one_hot_out
return
one_hot_out
def
global_step_counter
(
):
def
autoincreased_step_counter
(
counter_name
=
None
,
begin
=
1
,
step
=
1
):
"""
"""
NOTE: The counter will be automatically increased by 1 every mini-batch
Return the run counter of the main program, which is started with 1.
Return the run counter of the main program, which is started with 1.
Args:
counter_name(str): The counter name, default is '@STEP_COUNTER@'.
begin(int): The first value of this counter.
step(int): The increment step between each execution.
Returns(Variable): The global run counter.
Returns(Variable): The global run counter.
"""
"""
helper
=
LayerHelper
(
'global_step_counter'
)
helper
=
LayerHelper
(
'global_step_counter'
)
counter_name
=
'@STEP_COUNTER@'
if
counter_name
is
None
:
counter_name
=
'@STEP_COUNTER@'
counter
,
is_new_var
=
helper
.
create_or_get_global_variable
(
counter
,
is_new_var
=
helper
.
create_or_get_global_variable
(
name
=
counter_name
,
dtype
=
'int64'
,
shape
=
[
1
],
persistable
=
True
)
name
=
counter_name
,
dtype
=
'int64'
,
shape
=
[
1
],
persistable
=
True
)
if
is_new_var
:
if
is_new_var
:
helper
.
set_variable_initializer
(
helper
.
set_variable_initializer
(
counter
,
initializer
=
Constant
(
counter
,
initializer
=
Constant
(
value
=
0
,
force_cpu
=
True
))
value
=
begin
-
1
,
force_cpu
=
True
))
helper
.
main_program
.
global_block
().
prepend_op
(
helper
.
main_program
.
global_block
().
prepend_op
(
type
=
'increment'
,
type
=
'increment'
,
inputs
=
{
'X'
:
[
counter
]},
inputs
=
{
'X'
:
[
counter
]},
outputs
=
{
'Out'
:
[
counter
]})
outputs
=
{
'Out'
:
[
counter
]},
attrs
=
{
'step'
:
float
(
step
)})
counter
.
stop_gradient
=
True
counter
.
stop_gradient
=
True
return
counter
return
counter
python/paddle/fluid/learning_rate_decay.py
浏览文件 @
9db107da
...
@@ -32,7 +32,8 @@ strategy according to this module.
...
@@ -32,7 +32,8 @@ strategy according to this module.
def
float_global_step
():
def
float_global_step
():
# the first global step is zero in learning rate decay
# the first global step is zero in learning rate decay
global_step
=
layers
.
global_step_counter
()
-
1
global_step
=
layers
.
autoincreased_step_counter
(
counter_name
=
'@LR_DECAY_COUNTER@'
,
begin
=
0
,
step
=
1
)
global_step
=
layers
.
cast
(
global_step
,
'float32'
)
global_step
=
layers
.
cast
(
global_step
,
'float32'
)
return
global_step
return
global_step
...
...
python/paddle/fluid/tests/unittests/test_learning_rate_decay.py
浏览文件 @
9db107da
...
@@ -93,7 +93,9 @@ class TestLearningRateDecay(unittest.TestCase):
...
@@ -93,7 +93,9 @@ class TestLearningRateDecay(unittest.TestCase):
step_val
,
lr_val
=
exe
.
run
(
step_val
,
lr_val
=
exe
.
run
(
fluid
.
default_main_program
(),
fluid
.
default_main_program
(),
feed
=
[],
feed
=
[],
fetch_list
=
[
fluid
.
layers
.
global_step_counter
(),
decayed_lr
])
fetch_list
=
[
fluid
.
layers
.
autoincreased_step_counter
(),
decayed_lr
])
python_decayed_lr
=
python_decay_fn
(
python_decayed_lr
=
python_decay_fn
(
global_step
=
float
(
step
),
**
kwargs
)
global_step
=
float
(
step
),
**
kwargs
)
self
.
assertAlmostEqual
(
self
.
assertAlmostEqual
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录