|
a |
|
b/preprocessing/seed_process_slice.py |
|
|
1 |
# used for SEED dataset |
|
|
2 |
# train with 9 trials and test with 6 trials |
|
|
3 |
|
|
|
4 |
import numpy as np |
|
|
5 |
import scipy.io |
|
|
6 |
|
|
|
7 |
root_path = '/Data/SEED/seed_syh/data/' |
|
|
8 |
save_path = '/Data/SEED/seed_syh/data_1second/' |
|
|
9 |
# i, j, k subject, session, trial |
|
|
10 |
for i in range(15): |
|
|
11 |
one_subject = [] |
|
|
12 |
one_subject_label = [] |
|
|
13 |
for j in range(3): |
|
|
14 |
|
|
|
15 |
one_session = [] |
|
|
16 |
one_session_label = [] |
|
|
17 |
# todo save training data |
|
|
18 |
for k in range(9): |
|
|
19 |
one_trial = [] |
|
|
20 |
trial_tmp = scipy.io.loadmat(root_path + 'S%d_%d_%d.mat' % (i+1, j+1, k+1)) |
|
|
21 |
trial_data = trial_tmp['trial_data'] |
|
|
22 |
trial_label = np.squeeze(trial_tmp['trial_label']) |
|
|
23 |
# change to using 2 seconds 200*2 |
|
|
24 |
trial_number = np.int32(trial_data.shape[1]/200) |
|
|
25 |
for tmp_num in range(trial_number): |
|
|
26 |
one_trial.append(trial_data[:,tmp_num*200:(tmp_num+1)*200]) |
|
|
27 |
one_trial_label = [trial_label]*trial_number |
|
|
28 |
one_session.append(one_trial) |
|
|
29 |
one_session_label.append(one_trial_label) |
|
|
30 |
|
|
|
31 |
one_session = np.concatenate(one_session) |
|
|
32 |
one_session_label = np.concatenate(one_session_label) |
|
|
33 |
|
|
|
34 |
data = np.transpose(one_session, [2, 1, 0]) |
|
|
35 |
label = one_session_label |
|
|
36 |
np.save(save_path + 'S%d_session%dT.npy'%(i+1, j+1), data) |
|
|
37 |
np.save(save_path + 'S%d_session%dT_label'%(i+1, j+1), label) |
|
|
38 |
|
|
|
39 |
one_session = [] |
|
|
40 |
one_session_label = [] |
|
|
41 |
# todo save test data |
|
|
42 |
for k in range(9, 15): |
|
|
43 |
one_trial = [] |
|
|
44 |
trial_tmp = scipy.io.loadmat(root_path + 'S%d_%d_%d.mat' % (i+1, j+1, k+1)) |
|
|
45 |
trial_data = trial_tmp['trial_data'] |
|
|
46 |
trial_label = np.squeeze(trial_tmp['trial_label']) |
|
|
47 |
trial_number = np.int32(trial_data.shape[1]/200) |
|
|
48 |
for tmp_num in range(trial_number): |
|
|
49 |
one_trial.append(trial_data[:,tmp_num*200:(tmp_num+1)*200]) |
|
|
50 |
one_trial_label = [trial_label]*trial_number |
|
|
51 |
one_session.append(one_trial) |
|
|
52 |
one_session_label.append(one_trial_label) |
|
|
53 |
|
|
|
54 |
one_session = np.concatenate(one_session) |
|
|
55 |
one_session_label = np.concatenate(one_session_label) |
|
|
56 |
|
|
|
57 |
data = np.transpose(one_session, [2, 1, 0]) |
|
|
58 |
label = one_session_label |
|
|
59 |
np.save(save_path + 'S%d_session%dE.npy'%(i+1, j+1), data) |
|
|
60 |
np.save(save_path + 'S%d_session%dE_label'%(i+1, j+1), label) |
|
|
61 |
|
|
|
62 |
print('Finished Subject%d Session%d' % (i+1, j+1)) |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|