forked from Mhaiyang/CVPR2020_GDNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
47 lines (37 loc) · 1.38 KB
/
dataset.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
"""
@Time : 2020/3/15 18:56
@Author : TaylorMei
@E-mail : [email protected]
@Project : CVPR2020_GDNet
@File : dataset.py
@Function:
"""
import os
import os.path
import torch.utils.data as data
from PIL import Image
def make_dataset(root):
img_list = [os.path.splitext(f)[0] for f in os.listdir(os.path.join(root, 'image')) if f.endswith('.jpg')]
return [
(os.path.join(root, 'image', img_name + '.jpg'), os.path.join(root, 'mask', img_name + '.png'))
for img_name in img_list]
class ImageFolder(data.Dataset):
def __init__(self, root, joint_transform=None, img_transform=None, target_transform=None):
self.root = root
self.imgs = make_dataset(root)
self.joint_transform = joint_transform
self.img_transform = img_transform
self.target_transform = target_transform
def __getitem__(self, index):
img_path, gt_path = self.imgs[index]
img = Image.open(img_path).convert('RGB')
target = Image.open(gt_path).convert('L')
if self.joint_transform is not None:
img, target = self.joint_transform(img, target)
if self.img_transform is not None:
img = self.img_transform(img)
if self.target_transform is not None:
target = self.target_transform(target)
return img, target
def __len__(self):
return len(self.imgs)