Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
ebfbc23e
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看板
提交
ebfbc23e
编写于
7月 19, 2019
作者:
X
xiaoting
提交者:
lvmengsi
7月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update recognize readme (#780)
* modified reademe
上级
43d144e9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
18 deletion
+28
-18
02.recognize_digits/README.cn.md
02.recognize_digits/README.cn.md
+7
-5
02.recognize_digits/README.md
02.recognize_digits/README.md
+7
-4
02.recognize_digits/index.cn.html
02.recognize_digits/index.cn.html
+7
-5
02.recognize_digits/index.html
02.recognize_digits/index.html
+7
-4
未找到文件。
02.recognize_digits/README.cn.md
浏览文件 @
ebfbc23e
...
@@ -396,15 +396,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
...
@@ -396,15 +396,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
# 调用train_program 获取预测值,损失值,
# 调用train_program 获取预测值,损失值,
prediction
,
[
avg_loss
,
acc
]
=
train_program
()
prediction
,
[
avg_loss
,
acc
]
=
train_program
()
# 输入的原始图像数据,大小为28*28*1
# 输入的原始图像数据,名称为img,大小为28*28*1
img
=
fluid
.
layers
.
data
(
name
=
'img'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
# 标签层,名称为label,对应输入图片的类别标签
# 标签层,名称为label,对应输入图片的类别标签
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
img
,
label
],
place
=
place
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
‘
img
’
,
‘
label
’
],
place
=
place
)
# 选择Adam优化器
# 选择Adam优化器
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
optimizer
=
optimizer_program
(
)
optimizer
.
minimize
(
avg_loss
)
optimizer
.
minimize
(
avg_loss
)
```
```
...
@@ -528,9 +526,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
...
@@ -528,9 +526,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
```
python
```
python
def
load_image
(
file
):
def
load_image
(
file
):
# 读取图片文件,并将它转成灰度图
im
=
Image
.
open
(
file
).
convert
(
'L'
)
im
=
Image
.
open
(
file
).
convert
(
'L'
)
# 将输入图片调整为 28*28 的高质量图
im
=
im
.
resize
((
28
,
28
),
Image
.
ANTIALIAS
)
im
=
im
.
resize
((
28
,
28
),
Image
.
ANTIALIAS
)
# 将图片转换为numpy
im
=
numpy
.
array
(
im
).
reshape
(
1
,
1
,
28
,
28
).
astype
(
numpy
.
float32
)
im
=
numpy
.
array
(
im
).
reshape
(
1
,
1
,
28
,
28
).
astype
(
numpy
.
float32
)
# 对数据作归一化处理
im
=
im
/
255.0
*
2.0
-
1.0
im
=
im
/
255.0
*
2.0
-
1.0
return
im
return
im
...
...
02.recognize_digits/README.md
浏览文件 @
ebfbc23e
...
@@ -377,14 +377,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
...
@@ -377,14 +377,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
prediction
,
[
avg_loss
,
acc
]
=
train_program
()
prediction
,
[
avg_loss
,
acc
]
=
train_program
()
# input original image data in size of 28*28*1
# input original image data in size of 28*28*1
img
=
fluid
.
layers
.
data
(
name
=
'img'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
# label layer, called label, correspondent with label category of input picture.
# label layer, called label, correspondent with label category of input picture.
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
# It is informed that data in network consists of two parts. One is img value, the other is label value.
# It is informed that data in network consists of two parts. One is img value, the other is label value.
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
img
,
label
],
place
=
place
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
'img'
,
'label'
],
place
=
place
)
# choose Adam optimizer
# choose Adam optimizer
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
optimizer
=
optimizer_program
(
)
optimizer
.
minimize
(
avg_loss
)
optimizer
.
minimize
(
avg_loss
)
```
```
...
@@ -513,9 +512,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
...
@@ -513,9 +512,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
```
python
```
python
def
load_image
(
file
):
def
load_image
(
file
):
# open the image file and covert to grayscale
im
=
Image
.
open
(
file
).
convert
(
'L'
)
im
=
Image
.
open
(
file
).
convert
(
'L'
)
# adjust the input image to a 28*28 high quality image
im
=
im
.
resize
((
28
,
28
),
Image
.
ANTIALIAS
)
im
=
im
.
resize
((
28
,
28
),
Image
.
ANTIALIAS
)
# convert img to numpy
im
=
numpy
.
array
(
im
).
reshape
(
1
,
1
,
28
,
28
).
astype
(
numpy
.
float32
)
im
=
numpy
.
array
(
im
).
reshape
(
1
,
1
,
28
,
28
).
astype
(
numpy
.
float32
)
# normalize
im
=
im
/
255.0
*
2.0
-
1.0
im
=
im
/
255.0
*
2.0
-
1.0
return
im
return
im
...
...
02.recognize_digits/index.cn.html
浏览文件 @
ebfbc23e
...
@@ -438,15 +438,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
...
@@ -438,15 +438,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
# 调用train_program 获取预测值,损失值,
# 调用train_program 获取预测值,损失值,
prediction, [avg_loss, acc] = train_program()
prediction, [avg_loss, acc] = train_program()
# 输入的原始图像数据,大小为28*28*1
# 输入的原始图像数据,名称为img,大小为28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# 标签层,名称为label,对应输入图片的类别标签
# 标签层,名称为label,对应输入图片的类别标签
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
feeder = fluid.DataFeeder(feed_list=[
img, label
], place=place)
feeder = fluid.DataFeeder(feed_list=[
‘img’, ‘label’
], place=place)
# 选择Adam优化器
# 选择Adam优化器
optimizer =
fluid.optimizer.Adam(learning_rate=0.001
)
optimizer =
optimizer_program(
)
optimizer.minimize(avg_loss)
optimizer.minimize(avg_loss)
```
```
...
@@ -570,9 +568,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
...
@@ -570,9 +568,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
```python
```python
def load_image(file):
def load_image(file):
# 读取图片文件,并将它转成灰度图
im = Image.open(file).convert('L')
im = Image.open(file).convert('L')
# 将输入图片调整为 28*28 的高质量图
im = im.resize((28, 28), Image.ANTIALIAS)
im = im.resize((28, 28), Image.ANTIALIAS)
# 将图片转换为numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# 对数据作归一化处理
im = im / 255.0 * 2.0 - 1.0
im = im / 255.0 * 2.0 - 1.0
return im
return im
...
...
02.recognize_digits/index.html
浏览文件 @
ebfbc23e
...
@@ -419,14 +419,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
...
@@ -419,14 +419,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
prediction, [avg_loss, acc] = train_program()
prediction, [avg_loss, acc] = train_program()
# input original image data in size of 28*28*1
# input original image data in size of 28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# label layer, called label, correspondent with label category of input picture.
# label layer, called label, correspondent with label category of input picture.
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# It is informed that data in network consists of two parts. One is img value, the other is label value.
# It is informed that data in network consists of two parts. One is img value, the other is label value.
feeder = fluid.DataFeeder(feed_list=[
img, label
], place=place)
feeder = fluid.DataFeeder(feed_list=[
'img', 'label'
], place=place)
# choose Adam optimizer
# choose Adam optimizer
optimizer =
fluid.optimizer.Adam(learning_rate=0.001
)
optimizer =
optimizer_program(
)
optimizer.minimize(avg_loss)
optimizer.minimize(avg_loss)
```
```
...
@@ -555,9 +554,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
...
@@ -555,9 +554,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
```python
```python
def load_image(file):
def load_image(file):
# open the image file and covert to grayscale
im = Image.open(file).convert('L')
im = Image.open(file).convert('L')
# adjust the input image to a 28*28 high quality image
im = im.resize((28, 28), Image.ANTIALIAS)
im = im.resize((28, 28), Image.ANTIALIAS)
# convert img to numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# normalize
im = im / 255.0 * 2.0 - 1.0
im = im / 255.0 * 2.0 - 1.0
return im
return im
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录