Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
81361f1d
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看板
提交
81361f1d
编写于
2月 28, 2017
作者:
Y
Yuanpeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Translate Provide Data.
上级
0070052d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
1 deletion
+34
-1
recognize_digits/README.en.md
recognize_digits/README.en.md
+34
-1
未找到文件。
recognize_digits/README.en.md
浏览文件 @
81361f1d
...
...
@@ -264,7 +264,7 @@ Execute the following command to download [MNIST](http://yann.lecun.com/exdb/mni
|train-images-idx3-ubyte| Training images, 60,000 |
|train-labels-idx1-ubyte| Training labels, 60,000 |
|t10k-images-idx3-ubyte | Evaluation images, 10,000 |
|t10k-labels-idx1-ubyte | Evaluation labels
,
10,000 |
|t10k-labels-idx1-ubyte | Evaluation labels
,
10,000 |
Users can randomly generate 10 images with the following script (Refer to Fig. 1.)
...
...
@@ -305,6 +305,39 @@ def process(settings, filename): # settings is not used currently.
yield
{
"pixel"
:
images
[
i
,
:],
'label'
:
labels
[
i
]}
```
### Provide data for PaddlePaddle
We use python interface to convey data to system.
`mnist_provider.py`
shows a complete example for MNIST data.
```
python
# Define a py data provider
@
provider
(
input_types
=
{
'pixel'
:
dense_vector
(
28
*
28
),
'label'
:
integer_value
(
10
)})
def
process
(
settings
,
filename
):
# settings is not used currently.
# Open image file
with
open
(
filename
+
"-images-idx3-ubyte"
,
"rb"
)
as
f
:
# Read first 4 parameters. magic is data format. n is number of data, rows and cols are number of rows and columns, respectively
magic
,
n
,
rows
,
cols
=
struct
.
upack
(
">IIII"
,
f
.
read
(
16
))
# With empty string as a unit, read data one by one
images
=
np
.
fromfile
(
f
,
'ubyte'
,
count
=
n
*
rows
*
cols
).
reshape
(
n
,
rows
,
cols
).
astype
(
'float32'
)
# Normalize data of [0, 255] to [-1,1]
images
=
images
/
255.0
*
2.0
-
1.0
# Open label file
with
open
(
filename
+
"-labels-idx1-ubyte"
,
"rb"
)
as
l
:
# Read first two parameters
magic
,
n
=
struct
.
upack
(
">II"
,
l
.
read
(
8
))
# With empty string as a unit, read data one by one
labels
=
np
.
fromfile
(
l
,
'ubyte'
,
count
=
n
).
astype
(
"int"
)
for
i
in
xrange
(
n
):
yield
{
"pixel"
:
images
[
i
,
:],
'label'
:
labels
[
i
]}
```
## 模型配置说明
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录