-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRecognitionModel.py
More file actions
65 lines (45 loc) · 2.04 KB
/
RecognitionModel.py
File metadata and controls
65 lines (45 loc) · 2.04 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 27 23:59:24 2020
@author: aguasharo
"""
from recognitionFunctions import *
class RecognitionModel:
num_gestures = 6
def __init__(self,version,user):
self.user = user
self.version = version
def preProcessingData(self):
sample_type = self.version+'Samples'
# Reading the training samples
train_samples = self.user[sample_type]
# Preprocessing
train_segment_X = [get_x_train(self.user,sample) for sample in train_samples]
return train_segment_X
def featureExtraction(self, train_data):
# Finding the EMG that is the center of each class
centers = bestCenter_Class(train_data)
# Feature extraction by computing the DTW distance between each training
# example and the center of each cluster
# Preprocessing the feature vectors
X_train = getFeatureExtraction(train_data, centers)
return X_train, centers
def trainSoftmaxNN(self, X_train):
sample_type = self.version+'Samples'
# Reading the training samples
train_samples = self.user[sample_type]
# Training the feed-forward NN
y_train = decode_targets(get_y_train(train_samples))
X_val, y_val = get_xy_val(X_train, get_y_train(train_samples))
estimator = trainFeedForwardNetwork(X_train, y_train, X_val, y_val)
return estimator
def classifyGestures(self,version, estimator, centers) :
sample_type = self.version+'Samples'
# Reading the testing samples
test_samples = self.user[sample_type]
# Concatenating the predictions of all the users for computing the
# errors
response = ([testing_prediction(self.user, sample, centers, estimator) for sample in test_samples])
results = recognition_results(response)
return results