-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
55 lines (38 loc) · 1.74 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 numpy as np
import torchvision.datasets as datasets
#import cifar_customed_v2 as datasets
import torchvision.transforms as transforms
from torch.utils.data.sampler import SubsetRandomSampler
_DATASETS_MAIN_PATH = './datasets'
_IMAGENET_MAIN_PATH = '/home/pami/ImageNet2011'
_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 == '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)