提交 bd993696 编写于 作者: W Wang,Jeff

Change to use optimzer func

上级 325e0c1e
...@@ -62,6 +62,10 @@ def train_program(): ...@@ -62,6 +62,10 @@ def train_program():
return [avg_cost, acc] return [avg_cost, acc]
def optimizer_program():
return fluid.optimizer.Adam(learning_rate=0.001)
def main(): def main():
train_reader = paddle.batch( train_reader = paddle.batch(
paddle.reader.shuffle(paddle.dataset.mnist.train(), buf_size=500), paddle.reader.shuffle(paddle.dataset.mnist.train(), buf_size=500),
...@@ -71,10 +75,9 @@ def main(): ...@@ -71,10 +75,9 @@ def main():
use_cuda = os.getenv('WITH_GPU', '0') != '0' use_cuda = os.getenv('WITH_GPU', '0') != '0'
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
optimizer = fluid.optimizer.Adam(learning_rate=0.001)
trainer = fluid.Trainer( trainer = fluid.Trainer(
train_func=train_program, place=place, optimizer=optimizer) train_func=train_program, place=place, optimizer_func=optimizer_program)
# Save the parameter into a directory. The Inferencer can load the parameters from it to do infer # Save the parameter into a directory. The Inferencer can load the parameters from it to do infer
params_dirname = "recognize_digits_network.inference.model" params_dirname = "recognize_digits_network.inference.model"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册