/
dataset.py
99 lines (78 loc) · 1.91 KB
/
dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from abc import ABCMeta, abstractmethod
'''
Identifiers for known datasets.
'''
class Dataset:
'''
You should not subclass this in your own code, you should only use the
datasets defined here.
'''
@property
@abstractmethod
def shape(self):
raise NotImplementedError
@property
@abstractmethod
def labels(self):
raise NotImplementedError
class MNIST(Dataset):
'''
Data points are 28x28 arrays with elements in [0, 1].
'''
@property
def shape(self):
return (28, 28)
@property
def labels(self):
return 10
class FMNIST(Dataset):
'''
Data points are 28x28 arrays with elements in [0, 1].
'''
@property
def shape(self):
return (28, 28)
@property
def labels(self):
return 10
class GTS(Dataset):
'''
Data points are 32x32x3 arrays with elements in [0, 1].
'''
@property
def shape(self):
return (32, 32, 3)
@property
def labels(self):
return 43
class CIFAR10(Dataset):
'''
Data points are 32x32x3 arrays with elements in [0, 1].
'''
@property
def shape(self):
return (32, 32, 3)
@property
def labels(self):
return 10
class ImageNet(Dataset):
'''
Data points are ?x?x3 arrays with elements in [0, 1].
Dimensions are specified in the constructor.
'''
def __init__(self, shape=None):
'''
Shape is a 3-tuple (height, width, channels) describing the shape of
the input image to the model.
'''
if not isinstance(shape, tuple) or len(shape) != 3 \
or not all(isinstance(i, int) for i in shape) \
or not shape[-1] == 3:
raise ValueError('bad shape: %s' % str(shape))
self._shape = shape
@property
def shape(self):
return self._shape
@property
def labels(self):
return 1000