-
Notifications
You must be signed in to change notification settings - Fork 16
/
data.py
55 lines (50 loc) · 2.03 KB
/
data.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
import os
import torchvision.datasets as datasets
import torchvision.transforms as transforms
_IMAGENET_MAIN_PATH = ''
_DATASETS_MAIN_PATH = ''
_dataset_path = {
'cifar10': os.path.join(_DATASETS_MAIN_PATH, 'CIFAR10'),
'cifar100': os.path.join(_DATASETS_MAIN_PATH, 'CIFAR100'),
'stl10': os.path.join(_DATASETS_MAIN_PATH, 'STL10'),
'mnist': os.path.join(_DATASETS_MAIN_PATH, 'MNIST'),
'imagenet': {
'train': os.path.join(_IMAGENET_MAIN_PATH, 'train'),
'val': os.path.join(_IMAGENET_MAIN_PATH, 'val')
},
}
def get_dataset(name, split='train', transform=None,
target_transform=None, download=True):
train = (split == 'train')
if name == 'mnist':
return datasets.MNIST( root=_dataset_path['mnist'],
train=train,
transform=transform,
target_transform=target_transform,
download=download)
elif name == 'cifar10':
return datasets.CIFAR10(root=_dataset_path['cifar10'],
train=train,
transform=transform,
target_transform=target_transform,
download=download)
elif name == 'cifar100':
return datasets.CIFAR100(root=_dataset_path['cifar100'],
train=train,
transform=transform,
target_transform=target_transform,
download=download)
elif name == 'imagenet':
path = _dataset_path[name][split]
return datasets.ImageFolder(root=path,
transform=transform,
target_transform=target_transform)
def get_num_classes(name):
if name == 'mnist':
return 10
elif name == 'cifar10':
return 10
elif name == 'cifar100':
return 100
elif name == 'imagenet':
return 1000