Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
38a792f2
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
38a792f2
编写于
2月 24, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean mnist code
上级
d1ab3c80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
33 deletion
+33
-33
python/paddle/v2/data_set/config.py
python/paddle/v2/data_set/config.py
+8
-0
python/paddle/v2/data_set/mnist.py
python/paddle/v2/data_set/mnist.py
+25
-33
未找到文件。
python/paddle/v2/data_set/config.py
0 → 100644
浏览文件 @
38a792f2
import
os
__all__
=
[
'DATA_HOME'
]
DATA_HOME
=
os
.
path
.
expanduser
(
'~/.cache/paddle_data_set'
)
if
not
os
.
path
.
exists
(
DATA_HOME
):
os
.
makedirs
(
DATA_HOME
)
python/paddle/v2/data_set/mnist.py
浏览文件 @
38a792f2
import
sklearn.datasets.mldata
import
sklearn.model_selection
import
numpy
from
config
import
DATA_HOME
__all__
=
[
'MNIST
Reader'
,
'train_reader_creator'
,
'test_reader
_creator'
]
__all__
=
[
'MNIST
'
,
'train_creator'
,
'test
_creator'
]
DATA_HOME
=
None
def
__mnist_reader_creator__
(
data
,
target
):
def
reader
():
n_samples
=
data
.
shape
[
0
]
for
i
in
xrange
(
n_samples
):
yield
(
data
[
i
]
/
255.0
).
astype
(
numpy
.
float32
),
int
(
target
[
i
])
def
__mnist_reader__
(
data
,
target
):
n_samples
=
data
.
shape
[
0
]
for
i
in
xrange
(
n_samples
):
yield
data
[
i
].
astype
(
numpy
.
float32
),
int
(
target
[
i
])
return
reader
class
MNIST
Reader
(
object
):
class
MNIST
(
object
):
"""
mnist dataset reader. The `train_reader` and `test_reader` method returns
a iterator of each sample. Each sample is combined by 784-dim float and a
one-dim label
"""
def
__init__
(
self
,
random_state
):
def
__init__
(
self
,
random_state
=
0
,
test_size
=
10000
,
**
options
):
data
=
sklearn
.
datasets
.
mldata
.
fetch_mldata
(
"MNIST original"
,
data_home
=
DATA_HOME
)
n_train
=
60000
self
.
X_train
,
self
.
X_test
,
self
.
y_train
,
self
.
y_test
=
sklearn
.
model_selection
.
train_test_split
(
data
.
data
/
255.0
,
data
.
target
.
astype
(
"int"
),
train_size
=
n_train
,
random_state
=
random_state
)
data
.
data
,
data
.
target
,
test_size
=
test_size
,
random_state
=
random_state
,
**
options
)
def
train_
reade
r
(
self
):
return
__mnist_reader__
(
self
.
X_train
,
self
.
y_train
)
def
train_
creato
r
(
self
):
return
__mnist_reader_
creator_
_
(
self
.
X_train
,
self
.
y_train
)
def
test_
reade
r
(
self
):
return
__mnist_reader__
(
self
.
X_test
,
self
.
y_test
)
def
test_
creato
r
(
self
):
return
__mnist_reader_
creator_
_
(
self
.
X_test
,
self
.
y_test
)
__default_instance__
=
MNISTReader
(
0
)
def
train_reader_creator
():
"""
Default train set reader creator.
"""
return
__default_instance__
.
train_reader
def
test_reader_creator
():
"""
Default test set reader creator.
"""
return
__default_instance__
.
test_reader
__default_instance__
=
MNIST
()
train_creator
=
__default_instance__
.
train_creator
test_creator
=
__default_instance__
.
test_creator
def
unittest
():
assert
len
(
list
(
train_reader_creator
()()))
==
60000
size
=
12045
mnist
=
MNIST
(
test_size
=
size
)
assert
len
(
list
(
mnist
.
test_creator
()()))
==
size
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录