-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
31 lines (27 loc) · 947 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 typing import Callable, Optional
import numpy as np
from torchvision.datasets import VisionDataset
class ARPESDataset(VisionDataset):
def __init__(
self,
data,
targets: Optional[np.ndarray] = None,
normalize: bool = False,
transform: Optional[Callable] = None,
):
super().__init__(root=None, transform=transform)
self.data, self.targets = data, targets
self.if_normalize = normalize
def __getitem__(self, index):
X = self.data[index]
if self.transform is not None:
X = self.transform(X).squeeze(0)
if self.targets is not None:
y = self.targets[index]
if self.target_transform is not None:
y = self.target_transform(self.targets[index])
return X, y, index
else:
return X, index
def __len__(self):
return len(self.data)