Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
e5e810c3
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看板
未验证
提交
e5e810c3
编写于
6月 08, 2018
作者:
J
Jeff Wang
提交者:
GitHub
6月 08, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #542 from jetfuel/image_classification_new_api_markdown
Image classification new api markdown
上级
928d178c
716383db
变更
7
展开全部
显示空白变更内容
内联
并排
Showing
7 changed file
with
811 addition
and
812 deletion
+811
-812
02.recognize_digits/README.md
02.recognize_digits/README.md
+1
-1
02.recognize_digits/index.html
02.recognize_digits/index.html
+1
-1
03.image_classification/README.cn.md
03.image_classification/README.cn.md
+194
-197
03.image_classification/README.md
03.image_classification/README.md
+206
-203
03.image_classification/index.cn.html
03.image_classification/index.cn.html
+194
-197
03.image_classification/index.html
03.image_classification/index.html
+206
-203
03.image_classification/train.py
03.image_classification/train.py
+9
-10
未找到文件。
02.recognize_digits/README.md
浏览文件 @
e5e810c3
...
...
@@ -421,7 +421,7 @@ def load_image(file):
im = im / 255.0
*
2.0 - 1.0
return im
cur_dir =
cur_dir =
os.getcwd()
cur_dir = os.getcwd()
img = load_image(cur_dir + '/image/infer_3.png')
```
...
...
02.recognize_digits/index.html
浏览文件 @
e5e810c3
...
...
@@ -463,7 +463,7 @@ def load_image(file):
im = im / 255.0 * 2.0 - 1.0
return im
cur_dir =
cur_dir =
os.getcwd()
cur_dir = os.getcwd()
img = load_image(cur_dir + '/image/infer_3.png')
```
...
...
03.image_classification/README.cn.md
浏览文件 @
e5e810c3
此差异已折叠。
点击以展开。
03.image_classification/README.md
浏览文件 @
e5e810c3
此差异已折叠。
点击以展开。
03.image_classification/index.cn.html
浏览文件 @
e5e810c3
此差异已折叠。
点击以展开。
03.image_classification/index.html
浏览文件 @
e5e810c3
此差异已折叠。
点击以展开。
03.image_classification/train.py
浏览文件 @
e5e810c3
...
...
@@ -42,6 +42,10 @@ def train_network():
return
[
avg_cost
,
accuracy
]
def
optimizer_program
():
return
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
def
train
(
use_cuda
,
train_program
,
params_dirname
):
BATCH_SIZE
=
128
EPOCH_NUM
=
2
...
...
@@ -56,7 +60,7 @@ def train(use_cuda, train_program, params_dirname):
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
%
100
==
0
:
print
(
"Pass %d, Batch %d, Cost %f, Acc %f"
%
print
(
"
\n
Pass %d, Batch %d, Cost %f, Acc %f"
%
(
event
.
step
,
event
.
epoch
,
event
.
metrics
[
0
],
event
.
metrics
[
1
]))
else
:
...
...
@@ -67,15 +71,14 @@ def train(use_cuda, train_program, params_dirname):
avg_cost
,
accuracy
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
[
'pixel'
,
'label'
])
print
(
'Loss {0:2.2}, Acc {1:2.2}'
.
format
(
avg_cost
,
accuracy
))
print
(
'
\n
Test with Pass {0}, Loss {1:2.2}, Acc {2:2.2}'
.
format
(
event
.
epoch
,
avg_cost
,
accuracy
))
if
params_dirname
is
not
None
:
trainer
.
save_params
(
params_dirname
)
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
trainer
=
fluid
.
Trainer
(
train_func
=
train_program
,
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
),
place
=
place
)
train_func
=
train_program
,
optimizer_func
=
optimizer_program
,
place
=
place
)
trainer
.
train
(
reader
=
train_reader
,
...
...
@@ -99,14 +102,10 @@ def infer(use_cuda, inference_program, params_dirname=None):
im
=
im
.
resize
((
32
,
32
),
Image
.
ANTIALIAS
)
im
=
np
.
array
(
im
).
astype
(
np
.
float32
)
# The storage order of the loaded image is W(wid
ht
),
# The storage order of the loaded image is W(wid
th
),
# H(height), C(channel). PaddlePaddle requires
# the CHW order, so transpose them.
im
=
im
.
transpose
((
2
,
0
,
1
))
# CHW
# In the training phase, the channel order of CIFAR
# image is B(Blue), G(green), R(Red). But PIL open
# image in RGB mode. It must swap the channel order.
im
=
im
[(
2
,
1
,
0
),
:,
:]
# BGR
im
=
im
/
255.0
# Add one dimension to mimic the list format.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录