-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
116 lines (40 loc) · 1.67 KB
/
main.py
File metadata and controls
116 lines (40 loc) · 1.67 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 22:37:27 2020
@author: aguasharo
"""
from __future__ import print_function
import json
import os
import collections
from RecognitionModel import RecognitionModel
#%% Read user data
response = collections.defaultdict(dict)
num_gestures = 6
folderData = 'testingJSON'
cont = 0
entries = os.listdir(folderData)
num_users = len(entries)
for entry in entries:
cont = cont + 1
print('Processing data from user: ' + str(cont) + ' / '+ str(num_users))
file_selected = folderData + '/' + entry + '/' + entry + '.json'
with open(file_selected) as file:
# Read user data
user = json.load(file)
name_user = user['userInfo']['name']
currentUser = RecognitionModel('training', user)
# Preprocessing
train_segment_X = currentUser.preProcessingData()
# Feature extraction by computing the DTW distance between each training
# example and the center of each cluster
[X_train, centers] = currentUser.featureExtraction(train_segment_X)
# Training the feed-forward NN
estimator = currentUser.trainSoftmaxNN(X_train)
results = currentUser.classifyGestures('testing', estimator, centers)
# Concatenating the predictions of all the users for computing the
# errors
response[name_user]['testing'] = results
with open('responses.json', 'w') as json_file:
json.dump(response, json_file)