未验证 提交 cbca2c2f 编写于 作者: L lvmengsi 提交者: GitHub

Fix0109mistake (#805)

* update readme
上级 4d3d1663
......@@ -154,30 +154,23 @@ test_reader = paddle.batch(
batch_size=BATCH_SIZE)
```
如果想直接从txt文件中读取数据的话,可以参考以下方式。
如果想直接从txt文件中读取数据的话,可以参考以下方式(需要自行准备txt文件)
```text
feature_names = [
'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX',
'PTRATIO', 'B', 'LSTAT', 'convert'
]
feature_num = len(feature_names)
data = numpy.fromfile(filename, sep=' ') # 从文件中读取原始数据
data = data.reshape(data.shape[0] // feature_num, feature_num)
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
for i in six.moves.range(feature_num-1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves可以兼容python2和python3
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves可以兼容python2和python3
ratio = 0.8 # 训练集和验证集的划分比例
offset = int(data.shape[0]*ratio)
train_data = data[:offset]
test_data = data[offset:]
def reader(data):
......@@ -193,6 +186,7 @@ test_reader = paddle.batch(
paddle.reader.shuffle(
reader(test_data), buf_size=500),
batch_size=BATCH_SIZE)
```
### 配置训练程序
训练程序的目的是定义一个训练模型的网络结构。对于线性回归来讲,它就是一个从输入到输出的简单的全连接层。更加复杂的结果,比如卷积神经网络,递归神经网络等会在随后的章节中介绍。训练程序必须返回`平均损失`作为第一个返回值,因为它会被后面反向传播算法所用到。
......
......@@ -156,30 +156,23 @@ test_reader = paddle.batch(
batch_size=BATCH_SIZE)
```
If you want to read data directly from \*.txt file, you can refer to the method as follows.
If you want to read data directly from \*.txt file, you can refer to the method as follows(need to prepare txt file by yourself).
```text
feature_names = [
'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX',
'PTRATIO', 'B', 'LSTAT', 'convert'
]
feature_num = len(feature_names)
data = numpy.fromfile(filename, sep=' ') # Read primary data from file
data = data.reshape(data.shape[0] // feature_num, feature_num)
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
for i in six.moves.range(feature_num-1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves is compatible to python2 and python3
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves is compatible to python2 and python3
ratio = 0.8 # distribution ratio of train dataset and verification dataset
offset = int(data.shape[0]\*ratio)
train_data = data[:offset]
test_data = data[offset:]
train_reader = paddle.batch(
......@@ -191,6 +184,7 @@ test_reader = paddle.batch(
paddle.reader.shuffle(
test_data, buf_size=500),
batch_size=BATCH_SIZE)
```
### Configure Program for Training
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.
......
......@@ -196,30 +196,23 @@ test_reader = paddle.batch(
batch_size=BATCH_SIZE)
```
如果想直接从txt文件中读取数据的话,可以参考以下方式。
如果想直接从txt文件中读取数据的话,可以参考以下方式(需要自行准备txt文件)
```text
feature_names = [
'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX',
'PTRATIO', 'B', 'LSTAT', 'convert'
]
feature_num = len(feature_names)
data = numpy.fromfile(filename, sep=' ') # 从文件中读取原始数据
data = data.reshape(data.shape[0] // feature_num, feature_num)
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
for i in six.moves.range(feature_num-1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves可以兼容python2和python3
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves可以兼容python2和python3
ratio = 0.8 # 训练集和验证集的划分比例
offset = int(data.shape[0]*ratio)
train_data = data[:offset]
test_data = data[offset:]
def reader(data):
......@@ -235,6 +228,7 @@ test_reader = paddle.batch(
paddle.reader.shuffle(
reader(test_data), buf_size=500),
batch_size=BATCH_SIZE)
```
### 配置训练程序
训练程序的目的是定义一个训练模型的网络结构。对于线性回归来讲,它就是一个从输入到输出的简单的全连接层。更加复杂的结果,比如卷积神经网络,递归神经网络等会在随后的章节中介绍。训练程序必须返回`平均损失`作为第一个返回值,因为它会被后面反向传播算法所用到。
......
......@@ -198,30 +198,23 @@ test_reader = paddle.batch(
batch_size=BATCH_SIZE)
```
If you want to read data directly from \*.txt file, you can refer to the method as follows.
If you want to read data directly from \*.txt file, you can refer to the method as follows(need to prepare txt file by yourself).
```text
feature_names = [
'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX',
'PTRATIO', 'B', 'LSTAT', 'convert'
]
feature_num = len(feature_names)
data = numpy.fromfile(filename, sep=' ') # Read primary data from file
data = data.reshape(data.shape[0] // feature_num, feature_num)
maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
for i in six.moves.range(feature_num-1):
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves is compatible to python2 and python3
data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves is compatible to python2 and python3
ratio = 0.8 # distribution ratio of train dataset and verification dataset
offset = int(data.shape[0]\*ratio)
train_data = data[:offset]
test_data = data[offset:]
train_reader = paddle.batch(
......@@ -233,6 +226,7 @@ test_reader = paddle.batch(
paddle.reader.shuffle(
test_data, buf_size=500),
batch_size=BATCH_SIZE)
```
### Configure Program for Training
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.
......
......@@ -162,7 +162,7 @@ def bn(x, name=None, act='relu'):
- 卷积层
调用 `fluid.nets.simple_img_conv_pool` 实现卷积池化组,卷积核大小为3x3,池化窗口大小为2x2,窗口滑动步长为2,激活函数类型由具体网络结构指定。
调用 `fluid.nets.simple_img_conv_pool` 实现卷积池化组,卷积核大小为5x5,池化窗口大小为2x2,窗口滑动步长为2,激活函数类型由具体网络结构指定。
```python
def conv(x, num_filters, name=None, act=None):
......
......@@ -204,7 +204,7 @@ def bn(x, name=None, act='relu'):
- 卷积层
调用 `fluid.nets.simple_img_conv_pool` 实现卷积池化组,卷积核大小为3x3,池化窗口大小为2x2,窗口滑动步长为2,激活函数类型由具体网络结构指定。
调用 `fluid.nets.simple_img_conv_pool` 实现卷积池化组,卷积核大小为5x5,池化窗口大小为2x2,窗口滑动步长为2,激活函数类型由具体网络结构指定。
```python
def conv(x, num_filters, name=None, act=None):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册