Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f9556dca
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看板
提交
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:
```
bash
.
\_
mnist
.recordio-00000
|-mnist
.recordio-00001
|-mnist
.recordio-00002
|-mnist
.recordio-00003
|-mnist
.recordio-00004
\_
mnist
-00000.recordio
|-mnist
-00001.recordio
|-mnist
-00002.recordio
|-mnist
-00003.recordio
|-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,
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):
trainers
=
int
(
os
.
getenv
(
"TRAINERS"
))
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_INIT_TRAINER_ID"
))
data_file
=
fluid
.
layers
.
io
.
open_recordio_file
(
filename
=
gen_train_list
(
"./mnist.recordio*"
,
trainers
,
trainer_id
),
shapes
=
[(
-
1
,
784
),(
-
1
,
1
)],
lod_levels
=
[
0
,
0
],
dtypes
=
[
"float32"
,
"int32"
])
data_file
=
fluid
.
layers
.
io
.
batch
(
data_file
,
batch_size
=
4
)
data_file
=
fluid
.
layers
.
io
.
open_files
(
filenames
=
gen_train_list
(
"./mnist-[0-9]*.recordio"
,
2
,
0
),
thread_num
=
1
,
shapes
=
[(
-
1
,
784
),(
-
1
,
1
)],
lod_levels
=
[
0
,
0
],
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 {
static_cast
<
int
>
(
shape_concat
.
size
()),
"The accumulate of all ranks should be equal to the "
"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"
))
->
template
GetMutable
<
framework
::
ReaderHolder
>();
for
(
auto
&
fn
:
filenames
)
{
out
->
Reset
(
new
RecordIOFileReader
<
true
>
(
fn
,
RestoreShapes
(
shape_concat
,
ranks
)));
}
out
->
Reset
(
new
RecordIOFileReader
<
true
>
(
filename
,
RestoreShapes
(
shape_concat
,
ranks
)));
}
};
class
CreateRecordIOReaderOpMaker
:
public
FileReaderMakerBase
{
protected:
void
Apply
()
override
{
AddAttr
<
std
::
vector
<
std
::
string
>>
(
"filenames"
,
"The filenames of record io reader"
);
AddAttr
<
std
::
string
>
(
"filename"
,
"The filename of record io reader"
);
AddComment
(
R"DOC(
CreateRecordIOReader Operator
...
...
python/paddle/fluid/layers/io.py
浏览文件 @
f9556dca
...
...
@@ -21,7 +21,7 @@ from ..layer_helper import LayerHelper
from
..executor
import
global_scope
__all__
=
[
'data'
,
'BlockGuardServ'
,
'ListenAndServ'
,
'Send'
,
'open_recordio_file
s
'
,
'data'
,
'BlockGuardServ'
,
'ListenAndServ'
,
'Send'
,
'open_recordio_file'
,
'open_files'
,
'read_file'
,
'shuffle'
,
'batch'
,
'double_buffer'
,
'random_data_generator'
,
'Preprocessor'
]
...
...
@@ -291,12 +291,12 @@ def _copy_reader_create_op_(block, op):
return
new_op
def
open_recordio_file
s
(
filenames
,
shapes
,
lod_levels
,
dtypes
,
pass_num
=
1
,
for_parallel
=
True
):
def
open_recordio_file
(
filename
,
shapes
,
lod_levels
,
dtypes
,
pass_num
=
1
,
for_parallel
=
True
):
"""
Open a RecordIO file
...
...
@@ -304,7 +304,7 @@ def open_recordio_files(filenames,
Via the Reader Variable, we can get data from the given RecordIO file.
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.
lod_levels(list): List of ints which declaring data lod_level.
dtypes(list): List of strs which declaring data type.
...
...
@@ -336,8 +336,6 @@ def open_recordio_files(filenames,
ranks
.
append
(
len
(
shape
))
var_name
=
unique_name
(
'open_recordio_file'
)
if
isinstance
(
filenames
,
str
):
filenames
=
[
filenames
]
startup_blk
=
default_startup_program
().
current_block
()
startup_var
=
startup_blk
.
create_var
(
name
=
var_name
)
...
...
@@ -347,7 +345,7 @@ def open_recordio_files(filenames,
attrs
=
{
'shape_concat'
:
shape_concat
,
'lod_levels'
:
lod_levels
,
'filename
s'
:
filenames
,
'filename
'
:
filename
,
'ranks'
:
ranks
})
...
...
python/paddle/fluid/recordio_writer.py
浏览文件 @
f9556dca
...
...
@@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
core
import
contextlib
__all__
=
[
'convert_reader_to_recordio_file'
]
__all__
=
[
'convert_reader_to_recordio_file'
,
'convert_reader_to_recordio_files'
]
@
contextlib
.
contextmanager
...
...
@@ -48,7 +51,7 @@ def convert_reader_to_recordio_file(
def
convert_reader_to_recordio_files
(
filename
_suffix
,
filename
,
batch_per_file
,
reader_creator
,
feeder
,
...
...
@@ -57,13 +60,16 @@ def convert_reader_to_recordio_files(
feed_order
=
None
):
if
feed_order
is
None
:
feed_order
=
feeder
.
feed_names
f_name
,
f_ext
=
os
.
path
.
splitext
(
filename
)
assert
(
f_ext
==
".recordio"
)
lines
=
[]
f_idx
=
0
counter
=
0
for
idx
,
batch
in
enumerate
(
reader_creator
()):
lines
.
append
(
batch
)
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
,
max_num_records
)
as
writer
:
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录