-
Notifications
You must be signed in to change notification settings - Fork 0
/
accelCNNPredict.py
63 lines (53 loc) · 1.79 KB
/
accelCNNPredict.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
52
53
54
55
56
57
58
59
60
61
62
63
'''
https://www.machinecurve.com/index.php/2020/02/21/how-to-predict-new-samples-with-your-keras-model/
'''
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import csv
from os import listdir
model = tf.keras.models.load_model('./Model')
# Check its architecture
#model.summary()
def load_datasets():
subjects = list()
for filename in listdir('./testingdata'):
if filename.endswith("csv"):
values = csv.reader(open("./testingdata/" + filename, "r"), delimiter = ",") # opens training data
processedlist = []
for row in values:
temp = [row[0],row[1],row[2],row[3],row[4]]
processedlist.append(temp)
subjects.append(processedlist)
return subjects
def get_frames(df):
frames = []
labels = []
for dataset in df:
frame = []
for i in range(0,len(dataset)):
x = dataset['x'][i]
y = dataset['y'][i]
z = dataset['z'][i]
frame.append([int(x), int(y), int(z)])
frames.append(frame)
labels.append(int(dataset['label'][0]))
frames = np.asarray(frames)
labels = np.asarray(labels)
return frames,labels
columns = ["time", "x", "y", "z", "label"]
subjects = load_datasets()
datasets = []
for i in range(0,len(subjects)):
datasets.append(pd.DataFrame(data = subjects[i], columns = columns))
samples_predict, samples_answers = get_frames(datasets)
samples_predict = samples_predict.reshape(len(subjects), 1000, 3, 1)
predictions = model.predict(samples_predict)
classes = np.argmax(predictions, axis = 1)
correct = 0
for i in range(0,len(classes)):
if classes[i] == samples_answers[i]:
correct += 1
print("amount correct: " , correct/len(classes))
print(classes)