|
a |
|
b/Models/DatasetAPI/DataLoader.py |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
|
|
|
4 |
# Import useful packages |
|
|
5 |
import numpy as np |
|
|
6 |
import pandas as pd |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
def DatasetLoader(DIR): |
|
|
10 |
''' |
|
|
11 |
|
|
|
12 |
This is the Data Loader for our Library. |
|
|
13 |
The Dataset was supported via .csv file. |
|
|
14 |
In the CSV file, each line is a sample. |
|
|
15 |
For training or testing set, the columns are features of the EEG signals |
|
|
16 |
For training and testing labels, the columns are corresponding labels. |
|
|
17 |
In details, please refer to https://github.com/SuperBruceJia/EEG-Motor-Imagery-Classification-CNNs-TensorFlow |
|
|
18 |
to load the EEG Motor Movement Imagery Dataset, which is a benchmark for EEG Motor Imagery. |
|
|
19 |
|
|
|
20 |
Args: |
|
|
21 |
train_data: The training set for your Model |
|
|
22 |
train_labels: The corresponding training labels |
|
|
23 |
test_data: The testing set for your Model |
|
|
24 |
test_labels: The corresponding testing labels |
|
|
25 |
one_hot: One-hot representations for labels, if necessary |
|
|
26 |
|
|
|
27 |
Returns: |
|
|
28 |
train_data: [N_train X M] |
|
|
29 |
train_labels: [N_train X 1] |
|
|
30 |
test_data: [N_test X M] |
|
|
31 |
test_labels: [N_test X 1] |
|
|
32 |
(N: number of samples, M: number of features) |
|
|
33 |
|
|
|
34 |
''' |
|
|
35 |
|
|
|
36 |
# Read Training Data and Labels |
|
|
37 |
train_data = pd.read_csv(DIR + 'training_set.csv', header=None) |
|
|
38 |
train_data = np.array(train_data).astype('float32') |
|
|
39 |
|
|
|
40 |
train_labels = pd.read_csv(DIR + 'training_label.csv', header=None) |
|
|
41 |
train_labels = np.array(train_labels).astype('float32') |
|
|
42 |
# If you met the below error: |
|
|
43 |
# ValueError: Cannot feed value of shape (1024, 1) for Tensor 'input/label:0', which has shape '(1024,)' |
|
|
44 |
# Then you have to uncomment the below code: |
|
|
45 |
# train_labels = np.squeeze(train_labels) |
|
|
46 |
|
|
|
47 |
# Read Testing Data and Labels |
|
|
48 |
test_data = pd.read_csv(DIR + 'test_set.csv', header=None) |
|
|
49 |
test_data = np.array(test_data).astype('float32') |
|
|
50 |
|
|
|
51 |
test_labels = pd.read_csv(DIR + 'test_label.csv', header=None) |
|
|
52 |
test_labels = np.array(test_labels).astype('float32') |
|
|
53 |
# If you met the below error: |
|
|
54 |
# ValueError: Cannot feed value of shape (1024, 1) for Tensor 'input/label:0', which has shape '(1024,)' |
|
|
55 |
# Then you have to uncomment the below code: |
|
|
56 |
# test_labels = np.squeeze(test_labels) |
|
|
57 |
|
|
|
58 |
return train_data, train_labels, test_data, test_labels |