-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdataloader.py
50 lines (33 loc) · 1.71 KB
/
dataloader.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
import os
import torch
import torch.utils.data as data
from PIL import Image
class ImageData(data.Dataset):
def __init__(self, root_origin, root_pose, transform=None, loader=None):
def convert_str2int(path):
li_int = []
for filename in os.listdir(path):
if filename[0] == '0':
filename = filename[1:]
if filename.endswith('.png'):
li_int.append(int(filename.split('.')[0]))
return sorted(li_int)
li_origin = convert_str2int(root_origin)
li_pose = convert_str2int(root_pose)
#assert len(li_origin) == len(li_pose)
self.origin_set = [root_origin + '/' + str(file_origin) + '.png' for file_origin in li_origin]
self.pose_set = [root_pose + '/' + str(file_pose) + '.png' for file_pose in li_pose]
self.transform = transform
return None
def __getitem__(self, index):
path_img_origin_pre = self.origin_set[index]
path_img_pose_pre = self.pose_set[index]
path_img_origin_cur = self.origin_set[index+1]
path_img_pose_cur = self.pose_set[index+1]
img_origin_pre = self.transform(Image.open(path_img_origin_pre).convert('RGB'))
img_pose_pre = self.transform(Image.open(path_img_pose_pre).convert('RGB'))
img_origin_cur = self.transform(Image.open(path_img_origin_cur).convert('RGB'))
img_pose_cur = self.transform(Image.open(path_img_pose_cur).convert('RGB'))
return torch.cat([img_origin_pre, img_pose_pre]), torch.cat([img_origin_cur, img_pose_cur])
def __len__(self):
return len(self.origin_set)