-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataLoader.py
More file actions
48 lines (35 loc) · 1.12 KB
/
DataLoader.py
File metadata and controls
48 lines (35 loc) · 1.12 KB
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
from glob import glob
import numpy as np
import pickle
data = list()
outputs = list()
# Saves all top level dirs in data
dataFolders = glob('data/*')
# dict containing info on which folders are healthy, ictal
folderKeys = {}
folderKeys['Z'] = 'healthy'
folderKeys['O'] = 'healthy'
folderKeys['F'] = 'epileptic'
folderKeys['N'] = 'epileptic'
folderKeys['S'] = 'seizure'
# For each folder, for each text file in folder:
# append text file contents to data in numpy array, append output depending on if text file
# contains ictal activity or not
for folder in dataFolders:
health = folderKeys[folder[len(folder) - 1]]
print("Current folder: " + folder)
fileLoc = glob(folder + '\\*')
for file in fileLoc:
array = np.loadtxt(file)
data.append(array)
if health is 'healthy':
outputs.append(np.array((1, 0)))
else:
outputs.append(np.array((0, 1)))
# Store in dict for ease of serialization
seizureDict = dict()
seizureDict['inputs'] = data
seizureDict['outputs'] = outputs
# Dump data
pickle.dump(seizureDict, open('seizureDataSerialized.txt', 'wb'))
print("dumped")