Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
6d8aade8
B
book
项目概览
PaddlePaddle
/
book
通知
16
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看板
提交
6d8aade8
编写于
12月 05, 2018
作者:
L
lujun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ses-3,fix review for pr-646,update ploter,test=develop
上级
c8857716
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
20 addition
and
30 deletion
+20
-30
03.image_classification/README.cn.md
03.image_classification/README.cn.md
+10
-15
03.image_classification/index.cn.html
03.image_classification/index.cn.html
+10
-15
未找到文件。
03.image_classification/README.cn.md
浏览文件 @
6d8aade8
...
@@ -412,11 +412,11 @@ def train_test(program, reader):
...
@@ -412,11 +412,11 @@ def train_test(program, reader):
```
python
```
python
params_dirname
=
"image_classification_resnet.inference.model"
params_dirname
=
"image_classification_resnet.inference.model"
from
paddle.
v2
.plot
import
Ploter
from
paddle.
utils
.plot
import
Ploter
train_
title
=
"Train cost"
train_
prompt
=
"Train cost"
test_
title
=
"Test cost"
test_
prompt
=
"Test cost"
plot_cost
=
Ploter
(
test_
title
,
train_title
)
plot_cost
=
Ploter
(
test_
prompt
,
train_prompt
)
# main train loop.
# main train loop.
def
train_loop
():
def
train_loop
():
...
@@ -434,13 +434,13 @@ def train_loop():
...
@@ -434,13 +434,13 @@ def train_loop():
feed
=
feeder
.
feed
(
data_train
),
feed
=
feeder
.
feed
(
data_train
),
fetch_list
=
[
avg_cost
,
acc
])
fetch_list
=
[
avg_cost
,
acc
])
if
step
%
1
==
0
:
if
step
%
1
==
0
:
plot_cost
.
append
(
train_
title
,
step
,
avg_loss_value
[
0
])
plot_cost
.
append
(
train_
prompt
,
step
,
avg_loss_value
[
0
])
plot_cost
.
plot
()
plot_cost
.
plot
()
step
+=
1
step
+=
1
avg_cost_test
,
accuracy_test
=
train_test
(
test_program
,
avg_cost_test
,
accuracy_test
=
train_test
(
test_program
,
reader
=
test_reader
)
reader
=
test_reader
)
plot_cost
.
append
(
test_
title
,
step
,
avg_cost_test
)
plot_cost
.
append
(
test_
prompt
,
step
,
avg_cost_test
)
# save parameters
# save parameters
if
params_dirname
is
not
None
:
if
params_dirname
is
not
None
:
...
@@ -485,23 +485,18 @@ Test with Pass 0, Loss 1.1, Acc 0.6
...
@@ -485,23 +485,18 @@ Test with Pass 0, Loss 1.1, Acc 0.6
### 生成预测输入数据
### 生成预测输入数据
`dog.png`
is an example image of a dog. Turn it into an numpy array to match the data feeder format.
`dog.png`
是一张小狗的图片. 我们将它转换成
`numpy`
数组以满足
`feeder`
的格式.
### 生成预测输入数据
`dog.png`
is an example image of a dog. Turn it into an numpy array to match the data feeder format.
```
python
```
python
# Prepare testing data.
# Prepare testing data.
from
PIL
import
Image
from
PIL
import
Image
import
numpy
as
np
import
os
import
os
def
load_image
(
file
):
def
load_image
(
file
):
im
=
Image
.
open
(
file
)
im
=
Image
.
open
(
file
)
im
=
im
.
resize
((
32
,
32
),
Image
.
ANTIALIAS
)
im
=
im
.
resize
((
32
,
32
),
Image
.
ANTIALIAS
)
im
=
n
p
.
array
(
im
).
astype
(
np
.
float32
)
im
=
n
umpy
.
array
(
im
).
astype
(
numpy
.
float32
)
# The storage order of the loaded image is W(width),
# The storage order of the loaded image is W(width),
# H(height), C(channel). PaddlePaddle requires
# H(height), C(channel). PaddlePaddle requires
# the CHW order, so transpose them.
# the CHW order, so transpose them.
...
...
03.image_classification/index.cn.html
浏览文件 @
6d8aade8
...
@@ -454,11 +454,11 @@ def train_test(program, reader):
...
@@ -454,11 +454,11 @@ def train_test(program, reader):
```python
```python
params_dirname = "image_classification_resnet.inference.model"
params_dirname = "image_classification_resnet.inference.model"
from paddle.
v2
.plot import Ploter
from paddle.
utils
.plot import Ploter
train_
title
= "Train cost"
train_
prompt
= "Train cost"
test_
title
= "Test cost"
test_
prompt
= "Test cost"
plot_cost = Ploter(test_
title,train_title
)
plot_cost = Ploter(test_
prompt,train_prompt
)
# main train loop.
# main train loop.
def train_loop():
def train_loop():
...
@@ -476,13 +476,13 @@ def train_loop():
...
@@ -476,13 +476,13 @@ def train_loop():
feed=feeder.feed(data_train),
feed=feeder.feed(data_train),
fetch_list=[avg_cost, acc])
fetch_list=[avg_cost, acc])
if step % 1 == 0:
if step % 1 == 0:
plot_cost.append(train_
title
, step, avg_loss_value[0])
plot_cost.append(train_
prompt
, step, avg_loss_value[0])
plot_cost.plot()
plot_cost.plot()
step += 1
step += 1
avg_cost_test, accuracy_test = train_test(test_program,
avg_cost_test, accuracy_test = train_test(test_program,
reader=test_reader)
reader=test_reader)
plot_cost.append(test_
title
, step, avg_cost_test)
plot_cost.append(test_
prompt
, step, avg_cost_test)
# save parameters
# save parameters
if params_dirname is not None:
if params_dirname is not None:
...
@@ -527,23 +527,18 @@ Test with Pass 0, Loss 1.1, Acc 0.6
...
@@ -527,23 +527,18 @@ Test with Pass 0, Loss 1.1, Acc 0.6
### 生成预测输入数据
### 生成预测输入数据
`dog.png` is an example image of a dog. Turn it into an numpy array to match the data feeder format.
`dog.png` 是一张小狗的图片. 我们将它转换成 `numpy` 数组以满足`feeder`的格式.
### 生成预测输入数据
`dog.png` is an example image of a dog. Turn it into an numpy array to match the data feeder format.
```python
```python
# Prepare testing data.
# Prepare testing data.
from PIL import Image
from PIL import Image
import numpy as np
import os
import os
def load_image(file):
def load_image(file):
im = Image.open(file)
im = Image.open(file)
im = im.resize((32, 32), Image.ANTIALIAS)
im = im.resize((32, 32), Image.ANTIALIAS)
im = n
p.array(im).astype(np
.float32)
im = n
umpy.array(im).astype(numpy
.float32)
# The storage order of the loaded image is W(width),
# The storage order of the loaded image is W(width),
# H(height), C(channel). PaddlePaddle requires
# H(height), C(channel). PaddlePaddle requires
# the CHW order, so transpose them.
# the CHW order, so transpose them.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录