-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataloader.py
More file actions
28 lines (22 loc) · 777 Bytes
/
dataloader.py
File metadata and controls
28 lines (22 loc) · 777 Bytes
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
import torch
from sklearn.datasets import make_classification
class CustomData:
def __init__(self, data, targets):
self.data = data
self.targets = targets
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
current_sample = self.data[idx, :]
current_target = self.targets[idx]
return {
"x": torch.tensor(current_sample, dtype=torch.float),
"y": torch.tensor(current_target, dtype=torch.long),
}
if __name__ == '__main__':
data,target=make_classification(n_samples=100)
dataset=CustomData(data,target)
train_dataloder=torch.utils.data.DataLoader(dataset,batch_size=4,num_workers=2)
for value in train_dataloder:
print(value)
break