Skip to content

Commit 00b913e

Browse files
committed
adding unit test framework, cleaning reqs, readme, gitignore
1 parent 70aa0d5 commit 00b913e

File tree

6 files changed

+333
-252
lines changed

6 files changed

+333
-252
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.DS_Store
2+
eeg-notebooks/
3+
deepeeg/
24

35
# Byte-compiled / optimized / DLL files
46
__pycache__/

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,34 @@ MNE/Keras/Tensorflow library for classification of EEG data
66
* [Kory W. Mathewson](https://github.com/korymath)
77

88
![DeepEEG Image](DeepEEGImage2.png)
9-
10-
Keras/Tensorflow deep learning stacks that processes EEG trials or raw files from the MNE toolbox as input and predicts binary trial category as output (could scale to multiclass?). This is all made to run on Google Colab notebooks using cloud GPU capabilities, so the git repo's get loaded at the start of the code into the workspace. Minor mods may be needed to use local Jupyter notebook. Long term goal of command line interface and mne toolbox plugin.
9+
10+
DeepEEG is a Keras/Tensorflow deep learning library that processes EEG trials or raw files from the MNE toolbox as input and predicts binary trial category as output (could scale to multiclass?). This is all made to run on Google Colab notebooks using cloud GPU capabilities, so the git repo's get loaded at the start of the code into the workspace. Minor modifications may be needed to use local Jupyter notebook. Long term goal of command line interface and MNE toolbox plugin.
1111

1212
Colab Notebook Example:
1313
https://colab.research.google.com/github/kylemath/DeepEEG/blob/master/notebooks/DeepEEG.ipynb
1414

15-
Getting Started Locally:
15+
## Getting Started Locally:
1616

17+
DeepEEG is tested on macOS 10.14 with Python3.
18+
Prepare your environment the first time:
1719

18-
To prepare your environment the first time:
19-
```python
20+
```sh
21+
# using conda
2022
conda create -n deepeeg
2123
source activate deepeeg
24+
# using virtualenv
25+
# python3 -m venv deepeeg
26+
# source deepeeg/bin/activate
27+
```
28+
29+
```sh
2230
git clone https://github.com/kylemath/DeepEEG/
2331
cd DeepEEG
24-
chmod +x install.sh
25-
bash install.sh
32+
./install.sh
2633
git clone https://github.com/kylemath/eeg-notebooks
27-
python
2834
```
2935

36+
You are now ready to run DeepEEG.
3037

3138
This loads in some example data from eeg-notebooks
3239

@@ -64,16 +71,23 @@ model,_ = CreateModel(feats)
6471
TrainTestVal(model,feats)
6572
```
6673

74+
## Tests
75+
76+
You can run the unittests with the following command:
77+
```
78+
python -m unittest
79+
```
80+
6781
Strategy:
68-
* Load in Brain Products or Interaxon Muse files with mne as mne.raw,
82+
* Load in Brain Products or Interaxon Muse files with mne as mne.raw,
6983
* PreProcess(mne.raw) - normal ERP preprocessing to get trials by time by electrode mne.epochs
7084
* FeatureEngineer(mne.epochs) - Either time domain or frequency domain feature extraction in DeepEEG.Feats class
7185
* CreateModel(DeepEEG.Feats) - Customizes DeepEEG.Model for input data, pick from NN, CNN, LSTM, or AutoEncoders, splits data
7286
* TrainTestVal(DeepEEG.Feats,DeepEEG.Model) - Train the model, validate it during training, and test it once complete, Plot loss during learning and at test
73-
87+
7488
Dataset example:
7589
* Interaxon Muse - eeg-notebooks - https://github.com/kylemath/eeg-notebooks
76-
* Brain Recorder Data
90+
* Brain Recorder Data
7791

7892
API:
7993
* Input the data directory and subject numbers of any eeg-notebook experiment (https://github.com/kylemath/eeg-notebooks)
@@ -88,19 +102,19 @@ LearningModels:
88102
* Can also try using (AUTO) or (AUTODeep) to clean eeg data, or create features for other models
89103

90104
DataModels:
91-
* Try subject specific models
105+
* Try subject specific models
92106
* Then pool data over all subjects
93107
* Then try multilevel models (in the works)
94108

95-
Using:
109+
Using:
96110
* https://github.com/kylemath/eeg-notebooks
97111
* https://github.com/mne-tools/mne-python
98112
* https://github.com/keras-team/keras/blob/master/examples/imdb_cnn_lstm.py
99113
* https://github.com/ml4a/ml4a-guides/blob/master/notebooks/keras_classification.ipynb
100114
* https://github.com/tevisgehr/EEG-Classification
101115

102116
Resources:
103-
* https://arxiv.org/pdf/1901.05498.pdf
117+
* https://arxiv.org/pdf/1901.05498.pdf
104118
* http://proceedings.mlr.press/v56/Thodoroff16.pdf
105119
* https://arxiv.org/abs/1511.06448
106120
* https://github.com/ml4a

install.sh

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pip install --upgrade pip
12
pip install -r requirements.txt

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Keras-Applications==1.0.7
44
Keras-Preprocessing==1.0.9
55
mne==0.17.0
66
numpy==1.16.1
7-
PyYAML==4.2b1s
7+
PyYAML==4.2b1
88
scipy==1.2.0
99
six==1.12.0

tests.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import unittest
2+
from utils import Feats
3+
from utils import PreProcess
4+
from utils import CreateModel
5+
from utils import TrainTestVal
6+
from utils import LoadMuseData
7+
from utils import FeatureEngineer
8+
9+
10+
class ExampleTest(unittest.TestCase):
11+
"""
12+
Our basic test class
13+
"""
14+
15+
def test_addition(self):
16+
"""
17+
The actual test.
18+
Any method which starts with ``test_`` will considered as a test case.
19+
"""
20+
res = 2 + 2
21+
self.assertEqual(res, 4)
22+
23+
def test_feats(self):
24+
"""
25+
Testing utils import.
26+
"""
27+
feats = Feats()
28+
self.assertEqual(feats.num_classes, 2)
29+
30+
def test_example_muse(self):
31+
"""
32+
Testing example Muse code.
33+
"""
34+
35+
# Load Data
36+
raw = LoadMuseData(subs=[101, 102], nsesh=2, data_dir='visual/cueing')
37+
38+
# Pre-Process EEG Data
39+
epochs = PreProcess(raw=raw, event_id={'LeftCue': 1, 'RightCue': 2})
40+
41+
# Engineer Features for Model
42+
feats = FeatureEngineer(epochs=epochs)
43+
44+
# Create Model
45+
model, _ = CreateModel(feats=feats)
46+
47+
# Train with validation, then Test
48+
model, data = TrainTestVal(model=model,
49+
feats=feats,
50+
train_epochs=1,
51+
show_plots=False)
52+
53+
self.assertLess(data['acc'], 1)
54+
55+
if __name__ == '__main__':
56+
unittest.main()

0 commit comments

Comments
 (0)