forked from uwrealitylabs/universal-gestures-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_data.py
51 lines (40 loc) · 1.38 KB
/
process_data.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pandas as pd
import numpy as np
import torch
from torch.utils.data.dataset import Dataset
import os
import json
# WILL NEED TO SOMEHOW MODIFY THE DATA TO SUPPORT > 2 CLASSES
def process_data(dataset_file):
with open(dataset_file) as f:
json_data = json.load(f)
data_list = []
for entry in json_data:
hand_data = entry['handData']
confidence = entry['confidence']
combined_data = hand_data + [confidence]
data_list.append(combined_data)
# Convert the list of lists to a torch tensor
return data_list
def split():
data_files = os.listdir("data")
print("Loading data files")
full_dataset = []
train = []
for dataset_name in data_files:
full_dataset.extend(process_data("data/"+dataset_name))
print("Splitting data into training and testing")
train_size = int(0.8 * len(full_dataset))
test_size = len(full_dataset) - train_size
train, test= torch.utils.data.random_split(full_dataset, [train_size, test_size])
print("Processing training data")
train_tensor = torch.tensor(train)
torch.save(train_tensor, "train_data/train_0.pt")
print("Processing testing data")
test_tensor = torch.tensor(test)
torch.save(test_tensor, "test_data/test_0.pt")
def main():
split()
# process_data(data_path, output_path)
if __name__ == "__main__":
main()