-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset2.py
54 lines (46 loc) · 1.58 KB
/
dataset2.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
import torch
import os
import torchvision
import torchvision.transforms as transforms
import numpy as np
class Dataset:
def __init__(self, flags):
self.flags = flags
self.data_path = os.path.join(self.flags.dataset_dir, 'cfp/profile')
self.front_data_path = os.path.join(self.flags.dataset_dir, 'cfp/frontal')
def load_dataset(self):
train_dataset = torchvision.datasets.ImageFolder(
root=self.data_path,
transform = transforms.Compose([
transforms.Scale(128),
transforms.CenterCrop(128),
transforms.ToTensor(),
])
#transform=torchvision.transforms.ToTensor(),
)
train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=4,
#num_workers=4,
shuffle=False,
#pin_memory=True
)
return train_loader
def load_front_dataset(self):
train_dataset = torchvision.datasets.ImageFolder(
root=self.front_data_path,
transform=transforms.Compose([
transforms.Scale(128),
transforms.CenterCrop(128),
transforms.ToTensor(),
])
# transform=torchvision.transforms.ToTensor(),
)
train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=self.flags.batch_size,
#num_workers=4,
shuffle=False,
#pin_memory=True
)
return train_loader