-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransforms.py
37 lines (27 loc) · 1.04 KB
/
transforms.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
import torch
class ToTensor(object):
"""
This class implements a callable class which converts Numpy samples to Tensor samples
"""
def __call__(self, sample):
"""
:param sample: A dictionary of ndarray objects
:return: A dictionary tensor objects
"""
x, adj, y = sample['x'], sample['adj'], sample['y']
new_sample = {'x': torch.tensor(x, dtype=torch.float32),
'adj': torch.tensor(adj, dtype=torch.float32),
'y': torch.tensor(y, dtype=torch.float32)}
return new_sample
class SimpleToTensor(object):
"""
This class implements a callable class which converts Numpy samples to Tensor samples
"""
def __call__(self, sample):
"""
:param sample: A dictionary of ndarray objects
:return: A dictionary tensor objects
"""
x, y = sample['x'], sample['y']
new_sample = {'x': torch.tensor(x, dtype=torch.float32), 'y': torch.tensor(y, dtype=torch.float32)}
return new_sample