Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
ed9d603a
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ed9d603a
编写于
5月 31, 2019
作者:
L
lujun
提交者:
GitHub
5月 31, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix api doc: Optimizer.ModelAverage (#17395)
上级
90eae0b3
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
44 addition
and
14 deletion
+44
-14
paddle/fluid/API.spec
paddle/fluid/API.spec
+2
-2
python/paddle/dataset/mnist.py
python/paddle/dataset/mnist.py
+2
-2
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+40
-10
未找到文件。
paddle/fluid/API.spec
浏览文件 @
ed9d603a
...
...
@@ -500,13 +500,13 @@ paddle.fluid.optimizer.AdadeltaOptimizer.backward (ArgSpec(args=['self', 'loss',
paddle.fluid.optimizer.AdadeltaOptimizer.get_opti_var_name_list (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.optimizer.AdadeltaOptimizer.minimize (ArgSpec(args=['self', 'loss', 'startup_program', 'parameter_list', 'no_grad_set', 'grad_clip'], varargs=None, keywords=None, defaults=(None, None, None, None)), ('document', 'b15cffad0903fc81af77a0580ceb2a9b'))
paddle.fluid.optimizer.ModelAverage.__init__ (ArgSpec(args=['self', 'average_window_rate', 'min_average_window', 'max_average_window', 'regularization', 'name'], varargs=None, keywords=None, defaults=(10000, 10000, None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.optimizer.ModelAverage.apply (ArgSpec(args=['self', 'executor', 'need_restore'], varargs=None, keywords=None, defaults=(True,)), ('document', '
46234a5470590feb336346f70a3db715
'))
paddle.fluid.optimizer.ModelAverage.apply (ArgSpec(args=['self', 'executor', 'need_restore'], varargs=None, keywords=None, defaults=(True,)), ('document', '
648010d0ac1fa707dac0b89f74b0e35c
'))
paddle.fluid.optimizer.ModelAverage.apply_gradients (ArgSpec(args=['self', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', 'bfe7305918552aaecfdaa22411dbe871'))
paddle.fluid.optimizer.ModelAverage.apply_optimize (ArgSpec(args=['self', 'loss', 'startup_program', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', '5c46d1926a40f1f873ffe9f37ac89dae'))
paddle.fluid.optimizer.ModelAverage.backward (ArgSpec(args=['self', 'loss', 'startup_program', 'parameter_list', 'no_grad_set', 'callbacks'], varargs=None, keywords=None, defaults=(None, None, None, None)), ('document', 'ba3a113d0229ff7bc9d39bda0a6d947f'))
paddle.fluid.optimizer.ModelAverage.get_opti_var_name_list (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.optimizer.ModelAverage.minimize (ArgSpec(args=['self', 'loss', 'startup_program', 'parameter_list', 'no_grad_set', 'grad_clip'], varargs=None, keywords=None, defaults=(None, None, None, None)), ('document', 'b15cffad0903fc81af77a0580ceb2a9b'))
paddle.fluid.optimizer.ModelAverage.restore (ArgSpec(args=['self', 'executor'], varargs=None, keywords=None, defaults=None), ('document', '
18db9c70be9c4dd466f9844457b21bfe
'))
paddle.fluid.optimizer.ModelAverage.restore (ArgSpec(args=['self', 'executor'], varargs=None, keywords=None, defaults=None), ('document', '
5f14ea4adda2791e1c3b37ff327f6a83
'))
paddle.fluid.optimizer.LarsMomentumOptimizer.__init__ (ArgSpec(args=['self', 'learning_rate', 'momentum', 'lars_coeff', 'lars_weight_decay', 'regularization', 'name'], varargs=None, keywords=None, defaults=(0.001, 0.0005, None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.optimizer.LarsMomentumOptimizer.apply_gradients (ArgSpec(args=['self', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', 'bfe7305918552aaecfdaa22411dbe871'))
paddle.fluid.optimizer.LarsMomentumOptimizer.apply_optimize (ArgSpec(args=['self', 'loss', 'startup_program', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', '5c46d1926a40f1f873ffe9f37ac89dae'))
...
...
python/paddle/dataset/mnist.py
浏览文件 @
ed9d603a
...
...
@@ -90,7 +90,7 @@ def train():
MNIST training set creator.
It returns a reader creator, each sample in the reader is image pixels in
[
0
, 1] and label in [0, 9].
[
-1
, 1] and label in [0, 9].
:return: Training reader creator
:rtype: callable
...
...
@@ -107,7 +107,7 @@ def test():
MNIST test set creator.
It returns a reader creator, each sample in the reader is image pixels in
[
0
, 1] and label in [0, 9].
[
-1
, 1] and label in [0, 9].
:return: Test reader creator.
:rtype: callable
...
...
python/paddle/fluid/optimizer.py
浏览文件 @
ed9d603a
...
...
@@ -2145,22 +2145,45 @@ class ModelAverage(Optimizer):
regularization: A Regularizer, such as
fluid.regularizer.L2DecayRegularizer.
name: A optional name prefix.
Examples:
.. code-block:: python
optimizer = fluid.optimizer.Momentum()
optimizer.minimize(cost)
import paddle.fluid as fluid
import numpy
# First create the Executor.
place = fluid.CPUPlace() # fluid.CUDAPlace(0)
exe = fluid.Executor(place)
train_program = fluid.Program()
startup_program = fluid.Program()
with fluid.program_guard(train_program, startup_program):
# build net
data = fluid.layers.data(name='X', shape=[1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
loss = fluid.layers.mean(hidden)
optimizer = fluid.optimizer.Momentum(learning_rate=0.2, momentum=0.1)
optimizer.minimize(loss)
# build ModelAverage optimizer
model_average = fluid.optimizer.ModelAverage(0.15,
min_average_window=10000,
max_average_window=20000)
for pass_id in range(args.pass_num):
for data in train_reader():
exe.run(fluid.default_main_program()...)
exe.run(startup_program)
x = numpy.random.random(size=(10, 1)).astype('float32')
outs = exe.run(program=train_program,
feed={'X': x},
fetch_list=[loss.name])
# apply ModelAverage
with model_average.apply(exe):
for data in test_reader():
exe.run(inference_program...)
x = numpy.random.random(size=(10, 1)).astype('float32')
exe.run(program=train_program,
feed={'X': x},
fetch_list=[loss.name])
"""
def
__init__
(
self
,
...
...
@@ -2275,6 +2298,10 @@ class ModelAverage(Optimizer):
@
signature_safe_contextmanager
def
apply
(
self
,
executor
,
need_restore
=
True
):
"""Apply average values to parameters of current model.
Args:
executor(fluid.Executor): current executor.
need_restore(bool): If you finally need to do restore, set it to True. Default is True.
"""
executor
.
run
(
self
.
apply_program
)
try
:
...
...
@@ -2285,6 +2312,9 @@ class ModelAverage(Optimizer):
def
restore
(
self
,
executor
):
"""Restore parameter values of current model.
Args:
executor(fluid.Executor): current executor.
"""
executor
.
run
(
self
.
restore_program
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录