MNE/Keras/Tensorflow library for classification of EEG data
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?).
Colab Notebook Example: https://colab.research.google.com/github/kylemath/DeepEEG/blob/master/notebooks/DeepEEG.ipynb
DeepEEG is tested on macOS 10.14 with Python3. Prepare your environment the first time:
# using conda
conda create -n deepeeg python=3
source activate deepeeg
# using virtualenv
# python3 -m venv deepeeg
# source deepeeg/bin/activate
git clone https://github.com/kylemath/DeepEEG/
cd DeepEEG
./install.sh
git clone https://github.com/kylemath/eeg-notebooks
You are now ready to run DeepEEG.
This loads in some example data from eeg-notebooks
from utils import *
data_dir = 'visual/cueing'
subs = [101,102]
nsesh = 2
event_id = {'LeftCue': 1,'RightCue': 2}
Load muse data, preprocess into trials,prepare for model, create model, and train and test model
#Load Data
raw = LoadMuseData(subs,nsesh,data_dir)
#Pre-Process EEG Data
epochs = PreProcess(raw,event_id)
#Engineer Features for Model
feats = FeatureEngineer(epochs)
#Create Model
model,_ = CreateModel(feats)
#Train with validation, then Test
TrainTestVal(model,feats)
You can run the unittests with the following command:
python -m unittest tests
- Load in Brain Products or Interaxon Muse files with mne as mne.raw,
- PreProcess(mne.raw) - normal ERP preprocessing to get trials by time by electrode mne.epochs
- FeatureEngineer(mne.epochs) - Either time domain or frequency domain feature extraction in DeepEEG.Feats class
- CreateModel(DeepEEG.Feats) - Customizes DeepEEG.Model for input data, pick from NN, CNN, LSTM, or AutoEncoders, splits data
- TrainTestVal(DeepEEG.Feats,DeepEEG.Model) - Train the model, validate it during training, and test it once complete, Plot loss during learning and at test
- Interaxon Muse - eeg-notebooks - https://github.com/kylemath/eeg-notebooks
- Brain Recorder Data
- Input the data directory and subject numbers of any eeg-notebook experiment (https://github.com/kylemath/eeg-notebooks)
- Load in .vhdr brain products files by filename with mne io features
- FeatureEngineer can load any mne Epoch object too - https://martinos.org/mne/stable/generated/mne.Epochs.html
- To be moved to another repo eventually
- Bandpass filter
- Regression Eye movement correction (if eye channels)
- EOG Regression example: https://cbrnr.github.io/2017/10/20/removing-eog-regression/
- Original emcp paper: https://apps.dtic.mil/dtic/tr/fulltext/u2/a125699.pdf
- Generalized emcp paper: http://www.kylemathewson.com/wp-content/uploads/2010/03/MillerGrattonYee-1988-GeneralizeOcularRemoval.pdf
- 1988 Fortran, Gehring C code: http://gehringlab.org/emcp2001.zip
- Matlab implementation: https://github.com/kylemath/MathewsonMatlabTools/blob/master/EEG_analysis/gratton_emcp.m
- Epoch segmentation (time limits, baseline correction)
- Artifact rejection
- First try basic Neural Network (NN)
- Then try Convolution Neural Net (CNN)
- New is a 3D convolutional NN (CNN3D) in the frequency domain
- Then try Long-Short Term Memory Recurrant Neural Net (LSTM)
- Can also try using (AUTO) or (AUTODeep) to clean eeg data, or create features for other models
- Try subject specific models
- Then pool data over all subjects
- Then try multilevel models (in the works)
- Goal build models that can be integrated with https://github.com/NeuroTechX/moabb/