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

Fix the incorrect softmax functions

上级 70a91c62
......@@ -174,9 +174,8 @@ Let us create a data layer for reading images and connect it to the classificati
```python
def softmax_regression():
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
predict = paddle.layer.fc(input=img,
size=10,
act=paddle.activation.Softmax())
predict = fluid.layers.fc(
input=img, size=10, act='softmax')
return predict
```
......@@ -233,7 +232,7 @@ Please feel free to modify the code to test different results between `softmax r
def train_program():
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# predict = softmax_regression(images) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict = convolutional_neural_network() # uncomment for LeNet5
......@@ -319,6 +318,8 @@ train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
lists = []
# event_handler to plot a figure
def event_handler_plot(event):
global step
......@@ -336,6 +337,7 @@ def event_handler_plot(event):
avg_cost, acc = trainer.test(
reader=test_reader, feed_order=['img', 'label'])
cost_ploter.append(test_title, step, avg_cost)
lists.append((event.epoch, avg_cost, acc))
```
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
......
......@@ -216,9 +216,8 @@ Let us create a data layer for reading images and connect it to the classificati
```python
def softmax_regression():
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
predict = paddle.layer.fc(input=img,
size=10,
act=paddle.activation.Softmax())
predict = fluid.layers.fc(
input=img, size=10, act='softmax')
return predict
```
......@@ -275,7 +274,7 @@ Please feel free to modify the code to test different results between `softmax r
def train_program():
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# predict = softmax_regression(images) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict = convolutional_neural_network() # uncomment for LeNet5
......@@ -361,6 +360,8 @@ train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
lists = []
# event_handler to plot a figure
def event_handler_plot(event):
global step
......@@ -378,6 +379,7 @@ def event_handler_plot(event):
avg_cost, acc = trainer.test(
reader=test_reader, feed_order=['img', 'label'])
cost_ploter.append(test_title, step, avg_cost)
lists.append((event.epoch, avg_cost, acc))
```
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
......
......@@ -7,8 +7,7 @@ import paddle.fluid as fluid
def softmax_regression():
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
predict = paddle.layer.fc(
input=img, size=10, act=paddle.activation.Softmax())
predict = fluid.layers.fc(input=img, size=10, act='softmax')
return predict
......@@ -52,7 +51,7 @@ def train_program():
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# Here we can build the prediction network in different ways. Please
# predict = softmax_regression(images) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict = convolutional_neural_network() # uncomment for LeNet5
......@@ -83,6 +82,13 @@ def main():
lists = []
def event_handler(event):
if isinstance(event, fluid.EndStepEvent):
if event.step % 100 == 0:
# event.metrics maps with train program return arguments.
# event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example.
print "Pass %d, Batch %d, Cost %f" % (event.step, event.epoch,
event.metrics[0])
if isinstance(event, fluid.EndEpochEvent):
avg_cost, acc = trainer.test(
reader=test_reader, feed_order=['img', 'label'])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册