提交 b3cb6819 编写于 作者: R ruri 提交者: GitHub

Revert "Fix layers data (#816)"

This reverts commit 84a0d7b1.
上级 21bd7a30
...@@ -314,8 +314,8 @@ def resnet_cifar10(ipt, depth=32): ...@@ -314,8 +314,8 @@ def resnet_cifar10(ipt, depth=32):
```python ```python
def inference_program(): def inference_program():
# The image is 32 * 32 with RGB representation. # The image is 32 * 32 with RGB representation.
data_shape = [None, 3, 32, 32] data_shape = [3, 32, 32]
images = fluid.data(name='pixel', shape=data_shape, dtype='float32') images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
predict = resnet_cifar10(images, 32) predict = resnet_cifar10(images, 32)
# predict = vgg_bn_drop(images) # un-comment to use vgg net # predict = vgg_bn_drop(images) # un-comment to use vgg net
...@@ -326,7 +326,7 @@ def inference_program(): ...@@ -326,7 +326,7 @@ def inference_program():
然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。 然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。
在训练期间,它将从预测中计算 `avg_cost` 在训练期间,它将从预测中计算 `avg_cost`
在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.layers.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。
**注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。 **注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。
...@@ -334,7 +334,7 @@ def inference_program(): ...@@ -334,7 +334,7 @@ def inference_program():
def train_program(): def train_program():
predict = inference_program() predict = inference_program()
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=predict, label=label) cost = fluid.layers.cross_entropy(input=predict, label=label)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=predict, label=label) accuracy = fluid.layers.accuracy(input=predict, label=label)
......
...@@ -305,13 +305,13 @@ def resnet_cifar10(ipt, depth=32): ...@@ -305,13 +305,13 @@ def resnet_cifar10(ipt, depth=32):
## Inference Program Configuration ## Inference Program Configuration
The input to the network is defined as `fluid.data` , corresponding to image pixels in the context of image classification. The images in CIFAR10 are 32x32 coloured images with three channels. Therefore, the size of the input data is 3072 (3x32x32). The input to the network is defined as `fluid.layers.data` , corresponding to image pixels in the context of image classification. The images in CIFAR10 are 32x32 coloured images with three channels. Therefore, the size of the input data is 3072 (3x32x32).
```python ```python
def inference_program(): def inference_program():
# The image is 32 * 32 with RGB representation. # The image is 32 * 32 with RGB representation.
data_shape = [None, 3, 32, 32] data_shape = [3, 32, 32]
images = fluid.data(name='pixel', shape=data_shape, dtype='float32') images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
predict = resnet_cifar10(images, 32) predict = resnet_cifar10(images, 32)
# predict = vgg_bn_drop(images) # un-comment to use vgg net # predict = vgg_bn_drop(images) # un-comment to use vgg net
...@@ -322,7 +322,7 @@ def inference_program(): ...@@ -322,7 +322,7 @@ def inference_program():
Then we need to set up the the `train_program`. It takes the prediction from the inference_program first. Then we need to set up the the `train_program`. It takes the prediction from the inference_program first.
During the training, it will calculate the `avg_loss` from the prediction. During the training, it will calculate the `avg_loss` from the prediction.
In the context of supervised learning, labels of training images are defined in `fluid.data` as well. During training, the multi-class cross-entropy is used as the loss function and becomes the output of the network. During testing, the outputs are the probabilities calculated in the classifier. In the context of supervised learning, labels of training images are defined in `fluid.layers.data` as well. During training, the multi-class cross-entropy is used as the loss function and becomes the output of the network. During testing, the outputs are the probabilities calculated in the classifier.
**NOTE:** A training program should return an array and the first returned argument has to be `avg_cost` . **NOTE:** A training program should return an array and the first returned argument has to be `avg_cost` .
The trainer always uses it to calculate the gradients. The trainer always uses it to calculate the gradients.
...@@ -331,7 +331,7 @@ The trainer always uses it to calculate the gradients. ...@@ -331,7 +331,7 @@ The trainer always uses it to calculate the gradients.
def train_program(): def train_program():
predict = inference_program() predict = inference_program()
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=predict, label=label) cost = fluid.layers.cross_entropy(input=predict, label=label)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=predict, label=label) accuracy = fluid.layers.accuracy(input=predict, label=label)
......
...@@ -356,8 +356,8 @@ def resnet_cifar10(ipt, depth=32): ...@@ -356,8 +356,8 @@ def resnet_cifar10(ipt, depth=32):
```python ```python
def inference_program(): def inference_program():
# The image is 32 * 32 with RGB representation. # The image is 32 * 32 with RGB representation.
data_shape = [None, 3, 32, 32] data_shape = [3, 32, 32]
images = fluid.data(name='pixel', shape=data_shape, dtype='float32') images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
predict = resnet_cifar10(images, 32) predict = resnet_cifar10(images, 32)
# predict = vgg_bn_drop(images) # un-comment to use vgg net # predict = vgg_bn_drop(images) # un-comment to use vgg net
...@@ -368,7 +368,7 @@ def inference_program(): ...@@ -368,7 +368,7 @@ def inference_program():
然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。 然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。
在训练期间,它将从预测中计算 `avg_cost`。 在训练期间,它将从预测中计算 `avg_cost`。
在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.layers.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。
**注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。 **注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。
...@@ -376,7 +376,7 @@ def inference_program(): ...@@ -376,7 +376,7 @@ def inference_program():
def train_program(): def train_program():
predict = inference_program() predict = inference_program()
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=predict, label=label) cost = fluid.layers.cross_entropy(input=predict, label=label)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=predict, label=label) accuracy = fluid.layers.accuracy(input=predict, label=label)
......
...@@ -347,13 +347,13 @@ def resnet_cifar10(ipt, depth=32): ...@@ -347,13 +347,13 @@ def resnet_cifar10(ipt, depth=32):
## Inference Program Configuration ## Inference Program Configuration
The input to the network is defined as `fluid.data` , corresponding to image pixels in the context of image classification. The images in CIFAR10 are 32x32 coloured images with three channels. Therefore, the size of the input data is 3072 (3x32x32). The input to the network is defined as `fluid.layers.data` , corresponding to image pixels in the context of image classification. The images in CIFAR10 are 32x32 coloured images with three channels. Therefore, the size of the input data is 3072 (3x32x32).
```python ```python
def inference_program(): def inference_program():
# The image is 32 * 32 with RGB representation. # The image is 32 * 32 with RGB representation.
data_shape = [None, 3, 32, 32] data_shape = [3, 32, 32]
images = fluid.data(name='pixel', shape=data_shape, dtype='float32') images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
predict = resnet_cifar10(images, 32) predict = resnet_cifar10(images, 32)
# predict = vgg_bn_drop(images) # un-comment to use vgg net # predict = vgg_bn_drop(images) # un-comment to use vgg net
...@@ -364,7 +364,7 @@ def inference_program(): ...@@ -364,7 +364,7 @@ def inference_program():
Then we need to set up the the `train_program`. It takes the prediction from the inference_program first. Then we need to set up the the `train_program`. It takes the prediction from the inference_program first.
During the training, it will calculate the `avg_loss` from the prediction. During the training, it will calculate the `avg_loss` from the prediction.
In the context of supervised learning, labels of training images are defined in `fluid.data` as well. During training, the multi-class cross-entropy is used as the loss function and becomes the output of the network. During testing, the outputs are the probabilities calculated in the classifier. In the context of supervised learning, labels of training images are defined in `fluid.layers.data` as well. During training, the multi-class cross-entropy is used as the loss function and becomes the output of the network. During testing, the outputs are the probabilities calculated in the classifier.
**NOTE:** A training program should return an array and the first returned argument has to be `avg_cost` . **NOTE:** A training program should return an array and the first returned argument has to be `avg_cost` .
The trainer always uses it to calculate the gradients. The trainer always uses it to calculate the gradients.
...@@ -373,7 +373,7 @@ The trainer always uses it to calculate the gradients. ...@@ -373,7 +373,7 @@ The trainer always uses it to calculate the gradients.
def train_program(): def train_program():
predict = inference_program() predict = inference_program()
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=predict, label=label) cost = fluid.layers.cross_entropy(input=predict, label=label)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=predict, label=label) accuracy = fluid.layers.accuracy(input=predict, label=label)
......
...@@ -40,8 +40,8 @@ def parse_args(): ...@@ -40,8 +40,8 @@ def parse_args():
def inference_network(): def inference_network():
# The image is 32 * 32 with RGB representation. # The image is 32 * 32 with RGB representation.
data_shape = [None, 3, 32, 32] data_shape = [3, 32, 32]
images = fluid.data(name='pixel', shape=data_shape, dtype='float32') images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
predict = resnet_cifar10(images, 32) predict = resnet_cifar10(images, 32)
# predict = vgg_bn_drop(images) # un-comment to use vgg net # predict = vgg_bn_drop(images) # un-comment to use vgg net
...@@ -49,7 +49,7 @@ def inference_network(): ...@@ -49,7 +49,7 @@ def inference_network():
def train_network(predict): def train_network(predict):
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=predict, label=label) cost = fluid.layers.cross_entropy(input=predict, label=label)
avg_cost = fluid.layers.mean(cost) avg_cost = fluid.layers.mean(cost)
accuracy = fluid.layers.accuracy(input=predict, label=label) accuracy = fluid.layers.accuracy(input=predict, label=label)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册