Skip to content

Commit 245f622

Browse files
authored
Merge pull request #3479 from helinwang/recordio
Fix local recordio reader
2 parents 33d502e + b95668d commit 245f622

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

python/paddle/v2/reader/creator.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def reader():
5757
return reader
5858

5959

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

6868
import recordio as rec
6969
import paddle.v2.reader.decorator as dec
70+
import cPickle as pickle
7071

7172
def reader():
72-
a = ','.join(paths)
73-
f = rec.reader(a)
73+
if isinstance(paths, basestring):
74+
path = paths
75+
else:
76+
path = ",".join(paths)
77+
f = rec.reader(path)
7478
while True:
7579
r = f.read()
7680
if r is None:
7781
break
78-
yield r
82+
yield pickle.loads(r)
7983
f.close()
8084

8185
return dec.buffered(reader, buf_size)

python/paddle/v2/reader/tests/creator_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,27 @@ def test_text_file(self):
3434
self.assertEqual(e, str(idx * 2) + " " + str(idx * 2 + 1))
3535

3636

37+
class TestRecordIO(unittest.TestCase):
38+
def do_test(self, path):
39+
reader = paddle.v2.reader.creator.recordio(path)
40+
idx = 0
41+
for e in reader():
42+
if idx == 0:
43+
self.assertEqual(e, (1, 2, 3))
44+
elif idx == 1:
45+
self.assertEqual(e, (4, 5, 6))
46+
idx += 1
47+
self.assertEqual(idx, 2)
48+
49+
def test_recordIO(self):
50+
self.do_test(
51+
os.path.join(
52+
os.path.dirname(__file__), "test_reader_recordio.dat"))
53+
self.do_test([
54+
os.path.join(
55+
os.path.dirname(__file__), "test_reader_recordio.dat")
56+
])
57+
58+
3759
if __name__ == '__main__':
3860
unittest.main()
76 Bytes
Binary file not shown.

python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
requests==2.9.2
22
numpy>=1.12
33
protobuf==3.1
4-
recordio
4+
recordio>=0.1.0
55
matplotlib
66
rarfile
77
scipy>=0.19.0

0 commit comments

Comments
 (0)