-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
executable file
·64 lines (52 loc) · 2.09 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
56
57
58
59
60
61
62
63
64
from torchvision import datasets, transforms
import config as cf
def _permutate_image_pixels(image, permutation):
if permutation is None:
return image
c, h, w = image.size()
image = image.view(-1, c)
image = image[permutation, :]
image.view(c, h, w)
return image
transform_train_cifar10 = transforms.Compose([
transforms.RandomCrop(32, padding=4),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(cf.mean['cifar10'], cf.std['cifar10']),
]) # meanstd transformation
transform_test_cifar10 = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(cf.mean['cifar10'], cf.std['cifar10']),
])
transform_train_cifar100 = transforms.Compose([
transforms.RandomCrop(32, padding=4),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(cf.mean['cifar100'], cf.std['cifar100']),
]) # meanstd transformation
transform_test_cifar100 = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(cf.mean['cifar100'], cf.std['cifar100']),
])
def get_dataset(name, train=True, download=True, permutation=None):
if(name == 'cifar10_train'):
return datasets.CIFAR10(root='./data', train=True, download=True, transform=transform_train_cifar10)
elif(name == 'cifar10_test'):
return datasets.CIFAR10(root='./data', train=False, download=True, transform=transform_test_cifar10)
elif(name == 'cifar100_train'):
return datasets.CIFAR100(root='./data', train=True, download=True, transform=transform_train_cifar100)
elif(name == 'cifar100_test'):
return datasets.CIFAR100(root='./data', train=False, download=True, transform=transform_test_cifar100)
else:
print("Invalid dataset mentioned")
return None
AVAILABLE_DATASETS = {
'mnist': datasets.MNIST,
'cifar10' : datasets.CIFAR10,
'cifar100' : datasets.CIFAR100
}
DATASET_CONFIGS = {
'mnist': {'size': 32, 'channels': 1, 'classes': 10},
'cifar10' : {'size' : 32, 'channels' : 3, 'classes' : 10},
'cifar100' : {'size' : 32, 'channels' : 3, 'classes' : 100}
}