提交 8bfb2bc0 编写于 作者: L liaogang

update LeNet-5

上级 108c0aac
......@@ -172,7 +172,7 @@ def convolutional_neural_network(img):
num_channel=1,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
conv_pool_2 = paddle.networks.simple_img_conv_pool(
input=conv_pool_1,
......@@ -181,13 +181,9 @@ def convolutional_neural_network(img):
num_channel=20,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
fc1 = paddle.layer.fc(input=conv_pool_2,
size=128,
act=paddle.activation.Tanh())
predict = paddle.layer.fc(input=fc1,
predict = paddle.layer.fc(input=conv_pool_2,
size=10,
act=paddle.activation.Softmax())
return predict
......@@ -203,9 +199,9 @@ images = paddle.layer.data(
label = paddle.layer.data(
name='label', type=paddle.data_type.integer_value(10))
predict = softmax_regression(images)
#predict = multilayer_perceptron(images) # uncomment for MLP
#predict = convolutional_neural_network(images) # uncomment for LeNet5
# predict = softmax_regression(images)
# predict = multilayer_perceptron(images) # uncomment for MLP
predict = convolutional_neural_network(images) # uncomment for LeNet5
cost = paddle.layer.classification_cost(input=predict, label=label)
```
......
......@@ -173,7 +173,7 @@ def convolutional_neural_network(img):
num_channel=1,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
# 第二个卷积-池化层
conv_pool_2 = paddle.networks.simple_img_conv_pool(
input=conv_pool_1,
......@@ -182,13 +182,9 @@ def convolutional_neural_network(img):
num_channel=20,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
# 全连接层
fc1 = paddle.layer.fc(input=conv_pool_2,
size=128,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
# 以softmax为激活函数的全连接输出层,输出层的大小必须为数字的个数10
predict = paddle.layer.fc(input=fc1,
predict = paddle.layer.fc(input=conv_pool_2,
size=10,
act=paddle.activation.Softmax())
return predict
......@@ -205,9 +201,9 @@ images = paddle.layer.data(
label = paddle.layer.data(
name='label', type=paddle.data_type.integer_value(10))
predict = softmax_regression(images) # Softmax回归
#predict = multilayer_perceptron(images) #多层感知器
#predict = convolutional_neural_network(images) #LeNet5卷积神经网络
# predict = softmax_regression(images) # Softmax回归
# predict = multilayer_perceptron(images) #多层感知器
predict = convolutional_neural_network(images) #LeNet5卷积神经网络
cost = paddle.layer.classification_cost(input=predict, label=label)
```
......
......@@ -214,7 +214,7 @@ def convolutional_neural_network(img):
num_channel=1,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
conv_pool_2 = paddle.networks.simple_img_conv_pool(
input=conv_pool_1,
......@@ -223,13 +223,9 @@ def convolutional_neural_network(img):
num_channel=20,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
fc1 = paddle.layer.fc(input=conv_pool_2,
size=128,
act=paddle.activation.Tanh())
predict = paddle.layer.fc(input=fc1,
predict = paddle.layer.fc(input=conv_pool_2,
size=10,
act=paddle.activation.Softmax())
return predict
......@@ -245,9 +241,9 @@ images = paddle.layer.data(
label = paddle.layer.data(
name='label', type=paddle.data_type.integer_value(10))
predict = softmax_regression(images)
#predict = multilayer_perceptron(images) # uncomment for MLP
#predict = convolutional_neural_network(images) # uncomment for LeNet5
# predict = softmax_regression(images)
# predict = multilayer_perceptron(images) # uncomment for MLP
predict = convolutional_neural_network(images) # uncomment for LeNet5
cost = paddle.layer.classification_cost(input=predict, label=label)
```
......
......@@ -215,7 +215,7 @@ def convolutional_neural_network(img):
num_channel=1,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
# 第二个卷积-池化层
conv_pool_2 = paddle.networks.simple_img_conv_pool(
input=conv_pool_1,
......@@ -224,13 +224,9 @@ def convolutional_neural_network(img):
num_channel=20,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
# 全连接层
fc1 = paddle.layer.fc(input=conv_pool_2,
size=128,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
# 以softmax为激活函数的全连接输出层,输出层的大小必须为数字的个数10
predict = paddle.layer.fc(input=fc1,
predict = paddle.layer.fc(input=conv_pool_2,
size=10,
act=paddle.activation.Softmax())
return predict
......@@ -247,9 +243,9 @@ images = paddle.layer.data(
label = paddle.layer.data(
name='label', type=paddle.data_type.integer_value(10))
predict = softmax_regression(images) # Softmax回归
#predict = multilayer_perceptron(images) #多层感知器
#predict = convolutional_neural_network(images) #LeNet5卷积神经网络
# predict = softmax_regression(images) # Softmax回归
# predict = multilayer_perceptron(images) #多层感知器
predict = convolutional_neural_network(images) #LeNet5卷积神经网络
cost = paddle.layer.classification_cost(input=predict, label=label)
```
......
......@@ -29,7 +29,7 @@ def convolutional_neural_network(img):
num_channel=1,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
act=paddle.activation.Relu())
# second conv layer
conv_pool_2 = paddle.networks.simple_img_conv_pool(
input=conv_pool_1,
......@@ -38,14 +38,10 @@ def convolutional_neural_network(img):
num_channel=20,
pool_size=2,
pool_stride=2,
act=paddle.activation.Tanh())
# The first fully-connected layer
fc1 = paddle.layer.fc(
input=conv_pool_2, size=128, act=paddle.activation.Tanh())
# The softmax layer, note that the hidden size should be 10,
# which is the number of unique digits
act=paddle.activation.Relu())
# fully-connected layer
predict = paddle.layer.fc(
input=fc1, size=10, act=paddle.activation.Softmax())
input=conv_pool_2, size=10, act=paddle.activation.Softmax())
return predict
......@@ -58,9 +54,9 @@ label = paddle.layer.data(name='label', type=paddle.data_type.integer_value(10))
# Here we can build the prediction network in different ways. Please
# choose one by uncomment corresponding line.
predict = softmax_regression(images)
#predict = multilayer_perceptron(images)
#predict = convolutional_neural_network(images)
# predict = softmax_regression(images)
# predict = multilayer_perceptron(images)
predict = convolutional_neural_network(images)
cost = paddle.layer.classification_cost(input=predict, label=label)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册