Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0388d1cb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
0388d1cb
编写于
7月 24, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some update
上级
fab6287e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
18 addition
and
25 deletion
+18
-25
python/paddle/fluid/tests/demo/file_reader/.gitignore
python/paddle/fluid/tests/demo/file_reader/.gitignore
+0
-0
python/paddle/fluid/tests/demo/file_reader/convert_data_to_recordio.py
.../fluid/tests/demo/file_reader/convert_data_to_recordio.py
+1
-1
python/paddle/fluid/tests/demo/file_reader/train.py
python/paddle/fluid/tests/demo/file_reader/train.py
+17
-24
未找到文件。
python/paddle/fluid/tests/demo/
text_classification
/.gitignore
→
python/paddle/fluid/tests/demo/
file_reader
/.gitignore
浏览文件 @
0388d1cb
文件已移动
python/paddle/fluid/tests/demo/
text_classification
/convert_data_to_recordio.py
→
python/paddle/fluid/tests/demo/
file_reader
/convert_data_to_recordio.py
浏览文件 @
0388d1cb
...
@@ -50,7 +50,7 @@ feeder = fluid.DataFeeder(feed_list=[data, label], place=fluid.CPUPlace())
...
@@ -50,7 +50,7 @@ feeder = fluid.DataFeeder(feed_list=[data, label], place=fluid.CPUPlace())
BATCH_SIZE
=
128
BATCH_SIZE
=
128
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
imdb
.
train
(
word_dict
),
buf_size
=
10
000
),
paddle
.
dataset
.
imdb
.
train
(
word_dict
),
buf_size
=
25
000
),
batch_size
=
BATCH_SIZE
)
batch_size
=
BATCH_SIZE
)
test_reader
=
paddle
.
batch
(
test_reader
=
paddle
.
batch
(
...
...
python/paddle/fluid/tests/demo/
text_classification
/train.py
→
python/paddle/fluid/tests/demo/
file_reader
/train.py
浏览文件 @
0388d1cb
...
@@ -27,9 +27,6 @@ emb_dim = 128
...
@@ -27,9 +27,6 @@ emb_dim = 128
# hidden dim
# hidden dim
hid_dim
=
128
hid_dim
=
128
# hidden dim2
hid_dim2
=
96
# class num
# class num
class_dim
=
2
class_dim
=
2
...
@@ -42,13 +39,9 @@ def build_program(is_train):
...
@@ -42,13 +39,9 @@ def build_program(is_train):
filenames
=
TRAIN_FILES
if
is_train
else
TEST_FILES
,
filenames
=
TRAIN_FILES
if
is_train
else
TEST_FILES
,
shapes
=
[[
-
1
,
1
],
[
-
1
,
1
]],
shapes
=
[[
-
1
,
1
],
[
-
1
,
1
]],
lod_levels
=
[
1
,
0
],
lod_levels
=
[
1
,
0
],
dtypes
=
[
'int64'
,
'int64'
],
dtypes
=
[
'int64'
,
'int64'
])
thread_num
=
1
)
if
is_train
:
file_obj
=
fluid
.
layers
.
io
.
double_buffer
(
file_obj_handle
)
file_obj
=
fluid
.
layers
.
io
.
shuffle
(
file_obj_handle
,
buffer_size
=
1000
)
else
:
file_obj
=
file_obj_handle
file_obj
=
fluid
.
layers
.
io
.
double_buffer
(
file_obj
)
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
...
@@ -56,22 +49,24 @@ def build_program(is_train):
...
@@ -56,22 +49,24 @@ def build_program(is_train):
emb
=
fluid
.
layers
.
embedding
(
input
=
data
,
size
=
[
DICT_DIM
,
emb_dim
])
emb
=
fluid
.
layers
.
embedding
(
input
=
data
,
size
=
[
DICT_DIM
,
emb_dim
])
# sequence conv with window size = 3
win_size
=
3
conv_3
=
fluid
.
nets
.
sequence_conv_pool
(
conv_3
=
fluid
.
nets
.
sequence_conv_pool
(
input
=
emb
,
input
=
emb
,
num_filters
=
hid_dim
,
num_filters
=
hid_dim
,
filter_size
=
win_size
,
filter_size
=
3
,
act
=
"tanh"
,
act
=
"tanh"
,
pool_type
=
"
max
"
)
pool_type
=
"
sqrt
"
)
# fc layer after conv
conv_4
=
fluid
.
nets
.
sequence_conv_pool
(
fc_1
=
fluid
.
layers
.
fc
(
input
=
[
conv_3
],
size
=
hid_dim2
)
input
=
emb
,
num_filters
=
hid_dim
,
filter_size
=
4
,
act
=
"tanh"
,
pool_type
=
"sqrt"
)
# probability of each class
prediction
=
fluid
.
layers
.
fc
(
input
=
[
conv_3
,
conv_4
],
prediction
=
fluid
.
layers
.
fc
(
input
=
[
fc_1
],
size
=
class_dim
,
size
=
class_dim
,
act
=
"softmax"
)
act
=
"softmax"
)
# cross entropy loss
# cross entropy loss
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
...
@@ -117,11 +112,9 @@ def main():
...
@@ -117,11 +112,9 @@ def main():
try
:
try
:
batch_id
=
0
batch_id
=
0
while
True
:
while
True
:
result
=
map
(
numpy
.
array
,
loss
,
acc
=
map
(
numpy
.
array
,
train_exe
.
run
(
fetch_list
=
fetch_var_list
train_exe
.
run
(
fetch_list
=
fetch_var_list
))
if
batch_id
%
10
==
0
else
[]))
print
'Train epoch'
,
epoch_id
,
'batch'
,
batch_id
,
'loss:'
,
loss
,
'acc:'
,
acc
if
len
(
result
)
!=
0
:
print
'Train loss: '
,
result
batch_id
+=
1
batch_id
+=
1
except
fluid
.
core
.
EOFException
:
except
fluid
.
core
.
EOFException
:
print
'End of epoch'
,
epoch_id
print
'End of epoch'
,
epoch_id
...
@@ -138,7 +131,7 @@ def main():
...
@@ -138,7 +131,7 @@ def main():
acc
.
append
(
acc_np
[
0
])
acc
.
append
(
acc_np
[
0
])
except
:
except
:
test_args
[
'file'
].
reset
()
test_args
[
'file'
].
reset
()
print
'T
EST: '
,
numpy
.
mean
(
loss
)
,
numpy
.
mean
(
acc
)
print
'T
est loss:'
,
numpy
.
mean
(
loss
),
'acc:'
,
numpy
.
mean
(
acc
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录