1
1
module FashionMNIST
2
2
3
- using CodecZlib, Colors
4
-
5
- const Gray = Colors. Gray{Colors. N0f8}
3
+ using .. MNIST: gzopen, imageheader, rawimage, labelheader, rawlabel
6
4
7
5
const dir = joinpath (@__DIR__ , " ../../deps/fashion-mnist" )
8
6
9
- function gzopen (f, file)
10
- open (file) do io
11
- f (GzipDecompressorStream (io))
12
- end
13
- end
14
-
15
7
function load ()
16
8
mkpath (dir)
17
9
cd (dir) do
@@ -29,53 +21,11 @@ function load()
29
21
end
30
22
end
31
23
32
- const IMAGEOFFSET = 16
33
- const LABELOFFSET = 8
34
-
35
- const NROWS = 28
36
- const NCOLS = 28
37
-
38
24
const TRAINIMAGES = joinpath (dir, " train-images-idx3-ubyte" )
39
25
const TRAINLABELS = joinpath (dir, " train-labels-idx1-ubyte" )
40
26
const TESTIMAGES = joinpath (dir, " t10k-images-idx3-ubyte" )
41
27
const TESTLABELS = joinpath (dir, " t10k-labels-idx1-ubyte" )
42
28
43
- function imageheader (io:: IO )
44
- magic_number = bswap (read (io, UInt32))
45
- total_items = bswap (read (io, UInt32))
46
- nrows = bswap (read (io, UInt32))
47
- ncols = bswap (read (io, UInt32))
48
- return magic_number, Int (total_items), Int (nrows), Int (ncols)
49
- end
50
-
51
- function labelheader (io:: IO )
52
- magic_number = bswap (read (io, UInt32))
53
- total_items = bswap (read (io, UInt32))
54
- return magic_number, Int (total_items)
55
- end
56
-
57
- function rawimage (io:: IO )
58
- img = Array {Gray} (undef, NCOLS, NROWS)
59
- for i in 1 : NCOLS, j in 1 : NROWS
60
- img[i, j] = reinterpret (Colors. N0f8, read (io, UInt8))
61
- end
62
- return img
63
- end
64
-
65
- function rawimage (io:: IO , index:: Integer )
66
- seek (io, IMAGEOFFSET + NROWS * NCOLS * (index - 1 ))
67
- return rawimage (io)
68
- end
69
-
70
- rawlabel (io:: IO ) = Int (read (io, UInt8))
71
-
72
- function rawlabel (io:: IO , index:: Integer )
73
- seek (io, LABELOFFSET + (index - 1 ))
74
- return rawlabel (io)
75
- end
76
-
77
- getfeatures (io:: IO , index:: Integer ) = vec (getimage (io, index))
78
-
79
29
"""
80
30
images()
81
31
images(:test)
@@ -111,5 +61,4 @@ function labels(set = :train)
111
61
[rawlabel (io) for _ = 1 : N]
112
62
end
113
63
114
-
115
64
end
0 commit comments