Skip to content

Commit

Permalink
Merge pull request #2549 from gongweibao/recordio
Browse files Browse the repository at this point in the history
add local recordio reader interface
  • Loading branch information
gongweibao committed Jun 27, 2017
2 parents de77faf + aa47c62 commit dcece75
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion python/paddle/v2/reader/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
program.
"""

__all__ = ['np_array', 'text_file']
__all__ = ['np_array', 'text_file', "recordio"]


def np_array(x):
Expand Down Expand Up @@ -55,3 +55,24 @@ def reader():
f.close()

return reader


def recordio(path):
"""
Creates a data reader that outputs record one one by one from given recordio file
:path: path of recordio file
:returns: data reader of recordio file
"""

import recordio as rec

def reader():
f = rec.reader(path)
while True:
r = f.read()
if r is None:
break
yield r
f.close()

return reader
9 changes: 9 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,14 @@ def test_text_file(self):
self.assertEqual(e, str(idx * 2) + " " + str(idx * 2 + 1))


class TestRecordIO(unittest.TestCase):
def test_recordio(self):
path = os.path.join(
os.path.dirname(__file__), "test_recordio_creator.dat")
reader = paddle.v2.reader.creator.recordio(path)
for idx, r in enumerate(reader()):
self.assertSequenceEqual(r, str(idx))


if __name__ == '__main__':
unittest.main()
Binary file not shown.

0 comments on commit dcece75

Please sign in to comment.