diff --git a/01.fit_a_line/README.cn.md b/01.fit_a_line/README.cn.md index 715bc98e5dcbbcfb340478c5de8d448fa4d4cc55..69cc494df6608d9e1026efbe618e532b18fba8f3 100644 --- a/01.fit_a_line/README.cn.md +++ b/01.fit_a_line/README.cn.md @@ -194,8 +194,8 @@ test_reader = paddle.batch( 训练程序的目的是定义一个训练模型的网络结构。对于线性回归来讲,它就是一个从输入到输出的简单的全连接层。更加复杂的结果,比如卷积神经网络,递归神经网络等会在随后的章节中介绍。训练程序必须返回`平均损失`作为第一个返回值,因为它会被后面反向传播算法所用到。 ```python -x = fluid.data(name='x', shape=[-1, 13], dtype='float32') # 定义输入的形状和数据类型 -y = fluid.data(name='y', shape=[-1, 1], dtype='float32') # 定义输出的形状和数据类型 +x = fluid.data(name='x', shape=[None, 13], dtype='float32') # 定义输入的形状和数据类型 +y = fluid.data(name='y', shape=[None, 1], dtype='float32') # 定义输出的形状和数据类型 y_predict = fluid.layers.fc(input=x, size=1, act=None) # 连接输入和输出的全连接层 main_program = fluid.default_main_program() # 获取默认/全局主函数 diff --git a/01.fit_a_line/README.md b/01.fit_a_line/README.md index 29fdc1a6c72c4f3da0939688359fb98b296f87f6..8760bbf0c6ac488f183a3adedb7bf6cde4058942 100644 --- a/01.fit_a_line/README.md +++ b/01.fit_a_line/README.md @@ -196,8 +196,8 @@ test_reader = paddle.batch( The aim of the program for training is to define a network structure of a training model. For linear regression, it is a simple fully connected layer from input to output. More complex result, such as Convolutional Neural Network and Recurrent Neural Network, will be introduced in later chapters. It must return `mean error` as the first return value in program for training, for that `mean error` will be used for BackPropagation. ```python -x = fluid.data(name='x', shape=[-1, 13], dtype='float32') # define shape and data type of input -y = fluid.data(name='y', shape=[-1, 1], dtype='float32') # define shape and data type of output +x = fluid.data(name='x', shape=[None, 13], dtype='float32') # define shape and data type of input +y = fluid.data(name='y', shape=[None, 1], dtype='float32') # define shape and data type of output y_predict = fluid.layers.fc(input=x, size=1, act=None) # fully connected layer connecting input and output main_program = fluid.default_main_program() # get default/global main function diff --git a/01.fit_a_line/index.cn.html b/01.fit_a_line/index.cn.html index 40d91286ee06e375b056bdea95e5a2bbf5a43328..e47cda5f7e74d4e41d0d341fab126712dc78434a 100644 --- a/01.fit_a_line/index.cn.html +++ b/01.fit_a_line/index.cn.html @@ -236,8 +236,8 @@ test_reader = paddle.batch( 训练程序的目的是定义一个训练模型的网络结构。对于线性回归来讲,它就是一个从输入到输出的简单的全连接层。更加复杂的结果,比如卷积神经网络,递归神经网络等会在随后的章节中介绍。训练程序必须返回`平均损失`作为第一个返回值,因为它会被后面反向传播算法所用到。 ```python -x = fluid.data(name='x', shape=[-1, 13], dtype='float32') # 定义输入的形状和数据类型 -y = fluid.data(name='y', shape=[-1, 1], dtype='float32') # 定义输出的形状和数据类型 +x = fluid.data(name='x', shape=[None, 13], dtype='float32') # 定义输入的形状和数据类型 +y = fluid.data(name='y', shape=[None, 1], dtype='float32') # 定义输出的形状和数据类型 y_predict = fluid.layers.fc(input=x, size=1, act=None) # 连接输入和输出的全连接层 main_program = fluid.default_main_program() # 获取默认/全局主函数 diff --git a/01.fit_a_line/index.html b/01.fit_a_line/index.html index 184e8253bda3711afe6f3f2d60fc21aab2bcdb1c..70e7b0eab98652434f4e030e7888d07290176ef3 100644 --- a/01.fit_a_line/index.html +++ b/01.fit_a_line/index.html @@ -238,8 +238,8 @@ test_reader = paddle.batch( The aim of the program for training is to define a network structure of a training model. For linear regression, it is a simple fully connected layer from input to output. More complex result, such as Convolutional Neural Network and Recurrent Neural Network, will be introduced in later chapters. It must return `mean error` as the first return value in program for training, for that `mean error` will be used for BackPropagation. ```python -x = fluid.data(name='x', shape=[-1, 13], dtype='float32') # define shape and data type of input -y = fluid.data(name='y', shape=[-1, 1], dtype='float32') # define shape and data type of output +x = fluid.data(name='x', shape=[None, 13], dtype='float32') # define shape and data type of input +y = fluid.data(name='y', shape=[None, 1], dtype='float32') # define shape and data type of output y_predict = fluid.layers.fc(input=x, size=1, act=None) # fully connected layer connecting input and output main_program = fluid.default_main_program() # get default/global main function diff --git a/01.fit_a_line/train.py b/01.fit_a_line/train.py index 2ebe21e6fd9319c18369d177684ed62186bedd82..e7088986edace4df0a795c768ddc50ad0d9dde74 100644 --- a/01.fit_a_line/train.py +++ b/01.fit_a_line/train.py @@ -87,8 +87,8 @@ def main(): batch_size=batch_size) # feature vector of length 13 - x = fluid.data(name='x', shape=[-1, 13], dtype='float32') - y = fluid.data(name='y', shape=[-1, 1], dtype='float32') + x = fluid.data(name='x', shape=[None, 13], dtype='float32') + y = fluid.data(name='y', shape=[None, 1], dtype='float32') main_program = fluid.default_main_program() startup_program = fluid.default_startup_program() diff --git a/02.recognize_digits/README.cn.md b/02.recognize_digits/README.cn.md index 31c2adbb6b27fd53179643af099f336d713d3483..b36211907eafcc12d418b2eb380de10f8cf512c8 100644 --- a/02.recognize_digits/README.cn.md +++ b/02.recognize_digits/README.cn.md @@ -209,7 +209,7 @@ def softmax_regression(): predict_image -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 以softmax为激活函数的全连接层,输出层的大小必须为数字的个数10 predict = fluid.layers.fc( input=img, size=10, act='softmax') @@ -229,7 +229,7 @@ def multilayer_perceptron(): predict_image -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 第一个全连接层,激活函数为ReLU hidden = fluid.layers.fc(input=img, size=200, act='relu') # 第二个全连接层,激活函数为ReLU @@ -251,7 +251,7 @@ def convolutional_neural_network(): predict -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 第一个卷积-池化层 # 使用20个5*5的滤波器,池化大小为2,池化步长为2,激活函数为Relu conv_pool_1 = fluid.nets.simple_img_conv_pool( @@ -296,7 +296,7 @@ def train_program(): """ # 标签层,名称为label,对应输入图片的类别标签 - label = fluid.data(name='label', shape=[-1, 1], dtype='int64') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') # predict = softmax_regression() # 取消注释将使用 Softmax回归 # predict = multilayer_perceptron() # 取消注释将使用 多层感知器 diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index b3ca3c86f4b300841a6e0df7733453e0762c27a6..47691ef026b341e831cb8d828ad5799e3dd5264e 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -188,7 +188,7 @@ def softmax_regression(): predict_image -- result of classification """ # input original image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # With softmax as the fully connected layer of the activation function, the size of the output layer must be 10 predict = fluid.layers.fc( input=img, size=10, act='softmax') @@ -208,7 +208,7 @@ def multilayer_perceptron(): predict_image -- result of classification """ # input raw image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # the first fully connected layer, whose activation function is ReLU hidden = fluid.layers.fc(input=img, size=200, act='relu') # the second fully connected layer, whose activation function is ReLU @@ -230,7 +230,7 @@ def convolutional_neural_network(): predict -- result of classification """ # input raw image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # the first convolution-pooling layer # Use 20 5*5 filters, the pooling size is 2, the pooling step is 2, and the activation function is Relu. conv_pool_1 = fluid.nets.simple_img_conv_pool( @@ -275,7 +275,7 @@ def train_program(): """ # label layer, called label, correspondent with label category of input picture - label = fluid.data(name='label', shape=[-1, 1], dtype='int64') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') # predict = softmax_regression() # cancel note and run Softmax regression # predict = multilayer_perceptron() # cancel note and run multiple perceptron diff --git a/02.recognize_digits/index.cn.html b/02.recognize_digits/index.cn.html index 328815220ae2521fdaf91e7bb4cf3ef3aa29698f..d3f82cd1a86bbfdb994213846dc1acf31e7fc7d3 100644 --- a/02.recognize_digits/index.cn.html +++ b/02.recognize_digits/index.cn.html @@ -251,7 +251,7 @@ def softmax_regression(): predict_image -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 以softmax为激活函数的全连接层,输出层的大小必须为数字的个数10 predict = fluid.layers.fc( input=img, size=10, act='softmax') @@ -271,7 +271,7 @@ def multilayer_perceptron(): predict_image -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 第一个全连接层,激活函数为ReLU hidden = fluid.layers.fc(input=img, size=200, act='relu') # 第二个全连接层,激活函数为ReLU @@ -293,7 +293,7 @@ def convolutional_neural_network(): predict -- 分类的结果 """ # 输入的原始图像数据,大小为28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # 第一个卷积-池化层 # 使用20个5*5的滤波器,池化大小为2,池化步长为2,激活函数为Relu conv_pool_1 = fluid.nets.simple_img_conv_pool( @@ -338,7 +338,7 @@ def train_program(): """ # 标签层,名称为label,对应输入图片的类别标签 - label = fluid.data(name='label', shape=[-1, 1], dtype='int64') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') # predict = softmax_regression() # 取消注释将使用 Softmax回归 # predict = multilayer_perceptron() # 取消注释将使用 多层感知器 diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index 9ab5b1eccc9c35a1364b486ede01571d780d7c4e..04ff588588e54ae953873470f60f7724a6856492 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -230,7 +230,7 @@ def softmax_regression(): predict_image -- result of classification """ # input original image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # With softmax as the fully connected layer of the activation function, the size of the output layer must be 10 predict = fluid.layers.fc( input=img, size=10, act='softmax') @@ -250,7 +250,7 @@ def multilayer_perceptron(): predict_image -- result of classification """ # input raw image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # the first fully connected layer, whose activation function is ReLU hidden = fluid.layers.fc(input=img, size=200, act='relu') # the second fully connected layer, whose activation function is ReLU @@ -272,7 +272,7 @@ def convolutional_neural_network(): predict -- result of classification """ # input raw image data in size of 28*28*1 - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') # the first convolution-pooling layer # Use 20 5*5 filters, the pooling size is 2, the pooling step is 2, and the activation function is Relu. conv_pool_1 = fluid.nets.simple_img_conv_pool( @@ -317,7 +317,7 @@ def train_program(): """ # label layer, called label, correspondent with label category of input picture - label = fluid.data(name='label', shape=[-1, 1], dtype='int64') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') # predict = softmax_regression() # cancel note and run Softmax regression # predict = multilayer_perceptron() # cancel note and run multiple perceptron diff --git a/02.recognize_digits/train.py b/02.recognize_digits/train.py index 27cb3c72ed20a63993c5fc1c11cd222e5d72b5ef..1d1fa9a7c64e9c9dd99f0ae3b0234a139b4d6de0 100644 --- a/02.recognize_digits/train.py +++ b/02.recognize_digits/train.py @@ -101,8 +101,8 @@ def train(nn_type, test_reader = paddle.batch( paddle.dataset.mnist.test(), batch_size=BATCH_SIZE) - img = fluid.data(name='img', shape=[-1, 1, 28, 28], dtype='float32') - label = fluid.data(name='label', shape=[-1, 1], dtype='int64') + img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') if nn_type == 'softmax_regression': net_conf = softmax_regression diff --git a/09.gan/README.cn.md b/09.gan/README.cn.md index 99cf01ed570e122248a38982eeaf5b284034226a..4c0fd2298b34f8fcb87202039a9bf1d9542d279e 100644 --- a/09.gan/README.cn.md +++ b/09.gan/README.cn.md @@ -265,16 +265,16 @@ dg_program = fluid.Program() # 定义判别真实图片的program with fluid.program_guard(d_program): # 输入图片大小为28*28=784 - img = fluid.layers.data(name='img', shape=[784], dtype='float32') + img = fluid.data(name='img', shape=[None, 784], dtype='float32') # 标签shape=1 - label = fluid.layers.data(name='label', shape=[1], dtype='float32') + label = fluid.data(name='label', shape=[None, 1], dtype='float32') d_logit = D(img) d_loss = loss(d_logit, label) # 定义判别生成图片的program with fluid.program_guard(dg_program): - noise = fluid.layers.data( - name='noise', shape=[NOISE_SIZE], dtype='float32') + noise = fluid.data( + name='noise', shape=[None, NOISE_SIZE], dtype='float32') # 噪声数据作为输入得到生成图片 g_img = G(x=noise) diff --git a/09.gan/dc_gan.py b/09.gan/dc_gan.py index c08752aecf886c1fb882604b5116f3ec9ea1f00d..7234dc837109a1132612cff759634a8330c3c1e9 100644 --- a/09.gan/dc_gan.py +++ b/09.gan/dc_gan.py @@ -60,14 +60,14 @@ def train(args): dg_program = fluid.Program() with fluid.program_guard(d_program): - img = fluid.layers.data(name='img', shape=[784], dtype='float32') - label = fluid.layers.data(name='label', shape=[1], dtype='float32') + img = fluid.data(name='img', shape=[None, 784], dtype='float32') + label = fluid.data(name='label', shape=[None, 1], dtype='float32') d_logit = D(img) d_loss = loss(d_logit, label) with fluid.program_guard(dg_program): - noise = fluid.layers.data( - name='noise', shape=[NOISE_SIZE], dtype='float32') + noise = fluid.data( + name='noise', shape=[None, NOISE_SIZE], dtype='float32') g_img = G(x=noise) g_program = dg_program.clone() diff --git a/09.gan/index.cn.html b/09.gan/index.cn.html index 8947f5a1725538fea260a17b89f57e6f028a2336..a6b88e8ae0ad5a09bacae26410dba829a55c0c05 100644 --- a/09.gan/index.cn.html +++ b/09.gan/index.cn.html @@ -307,16 +307,16 @@ dg_program = fluid.Program() # 定义判别真实图片的program with fluid.program_guard(d_program): # 输入图片大小为28*28=784 - img = fluid.layers.data(name='img', shape=[784], dtype='float32') + img = fluid.data(name='img', shape=[None, 784], dtype='float32') # 标签shape=1 - label = fluid.layers.data(name='label', shape=[1], dtype='float32') + label = fluid.data(name='label', shape=[None, 1], dtype='float32') d_logit = D(img) d_loss = loss(d_logit, label) # 定义判别生成图片的program with fluid.program_guard(dg_program): - noise = fluid.layers.data( - name='noise', shape=[NOISE_SIZE], dtype='float32') + noise = fluid.data( + name='noise', shape=[None, NOISE_SIZE], dtype='float32') # 噪声数据作为输入得到生成图片 g_img = G(x=noise)