-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatasets.py
33 lines (28 loc) · 913 Bytes
/
datasets.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
from torch.utils.data import Dataset
from PIL import Image
class image_dataset(Dataset):
def __init__(self, file_list, transform=None):
self.file_list = file_list
self.transform = transform
self.label2idx = {
'grand': 0,
'modern': 1,
'antic': 2,
'vintage': 3,
'cozy': 4,
'gorgeous': 5,
'retro': 6,
'scenery': 7,
'classic': 8,
'calm': 9
}
def __len__(self):
self.filelength = len(self.file_list)
return self.filelength
def __getitem__(self, idx):
img_path = self.file_list[idx]
img = Image.open(img_path)
img_transformed = self.transform(img)
label = img_path.split('\\')[-1].split('_')[0]
label = self.label2idx[label]
return img_transformed, label