Skip to content

Commit 41b8a54

Browse files
authored
custom dataset
1 parent 547cdf1 commit 41b8a54

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

datasets.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os, glob, cv2
2+
from torch.utils.data import Dataset
3+
4+
class DAE_dataset(Dataset):
5+
def __init__(self, data_dir, transform = None):
6+
self.data_dir = data_dir
7+
self.transform = transform
8+
self.imgs_data = self.get_data(os.path.join(self.data_dir, 'imgs'))
9+
self.noisy_imgs_data = self.get_data(os.path.join(self.data_dir, 'noisy'))
10+
11+
def get_data(self, data_path):
12+
data = []
13+
for img_path in glob.glob(data_path + os.sep + '*'):
14+
data.append(img_path)
15+
return data
16+
17+
def __getitem__(self, index):
18+
img = 255 - cv2.imread(self.imgs_data[index] ,0)
19+
noisy_img = 255 - cv2.imread(self.noisy_imgs_data[index] ,0)
20+
21+
if self.transform is not None:
22+
img = self.transform(img)
23+
noisy_img = self.transform(noisy_img)
24+
return img, noisy_img
25+
26+
def __len__(self):
27+
return len(self.imgs_data)

0 commit comments

Comments
 (0)