-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathDataLoader.py
58 lines (46 loc) · 2.21 KB
/
DataLoader.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Import useful packages
import numpy as np
import pandas as pd
def DatasetLoader(DIR):
'''
This is the Data Loader for our Library.
The Dataset was supported via .csv file.
In the CSV file, each line is a sample.
For training or testing set, the columns are features of the EEG signals
For training and testing labels, the columns are corresponding labels.
In details, please refer to https://github.com/SuperBruceJia/EEG-Motor-Imagery-Classification-CNNs-TensorFlow
to load the EEG Motor Movement Imagery Dataset, which is a benchmark for EEG Motor Imagery.
Args:
train_data: The training set for your Model
train_labels: The corresponding training labels
test_data: The testing set for your Model
test_labels: The corresponding testing labels
one_hot: One-hot representations for labels, if necessary
Returns:
train_data: [N_train X M]
train_labels: [N_train X 1]
test_data: [N_test X M]
test_labels: [N_test X 1]
(N: number of samples, M: number of features)
'''
# Read Training Data and Labels
train_data = pd.read_csv(DIR + 'training_set.csv', header=None)
train_data = np.array(train_data).astype('float32')
train_labels = pd.read_csv(DIR + 'training_label.csv', header=None)
train_labels = np.array(train_labels).astype('float32')
# If you met the below error:
# ValueError: Cannot feed value of shape (1024, 1) for Tensor 'input/label:0', which has shape '(1024,)'
# Then you have to uncomment the below code:
# train_labels = np.squeeze(train_labels)
# Read Testing Data and Labels
test_data = pd.read_csv(DIR + 'test_set.csv', header=None)
test_data = np.array(test_data).astype('float32')
test_labels = pd.read_csv(DIR + 'test_label.csv', header=None)
test_labels = np.array(test_labels).astype('float32')
# If you met the below error:
# ValueError: Cannot feed value of shape (1024, 1) for Tensor 'input/label:0', which has shape '(1024,)'
# Then you have to uncomment the below code:
# test_labels = np.squeeze(test_labels)
return train_data, train_labels, test_data, test_labels