Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f3c7fbee
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
f3c7fbee
编写于
2月 23, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make minst to run
上级
c330af31
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
18 deletion
+25
-18
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+5
-4
python/paddle/v2/__init__.py
python/paddle/v2/__init__.py
+1
-0
python/paddle/v2/tests/test_data_feeder.py
python/paddle/v2/tests/test_data_feeder.py
+16
-6
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+3
-8
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
f3c7fbee
...
@@ -50,11 +50,12 @@ def main():
...
@@ -50,11 +50,12 @@ def main():
parameters
=
parameters
,
parameters
=
parameters
,
event_handler
=
event_handler
,
event_handler
=
event_handler
,
batch_size
=
32
,
# batch size should be refactor in Data reader
batch_size
=
32
,
# batch size should be refactor in Data reader
data_types
=
{
# data_types will be removed, It should be in
data_types
=
[
# data_types will be removed, It should be in
# network topology
# network topology
'pixel'
:
images
.
type
,
(
'pixel'
,
images
.
type
),
'label'
:
label
.
type
(
'label'
,
label
.
type
)],
})
reader_dict
=
{
'pixel'
:
0
,
'label'
:
1
}
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
python/paddle/v2/__init__.py
浏览文件 @
f3c7fbee
...
@@ -18,6 +18,7 @@ import parameters
...
@@ -18,6 +18,7 @@ import parameters
import
trainer
import
trainer
import
event
import
event
import
data_type
import
data_type
import
data_feeder
import
py_paddle.swig_paddle
as
api
import
py_paddle.swig_paddle
as
api
__all__
=
[
__all__
=
[
...
...
python/paddle/v2/tests/test_data_feeder.py
浏览文件 @
f3c7fbee
...
@@ -36,7 +36,7 @@ class DataFeederTest(unittest.TestCase):
...
@@ -36,7 +36,7 @@ class DataFeederTest(unittest.TestCase):
def
compare
(
input
):
def
compare
(
input
):
feeder
=
DataFeeder
([(
'image'
,
data_type
.
dense_vector
(
784
))],
feeder
=
DataFeeder
([(
'image'
,
data_type
.
dense_vector
(
784
))],
{
'image'
:
0
})
{
'image'
:
0
})
arg
=
feeder
(
[
input
]
)
arg
=
feeder
(
input
)
output
=
arg
.
getSlotValue
(
0
).
copyToNumpyMat
()
output
=
arg
.
getSlotValue
(
0
).
copyToNumpyMat
()
input
=
np
.
array
(
input
,
dtype
=
'float32'
)
input
=
np
.
array
(
input
,
dtype
=
'float32'
)
self
.
assertAlmostEqual
(
input
.
all
(),
output
.
all
())
self
.
assertAlmostEqual
(
input
.
all
(),
output
.
all
())
...
@@ -46,13 +46,17 @@ class DataFeederTest(unittest.TestCase):
...
@@ -46,13 +46,17 @@ class DataFeederTest(unittest.TestCase):
dim
=
784
dim
=
784
data
=
[]
data
=
[]
for
i
in
xrange
(
batch_size
):
for
i
in
xrange
(
batch_size
):
data
.
append
(
self
.
dense_reader
(
784
))
each_sample
=
[]
each_sample
.
append
(
self
.
dense_reader
(
dim
))
data
.
append
(
each_sample
)
compare
(
data
)
compare
(
data
)
# test list
# test list
data
=
[]
data
=
[]
for
i
in
xrange
(
batch_size
):
for
i
in
xrange
(
batch_size
):
data
.
append
(
self
.
dense_reader
(
784
).
tolist
())
each_sample
=
[]
each_sample
.
append
(
self
.
dense_reader
(
dim
).
tolist
())
data
.
append
(
each_sample
)
compare
(
data
)
compare
(
data
)
def
test_sparse_binary
(
self
):
def
test_sparse_binary
(
self
):
...
@@ -60,7 +64,9 @@ class DataFeederTest(unittest.TestCase):
...
@@ -60,7 +64,9 @@ class DataFeederTest(unittest.TestCase):
batch_size
=
32
batch_size
=
32
data
=
[]
data
=
[]
for
i
in
xrange
(
batch_size
):
for
i
in
xrange
(
batch_size
):
data
.
append
([
self
.
sparse_binary_reader
(
dim
,
50
)])
each_sample
=
[]
each_sample
.
append
(
self
.
sparse_binary_reader
(
dim
,
50
))
data
.
append
(
each_sample
)
feeder
=
DataFeeder
([(
'input'
,
data_type
.
sparse_binary_vector
(
dim
))],
feeder
=
DataFeeder
([(
'input'
,
data_type
.
sparse_binary_vector
(
dim
))],
{
'input'
:
0
})
{
'input'
:
0
})
arg
=
feeder
(
data
)
arg
=
feeder
(
data
)
...
@@ -76,11 +82,13 @@ class DataFeederTest(unittest.TestCase):
...
@@ -76,11 +82,13 @@ class DataFeederTest(unittest.TestCase):
w
=
[]
w
=
[]
data
=
[]
data
=
[]
for
dat
in
xrange
(
batch_size
):
for
dat
in
xrange
(
batch_size
):
each_sample
=
[]
a
=
self
.
sparse_binary_reader
(
dim
,
40
,
non_empty
=
True
)
a
=
self
.
sparse_binary_reader
(
dim
,
40
,
non_empty
=
True
)
b
=
self
.
dense_reader
(
len
(
a
)).
tolist
()
b
=
self
.
dense_reader
(
len
(
a
)).
tolist
()
v
.
append
(
a
)
v
.
append
(
a
)
w
.
append
(
b
[
0
])
w
.
append
(
b
[
0
])
data
.
append
([
zip
(
a
,
b
)])
each_sample
.
append
(
zip
(
a
,
b
))
data
.
append
(
each_sample
)
feeder
=
DataFeeder
([(
'input'
,
data_type
.
sparse_vector
(
dim
))],
feeder
=
DataFeeder
([(
'input'
,
data_type
.
sparse_vector
(
dim
))],
{
'input'
:
0
})
{
'input'
:
0
})
...
@@ -95,7 +103,9 @@ class DataFeederTest(unittest.TestCase):
...
@@ -95,7 +103,9 @@ class DataFeederTest(unittest.TestCase):
batch_size
=
32
batch_size
=
32
index
=
[]
index
=
[]
for
i
in
xrange
(
batch_size
):
for
i
in
xrange
(
batch_size
):
index
.
append
([
np
.
random
.
randint
(
dim
)])
each_sample
=
[]
each_sample
.
append
(
np
.
random
.
randint
(
dim
))
index
.
append
(
each_sample
)
feeder
=
DataFeeder
([(
'input'
,
data_type
.
integer_value
(
dim
))],
feeder
=
DataFeeder
([(
'input'
,
data_type
.
integer_value
(
dim
))],
{
'input'
:
0
})
{
'input'
:
0
})
arg
=
feeder
(
index
)
arg
=
feeder
(
index
)
...
...
python/paddle/v2/trainer.py
浏览文件 @
f3c7fbee
...
@@ -69,7 +69,8 @@ class SGD(ITrainer):
...
@@ -69,7 +69,8 @@ class SGD(ITrainer):
test_data_reader
=
None
,
test_data_reader
=
None
,
event_handler
=
None
,
event_handler
=
None
,
batch_size
=
32
,
batch_size
=
32
,
data_types
=
None
):
data_types
=
None
,
reader_dict
=
None
):
"""
"""
Training method. Will train num_passes of input data.
Training method. Will train num_passes of input data.
...
@@ -103,13 +104,7 @@ class SGD(ITrainer):
...
@@ -103,13 +104,7 @@ class SGD(ITrainer):
gm
.
start
()
gm
.
start
()
out_args
=
api
.
Arguments
.
createArguments
(
0
)
out_args
=
api
.
Arguments
.
createArguments
(
0
)
data_types_lists
=
[]
feeder
=
DataFeeder
(
data_types
,
reader_dict
)
for
each
in
topology
.
input_layer_names
:
if
each
not
in
data_types
:
raise
ValueError
()
data_types_lists
.
append
(
data_types
[
each
])
feeder
=
DataFeeder
(
input_types
=
data_types_lists
)
for
pass_id
in
xrange
(
num_passes
):
for
pass_id
in
xrange
(
num_passes
):
updater
.
startPass
()
updater
.
startPass
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录