-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathDataSet.py
46 lines (38 loc) · 1.48 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
import cv2
import torch.utils.data
import numpy as np
#============================================
__author__ = "Sachin Mehta"
__license__ = "MIT"
__maintainer__ = "Sachin Mehta"
#============================================
class MyDataset(torch.utils.data.Dataset):
'''
Class to load the dataset
'''
def __init__(self, imList, labelList, transform=None):
'''
:param imList: image list (Note that these lists have been processed and pickled using the loadData.py)
:param labelList: label list (Note that these lists have been processed and pickled using the loadData.py)
:param transform: Type of transformation. SEe Transforms.py for supported transformations
'''
self.imList = imList
self.labelList = labelList
self.transform = transform
def __len__(self):
return len(self.imList)
def __getitem__(self, idx):
'''
:param idx: Index of the image file
:return: returns the image and corresponding label file.
'''
image_name = self.imList[idx]
label_name = self.labelList[idx]
image = cv2.imread(image_name)
label = cv2.imread(label_name, 0)
# if you have 255 label in your label files, map it to the background class (19) in the Cityscapes dataset
if 255 in np.unique(label):
label[label==255] = 19
if self.transform:
[image, label] = self.transform(image, label)
return (image, label)