-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
31 lines (23 loc) · 904 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
from torch.utils.data import Dataset
import torchvision.transforms as transforms
from glob import glob
from PIL import Image
from tqdm import tqdm
class Anime(Dataset):
def __init__(self, dataset_dir, resolution):
self.transform = transform = transforms.Compose([
transforms.Resize((resolution, resolution)),
transforms.ToTensor(),
transforms.Normalize(mean=(0.5, 0.5, 0.5),
std=(0.5, 0.5, 0.5))
])
print("Loading Anime Dataset")
self.data = list()
for image_dir in glob(f'{dataset_dir}/*.png'):
image = Image.open(image_dir)
iamge = image.convert('RGB')
self.data.append(self.transform(image))
def __len__(self):
return len(self.data)
def __getitem__(self, index):
return self.data[index]