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

update LeNet-5

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