From 1b2433eee63a928be4f1a275d428766a8712cbae Mon Sep 17 00:00:00 2001 From: ruri Date: Thu, 17 Oct 2019 11:53:44 +0800 Subject: [PATCH] Revert "Fix layers data (#816)" (#829) revert 03 image classification: fluid.layers.data->fluid.data --- 03.image_classification/README.cn.md | 8 ++++---- 03.image_classification/README.md | 10 +++++----- 03.image_classification/index.cn.html | 8 ++++---- 03.image_classification/index.html | 10 +++++----- 03.image_classification/train.py | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/03.image_classification/README.cn.md b/03.image_classification/README.cn.md index d4fcef9..35035a7 100644 --- a/03.image_classification/README.cn.md +++ b/03.image_classification/README.cn.md @@ -314,8 +314,8 @@ def resnet_cifar10(ipt, depth=32): ```python def inference_program(): # The image is 32 * 32 with RGB representation. - data_shape = [None, 3, 32, 32] - images = fluid.data(name='pixel', shape=data_shape, dtype='float32') + data_shape = [3, 32, 32] + images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') predict = resnet_cifar10(images, 32) # predict = vgg_bn_drop(images) # un-comment to use vgg net @@ -326,7 +326,7 @@ def inference_program(): 然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。 在训练期间,它将从预测中计算 `avg_cost`。 -在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 +在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.layers.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 **注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。 @@ -334,7 +334,7 @@ def inference_program(): def train_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) avg_cost = fluid.layers.mean(cost) accuracy = fluid.layers.accuracy(input=predict, label=label) diff --git a/03.image_classification/README.md b/03.image_classification/README.md index 4704a4b..fa05900 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -305,13 +305,13 @@ def resnet_cifar10(ipt, depth=32): ## 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 def inference_program(): # The image is 32 * 32 with RGB representation. - data_shape = [None, 3, 32, 32] - images = fluid.data(name='pixel', shape=data_shape, dtype='float32') + data_shape = [3, 32, 32] + images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') predict = resnet_cifar10(images, 32) # predict = vgg_bn_drop(images) # un-comment to use vgg net @@ -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. 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` . 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(): 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) avg_cost = fluid.layers.mean(cost) accuracy = fluid.layers.accuracy(input=predict, label=label) diff --git a/03.image_classification/index.cn.html b/03.image_classification/index.cn.html index a0d6d22..910a837 100644 --- a/03.image_classification/index.cn.html +++ b/03.image_classification/index.cn.html @@ -356,8 +356,8 @@ def resnet_cifar10(ipt, depth=32): ```python def inference_program(): # The image is 32 * 32 with RGB representation. - data_shape = [None, 3, 32, 32] - images = fluid.data(name='pixel', shape=data_shape, dtype='float32') + data_shape = [3, 32, 32] + images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') predict = resnet_cifar10(images, 32) # predict = vgg_bn_drop(images) # un-comment to use vgg net @@ -368,7 +368,7 @@ def inference_program(): 然后我们需要设置训练程序 `train_program`。它首先从推理程序中进行预测。 在训练期间,它将从预测中计算 `avg_cost`。 -在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 +在有监督训练中需要输入图像对应的类别信息,同样通过`fluid.layers.data`来定义。训练中采用多类交叉熵作为损失函数,并作为网络的输出,预测阶段定义网络的输出为分类器得到的概率信息。 **注意:** 训练程序应该返回一个数组,第一个返回参数必须是 `avg_cost`。训练器使用它来计算梯度。 @@ -376,7 +376,7 @@ def inference_program(): def train_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) avg_cost = fluid.layers.mean(cost) accuracy = fluid.layers.accuracy(input=predict, label=label) diff --git a/03.image_classification/index.html b/03.image_classification/index.html index 50ed162..c336ab7 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -347,13 +347,13 @@ def resnet_cifar10(ipt, depth=32): ## 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 def inference_program(): # The image is 32 * 32 with RGB representation. - data_shape = [None, 3, 32, 32] - images = fluid.data(name='pixel', shape=data_shape, dtype='float32') + data_shape = [3, 32, 32] + images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') predict = resnet_cifar10(images, 32) # predict = vgg_bn_drop(images) # un-comment to use vgg net @@ -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. 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` . 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(): 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) avg_cost = fluid.layers.mean(cost) accuracy = fluid.layers.accuracy(input=predict, label=label) diff --git a/03.image_classification/train.py b/03.image_classification/train.py index c4e2941..47df180 100644 --- a/03.image_classification/train.py +++ b/03.image_classification/train.py @@ -40,8 +40,8 @@ def parse_args(): def inference_network(): # The image is 32 * 32 with RGB representation. - data_shape = [None, 3, 32, 32] - images = fluid.data(name='pixel', shape=data_shape, dtype='float32') + data_shape = [3, 32, 32] + images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') predict = resnet_cifar10(images, 32) # predict = vgg_bn_drop(images) # un-comment to use vgg net @@ -49,7 +49,7 @@ def inference_network(): 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) avg_cost = fluid.layers.mean(cost) accuracy = fluid.layers.accuracy(input=predict, label=label) -- GitLab