@@ -22,23 +22,21 @@ def reader():
22
22
# According to http://stackoverflow.com/a/38061619/724872, we
23
23
# cannot use standard package gzip here.
24
24
m = subprocess .Popen (["zcat" , image_filename ], stdout = subprocess .PIPE )
25
- m .stdout .read (16 ) # skip some magic bytes
25
+ m .stdout .read (16 ) # skip some magic bytes
26
26
27
27
l = subprocess .Popen (["zcat" , label_filename ], stdout = subprocess .PIPE )
28
- l .stdout .read (8 ) # skip some magic bytes
28
+ l .stdout .read (8 ) # skip some magic bytes
29
29
30
30
while True :
31
31
labels = numpy .fromfile (
32
- l .stdout , 'ubyte' , count = buffer_size
33
- ).astype ("int" )
32
+ l .stdout , 'ubyte' , count = buffer_size ).astype ("int" )
34
33
35
34
if labels .size != buffer_size :
36
- break # numpy.fromfile returns empty slice after EOF.
35
+ break # numpy.fromfile returns empty slice after EOF.
37
36
38
37
images = numpy .fromfile (
39
- m .stdout , 'ubyte' , count = buffer_size * 28 * 28
40
- ).reshape ((buffer_size , 28 * 28 )
41
- ).astype ('float32' )
38
+ m .stdout , 'ubyte' , count = buffer_size * 28 * 28 ).reshape (
39
+ (buffer_size , 28 * 28 )).astype ('float32' )
42
40
43
41
images = images / 255.0 * 2.0 - 1.0
44
42
@@ -50,18 +48,18 @@ def reader():
50
48
51
49
return reader ()
52
50
51
+
53
52
def train ():
54
53
return reader_creator (
55
- paddle .v2 .dataset .common .download (
56
- TRAIN_IMAGE_URL , 'mnist' , TRAIN_IMAGE_MD5 ),
57
- paddle .v2 .dataset .common .download (
58
- TRAIN_LABEL_URL , 'mnist' , TRAIN_LABEL_MD5 ),
59
- 100 )
54
+ paddle .v2 .dataset .common .download (TRAIN_IMAGE_URL , 'mnist' ,
55
+ TRAIN_IMAGE_MD5 ),
56
+ paddle .v2 .dataset .common .download (TRAIN_LABEL_URL , 'mnist' ,
57
+ TRAIN_LABEL_MD5 ), 100 )
58
+
60
59
61
60
def test ():
62
61
return reader_creator (
63
- paddle .v2 .dataset .common .download (
64
- TEST_IMAGE_URL , 'mnist' , TEST_IMAGE_MD5 ),
65
- paddle .v2 .dataset .common .download (
66
- TEST_LABEL_URL , 'mnist' , TEST_LABEL_MD5 ),
67
- 100 )
62
+ paddle .v2 .dataset .common .download (TEST_IMAGE_URL , 'mnist' ,
63
+ TEST_IMAGE_MD5 ),
64
+ paddle .v2 .dataset .common .download (TEST_LABEL_URL , 'mnist' ,
65
+ TEST_LABEL_MD5 ), 100 )
0 commit comments