Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local recordio reader #3479

Merged
merged 3 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions python/paddle/v2/reader/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def reader():
return reader


def recordio_local(paths, buf_size=100):
def recordio(paths, buf_size=100):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to recordio_reader to indicate it's a reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@typhoonzero It's used as paddle.v2.reader.creator.recordio, probably reader is indicated in the import path.

"""
Creates a data reader from given RecordIO file paths separated by ",",
glob pattern is supported.
Expand All @@ -67,15 +67,19 @@ def recordio_local(paths, buf_size=100):

import recordio as rec
import paddle.v2.reader.decorator as dec
import cPickle as pickle

def reader():
a = ','.join(paths)
f = rec.reader(a)
if isinstance(paths, basestring):
path = paths
else:
path = ",".join(paths)
f = rec.reader(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When training on distributed environment, reader should fetch only a part of all the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@typhoonzero The files will be read file by file. If we need to fetch only part of the data, maybe we can split them to different files. cloud_reader is much better for the distributed training environment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloud_reader is using master to dispatch tasks, I think we still need a version with out master, or master can dispatch files rather than recordio. This is in case that there are still many cases using Mapreduce output directly as training inputs.

Anyway, will discuss in another issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. The recordio file will be read entirely to parse the index before reading the first item, so in that case we need to shard the files.

while True:
r = f.read()
if r is None:
break
yield r
yield pickle.loads(r)
f.close()

return dec.buffered(reader, buf_size)
Expand Down
22 changes: 22 additions & 0 deletions python/paddle/v2/reader/tests/creator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,27 @@ def test_text_file(self):
self.assertEqual(e, str(idx * 2) + " " + str(idx * 2 + 1))


class TestRecordIO(unittest.TestCase):
def do_test(self, path):
reader = paddle.v2.reader.creator.recordio(path)
idx = 0
for e in reader():
if idx == 0:
self.assertEqual(e, (1, 2, 3))
elif idx == 1:
self.assertEqual(e, (4, 5, 6))
idx += 1
self.assertEqual(idx, 2)

def test_recordIO(self):
self.do_test(
os.path.join(
os.path.dirname(__file__), "test_reader_recordio.dat"))
self.do_test([
os.path.join(
os.path.dirname(__file__), "test_reader_recordio.dat")
])


if __name__ == '__main__':
unittest.main()
Binary file not shown.
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
requests==2.9.2
numpy>=1.12
protobuf==3.1
recordio
recordio>=0.1.0
matplotlib
rarfile
scipy>=0.19.0
Expand Down