-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataset.py
84 lines (64 loc) · 3.02 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
import torchvision
import torchvision.transforms as transforms
import pdb
'''
Ex)
train_set,test_set = dataset.IMAGENET(normalize=False)
test_loader = torch.utils.data.DataLoader(test_set,batch_size = 1,shuffle = False)
'''
def MNIST(root = '/dataset',normalize = False,download = False):
transform = transforms.Compose([
transforms.ToTensor()
])
train_set = torchvision.datasets.MNIST(root = root, train=True, transform=transform, target_transform=None, download=download)
val_set = torchvision.datasets.MNIST(root = root, train=False, transform=transform, target_transform=None, download=download)
return train_set,val_set
def FashionMNIST(root = 'dataset',normalize = False):
transform = transforms.Compose([
transforms.ToTensor()
])
train_set = torchvision.datasets.MNIST(root = root, train=True, transform=transform, target_transform=None, download=True)
val_set = torchvision.datasets.MNIST(root = root, train=False, transform=transform, target_transform=None, download=True)
return train_set,val_set
def CIFAR10(root = 'C:\\datasets\\CIFAR10',normalize = False,download = False):
if normalize == True:
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])
else:
transform = transforms.Compose([
transforms.ToTensor()
])
train_set = torchvision.datasets.CIFAR10(root = root, train=True, transform = transform, target_transform=None, download=download)
val_set = torchvision.datasets.CIFAR10(root = root , train=False, transform = transform, target_transform=None, download=download)
return train_set,val_set
def CIFAR100(root = 'C:\\datasets\\CIFAR10',normalize = False):
if normalize == True:
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])
else:
transform = transforms.Compose([
transforms.ToTensor()
])
train_set = torchvision.datasets.CIFAR100(root = root, train=True, transform = transform, target_transform=None, download=False)
val_set = torchvision.datasets.CIFAR100(root = root , train=False, transform = transform, target_transform=None, download=True)
return train_set,val_set
def IMAGENET(root = 'C:\\datasets\\ImageNet',normalize = False):
if normalize == False:
transform = transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor()
])
else:
transform = transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])
# train_set = torchvision.datasets.ImageFolder(root + 'train', transform = transform)
val_set = torchvision.datasets.ImageFolder(root + '\\val', transform = transform)
# return train_set,val_set
return None,val_set