-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyTorch_1_Datasets.py
More file actions
33 lines (27 loc) · 826 Bytes
/
PyTorch_1_Datasets.py
File metadata and controls
33 lines (27 loc) · 826 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
29
30
31
32
33
import torch
from torch.utils.data import Dataset
#crate a subclass from Dataset
class toy_set(Dataset):
#contructor
def __init__(self,length = 50,transform = None):
self.len = length
# pylint: disable=E1101
self.x = torch.ones(length,2)
self.y = torch.ones(length,1)
# pylint: enable=E1101
self.transform = transform
#return data at a given index
def __getitem__(self,index):
sample = self.x[index],self.y[index]
if self.transform:
sample = self.transform(sample)
return sample
#return length
def __len__(self):
return self.len
our_dataset = toy_set()
for idx in range(3):
x,y = our_dataset[idx]
print("x = {} y = {}".format(x,y))
for x,y in our_dataset:
print("x = {} y = {}".format(x,y))