This repo contains the implementation for my bachelor thesis "Deep Learning based Motor Imagery Brain Computer Interface" for the THU Ulm
You can further read about the project's topic in the published paper
- EEGNet Implementation in PyTorch
- Training, Testing, Benchmarking on PhysioNet Dataset , BCIC IV 2a , LSMR21
- Proposed Implementation for use on NVIDIA Jetson Nano
! Datasets ARE NOT INCLUDED in this repository !
- PHYS: Dataset is automatically loaded via the MNE Library
- BCIC: Has to be downloaded manually (see bcic_data_loading.py main method)
- LSMR21: Has to be downloaded via the scripts/lsmr21_download_convert.py script
Change the Location of the Datasets in paths.py
's datasets_folder
variable
Main Script to run Training/Benchmarking of EEGNet
main.py -train
- n-Class-Classification Training
- K-Fold Crossvalidation
- Saving results and trained model in ./results/{DateTime/Name}/training
- Dataset Selection with
--dataset
argument
main.py -benchmark
- Inference Benchmarking in batches with specified trained model (default size: 16)
- TensorRT optimization possible with
--trt
flag - Saving results (Batch Latency, Inference time per trial) in ./results/{model_path}/benchmark
main.py -train_ss
- Transfer Learning for further subject-specific Training of pretrained model
- Select pretrained model with
--model
argument - Subject to train on with
--subject
argument - Saving subject-specific trained model in ./results/{model_path}/training_ss/S{subject}
main.py -live_sim
- Simulation of a live EEG run classification of a single subject with subject-specific trained model
- Select subject-specific trained model with
--model
argument - Plotting the run in ./results/{model_path}/training_ss/S{subject}/live_sim
main.py --help
for all arguments
Global Default Configuration/Settings
- Training/Benchmarking Settings
- Bandpassfilters
- EEG Channel Configurations for sensorimotor Events
PyTorch Implementation of EEGNet
Original Source: xiaywang/q-eegnet_torch
Main loops for
- EEGNet Training + Testing on Physionet Dataset using 5-Fold CV
- Subject-specific Training with Transfer Learning
- Benchmarking of Inferencing over Physionet Dataset with pretrained model
- Live Simulation of real time Classification on Physionet Dataset Run
Main methods for
- Training
- Testing
- Benchmark
- Predicting on Batches of Data
- Data Loaders for the used Datasets
- Wrap Datasets in PyTorch Dataloader
- All important Properties of the Physionet Motorimagery Dataset
- List of available Subjects, Tasks, Runs
- Default Values for Epoching (tmin, tmax, ...)
- All important Properties of the BCIC Motorimagery Dataset
- List of available Subjects, Tasks, Runs
- Default Values for Epoching (tmin, tmax, ...)
- All important Properties of the LSMR21 Motorimagery Dataset
- List of available Subjects, Tasks, Runs
- Default Values for Epoching (tmin, tmax, ...)
- TrialsDataset class for usage with PyTorch Dataloader
- Utility methods ofr preprocessing data
Have to be executed as python modules with:
python3 -m scripts.<script_name>
- Showcases usage of all available modes in a single script
- Gives overview on how to use main.py with its arguments in a Terminal
- Can be used for Batchruns of Training Runs
- Training Configurations editable in Python Dictionary
- Creates .csv and .txt files containing Results of Training Batchruns
- Can be used to analyze influence of different Frequency bands
- Test neural responses in different time slices
- Can be used to Test trained model of neural_responses_training.py
- Tests different Fx-filtered Test Data of trained Model
- Runs main.py with all possible Configurations in benchmark mode (/w TRT (fp16/32))
- Saves results in parent folder ./results/{model_path}/benchmark/
- Benchmarking with different Batch Sizes with
--bs
argument
- Plots and saves Results from bench_all_confs.py Runs as .png
--model
specifies the folder location of the results.npz file
- All relevant paths, results folder locations, file names, ...
- Plot Results with Matplotlib
- Handles storing results/config .txt files
Python Playground for testing, has no further use
Use python3 -m pip install -r requirements.txt
to ensure all necessary libraries are installed
For usage of -benchmark
also ensure TensorRT is correctly setup on the system