-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.py
42 lines (34 loc) · 1.13 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
38
39
40
41
42
import torch
import kagglehub
from PIL import Image
from torch.utils.data import Dataset
from torchvision.datasets import CIFAR10
class CIFAR10Dataset(Dataset):
def __init__(self, transform, train):
super().__init__()
self.train = train
self.transform = transform
self.dataset = CIFAR10(root='./data', train=True, download=True)
def __len__(self):
if self.train:
return len(self.dataset)
else:
return 1000
def __getitem__(self, idx):
image, _ = self.dataset[idx]
return self.transform(image)
class CelebADataset(Dataset):
def __init__(self, timesteps, transform, train):
super().__init__()
self.timesteps = timesteps
self.transform = transform
self.train = train
self.path = kagglehub.dataset_download("badasstechie/celebahq-resized-256x256")
def __len__(self):
if self.train:
return 30000
else:
return 1000
def __getitem__(self, idx):
image = Image.open(f"{self.path}/celeba_hq_256/{idx:05d}.jpg")
return self.transform(image)