-
Notifications
You must be signed in to change notification settings - Fork 4
/
dataset3.py
76 lines (58 loc) · 2.48 KB
/
dataset3.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
import os
import os.path
import torch.utils.data as data
from PIL import Image
def make_dataset(root, is_train):
if is_train:
input = open(os.path.join(root, 'data/train_input.txt'))
ground_t = open(os.path.join(root, 'data/train_gt.txt'))
depth_t = open(os.path.join(root, 'data/train_depth.txt'))
image = [(os.path.join(root, 'train', img_name.strip('\n'))) for img_name in
input]
gt = [(os.path.join(root, 'image', img_name.strip('\n'))) for img_name in
ground_t]
depth = [(os.path.join(root, 'depth', img_name.strip('\n'))) for img_name in
depth_t]
input.close()
ground_t.close()
depth_t.close()
return [[image[i], gt[i], depth[i]]for i in range(len(image))]
else:
input = open(os.path.join(root, 'data/test_input.txt'))
ground_t = open(os.path.join(root, 'data/test_gt.txt'))
depth_t = open(os.path.join(root, 'data/test_depth.txt'))
image = [(os.path.join(root, 'test', img_name.strip('\n'))) for img_name in
input]
gt = [(os.path.join(root, 'image', img_name.strip('\n'))) for img_name in
ground_t]
depth = [(os.path.join(root, 'depth', img_name.strip('\n'))) for img_name in
depth_t]
input.close()
ground_t.close()
depth_t.close()
return [[image[i], gt[i], depth[i]]for i in range(len(image))]
class ImageFolder(data.Dataset):
def __init__(self, root, triple_transform=None, transform=None, target_transform=None, is_train=True):
self.root = root
self.imgs = make_dataset(root, is_train)
self.triple_transform = triple_transform
self.transform = transform
self.target_transform = target_transform
def __getitem__(self, index):
img_path, gt_path, depth_path = self.imgs[index]
#print(img_path)
#print(gt_path)
#print(depth_path)
img = Image.open(img_path)
target = Image.open(gt_path)
depth = Image.open(depth_path)
if self.triple_transform is not None:
img, target, depth = self.triple_transform(img, target, depth)
if self.transform is not None:
img = self.transform(img)
if self.target_transform is not None:
target = self.target_transform(target)
depth = self.target_transform(depth)
return img, target, depth
def __len__(self):
return len(self.imgs)