提交 dcece75b 编写于 作者: G gongweibao 提交者: GitHub

Merge pull request #2549 from gongweibao/recordio

add local recordio reader interface
......@@ -16,7 +16,7 @@ Creator package contains some simple reader creator, which could be used in user
program.
"""
__all__ = ['np_array', 'text_file']
__all__ = ['np_array', 'text_file', "recordio"]
def np_array(x):
......@@ -55,3 +55,24 @@ def text_file(path):
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
......@@ -34,5 +34,14 @@ class TestTextFile(unittest.TestCase):
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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册