diff --git a/03.image_classification/README.cn.md b/03.image_classification/README.cn.md index d4fcef9cf0dcf44f8cab19916d36ee06483fce01..35035a7dd20446de8adaddddc8623477b827ca98 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 4704a4baea4b87f846253de4001e5494e702c34a..fa05900a23c82bd00a1b06f8175d22ecfd4c4d15 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 a0d6d2231e04f0ff2b4431c1e151a8d9172b1225..910a837cafaf944fb24f67d7fefce2ddfab3a23d 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 50ed16241ce0268ddb633eb883611845c51efcc7..c336ab7d61f759e494c385821b119e87a7806385 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 c4e2941cd636a6179d9ea582c58b3f4a8ba488e4..47df1809b055e0b90c126816c49521e4166cc3f3 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)