Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
f9556dca
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f9556dca
编写于
6月 01, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use open_files reader to read multiple files
上级
a6a7b6f1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
33 deletion
+37
-33
doc/fluid/howto/cluster/fluid_recordio.md
doc/fluid/howto/cluster/fluid_recordio.md
+14
-12
paddle/fluid/operators/reader/create_recordio_file_reader_op.cc
.../fluid/operators/reader/create_recordio_file_reader_op.cc
+5
-7
python/paddle/fluid/layers/io.py
python/paddle/fluid/layers/io.py
+9
-11
python/paddle/fluid/recordio_writer.py
python/paddle/fluid/recordio_writer.py
+9
-3
tools/codestyle/docstring_checker.pyc
tools/codestyle/docstring_checker.pyc
+0
-0
未找到文件。
doc/
v2/howto/recordio/README
.md
→
doc/
fluid/howto/cluster/fluid_recordio
.md
浏览文件 @
f9556dca
...
@@ -89,14 +89,14 @@ The above codes would generate multiple RecordIO files on your host like:
...
@@ -89,14 +89,14 @@ The above codes would generate multiple RecordIO files on your host like:
```
bash
```
bash
.
.
\_
mnist
.recordio-00000
\_
mnist
-00000.recordio
|-mnist
.recordio-00001
|-mnist
-00001.recordio
|-mnist
.recordio-00002
|-mnist
-00002.recordio
|-mnist
.recordio-00003
|-mnist
-00003.recordio
|-mnist
.recordio-00004
|-mnist
-00004.recordio
```
```
1.
read these RecordIO files with
`fluid.layers.io.open_recordio_file
`
1.
open multiple RecordIO files by
`fluid.layers.io.open_files
`
For a distributed training job, the distributed operator system will schedule trainer process on multiple nodes,
For a distributed training job, the distributed operator system will schedule trainer process on multiple nodes,
each trainer process reads parts of the whole training data, we usually take the following approach to make the training
each trainer process reads parts of the whole training data, we usually take the following approach to make the training
...
@@ -113,10 +113,12 @@ def gen_train_list(file_pattern, trainers, trainer_id):
...
@@ -113,10 +113,12 @@ def gen_train_list(file_pattern, trainers, trainer_id):
trainers
=
int
(
os
.
getenv
(
"TRAINERS"
))
trainers
=
int
(
os
.
getenv
(
"TRAINERS"
))
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_INIT_TRAINER_ID"
))
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_INIT_TRAINER_ID"
))
data_file
=
fluid
.
layers
.
io
.
open_recordio_file
(
data_file
=
fluid
.
layers
.
io
.
open_files
(
filename
=
gen_train_list
(
"./mnist.recordio*"
,
trainers
,
trainer_id
),
filenames
=
gen_train_list
(
"./mnist-[0-9]*.recordio"
,
2
,
0
),
shapes
=
[(
-
1
,
784
),(
-
1
,
1
)],
thread_num
=
1
,
lod_levels
=
[
0
,
0
],
shapes
=
[(
-
1
,
784
),(
-
1
,
1
)],
dtypes
=
[
"float32"
,
"int32"
])
lod_levels
=
[
0
,
0
],
data_file
=
fluid
.
layers
.
io
.
batch
(
data_file
,
batch_size
=
4
)
dtypes
=
[
"float32"
,
"int32"
])
img
,
label
=
fluid
.
layers
.
io
.
read_file
(
data_files
)
...
```
```
paddle/fluid/operators/reader/create_recordio_file_reader_op.cc
浏览文件 @
f9556dca
...
@@ -65,22 +65,20 @@ class CreateRecordIOReaderOp : public framework::OperatorBase {
...
@@ -65,22 +65,20 @@ class CreateRecordIOReaderOp : public framework::OperatorBase {
static_cast
<
int
>
(
shape_concat
.
size
()),
static_cast
<
int
>
(
shape_concat
.
size
()),
"The accumulate of all ranks should be equal to the "
"The accumulate of all ranks should be equal to the "
"shape concat's length."
);
"shape concat's length."
);
auto
filenames
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"filenames
"
);
std
::
string
filename
=
Attr
<
std
::
string
>
(
"filename
"
);
auto
*
out
=
scope
.
FindVar
(
Output
(
"Out"
))
auto
*
out
=
scope
.
FindVar
(
Output
(
"Out"
))
->
template
GetMutable
<
framework
::
ReaderHolder
>();
->
template
GetMutable
<
framework
::
ReaderHolder
>();
for
(
auto
&
fn
:
filenames
)
{
out
->
Reset
(
out
->
Reset
(
new
RecordIOFileReader
<
true
>
(
new
RecordIOFileReader
<
true
>
(
fn
,
RestoreShapes
(
shape_concat
,
ranks
)));
filename
,
RestoreShapes
(
shape_concat
,
ranks
)));
}
}
}
};
};
class
CreateRecordIOReaderOpMaker
:
public
FileReaderMakerBase
{
class
CreateRecordIOReaderOpMaker
:
public
FileReaderMakerBase
{
protected:
protected:
void
Apply
()
override
{
void
Apply
()
override
{
AddAttr
<
std
::
vector
<
std
::
string
>>
(
"filenames"
,
AddAttr
<
std
::
string
>
(
"filename"
,
"The filename of record io reader"
);
"The filenames of record io reader"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
CreateRecordIOReader Operator
CreateRecordIOReader Operator
...
...
python/paddle/fluid/layers/io.py
浏览文件 @
f9556dca
...
@@ -21,7 +21,7 @@ from ..layer_helper import LayerHelper
...
@@ -21,7 +21,7 @@ from ..layer_helper import LayerHelper
from
..executor
import
global_scope
from
..executor
import
global_scope
__all__
=
[
__all__
=
[
'data'
,
'BlockGuardServ'
,
'ListenAndServ'
,
'Send'
,
'open_recordio_file
s
'
,
'data'
,
'BlockGuardServ'
,
'ListenAndServ'
,
'Send'
,
'open_recordio_file'
,
'open_files'
,
'read_file'
,
'shuffle'
,
'batch'
,
'double_buffer'
,
'open_files'
,
'read_file'
,
'shuffle'
,
'batch'
,
'double_buffer'
,
'random_data_generator'
,
'Preprocessor'
'random_data_generator'
,
'Preprocessor'
]
]
...
@@ -291,12 +291,12 @@ def _copy_reader_create_op_(block, op):
...
@@ -291,12 +291,12 @@ def _copy_reader_create_op_(block, op):
return
new_op
return
new_op
def
open_recordio_file
s
(
filenames
,
def
open_recordio_file
(
filename
,
shapes
,
shapes
,
lod_levels
,
lod_levels
,
dtypes
,
dtypes
,
pass_num
=
1
,
pass_num
=
1
,
for_parallel
=
True
):
for_parallel
=
True
):
"""
"""
Open a RecordIO file
Open a RecordIO file
...
@@ -304,7 +304,7 @@ def open_recordio_files(filenames,
...
@@ -304,7 +304,7 @@ def open_recordio_files(filenames,
Via the Reader Variable, we can get data from the given RecordIO file.
Via the Reader Variable, we can get data from the given RecordIO file.
Args:
Args:
filename(str)
or list(str)
: The RecordIO file's name.
filename(str): The RecordIO file's name.
shapes(list): List of tuples which declaring data shapes.
shapes(list): List of tuples which declaring data shapes.
lod_levels(list): List of ints which declaring data lod_level.
lod_levels(list): List of ints which declaring data lod_level.
dtypes(list): List of strs which declaring data type.
dtypes(list): List of strs which declaring data type.
...
@@ -336,8 +336,6 @@ def open_recordio_files(filenames,
...
@@ -336,8 +336,6 @@ def open_recordio_files(filenames,
ranks
.
append
(
len
(
shape
))
ranks
.
append
(
len
(
shape
))
var_name
=
unique_name
(
'open_recordio_file'
)
var_name
=
unique_name
(
'open_recordio_file'
)
if
isinstance
(
filenames
,
str
):
filenames
=
[
filenames
]
startup_blk
=
default_startup_program
().
current_block
()
startup_blk
=
default_startup_program
().
current_block
()
startup_var
=
startup_blk
.
create_var
(
name
=
var_name
)
startup_var
=
startup_blk
.
create_var
(
name
=
var_name
)
...
@@ -347,7 +345,7 @@ def open_recordio_files(filenames,
...
@@ -347,7 +345,7 @@ def open_recordio_files(filenames,
attrs
=
{
attrs
=
{
'shape_concat'
:
shape_concat
,
'shape_concat'
:
shape_concat
,
'lod_levels'
:
lod_levels
,
'lod_levels'
:
lod_levels
,
'filename
s'
:
filenames
,
'filename
'
:
filename
,
'ranks'
:
ranks
'ranks'
:
ranks
})
})
...
...
python/paddle/fluid/recordio_writer.py
浏览文件 @
f9556dca
...
@@ -12,9 +12,12 @@
...
@@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
os
import
core
import
core
import
contextlib
import
contextlib
__all__
=
[
'convert_reader_to_recordio_file'
]
__all__
=
[
'convert_reader_to_recordio_file'
,
'convert_reader_to_recordio_files'
]
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
...
@@ -48,7 +51,7 @@ def convert_reader_to_recordio_file(
...
@@ -48,7 +51,7 @@ def convert_reader_to_recordio_file(
def
convert_reader_to_recordio_files
(
def
convert_reader_to_recordio_files
(
filename
_suffix
,
filename
,
batch_per_file
,
batch_per_file
,
reader_creator
,
reader_creator
,
feeder
,
feeder
,
...
@@ -57,13 +60,16 @@ def convert_reader_to_recordio_files(
...
@@ -57,13 +60,16 @@ def convert_reader_to_recordio_files(
feed_order
=
None
):
feed_order
=
None
):
if
feed_order
is
None
:
if
feed_order
is
None
:
feed_order
=
feeder
.
feed_names
feed_order
=
feeder
.
feed_names
f_name
,
f_ext
=
os
.
path
.
splitext
(
filename
)
assert
(
f_ext
==
".recordio"
)
lines
=
[]
lines
=
[]
f_idx
=
0
f_idx
=
0
counter
=
0
counter
=
0
for
idx
,
batch
in
enumerate
(
reader_creator
()):
for
idx
,
batch
in
enumerate
(
reader_creator
()):
lines
.
append
(
batch
)
lines
.
append
(
batch
)
if
idx
>=
batch_per_file
and
idx
%
batch_per_file
==
0
:
if
idx
>=
batch_per_file
and
idx
%
batch_per_file
==
0
:
filename
=
"%s-%05d
"
%
(
filename_suffix
,
f_idx
)
filename
=
"%s-%05d
%s"
%
(
f_name
,
f_idx
,
f_ext
)
with
create_recordio_writer
(
filename
,
compressor
,
with
create_recordio_writer
(
filename
,
compressor
,
max_num_records
)
as
writer
:
max_num_records
)
as
writer
:
for
l
in
lines
:
for
l
in
lines
:
...
...
tools/codestyle/docstring_checker.pyc
0 → 100644
浏览文件 @
f9556dca
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录