-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
28 lines (22 loc) · 869 Bytes
/
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
from torch.utils.data import Dataset
import cv2
import numpy as np
class DATASET(Dataset):
def __init__(self, images_path, masks_path, size, transform=None):
super().__init__()
self.images_path = images_path
self.masks_path = masks_path
self.transform = transform
self.n_samples = len(images_path)
self.size = size
def __getitem__(self, index):
""" Image """
image = cv2.imread(self.images_path[index], cv2.IMREAD_COLOR)
mask = cv2.imread(self.masks_path[index], cv2.IMREAD_GRAYSCALE)
if self.transform is not None:
augmentations = self.transform(image=image, mask=mask)
image = augmentations["image"]
mask = augmentations["mask"]
return image, mask
def __len__(self):
return self.n_samples