-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathDataSet.py
37 lines (31 loc) · 1.15 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
import torch
import cv2
import torch.utils.data
__author__ = "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 self.transform:
[image, label] = self.transform(image, label)
return (image, label)