forked from SamuelQZQ/StyleBank.Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_loader.py
53 lines (37 loc) · 1.29 KB
/
data_loader.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
import torch
import torch.utils.data as data
import os
import numpy as np
import nltk
import random
from PIL import Image
dataDir = 'data_contents/VIPSL_FaceSketch/'
contentDir = dataDir + 'photos/'
styleDir0 = dataDir + 'sketches/'
styleDir1 = dataDir + 'sketches1/'
class VIPSLDataset(data.Dataset):
def __init__(self, transform):
self.transform = transform
filenames = os.listdir(contentDir)
self.len = len(filenames)
def __getitem__(self, index):
index = index + 1
contentFile = str(index) + '.jpg'
img = Image.open(contentDir + contentFile)
img = self.transform(img)
styleFile0 = str(index).zfill(4) + '.jpg'
style0 = Image.open(styleDir0 + styleFile0)
styleFile1 = str(index) + '.jpg'
style1 = Image.open(styleDir1 + styleFile1)
style0 = self.transform(style0)
style1 = self.transform(style1)
return img, style0, style1
def __len__(self):
return 200
def collate_fn(data):
images, styles0, styles1 = zip(*data)
# Merge images (from tuple of 1D tensor to 2D tensor).
images = torch.stack(images, 0)
styles0 = torch.stack(styles0, 0)
styles1 = torch.stack(styles1, 0)
return images, styles0, styles1