-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
44 lines (37 loc) · 1.56 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
import cv2
import numpy
import torch.utils.data
class Dataset(torch.utils.data.Dataset):
'''
Class to load the dataset
'''
def __init__(self, dataset, file_root='data/', transform=None):
"""
dataset: dataset name, e.g. NJU2K_NLPR_train
file_root: root of data_path, e.g. ./data/
"""
self.file_list = open(file_root + '/' + dataset + '/list/' + dataset + '.txt').read().splitlines()
self.pre_images = [file_root + '/' + dataset + '/A/' + x for x in self.file_list]
self.post_images = [file_root + '/' + dataset + '/B/' + x for x in self.file_list]
self.gts = [file_root + '/' + dataset + '/label/' + x for x in self.file_list]
self.transform = transform
def __len__(self):
return len(self.pre_images)
def __getitem__(self, idx):
pre_image_name = self.pre_images[idx]
label_name = self.gts[idx]
post_image_name = self.post_images[idx]
pre_image = cv2.imread(pre_image_name)
label = cv2.imread(label_name, 0)
post_image = cv2.imread(post_image_name)
img = numpy.concatenate((pre_image, post_image), axis=2)
# if self.transform:
# [pre_image, label, post_image] = self.transform(pre_image, label, post_image)
#
# return pre_image, label, post_image
if self.transform:
[img, label] = self.transform(img, label)
return img, label
def get_img_info(self, idx):
img = cv2.imread(self.pre_images[idx])
return {"height": img.shape[0], "width": img.shape[1]}