-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset.py
39 lines (29 loc) · 902 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
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 24 13:32:18 2022
@author: ahmedemam576
"""
from torch.utils.data import Dataset
import glob
import os
from PIL import Image
import torch
#from skimage.color import gray2rgba
import numpy as np
path = 'horse2zebra'
mode = 'train'
class ZebraDataset(Dataset):
def __init__(self, path, mode, transform):
super(ZebraDataset, self).__init__()
self.horse_file = sorted(glob.glob(os.path.join(path, '%sB' % mode) + '/*.*'))
assert len(self.horse_file)> 0
self.transform = transform
def __len__(self):
return len(self.horse_file)
def __getitem__(self, index):
img = Image.open(self.horse_file[index])
if len(img.mode) != 3:
img = img.convert('RGB')
img = self.transform(img)
return img