Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
cefab6bb
B
book
项目概览
PaddlePaddle
/
book
通知
17
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cefab6bb
编写于
7月 14, 2018
作者:
J
JiabinYang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/book
into book04_refine
上级
9961f79a
804beca1
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
82 addition
and
32 deletion
+82
-32
01.fit_a_line/README.cn.md
01.fit_a_line/README.cn.md
+17
-6
01.fit_a_line/README.md
01.fit_a_line/README.md
+17
-6
01.fit_a_line/image/ranges.png
01.fit_a_line/image/ranges.png
+0
-0
01.fit_a_line/index.cn.html
01.fit_a_line/index.cn.html
+17
-6
01.fit_a_line/index.html
01.fit_a_line/index.html
+17
-6
03.image_classification/README.cn.md
03.image_classification/README.cn.md
+4
-3
03.image_classification/README.md
03.image_classification/README.md
+3
-1
03.image_classification/index.cn.html
03.image_classification/index.cn.html
+4
-3
03.image_classification/index.html
03.image_classification/index.html
+3
-1
未找到文件。
01.fit_a_line/README.cn.md
浏览文件 @
cefab6bb
...
@@ -100,6 +100,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$
...
@@ -100,6 +100,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
numpy
import
numpy
from
__future__
import
print_function
```
```
我们通过uci_housing模块引入了数据集合
[
UCI Housing Data Set
](
https://archive.ics.uci.edu/ml/datasets/Housing
)
我们通过uci_housing模块引入了数据集合
[
UCI Housing Data Set
](
https://archive.ics.uci.edu/ml/datasets/Housing
)
...
@@ -179,7 +180,7 @@ feed_order=['x', 'y']
...
@@ -179,7 +180,7 @@ feed_order=['x', 'y']
除此之外,可以定义一个事件相应器来处理类似
`打印训练进程`
的事件:
除此之外,可以定义一个事件相应器来处理类似
`打印训练进程`
的事件:
```
python
```
python
# Specify the directory
path
to save the parameters
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
params_dirname
=
"fit_a_line.inference.model"
# Plot data
# Plot data
...
@@ -190,11 +191,11 @@ plot_cost = Ploter(train_title, test_title)
...
@@ -190,11 +191,11 @@ plot_cost = Ploter(train_title, test_title)
step
=
0
step
=
0
# event_handler
to print
training and testing info
# event_handler
prints
training and testing info
def
event_handler_plot
(
event
):
def
event_handler_plot
(
event
):
global
step
global
step
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
%
10
==
0
:
#
every 10 batches, record a test cost
if
event
.
step
%
10
==
0
:
#
record the test cost every 10 seconds
test_metrics
=
trainer
.
test
(
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
reader
=
test_reader
,
feed_order
=
feed_order
)
...
@@ -251,10 +252,20 @@ inferencer = fluid.Inferencer(
...
@@ -251,10 +252,20 @@ inferencer = fluid.Inferencer(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
batch_size
=
10
batch_size
=
10
tensor_x
=
numpy
.
random
.
uniform
(
0
,
10
,
[
batch_size
,
13
]).
astype
(
"float32"
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
()
test_feat
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_label
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
results
=
inferencer
.
infer
({
'x'
:
tensor_x
})
results
=
inferencer
.
infer
({
'x'
:
test_feat
})
print
(
"infer results: "
,
results
[
0
])
print
(
"infer results: (House Price)"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
results
[
0
][
k
]))
print
(
"
\n
ground truth:"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
test_label
[
k
]))
```
```
## 总结
## 总结
...
...
01.fit_a_line/README.md
浏览文件 @
cefab6bb
...
@@ -108,6 +108,7 @@ Our program starts with importing necessary packages:
...
@@ -108,6 +108,7 @@ Our program starts with importing necessary packages:
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
numpy
import
numpy
from
__future__
import
print_function
```
```
We encapsulated the
[
UCI Housing Data Set
](
https://archive.ics.uci.edu/ml/datasets/Housing
)
in our Python module
`uci_housing`
. This module can
We encapsulated the
[
UCI Housing Data Set
](
https://archive.ics.uci.edu/ml/datasets/Housing
)
in our Python module
`uci_housing`
. This module can
...
@@ -189,7 +190,7 @@ feed_order=['x', 'y']
...
@@ -189,7 +190,7 @@ feed_order=['x', 'y']
Moreover, an event handler is provided to print the training progress:
Moreover, an event handler is provided to print the training progress:
```
python
```
python
# Specify the directory
path
to save the parameters
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
params_dirname
=
"fit_a_line.inference.model"
# Plot data
# Plot data
...
@@ -200,11 +201,11 @@ plot_cost = Ploter(train_title, test_title)
...
@@ -200,11 +201,11 @@ plot_cost = Ploter(train_title, test_title)
step
=
0
step
=
0
# event_handler
to print
training and testing info
# event_handler
prints
training and testing info
def
event_handler_plot
(
event
):
def
event_handler_plot
(
event
):
global
step
global
step
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
%
10
==
0
:
#
every 10 batches, record a test cost
if
event
.
step
%
10
==
0
:
#
record a test cost every 10 batches
test_metrics
=
trainer
.
test
(
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
reader
=
test_reader
,
feed_order
=
feed_order
)
...
@@ -263,10 +264,20 @@ inferencer = fluid.Inferencer(
...
@@ -263,10 +264,20 @@ inferencer = fluid.Inferencer(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
batch_size
=
10
batch_size
=
10
tensor_x
=
numpy
.
random
.
uniform
(
0
,
10
,
[
batch_size
,
13
]).
astype
(
"float32"
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
()
test_feat
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_label
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
results
=
inferencer
.
infer
({
'x'
:
tensor_x
})
results
=
inferencer
.
infer
({
'x'
:
test_feat
})
print
(
"infer results: "
,
results
[
0
])
print
(
"infer results: (House Price)"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
results
[
0
][
k
]))
print
(
"
\n
ground truth:"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
test_label
[
k
]))
```
```
## Summary
## Summary
...
...
01.fit_a_line/image/ranges.png
查看替换文件 @
9961f79a
浏览文件 @
cefab6bb
6.5 KB
|
W:
|
H:
6.6 KB
|
W:
|
H:
2-up
Swipe
Onion skin
01.fit_a_line/index.cn.html
浏览文件 @
cefab6bb
...
@@ -142,6 +142,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$
...
@@ -142,6 +142,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$
import paddle
import paddle
import paddle.fluid as fluid
import paddle.fluid as fluid
import numpy
import numpy
from __future__ import print_function
```
```
我们通过uci_housing模块引入了数据集合[UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing)
我们通过uci_housing模块引入了数据集合[UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing)
...
@@ -221,7 +222,7 @@ feed_order=['x', 'y']
...
@@ -221,7 +222,7 @@ feed_order=['x', 'y']
除此之外,可以定义一个事件相应器来处理类似`打印训练进程`的事件:
除此之外,可以定义一个事件相应器来处理类似`打印训练进程`的事件:
```python
```python
# Specify the directory
path
to save the parameters
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
params_dirname = "fit_a_line.inference.model"
# Plot data
# Plot data
...
@@ -232,11 +233,11 @@ plot_cost = Ploter(train_title, test_title)
...
@@ -232,11 +233,11 @@ plot_cost = Ploter(train_title, test_title)
step = 0
step = 0
# event_handler
to print
training and testing info
# event_handler
prints
training and testing info
def event_handler_plot(event):
def event_handler_plot(event):
global step
global step
if isinstance(event, fluid.EndStepEvent):
if isinstance(event, fluid.EndStepEvent):
if event.step % 10 == 0: #
every 10 batches, record a test cost
if event.step % 10 == 0: #
record the test cost every 10 seconds
test_metrics = trainer.test(
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
reader=test_reader, feed_order=feed_order)
...
@@ -293,10 +294,20 @@ inferencer = fluid.Inferencer(
...
@@ -293,10 +294,20 @@ inferencer = fluid.Inferencer(
infer_func=
inference_program,
param_path=
params_dirname,
place=
place)
infer_func=
inference_program,
param_path=
params_dirname,
place=
place)
batch_size =
10
batch_size =
10
tensor_x =
numpy.random.uniform(0,
10,
[
batch_size
,
13]).
astype
("
float32
")
test_reader =
paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size)
test_data =
test_reader().next()
test_feat =
numpy.array([data[0]
for
data
in
test_data
]).
astype
("
float32
")
test_label =
numpy.array([data[1]
for
data
in
test_data
]).
astype
("
float32
")
results =
inferencer.infer({'x':
tensor_x
})
results =
inferencer.infer({'x':
test_feat
})
print
("
infer
results:
",
results
[0])
print
("
infer
results:
(
House
Price
)")
for
k
in
range
(0,
batch_size-1
)
:
print
("%
d.
%
f
"
%
(
k
,
results
[0][
k
]))
print
("\
nground
truth:
")
for
k
in
range
(0,
batch_size-1
)
:
print
("%
d.
%
f
"
%
(
k
,
test_label
[
k
]))
```
```
##
总结
##
总结
...
...
01.fit_a_line/index.html
浏览文件 @
cefab6bb
...
@@ -150,6 +150,7 @@ Our program starts with importing necessary packages:
...
@@ -150,6 +150,7 @@ Our program starts with importing necessary packages:
import paddle
import paddle
import paddle.fluid as fluid
import paddle.fluid as fluid
import numpy
import numpy
from __future__ import print_function
```
```
We encapsulated the [UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) in our Python module `uci_housing`. This module can
We encapsulated the [UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) in our Python module `uci_housing`. This module can
...
@@ -231,7 +232,7 @@ feed_order=['x', 'y']
...
@@ -231,7 +232,7 @@ feed_order=['x', 'y']
Moreover, an event handler is provided to print the training progress:
Moreover, an event handler is provided to print the training progress:
```python
```python
# Specify the directory
path
to save the parameters
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
params_dirname = "fit_a_line.inference.model"
# Plot data
# Plot data
...
@@ -242,11 +243,11 @@ plot_cost = Ploter(train_title, test_title)
...
@@ -242,11 +243,11 @@ plot_cost = Ploter(train_title, test_title)
step = 0
step = 0
# event_handler
to print
training and testing info
# event_handler
prints
training and testing info
def event_handler_plot(event):
def event_handler_plot(event):
global step
global step
if isinstance(event, fluid.EndStepEvent):
if isinstance(event, fluid.EndStepEvent):
if event.step % 10 == 0: #
every 10 batches, record a test cost
if event.step % 10 == 0: #
record a test cost every 10 batches
test_metrics = trainer.test(
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
reader=test_reader, feed_order=feed_order)
...
@@ -305,10 +306,20 @@ inferencer = fluid.Inferencer(
...
@@ -305,10 +306,20 @@ inferencer = fluid.Inferencer(
infer_func=
inference_program,
param_path=
params_dirname,
place=
place)
infer_func=
inference_program,
param_path=
params_dirname,
place=
place)
batch_size =
10
batch_size =
10
tensor_x =
numpy.random.uniform(0,
10,
[
batch_size
,
13]).
astype
("
float32
")
test_reader =
paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size)
test_data =
test_reader().next()
test_feat =
numpy.array([data[0]
for
data
in
test_data
]).
astype
("
float32
")
test_label =
numpy.array([data[1]
for
data
in
test_data
]).
astype
("
float32
")
results =
inferencer.infer({'x':
tensor_x
})
results =
inferencer.infer({'x':
test_feat
})
print
("
infer
results:
",
results
[0])
print
("
infer
results:
(
House
Price
)")
for
k
in
range
(0,
batch_size-1
)
:
print
("%
d.
%
f
"
%
(
k
,
results
[0][
k
]))
print
("\
nground
truth:
")
for
k
in
range
(0,
batch_size-1
)
:
print
("%
d.
%
f
"
%
(
k
,
test_label
[
k
]))
```
```
##
Summary
##
Summary
...
...
03.image_classification/README.cn.md
浏览文件 @
cefab6bb
...
@@ -160,6 +160,7 @@ import paddle
...
@@ -160,6 +160,7 @@ import paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
numpy
import
numpy
import
sys
import
sys
from
__future__
import
print_function
```
```
本教程中我们提供了VGG和ResNet两个模型的配置。
本教程中我们提供了VGG和ResNet两个模型的配置。
...
@@ -426,7 +427,7 @@ def event_handler(event):
...
@@ -426,7 +427,7 @@ def event_handler(event):
通过
`trainer.train`
函数训练:
通过
`trainer.train`
函数训练:
**注意:**
CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高
培训
速度。
**注意:**
CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高
训练
速度。
```
python
```
python
trainer
.
train
(
trainer
.
train
(
...
@@ -499,10 +500,10 @@ img = load_image(cur_dir + '/image/dog.png')
...
@@ -499,10 +500,10 @@ img = load_image(cur_dir + '/image/dog.png')
```
python
```
python
inferencer
=
fluid
.
Inferencer
(
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
label_list
=
[
"airplane"
,
"automobile"
,
"bird"
,
"cat"
,
"deer"
,
"dog"
,
"frog"
,
"horse"
,
"ship"
,
"truck"
]
# inference
# inference
results
=
inferencer
.
infer
({
'pixel'
:
img
})
results
=
inferencer
.
infer
({
'pixel'
:
img
})
print
(
"infer results:
"
,
results
)
print
(
"infer results:
%s"
%
label_list
[
np
.
argmax
(
results
[
0
])]
)
```
```
## 总结
## 总结
...
...
03.image_classification/README.md
浏览文件 @
cefab6bb
...
@@ -171,6 +171,7 @@ import paddle
...
@@ -171,6 +171,7 @@ import paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
numpy
import
numpy
import
sys
import
sys
from
__future__
import
print_function
```
```
Now we are going to walk you through the implementations of the VGG and ResNet.
Now we are going to walk you through the implementations of the VGG and ResNet.
...
@@ -514,9 +515,10 @@ Now we are ready to do inference.
...
@@ -514,9 +515,10 @@ Now we are ready to do inference.
inferencer
=
fluid
.
Inferencer
(
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
label_list
=
[
"airplane"
,
"automobile"
,
"bird"
,
"cat"
,
"deer"
,
"dog"
,
"frog"
,
"horse"
,
"ship"
,
"truck"
]
# inference
# inference
results
=
inferencer
.
infer
({
'pixel'
:
img
})
results
=
inferencer
.
infer
({
'pixel'
:
img
})
print
(
"infer results:
"
,
results
)
print
(
"infer results:
%s"
%
label_list
[
np
.
argmax
(
results
[
0
])]
)
```
```
...
...
03.image_classification/index.cn.html
浏览文件 @
cefab6bb
...
@@ -202,6 +202,7 @@ import paddle
...
@@ -202,6 +202,7 @@ import paddle
import paddle.fluid as fluid
import paddle.fluid as fluid
import numpy
import numpy
import sys
import sys
from __future__ import print_function
```
```
本教程中我们提供了VGG和ResNet两个模型的配置。
本教程中我们提供了VGG和ResNet两个模型的配置。
...
@@ -468,7 +469,7 @@ def event_handler(event):
...
@@ -468,7 +469,7 @@ def event_handler(event):
通过`trainer.train`函数训练:
通过`trainer.train`函数训练:
**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高
培训
速度。
**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高
训练
速度。
```python
```python
trainer.train(
trainer.train(
...
@@ -541,10 +542,10 @@ img = load_image(cur_dir + '/image/dog.png')
...
@@ -541,10 +542,10 @@ img = load_image(cur_dir + '/image/dog.png')
```python
```python
inferencer = fluid.Inferencer(
inferencer = fluid.Inferencer(
infer_func=inference_program, param_path=params_dirname, place=place)
infer_func=inference_program, param_path=params_dirname, place=place)
label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
# inference
# inference
results = inferencer.infer({'pixel': img})
results = inferencer.infer({'pixel': img})
print("infer results:
", results
)
print("infer results:
%s" % label_list[np.argmax(results[0])]
)
```
```
## 总结
## 总结
...
...
03.image_classification/index.html
浏览文件 @
cefab6bb
...
@@ -213,6 +213,7 @@ import paddle
...
@@ -213,6 +213,7 @@ import paddle
import paddle.fluid as fluid
import paddle.fluid as fluid
import numpy
import numpy
import sys
import sys
from __future__ import print_function
```
```
Now we are going to walk you through the implementations of the VGG and ResNet.
Now we are going to walk you through the implementations of the VGG and ResNet.
...
@@ -556,9 +557,10 @@ Now we are ready to do inference.
...
@@ -556,9 +557,10 @@ Now we are ready to do inference.
inferencer = fluid.Inferencer(
inferencer = fluid.Inferencer(
infer_func=inference_program, param_path=params_dirname, place=place)
infer_func=inference_program, param_path=params_dirname, place=place)
label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
# inference
# inference
results = inferencer.infer({'pixel': img})
results = inferencer.infer({'pixel': img})
print("infer results:
", results
)
print("infer results:
%s" % label_list[np.argmax(results[0])]
)
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录