-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
34 lines (24 loc) · 821 Bytes
/
data.py
File metadata and controls
34 lines (24 loc) · 821 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
34
import torch
import json
class PoseDataset(torch.utils.data.Dataset):
def __init__(self, json_file):
data = []
with open(json_file) as file:
for line in file.readlines():
data += json.loads(line)
data = map(lambda x: list(x.values()), data)
data = list(data)
self.data = torch.tensor(data, dtype=torch.float)
# Normalizaiton
mean = (torch.mean(self.data, dim=0))
std = (torch.std(self.data, dim=0))
# print(mean)
print(self.data.mean())
torch.save(mean, 'mean.pt')
torch.save(std, 'std.pt')
self.data = (self.data - mean) / std
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
sample = self.data[idx]
return sample