-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
63 lines (53 loc) · 1.6 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
import os
import pandas as pd
import numpy as np
from sklearn.utils import shuffle
from scipy import signal
import scipy
DATA_DIR = "dataset/"
class_names = ['left', 'right', 'front', 'back']
class_names_label = {
'left': 0,
'right': 1,
'front': 2,
'back': 3
}
nb_classes = 4
# Butter filter params
# fs = 17000
# fc = 50
# t = np.arange(17000) / fs
# w = fc / (fs / 2)
# b, a = scipy.signal.butter(5, w, 'low')
def load_data():
datasets = ['train']
for dataset in datasets:
directory = DATA_DIR + dataset
csv = []
labels = []
for folder in os.listdir(directory):
curr_label = class_names_label[folder]
for file in os.listdir(os.path.join(directory, folder)):
X_path = os.path.join(directory, folder, file)
X_csv = pd.read_csv(X_path)
X_csv.drop('Time', inplace=True, axis=1)
X_csv[~X_csv.isin([np.nan, np.inf, -np.inf]).any(1)].astype(np.float64)
# X_csv = X_csv.iloc[:, 0:23]
value = X_csv.shape[0] - 17000
X_csv = X_csv.iloc[:-value]
# for channel in X_csv:
# signal = np.array(X_csv[channel])
# X_csv[channel] = scipy.signal.filtfilt(b, a, signal)
X_csv = X_csv.to_numpy()
csv.append(X_csv)
labels.append(curr_label)
sample = np.array(csv)
data = np.dstack(sample)
labels = np.array(labels)
return data, labels
# X, y = load_data()
# print("Training examples shape: " + str(X.transpose().shape))
# print("Training labels shape: " + str(y.shape))
# print(np.isinf(X).any())
# print("Testing examples shape: " + str(test_X.shape))
# print("Testing labels shape: " + str(test_y.shape))